-
Notifications
You must be signed in to change notification settings - Fork 507
/
main.js
277 lines (229 loc) · 8.88 KB
/
main.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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
// QQPlay window need to be inited first
if (false) {
BK.Script.loadlib('GameRes://libs/qqplay-adapter.js');
}
var loadingBool = true;
var loadingNum = 0;
window.boot = function() {
var settings = window._CCSettings;
window._CCSettings = undefined;
if (!settings.debug) {
var uuids = settings.uuids;
var rawAssets = settings.rawAssets;
var assetTypes = settings.assetTypes;
var realRawAssets = settings.rawAssets = {};
for (var mount in rawAssets) {
var entries = rawAssets[mount];
var realEntries = realRawAssets[mount] = {};
for (var id in entries) {
var entry = entries[id];
var type = entry[1];
// retrieve minified raw asset
if (typeof type === 'number') {
entry[1] = assetTypes[type];
}
// retrieve uuid
realEntries[uuids[id] || id] = entry;
}
}
var scenes = settings.scenes;
for (var i = 0; i < scenes.length; ++i) {
var scene = scenes[i];
if (typeof scene.uuid === 'number') {
scene.uuid = uuids[scene.uuid];
}
}
var packedAssets = settings.packedAssets;
for (var packId in packedAssets) {
var packedIds = packedAssets[packId];
for (var j = 0; j < packedIds.length; ++j) {
if (typeof packedIds[j] === 'number') {
packedIds[j] = uuids[packedIds[j]];
}
}
}
var subpackages = settings.subpackages;
for (var subId in subpackages) {
var uuidArray = subpackages[subId].uuids;
if (uuidArray) {
for (var k = 0, l = uuidArray.length; k < l; k++) {
if (typeof uuidArray[k] === 'number') {
uuidArray[k] = uuids[uuidArray[k]];
}
}
}
}
}
function setLoadingDisplay() {
// Loading splash scene
var splash = document.getElementById('splash');
// var progressBar = splash.querySelector('.progress-bar span');
cc.loader.onProgress = function(completedCount, totalCount, item) {
loadData.completedCount = completedCount;
loadData.totalCount = totalCount;
if (loadingBool) {
var loadintT = document.getElementById("loadingText")
}
var percent = 100 * completedCount / totalCount;
if (loadingBool && loadingNum >= 1 && totalCount > 1) {
if (percent.toFixed(0) >= 100) {
loadintT.innerHTML = 'loading......100' + '%';
setTimeout(function() {
loadingBool = false;
loadintT.remove();
}, 0.1 * 1000);
clearInterval(timer);
}
}
loadingNum++;
// if(loadingBool){
// var loadintT = document.getElementById("loadingText")
// }
// var percent = 100 * completedCount / totalCount;
// if(loadingBool && loadingNum >= 1){
// console.log("dskpi",loadingNum);
// loadintT.innerHTML = 'loading......' + parseInt(percent) + '%';
// if(percent.toFixed(0) >= 100){
// loadingBool = false;
// loadintT.remove();
// }
// }
// loadingNum ++;
// var percent = 100 * completedCount / totalCount;
// if (progressBar) {
// progressBar.style.width = percent.toFixed(2) + '%';
// }
};
splash.style.display = 'block';
// progressBar.style.width = '0%';
cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function() {
splash.style.display = 'none';
});
}
var onStart = function() {
cc.loader.downloader._subpackages = settings.subpackages;
cc.view.enableRetina(true);
cc.view.resizeWithBrowserSize(true);
if (!false && !false) {
if (cc.sys.isBrowser) {
setLoadingDisplay();
}
if (cc.sys.isMobile) {
if (settings.orientation === 'landscape') {
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
} else if (settings.orientation === 'portrait') {
cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
}
// cc.view.enableAutoFullScreen([
// cc.sys.BROWSER_TYPE_BAIDU,
// cc.sys.BROWSER_TYPE_WECHAT,
// cc.sys.BROWSER_TYPE_MOBILE_QQ,
// cc.sys.BROWSER_TYPE_MIUI,
// ].indexOf(cc.sys.browserType) < 0);
cc.view.enableAutoFullScreen(false);
}
// Limit downloading max concurrent task to 2,
// more tasks simultaneously may cause performance draw back on some android system / browsers.
// You can adjust the number based on your own test result, you have to set it before any loading process to take effect.
if (cc.sys.isBrowser && cc.sys.os === cc.sys.OS_ANDROID) {
cc.macro.DOWNLOAD_MAX_CONCURRENT = 2;
}
}
// function loadScene(launchScene) {
// cc.director.loadScene(launchScene, null,
// function () {
// if (cc.sys.isBrowser) {
// // show canvas
// var canvas = document.getElementById('GameCanvas');
// canvas.style.visibility = '';
// var div = document.getElementById('GameDiv');
// if (div) {
// div.style.backgroundImage = '';
// }
// }
// cc.loader.onProgress = null;
// console.log('Success to load scene: ' + launchScene);
// }
// );
// }
var launchScene = settings.launchScene;
// load scene
// loadScene(launchScene);
var canvas;
if (cc.sys.isBrowser) {
canvas = document.getElementById('GameCanvas');
}
var launchScene = settings.launchScene;
console.log("landscape,", launchScene);
var MainManger = __require("MainManage");
MainManger.init(launchScene, cc.sys.isBrowser, canvas.style.visibility);
};
// jsList
var jsList = settings.jsList;
if (false) {
BK.Script.loadlib();
} else {
var bundledScript = settings.debug ? 'src/project.dev.js' : 'src/project.js';
if (jsList) {
jsList = jsList.map(function(x) {
return 'src/' + x;
});
jsList.push(bundledScript);
} else {
jsList = [bundledScript];
}
}
var option = {
id: 'GameCanvas',
scenes: settings.scenes,
debugMode: settings.debug ? cc.debug.DebugMode.INFO : cc.debug.DebugMode.ERROR,
showFPS: !false && settings.debug,
frameRate: 60,
jsList: jsList,
groupList: settings.groupList,
collisionMatrix: settings.collisionMatrix,
}
// init assets
cc.AssetLibrary.init({
libraryPath: 'res/import',
rawAssetsBase: 'res/raw-',
rawAssets: settings.rawAssets,
packedAssets: settings.packedAssets,
md5AssetsMap: settings.md5AssetsMap,
subpackages: settings.subpackages
});
cc.game.run(option, onStart);
};
// main.js is qqplay and jsb platform entry file, so we must leave platform init code here
if (false) {
BK.Script.loadlib('GameRes://src/settings.js');
BK.Script.loadlib();
BK.Script.loadlib('GameRes://libs/qqplay-downloader.js');
var ORIENTATIONS = {
'portrait': 1,
'landscape left': 2,
'landscape right': 3
};
BK.Director.screenMode = ORIENTATIONS[window._CCSettings.orientation];
initAdapter();
cc.game.once(cc.game.EVENT_ENGINE_INITED, function() {
initRendererAdapter();
});
qqPlayDownloader.REMOTE_SERVER_ROOT = "";
var prevPipe = cc.loader.md5Pipe || cc.loader.assetLoader;
cc.loader.insertPipeAfter(prevPipe, qqPlayDownloader);
window.boot();
} else if (window.jsb) {
var isRuntime = (typeof loadRuntime === 'function');
if (isRuntime) {
require('src/settings.js');
require('src/cocos2d-runtime.js');
require('jsb-adapter/engine/index.js');
} else {
require('src/settings.js');
require('src/cocos2d-jsb.js');
require('jsb-adapter/jsb-engine.js');
}
cc.macro.CLEANUP_IMAGE_CACHE = true;
window.boot();
}