2
0

action.js 955 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. class Action{
  2. label = 'Label missing';
  3. styleClass = 'action';
  4. passage = '';
  5. priority = 0;
  6. contents = '';
  7. captured = {};
  8. constructor(settings={}){
  9. Object.keys(settings).forEach(function (pn) {
  10. this[pn] = clone(settings[pn]);
  11. }, this);
  12. }
  13. execute(){
  14. for (const [capturedKey, capturedValue] of Object.entries(this.captured)) {
  15. State.setVar(capturedKey,capturedValue);
  16. }
  17. $.wiki(this.contents);
  18. }
  19. //#region System
  20. _init(action){
  21. Object.keys(action).forEach(function (pn) {
  22. this[pn] = clone(action[pn]);
  23. }, this);
  24. return this;
  25. }
  26. clone = function () {
  27. return (new setup.Action())._init(this);
  28. };
  29. toJSON = function () {
  30. var ownData = {};
  31. Object.keys(this).forEach(function (pn) {
  32. if(typeof this[pn] !== "function")
  33. ownData[pn] = clone(this[pn]);
  34. }, this);
  35. return JSON.reviveWrapper('(new setup.Action())._init($ReviveData$)', ownData);
  36. };
  37. //#endregion
  38. }
  39. setup.Action ??= Action;