|
1 | 1 | (() => { |
2 | 2 | const isQuickCompareTauri = !!window.__TAURI__; |
3 | 3 |
|
| 4 | + function fileLabel(entry) { |
| 5 | + return entry.label || entry.path.split("/").pop(); |
| 6 | + } |
| 7 | + |
4 | 8 | function getGroupFileName(groupName) { |
5 | | - const state = trame.state.state; |
6 | 9 | const nameTokens = [groupName]; |
7 | 10 |
|
8 | | - state.available_animation_tracks.forEach((name) => { |
| 11 | + trame.state.state.available_animation_tracks.forEach((name) => { |
9 | 12 | nameTokens.push(name); |
10 | | - const nDigit = Math.floor(Math.log10(state[name].length) + 1); |
11 | | - const idx = state[`${name}_idx`]; |
| 13 | + const nDigit = Math.floor(Math.log10(trame.state.state[name].length) + 1); |
| 14 | + const idx = trame.state.state[`${name}_idx`]; |
12 | 15 | nameTokens.push(String(idx).padStart(nDigit, "0")); |
13 | 16 | }); |
14 | 17 |
|
|
55 | 58 | downloadURL(dataURL, fileName); |
56 | 59 | } |
57 | 60 |
|
| 61 | + |
| 62 | + function setSimulationLabel(path, label) { |
| 63 | + trame.state.set( |
| 64 | + "simulation_configs", |
| 65 | + trame.state.state.simulation_configs.map((sim) => |
| 66 | + sim.path === path ? { ...sim, label } : sim, |
| 67 | + ), |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + function setSimulationInclude(path, include) { |
| 72 | + trame.state.set( |
| 73 | + "simulation_configs", |
| 74 | + trame.state.state.simulation_configs.map((sim) => |
| 75 | + sim.path === path ? { ...sim, include: !!include } : sim, |
| 76 | + ), |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + function loadedSimulationsText(simulationConfigs, controlPath) { |
| 81 | + if (!simulationConfigs?.length) { |
| 82 | + return "Loaded simulations:\nnone"; |
| 83 | + } |
| 84 | + |
| 85 | + const lines = simulationConfigs.map((sim) => { |
| 86 | + const suffix = sim.path === controlPath ? " (ctrl)" : ""; |
| 87 | + return `${fileLabel(sim)}${suffix}`; |
| 88 | + }); |
| 89 | + |
| 90 | + return `Loaded simulations:\n${lines.join("\n")}`; |
| 91 | + } |
| 92 | + |
58 | 93 | window.trame = window.trame || {}; |
59 | 94 | window.trame.utils = window.trame.utils || {}; |
60 | | - window.trame.utils.quickcompare = { |
61 | | - async captureGroup(groupName) { |
62 | | - await captureTarget(findGroupToCapture(groupName), getGroupFileName(groupName)); |
| 95 | + const quickcompare = window.trame.utils.quickcompare || {}; |
| 96 | + |
| 97 | + Object.assign(quickcompare, { |
| 98 | + captureGroup(groupName) { |
| 99 | + return captureTarget(findGroupToCapture(groupName), getGroupFileName(groupName)); |
63 | 100 | }, |
64 | | - }; |
| 101 | + setSimulationLabel, |
| 102 | + setSimulationInclude, |
| 103 | + loadedSimulationsText, |
| 104 | + }); |
| 105 | + window.trame.utils.quickcompare = quickcompare; |
65 | 106 | })(); |
0 commit comments