-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
203 lines (176 loc) · 6.62 KB
/
index.html
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>jGen Map Editor</title>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
<script type="text/javascript" src="scripts/oop.js"></script>
<script type="text/javascript" src="scripts/string.js"></script>
<script type="text/javascript" src="scripts/html.js"></script>
<script type="text/javascript" src="scripts/math.js"></script>
<script type="text/javascript" src="scripts/map.js"></script>
<script type="text/javascript" src="scripts/editor.js"></script>
<script type="text/javascript">
var TEngine = Class.create({
callback: null,
eventHandler: null,
gameState: {
height: 0,
keys: {},
mouse: {},
metaKey: false
},
constructor: function(oViewPort, fCallback) {
var oThis = this;
this.viewPort = oViewPort;
this.callback = fCallback;
this.eventHandler = function(oEvent) {
// update metakey state
oThis.gameState.metaKey = oEvent.metaKey;
if (oEvent.type == 'keydown') oThis.gameState.keys[oEvent.keyCode] = true;
else if (oEvent.type == 'keyup') oThis.gameState.keys[oEvent.keyCode] = false;
else if (oEvent.type == 'mousedown') oThis.gameState.mouse.down = true;
else if (oEvent.type == 'mouseup') oThis.gameState.mouse.down = false;
else if (oEvent.type == 'mousemove') {
oThis.gameState.mouse.x = (oEvent.clientX - oThis.viewPort.offsetLeft);
oThis.gameState.mouse.y = (oEvent.clientY - oThis.viewPort.offsetTop);
}
};
},
start: function(oViewPort) {
var oThis = this;
document.addEventListener('keydown', this.eventHandler, false);
document.addEventListener('keyup', this.eventHandler, false);
this.viewPort.addEventListener('mousemove', this.eventHandler, false);
this.viewPort.addEventListener('mousedown', this.eventHandler, false);
this.viewPort.addEventListener('mouseup', this.eventHandler, false);
window.top.testInterval = function() {
oThis.callback.call(oThis, oThis.gameState);
}
for (var c = 0; c < 1; c++) {
setInterval(window.top.testInterval, 0);
}
}
});
</script>
<script type="text/javascript">
function start() {
oEditor = new TEditor();
oEditor.loadLibrary('library/library.xml', function() {
this.renderPalette(document.querySelector('.leftColumn'));
this.renderWorkspace(document.querySelector('.viewPort'));
var iHeight = 0;
var iScrollX = iNewScrollX = 0;
var iScrollY = iNewScrollY = 0;
var iCaptureX = iCaptureY = -1;
window.addEventListener('resize', function() {
oEditor.map.initViewPort(oEditor.map.viewPort.offsetWidth, oEditor.map.viewPort.offsetHeight);
oEditor.renderMap(iScrollX, iScrollY);
}, false);
var iSecond = (new Date()).getSeconds();
var iCounter = 0;
var oFPSWindow = document.querySelector('.fpsWindow');
(new TEngine(oEditor.map.viewPort.parentNode, function(oGameState) {
iCounter++;
var aCursorPos = oEditor.map.screen2map(
oGameState.mouse.x,
oGameState.mouse.y,
iScrollX,
iScrollY
);
/*
var aTilePos = oEditor.map.map2screen(
aCursorPos[0],
aCursorPos[1]
);
oEditor.cursor.setStyle({
'left': (aTilePos[0] + 'px'),
'top': (aTilePos[1] + 'px')
});
*/
if (oGameState.mouse.down) {
if ((oGameState.metaKey) && (iCaptureX == -1) && (iCaptureY == -1)) {
iCaptureX = oGameState.mouse.x + iScrollX;
iCaptureY = oGameState.mouse.y + iScrollY;
} else if (oGameState.metaKey) {
iNewScrollX = (iCaptureX - oGameState.mouse.x);
iNewScrollY = (iCaptureY - oGameState.mouse.y);
if ((iNewScrollX != iScrollX) || (iNewScrollY != iScrollY)) {
oEditor.renderMap(iNewScrollX, iNewScrollY);
iScrollX = iNewScrollX;
iScrollY = iNewScrollY;
}
} else if (oEditor.selectedObject) {
var sIndex = aCursorPos[1] + '.' + aCursorPos[0];
var sBrush = oEditor.selectedObject.name;
if (!oEditor.map.tiles[sBrush]) {
oEditor.map.tiles[sBrush] = oEditor.map.createTile(
oEditor.selectedObject.src,
oEditor.selectedObject.width,
oEditor.selectedObject.height
);
}
oEditor.map.objects[sIndex] = (oEditor.selectedObject.name);
if (oEditor.map.mapData[sIndex]) {
oEditor.map.mapData[sIndex].parentNode.removeChild(oEditor.map.mapData[sIndex]);
delete(oEditor.map.mapData[sIndex]);
}
oEditor.renderMap(iScrollX, iScrollY);
console.info(oEditor.map.tiles);
}
} else {
iCaptureX = -1;
iCaptureY = -1;
}
var iNewSecond = (new Date()).getSeconds();
if (iNewSecond != iSecond) {
iSecond = iNewSecond;
oFPSWindow.innerHTML = 'FPS: ' + iCounter;
iCounter = 0;
}
})).start();
});
}
function saveFileDialogInit() {
document.querySelector('.saveFileDialog object').addEventListener('onsave', function() {
return {
'data': oEditor.saveMapData(),
'filename': 'map.xml'
};
}.toString());
}
function openFileDialogInit() {
document.querySelector('.openFileDialog object').addEventListener('onload', function(sData) {
oEditor.loadMapData(window.atob(sData));
}.toString());
}
</script>
</head>
<body onload="start();">
<div class="toolbar">
<div class="toolbarButton toolbarButtonLeft openFileDialog">
<object>
<param name="movie" value="scripts/fsutils.swf" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="FlashVars" value="onload=openFileDialogInit&dialogType=open&fileFilter=*.xml" />
<param name="wmode" value="transparent" />
</object>
<div>Load Map...</div>
</div>
<div class="toolbarButton toolbarButtonLeft saveFileDialog">
<object>
<param name="movie" value="scripts/fsutils.swf" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="FlashVars" value="onload=saveFileDialogInit&dialogType=save" />
<param name="wmode" value="transparent" />
</object>
<div>Save Map...</div>
</div>
<div class="toolbarButton toolbarButtonRight hideGrid">Hide Grid</div>
<div class="toolbarButton toolbarButtonRight showGrid">Show Grid</div>
</div>
<div class="leftColumn"></div>
<div class="viewPort">
<div class="fpsWindow"></div>
</div>
</body>
</html>