-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit.js
112 lines (102 loc) · 2.07 KB
/
init.js
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
/********************** public functions *********************/
function waitForLoad()
{
if (!gameLoaded())
{
setTimeout(waitForLoad,10);
return;
}
gameState=0;
openResources();
startImage.remove();
delete startImage;
showTitle();
loadFiles();
createWindows();
initMenus();
createMenus();
addDeskAccessory("More Games...",0x901);
addDeskAccessory("Adjust Volume...",0x900);
addDeskAccessory("Help",0x903);
// addDeskAccessory("Win!", 0x902);
enableFeatureMenus();
textWin.setTitle(resGetUntitled());
if (gameparts.length>1) //save game to load
{
saveName=gameparts[1];
var g=window.JSON.parse(window.localStorage.getItem(saveName).toString());
game=g['gamedata'];
globals=g['globals'];
textEdit.html(g['text']);
textWin.setTitle(saveName);
}
else
{
var g=getFile(resGetDefault());
game=new Array(numGroups);
globals=new Array(numGlobals);
for (var i=0;i<numGroups;i++)
{
game[i]=new Array(numObjects);
for (var o=0;o<numObjects;o++)
game[i][o]=g.r16();
}
for (var i=0;i<numGlobals;i++)
globals[i]=g.r16();
}
calculateRelations();
if (saveName=='')
{
cmdReady=true;
selectedCtl=1;
curSelection.push(get(1,0));
}
setTimeout(finishLoading,500);
}
//calculate the children for each object and save in list
function calculateRelations()
{
var val,next;
for (var i=0;i<numObjects*2;i++)
relations[i]=0;
for (var i=numObjects-1;i;i--)
{
val=game[0][i];
next=relations[val*2];
if (next) relations[i*2+1]=next;
relations[val*2]=i;
}
}
function reset()
{
resetWindows();
inventory.num=0;
queue=[];
soundQueue=[];
textQueue=[];
inQueue=[];
}
/********************** private functions *********************/
var relations;
function finishLoading()
{
showWindows();
lastViewed=textEdit.get(0).scrollHeight;
textEdit.scrollTop(lastViewed-(lastViewed%textLH));
set(get(1,0),6,1);
gameChanged=false;
runMain();
}
function showWindows()
{
closeWindow(titleWin);
delete titleWin;
showMenus();
commandsWin.show();
selfWin.show();
updateWindow(selfWin);
exitWin.show();
textWin.show();
mainWin.show();
gameState=1;
}