Skip to content

Commit

Permalink
fix variable get/set and initial values for variables
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Nov 22, 2024
1 parent 94d9c2e commit 14ed0c6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/BasicBehaveEngine/BasicBehaveEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ export class BasicBehaveEngine implements IBehaveEngine {
events: this.events,
};

this.variables.forEach(variable => {
if (variable.value === undefined) {
// TODO get the default value from the type
variable.value = 0;
}
// sanitize, these need to be arrays
if (!Array.isArray(variable.value)) {
variable.value = [variable.value];
}
});

let index = 0;
this.nodes.forEach(node => {
const behaviourNodeProps: IBehaviourNodeProps = {
Expand Down
7 changes: 6 additions & 1 deletion src/BasicBehaveEngine/nodes/variable/VariableGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export class VariableGet extends BehaveEngineNode {
this.graphEngine.processNodeStarted(this);

const result: Record<string, IValue> = {};
result["value"] = this.variables[this._variable];
const res = this.variables[this._variable];
// TODO It's unclear when the value needs to be a glTF value (always an array)
// or when it needs to be the actual value. Since the result of this node is always parsed
// with parseType, it currently needs to be an array.
if (!Array.isArray(res.value)) res.value = [res.value];
result["value"] = res;
return result;
}
}
2 changes: 1 addition & 1 deletion src/BasicBehaveEngine/nodes/variable/VariableSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class VariableSet extends BehaveEngineNode {
const vals = this.evaluateAllValues(["value"]);
this.graphEngine.processNodeStarted(this);

this.variables[this._variable].value = vals[variable.id];
this.variables[this._variable].value = vals["value"];

super.processNode(flowSocket);
}
Expand Down

0 comments on commit 14ed0c6

Please sign in to comment.