Home Reference Source

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

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