-
Notifications
You must be signed in to change notification settings - Fork 1
/
home.js
98 lines (84 loc) · 1.96 KB
/
home.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
//////////////////////////////////////////////////////////////////////
// home //
//////////////////////////////////////////////////////////////////////
function home(){
this.name = 'home';
let panel, img, x, y, scale, xOffset, yOffset, mouseLocked;
this.setup = function(){
panel = createDiv()
.parent(toolPanelsContainer)
.hide();
createButton('start a new game')
.mousePressed(newGame)
.parent(panel);
if(game){
createButton('continue working on the game')
.mousePressed(continueGame)
.parent(panel);
}
createElement('hr')
.parent(panel)
createSpan('import a game:')
.parent(panel)
createFileInput(importGame)
.parent(panel)
}
this.enter = function(){
background(0);
fill(255);
textAlign(CENTER);
text('welcome to imgm !', width/2, height/2);
panel.show();
};
this.exit = function (){
panel.hide();
};
function importGame(file){
let tempDiv = createDiv(file.data).hide()
print(tempDiv)
let imgmGame = select('#imgmGame', tempDiv)
if(imgmGame){
let images = selectAll('img', imgmGame);
let maps = selectAll('map', imgmGame);
let scenes = []
for(let i=0; i<images.length; i++){
let imageData = images[i].attribute('src')
let gates = []
let areas = selectAll('area', maps[i])
for(let j=0; j<areas.length; j++){
let gate = {
poly:int(split(areas[j].attribute('coords'), ',')),
sceneId:areas[j].attribute('href').substring(1)
};
gates.push(gate);
}
let scene = {
imageData:imageData,
gates:gates
}
scenes.push(scene);
}
tempDiv.remove()
game = {
scenes:scenes
};
sceneIndex = 0;
mgr.showScene(editScene);
return true;
}
else {
return false;
}
}
function newGame(){
game = {
scenes: [],
};
sceneIndex = newScene();
mgr.showScene(editScene);
};
function continueGame(file){
sceneIndex = 0;
mgr.showScene(editScene)
};
}