eventPPStateScript.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. const id = "PM_EVENT_PLATPLUS_STATE_SCRIPT";
  2. const groups = ["Platformer+"];
  3. const name = "Attach a Script to A Platformer+ State";
  4. const fields = [
  5. {
  6. key: "state",
  7. label: "Select Player State",
  8. type: "select",
  9. defaultValue: "0",
  10. options: [
  11. ["0", "Start Falling"],
  12. ["1", "Falling"],
  13. ["2", "End Falling"],
  14. ["3", "Start Grounded"],
  15. ["4", "Grounded"],
  16. ["5", "End Grounded"],
  17. ["6", "Start Jumping"],
  18. ["7", "Jumping"],
  19. ["8", "End Jumping"],
  20. ["9", "Start Dashing"],
  21. ["10", "Dashing"],
  22. ["11", "End Dashing"],
  23. ["12", "Start Climbing Ladder"],
  24. ["13", "Climbing Ladder"],
  25. ["14", "End Climbing Ladder"],
  26. ["15", "Start Wall Slide"],
  27. ["16", "Wall Sliding"],
  28. ["17", "End Wall Slide"],
  29. ["18", "Knockback State Start"],
  30. ["19", "Knockback State"],
  31. ["21", "Blank State Start"],
  32. ["22", "Blank State"]
  33. ],
  34. },
  35. {
  36. key: "__scriptTabs",
  37. type: "tabs",
  38. defaultValue: "scriptinput",
  39. values: {
  40. scriptinput: "On State",
  41. },
  42. },
  43. {
  44. key: "script",
  45. label: "State Script",
  46. description: "State Script",
  47. type: "events",
  48. allowedContexts: ["global", "entity"],
  49. conditions: [
  50. {
  51. key: "__scriptTabs",
  52. in: [undefined, "scriptinput"],
  53. },
  54. ],
  55. },
  56. ];
  57. const compile = (input, helpers) => {
  58. const {appendRaw, _compileSubScript, _addComment, vm_call_native, event } = helpers;
  59. const ScriptRef = _compileSubScript("state", input.script, "test_symbol"+input.state);
  60. const stateNumber = `${input.state}`;
  61. const bank = `___bank_${ScriptRef}`;
  62. const ptr = `_${ScriptRef}`
  63. _addComment("Set Platformer Script");
  64. appendRaw(`VM_PUSH_CONST ${stateNumber}`);
  65. appendRaw(`VM_PUSH_CONST ${bank}`);
  66. appendRaw(`VM_PUSH_CONST ${ptr}`);
  67. appendRaw(`VM_CALL_NATIVE b_assign_state_script, _assign_state_script`);
  68. appendRaw(`VM_POP 3`);
  69. };
  70. module.exports = {
  71. id,
  72. name,
  73. groups,
  74. fields,
  75. compile,
  76. allowedBeforeInitFade: true,
  77. };