-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui-debug.js
More file actions
214 lines (197 loc) · 9.74 KB
/
Copy pathui-debug.js
File metadata and controls
214 lines (197 loc) · 9.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
// ============================================================================
// UI-DEBUG.JS : GAME ENGINE CONFIGURATION & SANDBOX CONTROLS
// ============================================================================
/**
* Render the dynamic debug menu with configuration sliders.
*/
window.renderDebugMenu = function() {
const ui = GameUI();
const engine = GameEngine();
const container = document.getElementById('debugControls');
if (!container) return;
container.innerHTML = '';
// Seed replay controls are deliberately transient: they restart only the
// current round and never rewrite the persisted campaign checkpoint.
const seedHeader = document.createElement('h3');
seedHeader.innerText = 'Seed Replay';
seedHeader.style.margin = '10px 0';
seedHeader.style.borderBottom = '1px solid #ccc';
container.appendChild(seedHeader);
const seedRow = document.createElement('div');
seedRow.className = 'debug-row';
const seedLabel = document.createElement('span');
seedLabel.innerText = 'Round seed';
const seedControls = document.createElement('div');
seedControls.className = 'debug-seed-controls';
const seedInput = document.createElement('input');
seedInput.type = 'number';
seedInput.min = '1';
seedInput.max = '2147483646';
seedInput.step = '1';
seedInput.value = Registry.debugSeedOverrideRound === Registry.stats.round
? Registry.debugSeedOverride
: Registry.seed;
seedInput.title = 'Temporary seed for the current round';
const randomSeedButton = document.createElement('button');
randomSeedButton.className = 'btn btn-gray btn-small';
randomSeedButton.innerText = 'Randomise';
randomSeedButton.onclick = () => { seedInput.value = window.Game.Campaign?.generateSeed?.() || Math.floor(Math.random() * 2147483646) + 1; };
const copySeedButton = document.createElement('button');
copySeedButton.className = 'btn btn-blue btn-small';
copySeedButton.innerText = 'Copy';
copySeedButton.onclick = async () => {
const value = Number(seedInput.value);
if (!Number.isInteger(value)) return;
await navigator.clipboard?.writeText?.(String(value));
ui.showToast?.(`Seed ${value} copied.`);
};
const applySeedButton = document.createElement('button');
applySeedButton.className = 'btn btn-purple btn-small';
applySeedButton.innerText = 'Apply & Restart Round';
applySeedButton.onclick = () => {
const value = Number(seedInput.value);
if (!Number.isInteger(value) || value < 1 || value >= 2147483647) {
ui.showToast?.('Enter a valid seed between 1 and 2147483646.');
return;
}
Registry.debugSeedOverride = value;
Registry.debugSeedOverrideRound = Registry.stats.round;
window.initializeRound(Registry.stats.round, { showBriefing: false, seedOverride: value });
document.getElementById('debugOverlay')?.style.setProperty('display', 'none');
window.startRoundCountdown?.(window.getRoundCountdownSeconds?.());
ui.showToast?.(`Round restarted with Debug seed ${value}.`);
};
seedControls.append(seedInput, randomSeedButton, copySeedButton, applySeedButton);
seedRow.append(seedLabel, seedControls);
container.appendChild(seedRow);
/* Retired RC1.0 internal quick actions. Automated tests run from npm,
while Endless and UNIT_01 are not player-facing product modes.
// Quick Actions Group
const quickGroup = document.createElement('div');
quickGroup.style.padding = "10px";
quickGroup.style.background = "#ecf0f1";
quickGroup.style.display = "flex";
quickGroup.style.gap = "8px";
quickGroup.style.borderBottom = "2px solid #bdc3c7";
const resetAwardsBtn = document.createElement('button');
resetAwardsBtn.className = "btn btn-red btn-small";
resetAwardsBtn.innerText = "🔄 Reset Career Medals";
resetAwardsBtn.onclick = () => {
const currentPlayer = Registry.playerName || window.Game.Storage.get(window.Game.Keys.PLAYER, 'Pilot 1');
localStorage.removeItem(window.Game.Keys.ACHIEVEMENTS + currentPlayer);
localStorage.removeItem(window.Game.Keys.TROPHIES);
Registry.trophyCase = [];
if (typeof ui.showToast === 'function') ui.showToast("Wiped career achievement storage map.");
};
quickGroup.appendChild(resetAwardsBtn);
const runTestsBtn = document.createElement('button');
runTestsBtn.className = "btn btn-blue btn-small";
runTestsBtn.innerText = "🧪 Run Simulation Tests";
runTestsBtn.onclick = async () => {
if (typeof window.Game.Tests !== 'undefined' && typeof window.Game.Tests.runAll === 'function') {
runTestsBtn.disabled = true;
runTestsBtn.innerText = "⏳ Running...";
await window.Game.Tests.runAll();
runTestsBtn.innerText = "🧪 Tests Detailed in Console";
runTestsBtn.disabled = false;
}
};
quickGroup.appendChild(runTestsBtn);
const autoBtn = document.createElement('button');
autoBtn.className = Registry.autoPilotActive ? "btn btn-red btn-small" : "btn btn-green btn-small";
autoBtn.innerText = Registry.autoPilotActive ? "🤖 Hault UNIT_01" : "🚀 Launch UNIT_01";
autoBtn.onclick = () => {
console.log("UNIT_01 Button Clicked. Active:", Registry.autoPilotActive);
Registry.autoPilotActive = !Registry.autoPilotActive;
Config.autoPilot = Registry.autoPilotActive;
if (Registry.autoPilotActive) {
console.log("Engaging UNIT_01 and closing modal...");
Registry.manualIntervention = false;
const monkey = Registry.monkeySettings || {};
Registry.agentSeed = monkey.agentSeed || Config.autoPilotSettings.agentSeed;
const shortDuration = monkey.roundDurationSeconds || Config.autoPilotSettings.shortRoundDuration || 30;
Config.roundTime = shortDuration;
if (Registry.stats.round !== 12) Registry.stats.timeLeft = shortDuration;
const hb = document.getElementById('heartbeatMonitor');
if (hb) hb.classList.remove('hidden');
if (typeof ui.showToast === 'function') ui.showToast("UNIT_01 Autonomous Agent Engaged.");
// Close the debug modal so the user can watch the agent
const debugOverlay = document.getElementById("debugOverlay");
if (debugOverlay) debugOverlay.style.display = "none";
if (typeof engine.resume === "function") engine.resume();
return; // Modal closed, stop execution
} else {
if (typeof engine.disengageAutoPilot === 'function') engine.disengageAutoPilot(false);
else if (typeof window.disengageAutoPilot === 'function') window.disengageAutoPilot(false);
if (typeof ui.showToast === 'function') ui.showToast("UNIT_01 Disengaged.");
}
window.renderDebugMenu();
};
quickGroup.appendChild(autoBtn);
if (Config.debugMode && window.Game.EndlessOperations) {
const endlessBtn = document.createElement('button');
endlessBtn.className = 'btn btn-purple btn-small';
endlessBtn.innerText = '♾️ Start Endless Alpha';
endlessBtn.title = 'Start a deterministic, pre-checked generated operation';
endlessBtn.onclick = () => {
const operation = window.startEndlessOperation(Registry.seed);
if (operation) {
const overlay = document.getElementById('debugOverlay');
if (overlay) overlay.style.display = 'none';
if (typeof ui.showToast === 'function') ui.showToast(`Endless alpha: ${operation.definition?.templateRound || Registry.stats.round}`);
} else if (typeof ui.showToast === 'function') {
ui.showToast('No valid Endless alpha operation was generated.');
}
};
quickGroup.appendChild(endlessBtn);
}
container.appendChild(quickGroup);
*/
const supportNote = document.createElement('p');
supportNote.className = 'modal-help';
supportNote.innerText = 'Warp and seed replay are temporary playtest tools. Use Give Feedback to include the current build and round details.';
container.appendChild(supportNote);
};
/* Retired RC1.0 in-game regression-suite loader.
window.loadDebugTestSuite = function() {
if (window.Game && window.Game.RegressionSuite) return Promise.resolve();
const sources = [
'tests/config_test.js',
'tests/simulation-tests.js',
'tests/regression-suite.js'
];
return sources.reduce((promise, source) => promise.then(() => new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = source;
script.onload = resolve;
script.onerror = () => reject(new Error(`Unable to load ${source}`));
document.head.appendChild(script);
})), Promise.resolve());
};
window.refreshDebugVisibility = function() {
const btn = document.getElementById('openDebugBtn');
if (btn) {
if (Config.debugMode) btn.classList.remove('hidden');
else btn.classList.add('hidden');
}
};
window.openDebugModal = function() {
if (!Config.debugMode) return;
GameEngine().pause();
window.Game.Audio?.setContext('menu');
window.renderDebugMenu();
window.openModalExclusive('debugOverlay');
};
*/
// Player-facing Debug retains only supported inspection and Warp controls.
window.refreshDebugVisibility = function() {
const btn = document.getElementById('openDebugBtn');
if (btn) btn.classList.toggle('hidden', !Config.debugMode);
};
window.openDebugModal = function() {
if (!Config.debugMode) return;
GameEngine().pause();
window.Game.Audio?.setContext('menu');
window.renderDebugMenu();
window.openModalExclusive('debugOverlay');
};