-
Notifications
You must be signed in to change notification settings - Fork 1
/
playGame.js
95 lines (78 loc) · 1.94 KB
/
playGame.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
//////////////////////////////////////////////////////////////////////
// playGame //
//////////////////////////////////////////////////////////////////////
function playGame() {
this.name = 'play game'
let panel, gameContainer;
this.setup = function(){
panel = createDiv()
.parent(toolPanelsContainer)
.hide();
gameContainer = select('#imgmGame')
.style('width', gameWidth + 'px')
.style('height', gameHeight + 'px')
.style('overflow', 'hidden')
.hide();
createButton('export')
.mousePressed(exportGame)
.parent(panel);
createElement('hr')
.parent(panel);
createButton('back')
.mousePressed(edit)
.parent(panel);
}
this.exit = function(){
panel.hide();
gameContainer.html('');
gameContainer.hide();
};
this.enter = function(){
panel.show();
gameContainer.show();
generateGame();
};
function generateMap(i){
let scene = game.scenes[i];
let mapElement = createElement('map')
.attribute('name', i)
.parent(gameContainer);
for(let j=0; j<scene.gates.length; j++){
let gate = scene.gates[j];
createElement('area')
.attribute('shape', 'poly')
.attribute('coords', gate.poly.join(','))
.attribute('href', '#'+gate.sceneId)
.parent(mapElement);
}
}
function generateImg(i){
let scene = game.scenes[i];
createImg(scene.imageData || defaultImage, str(i))
.id(i)
.attribute('usemap', '#'+i)
.style('width', '100%')
.style('height', '100%')
.parent(gameContainer);
}
function generateGame(){
for(let i=0; i < game.scenes.length; i++){
generateMap(i);
generateImg(i);
}
}
function exportGame(){
let page = [];
let values = {
mood:getToolsMoodText(),
imgmGame:gameContainer.elt.outerHTML
};
for (let i=0; i<template.length; i++){
page.push(formatString(template[i], values));
}
saveStrings(page, 'game', 'html');
}
function edit(){
mgr.showScene(editScene);
}
}