forked from cliffe/BreakEscape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-infusion-pump-minigame.html
More file actions
428 lines (380 loc) · 18.4 KB
/
test-infusion-pump-minigame.html
File metadata and controls
428 lines (380 loc) · 18.4 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MG-08 Infusion Pump Minigame Test</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=VT323&display=swap" rel="stylesheet">
<link rel="stylesheet" href="public/break_escape/css/minigames-framework.css">
<link rel="stylesheet" href="public/break_escape/css/infusion-pump-minigame.css">
<!-- Phaser 3.60 — required by the Phaser-based InfusionPumpMinigame -->
<script src="https://cdn.jsdelivr.net/npm/phaser@3.60.0/dist/phaser.min.js"></script>
<style>
*, *::before, *::after { box-sizing: border-box; }
body {
margin: 0;
background: #050a14;
font-family: 'Press Start 2P', monospace;
}
/* Minigame viewport: leaves 220px for the test bar */
.ip-test-wrap {
position: fixed !important;
top: 0 !important;
left: 0 !important;
width: 100vw !important;
height: calc(100vh - 220px) !important;
z-index: 1500;
background: rgba(0, 0, 0, 0.95);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
/* Constrain panel width on wide viewports */
.ip-test-wrap .ip-panel-wrap {
max-width: 900px;
width: 100%;
height: 100%;
}
/* Test harness bar fixed at bottom */
#test-harness {
position: fixed;
bottom: 0; left: 0; right: 0;
height: 220px;
z-index: 2000;
background: #080e1b;
border-top: 2px solid #1e2d4a;
display: flex;
flex-direction: column;
}
#test-toolbar {
display: flex;
align-items: center;
gap: 10px;
padding: 7px 14px;
border-bottom: 2px solid #1e2d4a;
flex-shrink: 0;
flex-wrap: wrap;
}
.toolbar-title { font-size: 8px; color: #f59e0b; letter-spacing: 1px; margin-right: 4px; }
.toolbar-label { font-size: 7px; color: #4a6090; letter-spacing: 1px; }
.toolbar-hint { font-size: 6px; color: #2a3a5a; letter-spacing: 0.5px; }
.dose-badge {
font-family: 'VT323', monospace;
font-size: 20px;
color: #00e5ff;
background: #070d1a;
border: 2px solid #1e2d4a;
padding: 1px 10px;
letter-spacing: 4px;
}
.toolbar-sep { width: 2px; height: 18px; background: #1e2d4a; flex-shrink: 0; }
.test-btn {
font-family: 'Press Start 2P', monospace;
font-size: 7px;
background: #101829;
color: #c8d8ff;
border: 2px solid #2a3a5a;
padding: 5px 10px;
cursor: pointer;
transition: background 0.1s, border-color 0.1s;
line-height: 1;
}
.test-btn:hover { background: #162040; border-color: #4a6090; }
.test-btn.green { border-color: #065f46; color: #34d399; }
.test-btn.green:hover { background: #061812; border-color: #34d399; }
.test-btn.amber { border-color: #92400e; color: #fbbf24; }
.test-btn.amber:hover { background: #1a1200; border-color: #fbbf24; }
.test-btn.amber.active { background: #2a1a00; border-color: #f59e0b; color: #f59e0b; }
.test-btn.red { border-color: #7f1d1d; color: #f87171; }
.test-btn.red:hover { background: #1a0000; border-color: #f87171; }
.test-btn.red.active { background: #2a0000; border-color: #ef4444; color: #ef4444; }
#event-log {
flex: 1;
overflow-y: auto;
padding: 4px 14px 6px;
display: flex;
flex-direction: column;
gap: 1px;
}
.log-row {
display: flex;
align-items: baseline;
gap: 8px;
font-family: 'VT323', monospace;
font-size: 17px;
line-height: 1.2;
}
.log-ts { color: #1e2d4a; min-width: 58px; font-size: 14px; flex-shrink: 0; }
.log-info { color: #6a82aa; }
.log-global { color: #00e5ff; }
.log-success { color: #00e676; }
.log-failure { color: #ef4444; }
.log-warn { color: #f59e0b; }
.log-sep { color: #2a3a5a; }
</style>
</head>
<body>
<!-- Required by MinigameFramework endMinigame cleanup -->
<div class="popup-overlay"></div>
<!-- Test harness panel -->
<div id="test-harness">
<div id="test-toolbar">
<span class="toolbar-title">MG-08 INFUSION PUMP</span>
<div class="toolbar-sep"></div>
<span class="toolbar-label">CORRECT DOSE</span>
<span class="dose-badge" id="badge-dose">10</span>
<span class="toolbar-label">mg/hr</span>
<div class="toolbar-sep"></div>
<button class="test-btn green" id="btn-restart">▶ RESTART</button>
<button class="test-btn" id="btn-clear">CLEAR LOG</button>
<div class="toolbar-sep"></div>
<button class="test-btn amber" id="btn-library">DRUG LIB: INTACT</button>
<button class="test-btn red" id="btn-charts">CHARTS: COLLECTED</button>
<div class="toolbar-sep"></div>
<span class="toolbar-hint">Enter 10 for correct dose | Enter 100 to trigger double-check modal | Toggle library to test silent accept</span>
</div>
<div id="event-log"></div>
</div>
<!--
Step 1: Inject <script type="importmap"> via document.write so it lands
in the HTML stream before any ES module is parsed.
Redirects the single engine import (base-minigame.js) to a data: URI mock.
InfusionPumpMinigame does NOT import unlock-system.js so no second mock needed.
-->
<script>
(function () {
// MinigameScene mock — replicates base-minigame.js public interface
var BASE_MOCK = [
'export class MinigameScene {',
' constructor(container, params) {',
' this.container = container;',
' this.params = params;',
' this.gameState = { isActive: false, mouseDown: false, currentTool: null };',
' this.gameResult = null;',
' this._eventListeners = [];',
' this._esc = null;',
' }',
' init() {',
' var showCancel = this.params.showCancel !== false;',
' var disableClose = this.params.disableClose === true;',
" var closeAttr = disableClose ? ' style=\"display:none\"' : '';",
" var cancelHtml = showCancel",
" ? '<div class=\"minigame-controls\"><button class=\"minigame-button\" id=\"minigame-cancel\">'",
" + (this.params.cancelText || 'Cancel') + '</button></div>'",
" : '';",
' this.container.innerHTML =',
" '<button class=\"minigame-close-button\" id=\"minigame-close\"' + closeAttr + '>\u00d7</button>' +",
" '<div class=\"minigame-header\"><h3>' + (this.params.title || 'Minigame') + '</h3></div>' +",
" '<div class=\"minigame-game-container\"></div>' +",
" '<div class=\"minigame-message-container\"></div>' +",
' cancelHtml;',
" this.headerElement = this.container.querySelector('.minigame-header');",
" this.gameContainer = this.container.querySelector('.minigame-game-container');",
" this.messageContainer = this.container.querySelector('.minigame-message-container');",
" this.controlsElement = this.container.querySelector('.minigame-controls');",
' var self = this;',
' if (!disableClose) {',
" var cb = this.container.querySelector('#minigame-close');",
' if (cb) cb.addEventListener("click", function () { self.complete(false); });',
' }',
" var xb = this.container.querySelector('#minigame-cancel');",
' if (xb) xb.addEventListener("click", function () { self.complete(false); });',
' if (!this.params.headerElement && this.headerElement) {',
' this.headerElement.style.display = "none";',
' }',
' }',
' start() {',
' this.gameState.isActive = true;',
' if (this.params.disableClose !== true) {',
' var self = this;',
' this._esc = function (e) { if (e.key === "Escape") self.complete(false); };',
' document.addEventListener("keydown", this._esc);',
' }',
' }',
' complete(success, result) {',
' if (this._esc) { document.removeEventListener("keydown", this._esc); this._esc = null; }',
' if (window.MinigameFramework) window.MinigameFramework.endMinigame(success, result);',
' }',
' cleanup() {',
' if (this._esc) { document.removeEventListener("keydown", this._esc); this._esc = null; }',
' this._eventListeners.forEach(function (h) {',
' try { h.el.removeEventListener(h.event, h.fn); } catch (e) {}',
' });',
' this._eventListeners = [];',
' }',
' addEventListener(el, event, fn) {',
' if (!el) return;',
' el.addEventListener(event, fn);',
' this._eventListeners.push({ el: el, event: event, fn: fn });',
' }',
' showSuccess(msg) { console.log("[mock MinigameScene] showSuccess:", msg); }',
' showFailure(msg) { console.log("[mock MinigameScene] showFailure:", msg); }',
'}'
].join('\n');
var importMap = JSON.stringify({
imports: {
'/public/break_escape/js/minigames/framework/base-minigame.js':
'data:text/javascript,' + encodeURIComponent(BASE_MOCK)
}
});
document.write('<script type="importmap">' + importMap + '<\/script>');
}());
</script>
<!--
Step 2: Import the REAL InfusionPumpMinigame.
Its only engine import (base-minigame.js) is redirected to the mock above.
-->
<script type="module">
import { InfusionPumpMinigame } from '/public/break_escape/js/minigames/infusion-pump/infusion-pump-minigame.js';
// ── Test configuration ─────────────────────────────────────────────────
const DRUG_NAME = 'MORPHINE SULPHATE';
const CORRECT_DOSE = '10';
// Global state: paper charts ON by default, library intact by default
window.gameState = {
globalVariables: {
paper_charts_collected: true,
drug_library_compromised: false,
pump_dose_correct: false,
pump_dose_error: false
}
};
const mockLockable = {
scenarioData: {
id: 'bed2_pump_terminal',
drug_name: DRUG_NAME,
correct_dose: CORRECT_DOSE
},
layer: null
};
// ── Event log ──────────────────────────────────────────────────────────
const logEl = document.getElementById('event-log');
function log(msg, type = 'info') {
const now = new Date();
const ts = String(now.getMinutes()).padStart(2, '0') + ':' +
String(now.getSeconds()).padStart(2, '0') + '.' +
String(now.getMilliseconds()).padStart(3, '0').slice(0, 2);
const row = document.createElement('div');
row.className = 'log-row';
row.innerHTML = `<span class="log-ts">${ts}</span><span class="log-${type}">${msg}</span>`;
logEl.appendChild(row);
logEl.scrollTop = logEl.scrollHeight;
}
// Exposed so mocks can write to the log
window._testLog = log;
// ── Mock MinigameFramework ─────────────────────────────────────────────
let currentMinigame = null;
window.MinigameFramework = {
currentMinigame: null,
endMinigame(success, result) {
const label = success ? 'COMPLETED \u2713' : 'DISMISSED / CANCELLED \u2715';
log(`MinigameFramework.endMinigame \u2014 ${label}`, success ? 'success' : 'failure');
if (currentMinigame) {
currentMinigame.params?.onComplete?.(success, result);
currentMinigame.cleanup();
currentMinigame = null;
this.currentMinigame = null;
}
document.querySelectorAll('.ip-test-wrap').forEach(el => el.remove());
}
};
// ── Mock npcManager ────────────────────────────────────────────────────
// InfusionPumpMinigame.setGlobalAndNotify() calls window.npcManager.setGlobalVariable
// as its preferred path. This captures every global write for the log.
window.npcManager = {
setGlobalVariable(name, value) {
if (window.gameState?.globalVariables) {
window.gameState.globalVariables[name] = value;
}
log(`setGlobal: ${name} = ${JSON.stringify(value)}`, 'global');
}
};
// ── Launch ─────────────────────────────────────────────────────────────
function launch() {
const outer = document.createElement('div');
outer.className = 'ip-test-wrap';
document.body.insertBefore(outer, document.body.firstChild);
const libCompromised = window.gameState.globalVariables.drug_library_compromised;
const chartsHeld = window.gameState.globalVariables.paper_charts_collected;
currentMinigame = new InfusionPumpMinigame(outer, {
lockable: mockLockable,
type: 'object',
showCancel: true,
cancelText: 'Close',
onComplete(success, result) {
log(`onComplete callback \u2014 success: ${success}`, success ? 'success' : 'failure');
// Report which global was set
const gv = window.gameState.globalVariables;
if (gv.pump_dose_correct) log(' pump_dose_correct = true', 'success');
if (gv.pump_dose_error) log(' pump_dose_error = true', 'warn');
}
});
window.MinigameFramework.currentMinigame = currentMinigame;
currentMinigame.init();
currentMinigame.start();
log(
`Launched \u2014 drug: ${DRUG_NAME} \u2014 correct dose: ${CORRECT_DOSE} mg/hr` +
` \u2014 charts: ${chartsHeld ? 'YES' : 'NO'}` +
` \u2014 library: ${libCompromised ? 'COMPROMISED' : 'intact'}`,
'info'
);
if (!chartsHeld) {
log(' No charts \u2014 guard screen will show, minigame closes in 3s', 'warn');
}
if (libCompromised) {
log(' Library compromised \u2014 wrong dose will be silently accepted (no modal)', 'warn');
}
}
// ── Controls ───────────────────────────────────────────────────────────
document.getElementById('btn-restart').addEventListener('click', () => {
if (currentMinigame) {
currentMinigame.cleanup();
currentMinigame = null;
window.MinigameFramework.currentMinigame = null;
}
document.querySelectorAll('.ip-test-wrap').forEach(el => el.remove());
// Reset dose outcome flags for next run
window.gameState.globalVariables.pump_dose_correct = false;
window.gameState.globalVariables.pump_dose_error = false;
log('\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 RESTART \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500', 'sep');
launch();
});
document.getElementById('btn-clear').addEventListener('click', () => {
logEl.innerHTML = '';
});
// Toggle: drug_library_compromised
const btnLibrary = document.getElementById('btn-library');
btnLibrary.addEventListener('click', () => {
const current = window.gameState.globalVariables.drug_library_compromised;
const next = !current;
window.gameState.globalVariables.drug_library_compromised = next;
btnLibrary.textContent = `DRUG LIB: ${next ? 'COMPROMISED' : 'INTACT'}`;
btnLibrary.classList.toggle('active', next);
log(
`drug_library_compromised = ${next}` +
(next ? ' \u2192 wrong dose will be silently accepted' : ' \u2192 double-check modal restored'),
next ? 'warn' : 'info'
);
});
// Toggle: paper_charts_collected
const btnCharts = document.getElementById('btn-charts');
btnCharts.addEventListener('click', () => {
const current = window.gameState.globalVariables.paper_charts_collected;
const next = !current;
window.gameState.globalVariables.paper_charts_collected = next;
btnCharts.textContent = `CHARTS: ${next ? 'COLLECTED' : 'NOT FOUND'}`;
btnCharts.classList.toggle('active', !next);
log(
`paper_charts_collected = ${next}` +
(!next ? ' \u2192 restart to see guard screen' : ''),
next ? 'info' : 'warn'
);
});
// ── Auto-launch ────────────────────────────────────────────────────────
launch();
</script>
</body>
</html>