1
1

DialogueBranch.ts 836 B

123456789101112131415161718192021222324252627
  1. /// <reference path="DialogueNode.ts" />
  2. class DialogueBranch extends DialogueNode {
  3. public type = NodeType.Branch;
  4. public variable : () => any = () => {return true;}
  5. public branchIds : Array<string> = [];
  6. public branchConditions : Array<() => any> = [];
  7. public setVariable (varFunc : () => any) {
  8. this.variable = varFunc;
  9. }
  10. public addBranch (targetid : string, valueFunc : () => any) {
  11. this.branchIds.push(targetid);
  12. this.branchConditions.push(valueFunc);
  13. }
  14. public getNext () {
  15. let variable = this.variable();
  16. for (let i = 0; i < this.branchIds.length; i++) {
  17. let comparing = this.branchConditions[i]();
  18. if (comparing == variable) {
  19. return this.branchIds[i];
  20. }
  21. }
  22. return this.next;
  23. }
  24. }