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