Home Reference Source

cables_dev/cables_ui/src/ui/commands/commands.js

  1. import debugCommands from "./cmd_debug.js";
  2. import opCommands from "./cmd_op.js";
  3. import patchCommands from "./cmd_patch.js";
  4. import rendererCommands from "./cmd_renderer.js";
  5. import timelineCommands from "./cmd_timeline.js";
  6. import uiCommands from "./cmd_ui.js";
  7.  
  8. const CMD = {};
  9. let commands = [];
  10.  
  11. commands = commands.concat(debugCommands.commands);
  12. commands = commands.concat(patchCommands.commands);
  13. commands = commands.concat(rendererCommands.commands);
  14. commands = commands.concat(timelineCommands.commands);
  15. commands = commands.concat(uiCommands.commands);
  16. commands = commands.concat(opCommands.commands);
  17.  
  18. CMD.DEBUG = debugCommands.functions;
  19. CMD.PATCH = patchCommands.functions;
  20. CMD.OP = opCommands.functions;
  21. CMD.RENDERER = rendererCommands.functions;
  22. CMD.TIMELINE = timelineCommands.functions;
  23. CMD.UI = uiCommands.functions;
  24.  
  25. CMD.commands = commands;
  26.  
  27. for (let i = 0; i < commands.length; i++)
  28. {
  29. if (!commands[i].category)console.log("cmd has no category ", commands[i].cmd);
  30. }
  31.  
  32. export default CMD;
  33.  
  34. CMD.exec = function (cmd)
  35. {
  36. let found = false;
  37. for (let i = 0; i < CMD.commands.length; i++)
  38. {
  39. if (CMD.commands[i].cmd == cmd)
  40. {
  41. if (CMD.commands[i].func)
  42. {
  43. CMD.commands[i].func();
  44. found = true;
  45. }
  46. else
  47. {
  48. console.warn("cmd has no func", cmd, CMD.commands[i]);
  49. }
  50. }
  51. }
  52.  
  53.  
  54. if (!found)console.warn("command not found:" + cmd);
  55. };
  56.