-
Notifications
You must be signed in to change notification settings - Fork 317
/
index_low.html
236 lines (191 loc) · 6.29 KB
/
index_low.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html>
<html lang="en">
<head>
<title>3D.CITY</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link rel="icon" href="favicon.ico" />
<style>
*{ padding:0; margin: 0; -o-user-select:none; -ms-user-select:none; -khtml-user-select:none; -webkit-user-select:none; -moz-user-select: none;}
html { width:100%; height:100%; }
body { background:#3C89CD; font:11px sans-serif; width:100%; height:100%; color:#DCDCDC; overflow: hidden; }
#container{ min-width:480px; min-height:480px; width:100%; height:100%; overflow:hidden; text-align:center; }
#container canvas{position:absolute;top:0;left:0;width:100%;height:100%}
#debug{ position:absolute; padding:5px; right:0; bottom:0; text-align:right; width:20%; pointer-events:none; display:block; }
#hub{ position:absolute; top:0; left:0; height:100%; width:100%; pointer-events:none; display:block; text-align:center;}
#miniGlCanvas{ position:absolute; bottom:60px; left:15px; pointer-events:none;}
#logo{ position:absolute; left:50%; top:50%; margin-left:-150px; margin-top:-150px; width:300px; height:320px; pointer-events:none; display:none;}
</style>
<script src="js/three.min.js"></script>
<script src="js/sea3d.min.js"></script>
<script src="src3d/ImprovedNoise.js"></script>
<script src="src3d/view3d.js"></script>
<script src="src3d/hub.js"></script>
<!--<script src="src3d/saveLoad.js"></script>-->
</head>
<body>
<div id="container"></div>
<div id="debug">v 0.4</div>
<canvas id="miniGlCanvas"></canvas>
<div id="hub"></div>
<object id="logo" width="300" height="320" type="image/svg+xml" data="img/logo.svg"></object>
<script>
var d = document.getElementById('debug');
var miniGlCanvas = document.getElementById("miniGlCanvas");
var simulation_timestep = 30;
var stats = null;
var tilesData = null;
var spriteData = null;
var gameData = null;
var powerData = null;
var isMobile = false;
var trans = false;
var newup = false;
var powerup = false;
var cityWorker = new Worker('js/worker.city.js');
var view3d, hub, im;
function debug(txt){ d.innerHTML += "<br>"+txt; }
window.onload = init;
function testMobile() {
if (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i)) return true;
else return false;
}
function init(){
isMobile = testMobile();
hub = new HUB.Base();
view3d = new V3D.Base(isMobile, 0.5, true);
}
//=======================================
// 3D LOOP
//=======================================
function loop() {
requestAnimationFrame( loop );
if(newup){
view3d.paintMap();
view3d.moveSprite();
newup = false;
}
if(powerup){
view3d.showPower();
powerup = false;
}
if(view3d.mouse.dragView || view3d.mouse.button===2){
view3d.dragCenterposition();
}else{
if(!isMobile)view3d.updateKey();
}
view3d.renderer.render( view3d.scene, view3d.camera );
}
//=======================================
// SAVE LOAD
//=======================================
function saveGame(){
console.log("save game");
cityWorker.postMessage({tell:"SAVEGAME"});
//saveTextAsFile('test', 'game is saved');
}
function loadGame(){
console.log("load game");
loadFileAsText();
//saveTextAsFile('test', 'game is saved');
}
function newGameMap(){
console.log("new map");
//saveTextAsFile('test', 'game is saved');
}
//=======================================
// CITY INIT
//=======================================
var ARRAY_TYPE;
if(!ARRAY_TYPE) { ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array; }
function start() {
initCity();
}
function setTimeColors(id) {
view3d.setTimeColors(id);
}
function newMap() {
if(view3d.isWithHeight){ view3d.resetHeight();}
cityWorker.postMessage({tell:"NEWMAP"});
}
function newHeightMap() {
view3d.isWithHeight = true;
cityWorker.postMessage({tell:"NEWMAP"});
}
function playMap() {
hub.initGameHub();
view3d.startZoom();
cityWorker.postMessage({tell:"PLAYMAP"});
}
function selectTool(id) {
view3d.selectTool(id);
}
function sendTool(name) {
cityWorker.postMessage({tell:"TOOL", name:name});
}
function setDifficulty(n){
cityWorker.postMessage({tell:"DIFFICULTY", n:n });
}
function setSpeed(n){
cityWorker.postMessage({tell:"SPEED", n:n });
}
function getBudjet(){
cityWorker.postMessage({ tell:"BUDGET" });
}
function setBudjet(budgetData){
cityWorker.postMessage({ tell:"NEWBUDGET", budgetData:budgetData });
}
function getEval(){
cityWorker.postMessage({ tell:"EVAL" });
}
function setDisaster(disaster){
console.log(disaster);
cityWorker.postMessage({ tell:"DISASTER", disaster:disaster });
}
function destroy(x,y) {
cityWorker.postMessage({tell:"DESTROY", x:x, y:y});
}
function mapClick() {
var p = view3d.pos;
if(p.x>0 && p.z>0) cityWorker.postMessage({tell:"MAPCLICK", x:p.x, y:p.z });
}
function initCity() {
hub.subtitle.innerHTML = "Generating world...";
loop();
cityWorker.postMessage = cityWorker.webkitPostMessage || cityWorker.postMessage;
cityWorker.postMessage({tell:"INIT", url:document.location.href.replace(/\/[^/]*$/,"/") + "build/city.3d.min.js", timestep:simulation_timestep });
}
cityWorker.onmessage = function(e) {
var phase = e.data.tell;
if( phase == "NEWMAP"){
tilesData = e.data.tilesData;
view3d.paintMap( e.data.mapSize, e.data.island, true);
//trans = e.data.trans;
hub.start();
}
if( phase == "BUILD"){
view3d.build(e.data.x, e.data.y);
}
if( phase == "RUN"){
tilesData = e.data.tilesData;
powerData = e.data.powerData;
spriteData = e.data.sprites;
hub.updateCITYinfo(e.data.infos);
newup = true;
if(powerData) powerup = true;
}
if( phase == "BUDGET"){
hub.openBudget(e.data.budgetData);
}
if( phase == "QUERY"){
hub.openQuery(e.data.queryTxt);
}
if( phase == "EVAL"){
hub.openEval(e.data.evalData);
}
if( phase == "SAVEGAME"){
saveTextAsFile('test', e.data.saveData);
}
}
</script></body></html>