Repository navigation
Expand file tree
/
Copy pathfive-nights-at-morgans.ui.js
More file actions
112 lines (99 loc) · 3.68 KB
/
Copy pathfive-nights-at-morgans.ui.js
File metadata and controls
112 lines (99 loc) · 3.68 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
function setLightVisual(side,on){
const btn=$id(`btn-light-${side}`);
const ov=$id(`light-overlay-${side}`);
if(btn) btn.classList.toggle('on',!!on);
if(ov) ov.classList.toggle('on',!!on);
}
function toggleLight(side){
if(!state.running||state.gameOver||state.power<=0) return;
AUDIO.sfxLight();
if(side==='left') state.lightLeft=!state.lightLeft;
else state.lightRight=!state.lightRight;
setLightVisual(side,side==='left'?state.lightLeft:state.lightRight);
updateShadowOfficeVisual();
if(typeof updateUsageDisplay==='function' && typeof getRawDrain==='function' && typeof getNightMultiplier==='function'){
updateUsageDisplay(getRawDrain(),getNightMultiplier());
}
}
function openCamPanel(){
if(!state.running||state.gameOver||state.power<=0) return;
$id('cam-panel-overlay').style.display='flex';
AUDIO.sfxCamOpen();
state.camLightOn=false;
updateCamLightVisual();
if(typeof addHamletProgress==='function'){
const ai=(typeof getAILevel==='function')?getAILevel('hamlet'):10;
const scale=ai/10;
addHamletProgress(Math.max(1,Math.round(4*scale)));
}
if(typeof updateUsageDisplay==='function' && typeof getRawDrain==='function' && typeof getNightMultiplier==='function'){
updateUsageDisplay(getRawDrain(),getNightMultiplier());
}
checkMorganOnCurrentCam();
checkShadowOnCurrentCam();
}
function closeCamPanel(){
$id('cam-panel-overlay').style.display='none';
AUDIO.sfxCamClose();
state.camLightOn=false;
updateCamLightVisual();
state.hamletCamSessionSeconds=0;
if(typeof updateUsageDisplay==='function' && typeof getRawDrain==='function' && typeof getNightMultiplier==='function'){
updateUsageDisplay(getRawDrain(),getNightMultiplier());
}
hideMorganOnCam();
hideShadowOnCam();
}
function updateCamLightVisual(){
const feed=$id('cam-feed');
if(feed) feed.classList.toggle('cam-lit',!!state.camLightOn);
const btn=$id('btn-cam-light');
if(btn) btn.classList.toggle('on',!!state.camLightOn);
}
function toggleCamLight(){
if(!state.running||state.gameOver||state.power<=0) return;
if(!isCamPanelOpen()) return;
state.camLightOn=!state.camLightOn;
AUDIO.sfxLight();
updateCamLightVisual();
if(typeof updateUsageDisplay==='function' && typeof getRawDrain==='function' && typeof getNightMultiplier==='function'){
updateUsageDisplay(getRawDrain(),getNightMultiplier());
}
}
function toggleCamPanel(){
const overlay=$id('cam-panel-overlay');
if(!overlay) return;
if(overlay.style.display==='none' || overlay.style.display==='') openCamPanel();
else closeCamPanel();
}
document.addEventListener('keydown',(e)=>{
if(e.key!=='Escape') return;
const overlay=$id('cam-panel-overlay');
if(!overlay) return;
if(overlay.style.display!=='none' && overlay.style.display!=='') closeCamPanel();
});
document.addEventListener('keydown',(e)=>{
if(e.key!==' ' && e.key!=='Enter') return;
if(!state || !state.twiggActive) return;
if(typeof twiggAttempt==='function') twiggAttempt();
});
document.addEventListener('click',(e)=>{
const overlay=$id('cam-panel-overlay');
if(!overlay) return;
if(overlay.style.display==='none' || overlay.style.display==='') return;
if(e.target===overlay) closeCamPanel();
});
function showScreen(id){
document.querySelectorAll('.screen').forEach(s=>s.classList.remove('active'));
$id(id).classList.add('active');
}
function showAlert(msg){
const bar=$id('alert-bar');
bar.textContent=msg;bar.classList.add('show');
if(alertTimeout)clearTimeout(alertTimeout);
alertTimeout=setTimeout(()=>bar.classList.remove('show'),2800);
}
function clearAlert(){$id('alert-bar').classList.remove('show');}
function updateNightIndicator(){
$id('night-indicator').textContent=`— Night ${state.night} —`;
}