-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameSetup.js
More file actions
92 lines (79 loc) · 2.67 KB
/
Copy pathgameSetup.js
File metadata and controls
92 lines (79 loc) · 2.67 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
"use strict";
function createGameSetup(onDone, onExit, assets, config) {
let SettingsStates = {setup: 0, getPlayerNames: 1};
let currentState = SettingsStates.setup;
let gameSettings = null;
let currentPlayerIndex = 0;
let playerNames = [];
let lastSettings = null;
let mainContainer = new createjs.Container();
let backgroundContainer = createBackground();
let settingsDialog = createGameSetupSettingsDialog(assets, onSettingsDone, onExit, config);
let playerNamesDialog = createPlayerNamesDialog(assets, onPlayerNameDone);
mainContainer.addChild(backgroundContainer);
mainContainer.addChild(settingsDialog.container);
return {
container: mainContainer,
onKeyDown: onKeyDown,
onKeyPress: onKeyPress,
onShow: onShow,
getSettings: getSettings
};
function createBackground() {
/*
Show_PCX('Gfx\frame.pcx',GetMaxX div 2 -318,GetMaxY div 2 - 235,636,235);
Show_PCX('Gfx\frame.pcx',GetMaxX div 2 -318,GetMaxY div 2,636,235);
*/
let backgroundContainer = new createjs.Container();
showPCX(assets, backgroundContainer, "frame.pcx", SCREEN_WIDTH_CENTER - 318, SCREEN_HEIGHT_CENTER - 235, 636, 235);
showPCX(assets, backgroundContainer, "frame.pcx", SCREEN_WIDTH_CENTER - 318, SCREEN_HEIGHT_CENTER, 636, 235);
return backgroundContainer;
}
function onKeyDown(stage, key) {
if (currentState === SettingsStates.getPlayerNames) {
playerNamesDialog.onKeyDown(stage, key);
}
else {
settingsDialog.onKeyDown(stage, key);
}
}
function onKeyPress(stage, key) {
if (currentState === SettingsStates.getPlayerNames) {
playerNamesDialog.onKeyPress(stage, key);
}
}
function onSettingsDone(settings) {
gameSettings = settings;
lastSettings = settings;
currentState = SettingsStates.getPlayerNames;
mainContainer.removeChild(settingsDialog.container);
mainContainer.addChild(playerNamesDialog.container);
}
function onPlayerNameDone(playerName) {
playerNames[currentPlayerIndex] = playerName;
if (currentPlayerIndex < gameSettings.numPlayers - 1) {
currentPlayerIndex++;
playerNamesDialog.setPlayerIndex(currentPlayerIndex)
}
else {
onDone(playerNames);
}
}
function onShow() {
// reset state
if (currentState === SettingsStates.getPlayerNames) {
mainContainer.removeChild(playerNamesDialog.container);
mainContainer.addChild(settingsDialog.container);
}
currentState = SettingsStates.setup;
gameSettings = null;
lastSettings = null;
currentPlayerIndex = 0;
playerNames = [];
playerNamesDialog.setPlayerIndex(currentPlayerIndex)
settingsDialog.onShow();
}
function getSettings() {
return lastSettings;
}
}