Home Reference Source

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

  1. import GlDebugTab from "../components/tabs/tab_debugglui.js";
  2. import MetaHistory from "../components/tabs/tab_history.js";
  3. import LogTab from "../components/tabs/tab_log.js";
  4. import LoggingTab from "../components/tabs/tab_logfilter.js";
  5. import OpDocsJson from "../components/tabs/tab_opdocsjson.js";
  6. import OpSerialized from "../components/tabs/tab_opserialized.js";
  7. import OpWatchUiAttribs from "../components/tabs/tab_uiattribs.js";
  8. import Gui from "../gui.js";
  9. import CMD from "./commands.js";
  10.  
  11. const CABLES_CMD_DEBUG = {};
  12. const CMD_DEBUG_COMMANDS = [];
  13.  
  14. const debugCommands =
  15. {
  16. "commands": CMD_DEBUG_COMMANDS,
  17. "functions": CABLES_CMD_DEBUG
  18. };
  19.  
  20. export default debugCommands;
  21.  
  22. CABLES_CMD_DEBUG.testCommands = function ()
  23. {
  24. for (let i = 0; i < CMD.commands.length; i++)
  25. {
  26. if (CMD.commands[i].cmd.indexOf("Test all") == -1 &&
  27. CMD.commands[i].cmd != "Upload file" &&
  28. CMD.commands[i].cmd != "Reload patch" &&
  29. CMD.commands[i].cmd != "Open patch website" &&
  30. CMD.commands[i].cmd != "Toggle window fullscreen")
  31. {
  32. console.log("CMD: " + CMD.commands[i].cmd);
  33. if (!CMD.commands[i].func)console.error("cmd has no function");
  34. else CMD.commands[i].func();
  35. }
  36. }
  37. };
  38.  
  39. CABLES_CMD_DEBUG.testBlueprint2 = function ()
  40. {
  41. const p = gui.corePatch();
  42.  
  43. const sub = gui.patchView.getCurrentSubPatch();
  44.  
  45. let ops = p.getSubPatchOps(sub, true);
  46. console.log(ops);
  47. const serOps = [];
  48.  
  49. for (let i = 0; i < ops.length; i++)
  50. {
  51. serOps.push(ops[i].getSerialized());
  52. }
  53.  
  54. console.log(JSON.stringify(serOps));
  55. };
  56.  
  57. CABLES_CMD_DEBUG.globalVarDump = function ()
  58. {
  59. CABLESUILOADER.GlobalVarTester.after(window);
  60. };
  61.  
  62. CABLES_CMD_DEBUG.glguiTab = function ()
  63. {
  64. const t = new CABLES.GLGUI.GlGuiTab(gui.mainTabs);
  65. };
  66.  
  67. CABLES_CMD_DEBUG.toggleMultiplayer = function ()
  68. {
  69. CABLESUILOADER.talkerAPI.send(
  70. "toggleMultiplayerSession",
  71. { "projectId": this._patchId },
  72. (err, res) =>
  73. {
  74. // window reloaded from outside
  75. },
  76. );
  77. /*
  78. if (!gui.getSavedState())
  79. {
  80. console.log("SHOW MODAL");
  81. }
  82. else
  83. {
  84. CABLESUILOADER.talkerAPI.send(
  85. "toggleMultiplayerSession",
  86. { "projectId": this._patchId },
  87. (err, res) =>
  88. {
  89. // window reloaded from outside
  90. },
  91. );
  92. }
  93. */
  94. };
  95.  
  96.  
  97. CABLES_CMD_DEBUG.glguiFull = function ()
  98. {
  99. new CABLES.GLGUI.GlGuiFull();
  100. };
  101.  
  102. CABLES_CMD_DEBUG.debugGlUi = function ()
  103. {
  104. new GlDebugTab(gui.mainTabs);
  105. gui.maintabPanel.show(true);
  106. };
  107.  
  108. CABLES_CMD_DEBUG.logConsole = function ()
  109. {
  110. gui.showBottomTabs();
  111. };
  112.  
  113. CABLES_CMD_DEBUG.logging = function ()
  114. {
  115. new LoggingTab(gui.mainTabs);
  116. gui.maintabPanel.show(true);
  117. };
  118.  
  119. CABLES_CMD_DEBUG.logSocketCluster = function ()
  120. {
  121. if (gui.socket) gui.socket.enableVerboseLogging();
  122. };
  123.  
  124. CABLES_CMD_DEBUG.restrictRemoteView = () =>
  125. {
  126. gui.setRestriction(Gui.RESTRICT_MODE_REMOTEVIEW);
  127. };
  128. CABLES_CMD_DEBUG.restrictFollow = () =>
  129. {
  130. gui.setRestriction(Gui.RESTRICT_MODE_FOLLOWER);
  131. };
  132. CABLES_CMD_DEBUG.restrictExplorer = () =>
  133. {
  134. gui.setRestriction(Gui.RESTRICT_MODE_EXPLORER);
  135. };
  136. CABLES_CMD_DEBUG.restrictFull = () =>
  137. {
  138. gui.setRestriction(Gui.RESTRICT_MODE_FULL);
  139. };
  140.  
  141. CABLES_CMD_DEBUG.testAllOps = function ()
  142. {
  143. const ops = gui.opDocs.getAll();
  144.  
  145. console.log(ops);
  146.  
  147. for (const i in ops)
  148. {
  149. console.log(ops[i].name);
  150. const opname = ops[i].name;
  151.  
  152. load(opname);
  153. }
  154. };
  155.  
  156. CABLES_CMD_DEBUG.focusOpAnim = function ()
  157. {
  158. const ops = gui.patchView.getSelectedOps();
  159. if (ops.length > 0) gui.patchView.patchRenderer.focusOpAnim(ops[0].id);
  160. };
  161.  
  162. CABLES_CMD_DEBUG.testOp = function ()
  163. {
  164. const ops = gui.patchView.getSelectedOps();
  165.  
  166. for (let i = 0; i < ops.length; i++)
  167. {
  168. for (let j = 0; j < 100; j++)
  169. {
  170. for (let ip = 0; ip < ops[i].portsIn.length; ip++)
  171. {
  172. const p = ops[i].portsIn[ip];
  173.  
  174. if (p.type == CABLES.OP_PORT_TYPE_ARRAY)
  175. {
  176. const tests = [
  177. () => { p.set([]); },
  178. () => { p.set(null); },
  179. () => { p.set(undefined); },
  180. () => { p.set([0]); },
  181. () => { p.set([0, 1]); },
  182. () => { p.set([0, 1, 2]); },
  183. () => { p.set([-0, -1, -2]); },
  184. () => { p.set([0, 1, 2, 3]); },
  185. () => { p.set([0, 1, 2, 3, 4]); },
  186. () => { p.set([0, 1, null, 3, 4]); },
  187. () => { p.set([0, "hallo", 2, 3, 4]); },
  188. ];
  189. tests[Math.floor(tests.length * Math.random())]();
  190. }
  191. if (p.type == CABLES.OP_PORT_TYPE_VALUE)
  192. {
  193. const tests = [
  194. () => { p.set(0); },
  195. () => { p.set(1); },
  196. () => { p.set(1.2); },
  197. () => { p.set(100); },
  198. () => { p.set(-100); },
  199. ];
  200. tests[Math.floor(tests.length * Math.random())]();
  201. }
  202. if (p.type == CABLES.OP_PORT_TYPE_STRING)
  203. {
  204. const tests = [
  205. () => { p.set("hello"); },
  206. () => { p.set(""); },
  207. () => { p.set(null); },
  208. () => { p.set(undefined); }
  209. ];
  210. tests[Math.floor(tests.length * Math.random())]();
  211. }
  212. if (p.type == CABLES.OP_PORT_TYPE_OBJECT)
  213. {
  214. const tests = [
  215. () => { p.set(null); },
  216. () => { p.set(undefined); },
  217. () => { p.set({ "a": () => { console.log(1); } }); },
  218. () => { p.set({ "a": 1234 }); },
  219. () => { p.set({ "b": null }); }
  220. ];
  221. tests[Math.floor(tests.length * Math.random())]();
  222. }
  223. if (p.type == CABLES.OP_PORT_TYPE_FUNCTION)
  224. {
  225. const tests = [
  226. () => { p.trigger(); },
  227. () => { },
  228. ];
  229. tests[Math.floor(tests.length * Math.random())]();
  230. }
  231. }
  232. }
  233. }
  234.  
  235. console.log("op test finished!");
  236. };
  237.  
  238. function load(opname)
  239. {
  240. gui.serverOps.loadOpDependencies(opname, function ()
  241. {
  242. gui.corePatch().addOp(opname);
  243. });
  244. }
  245.  
  246. CABLES_CMD_DEBUG.watchOpSerialized = function ()
  247. {
  248. new OpSerialized(gui.mainTabs);
  249. gui.maintabPanel.show(true);
  250. };
  251.  
  252. CABLES_CMD_DEBUG.watchOpDocsJson = function ()
  253. {
  254. new OpDocsJson(gui.mainTabs);
  255. gui.maintabPanel.show(true);
  256. };
  257.  
  258.  
  259. CABLES_CMD_DEBUG.watchOpUiAttribs = function ()
  260. {
  261. new OpWatchUiAttribs(gui.mainTabs);
  262. gui.maintabPanel.show(true);
  263. };
  264.  
  265. CABLES_CMD_DEBUG.saveWithOutObjnames = () =>
  266. {
  267. gui.corePatch().storeObjNames = false;
  268. CABLES.CMD.PATCH.save();
  269. };
  270.  
  271. CABLES_CMD_DEBUG.undoHistory = () =>
  272. {
  273. new MetaHistory(gui.mainTabs); gui.maintabPanel.show(true);
  274. };
  275.  
  276.  
  277. CMD_DEBUG_COMMANDS.push(
  278. {
  279. "cmd": "Glui debug",
  280. "category": "debug",
  281. "func": CABLES_CMD_DEBUG.debugGlUi,
  282. "icon": "command"
  283. },
  284. {
  285. "cmd": "Test all ops",
  286. "category": "debug",
  287. "func": CABLES_CMD_DEBUG.testAllOps,
  288. "icon": "command"
  289. },
  290. {
  291. "cmd": "Dump global vars",
  292. "category": "debug",
  293. "func": CABLES_CMD_DEBUG.globalVarDump,
  294. "icon": "command"
  295. },
  296. {
  297. "cmd": "Logging",
  298. "category": "debug",
  299. "func": CABLES_CMD_DEBUG.logging,
  300. "icon": "command"
  301. },
  302. {
  303. "cmd": "Log console",
  304. "category": "debug",
  305. "func": CABLES_CMD_DEBUG.logConsole,
  306. "icon": "list"
  307. },
  308. {
  309. "cmd": "Log socketcluster traffic",
  310. "category": "debug",
  311. "func": CABLES_CMD_DEBUG.logSocketCluster,
  312. "icon": "command"
  313. },
  314. {
  315. "cmd": "Glgui tab",
  316. "category": "debug",
  317. "func": CABLES_CMD_DEBUG.glguiTab,
  318. "icon": "command"
  319. },
  320. {
  321. "cmd": "Toggle multiplayer",
  322. "category": "debug",
  323. "func": CABLES_CMD_DEBUG.toggleMultiplayer,
  324. "icon": "command"
  325. },
  326. {
  327. "cmd": "Restriction remoteviewer",
  328. "category": "debug",
  329. "func": CABLES_CMD_DEBUG.restrictRemoteView,
  330. "icon": "command"
  331. },
  332. {
  333. "cmd": "Restriction follow",
  334. "category": "debug",
  335. "func": CABLES_CMD_DEBUG.restrictFollow,
  336. "icon": "command"
  337. },
  338. {
  339. "cmd": "Restriction explorer",
  340. "category": "debug",
  341. "func": CABLES_CMD_DEBUG.restrictExplorer,
  342. "icon": "command"
  343. },
  344. {
  345. "cmd": "Restriction full",
  346. "category": "debug",
  347. "func": CABLES_CMD_DEBUG.restrictFull,
  348. "icon": "command"
  349. },
  350. {
  351. "cmd": "Test op",
  352. "category": "debug",
  353. "func": CABLES_CMD_DEBUG.testOp,
  354. "icon": "op"
  355. },
  356. {
  357. "cmd": "Show op docs json",
  358. "func": CABLES_CMD_DEBUG.watchOpDocsJson,
  359. "category": "debug",
  360. "icon": "op"
  361. },
  362. {
  363. "cmd": "Show op serialized",
  364. "func": CABLES_CMD_DEBUG.watchOpSerialized,
  365. "category": "debug",
  366. "icon": "op"
  367. },
  368. {
  369. "cmd": "Show op uiattribs",
  370. "func": CABLES_CMD_DEBUG.watchOpUiAttribs,
  371. "category": "debug",
  372. "icon": "op"
  373. },
  374. {
  375. "cmd": "Save without objnames",
  376. "func": CABLES_CMD_DEBUG.saveWithOutObjnames,
  377. "category": "debug",
  378. "icon": "op"
  379. },
  380. {
  381. "cmd": "Glui focusOpAnim",
  382. "func": CABLES_CMD_DEBUG.focusOpAnim,
  383. "category": "debug",
  384. },
  385. {
  386. "cmd": "Undo history",
  387. "func": CABLES_CMD_DEBUG.undoHistory,
  388. "category": "debug",
  389. },
  390. {
  391. "cmd": "Test all commands",
  392. "func": CABLES_CMD_DEBUG.testCommands,
  393. "category": "debug",
  394. },
  395.  
  396.  
  397. );