Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(expressions): allows expressions on module and group controls #721

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/application/utils/apply-expression.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import store from "../worker/store";

export function applyExpression({ value, inputId }) {
const expressionAssignment = store.getters["expressions/getByInputId"](
inputId
);

let dataOut = value;

if (expressionAssignment) {
const scope = {
value: dataOut,
time: Date.now()
};

dataOut = expressionAssignment.func.evaluate(scope);
}

return dataOut;
}
11 changes: 11 additions & 0 deletions src/application/worker/store/modules/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SWAP from "./common/swap";
import store from "../";
import constants from "../../../constants";
import uuidv4 from "uuid/v4";
import { applyExpression } from "../../../utils/apply-expression";

/**
* @typedef {Object} Group
Expand Down Expand Up @@ -248,6 +249,16 @@ const actions = {
}

return;
},

updateGroupInput({ commit }, { groupId, key, data, writeToSwap }) {
let dataOut = data;

const group = state.groups.find(group => group.id === groupId);
const inputId = group[`${key}InputId`];
dataOut = applyExpression({ inputId, value: dataOut });

commit("UPDATE_GROUP_BY_KEY", { groupId, key, data: dataOut, writeToSwap });
}
};

Expand Down
53 changes: 34 additions & 19 deletions src/application/worker/store/modules/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import get from "lodash.get";
import set from "lodash.set";

import uuidv4 from "uuid/v4";
import { applyExpression } from "../../../utils/apply-expression";

// Any keys marked false or arrays with keys given
// will not be moved from the base state when swapped
Expand Down Expand Up @@ -254,25 +255,25 @@ const actions = {

if (!moduleMeta.isGallery) {
const alphaInputBind = await store.dispatch("inputs/addInput", {
type: "commit",
location: "modules/UPDATE_ACTIVE_MODULE_META",
type: "action",
location: "modules/updateMeta",
data: { id: module.$id, metaKey: "alpha" }
});

module.meta.alphaInputId = alphaInputBind.id;

const enabledInputBind = await store.dispatch("inputs/addInput", {
type: "commit",
location: "modules/UPDATE_ACTIVE_MODULE_META",
type: "action",
location: "modules/updateMeta",
data: { id: module.$id, metaKey: "enabled" }
});

module.meta.enabledInputId = enabledInputBind.id;

const coInputBind = await store.dispatch("inputs/addInput", {
type: "commit",
location: "modules/UPDATE_ACTIVE_MODULE_META",
data: { id: module.$id, metaKey: "compositeOperation" }
type: "action",
location: "modules/updateMeta",
data: { moduleId: module.$id, metaKey: "compositeOperation" }
});

module.meta.compositeOperationInputId = coInputBind.id;
Expand Down Expand Up @@ -395,18 +396,7 @@ const actions = {

let dataOut = data;

const expressionAssignment = store.getters["expressions/getByInputId"](
inputId
);

if (expressionAssignment) {
const scope = {
value: dataOut,
time: Date.now()
};

dataOut = expressionAssignment.func.evaluate(scope);
}
dataOut = applyExpression({ inputId, value: dataOut });

if (store.state.dataTypes[type] && store.state.dataTypes[type].create) {
dataOut = await store.state.dataTypes[type].create(dataOut);
Expand Down Expand Up @@ -461,6 +451,31 @@ const actions = {
}
},

async updateMeta({ commit }, { id: moduleId, metaKey, data, writeToSwap }) {
if (!state.active[moduleId]) {
console.error(`The module with the moduleId ${moduleId} doesn't exist.`);
return;
}

const currentValue = state.active[moduleId].meta[metaKey];
const inputId = state.active[moduleId].meta[`${metaKey}InputId`];

if (data === currentValue) {
return;
}

let dataOut = data;

dataOut = applyExpression({ inputId, value: dataOut });

commit("UPDATE_ACTIVE_MODULE_META", {
id: moduleId,
metaKey,
data: dataOut,
writeToSwap
});
},

resize({ commit, state }, { moduleId, width, height }) {
const module = state.active[moduleId];
const moduleName = module.$moduleName;
Expand Down
2 changes: 1 addition & 1 deletion src/components/InputLinkComponents/Expression.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default {
return {
iVTitle: "Expression",
iVBody:
"Expressions allow assigned input values to be shaped with JavaScript synax and math. Multiplication, division, custom intensity curves - whatever goes. `value` is the incoming number, want to make everything 3 times as punchy? `value * 3`. Need to soften things a little? `value / 2`. More examples can be found on modV's website under Guides, Expression.",
"Expressions allow assigned input values to be shaped with JavaScript syntax and math. Multiplication, division, custom intensity curves - whatever goes. `value` is the incoming number, want to make everything 3 times as punchy? `value * 3`. Need to soften things a little? `value / 2`. More examples can be found on modV's website under Guides, Expression.",
iVID: "Expression",

expression: "value",
Expand Down