diff --git a/libs/loader.js b/libs/loader.js index 1395d34f..8ca0868f 100644 --- a/libs/loader.js +++ b/libs/loader.js @@ -305,6 +305,22 @@ loader.prototype.loadImagesFromZip = function (url, names, toSave, onprogress, o loader.prototype._loadAnimates_sync = function () { this._setStartLoadTipText("正在加载动画文件..."); + if (main.supportBunch) { + if (core.animates.length > 0) { + core.http('GET', '__all_animates__?v=' + main.version + '&id=' + core.animates.join(','), null, function (content) { + var u = content.split('@@@~~~###~~~@@@'); + for (var i = 0; i < core.animates.length; ++i) { + if (u[i] != '') { + core.material.animates[core.animates[i]] = core.loader._loadAnimate(u[i]); + } else { + console.error('无法找到动画文件' + core.animates[i] + '!'); + } + } + }, "text/plain; charset=x-user-defined"); + } + return; + } + core.animates.forEach(function (t) { core.http('GET', 'project/animates/' + t + ".animate?v=" + main.version, null, function (content) { core.material.animates[t] = core.loader._loadAnimate(content); diff --git a/main.js b/main.js index 88379e9d..d610691a 100644 --- a/main.js +++ b/main.js @@ -290,8 +290,19 @@ main.prototype.loadFloors = function (callback) { main.dom.mainTips.style.display = 'none'; callback(); } + return; } - else { + + // 高层塔优化 + var script = document.createElement('script'); + script.src = '__all_floors__.js?v=' + this.version + '&id=' + main.floorIds.join(','); + script.onload = function () { + main.dom.mainTips.style.display = 'none'; + main.supportBunch = true; + callback(); + } + script.onerror = script.onabort = script.ontimeout = function (e) { + console.clear(); for (var i = 0; i < main.floorIds.length; i++) { main.loadFloor(main.floorIds[i], function (modName) { main.setMainTipsText("楼层 " + modName + '.js 加载完毕'); @@ -300,8 +311,9 @@ main.prototype.loadFloors = function (callback) { callback(); } }); - } + } } + main.dom.body.appendChild(script); } ////// 加载某一个楼层 ////// diff --git a/server.py b/server.py index 04533e94..cad5e4a1 100644 --- a/server.py +++ b/server.py @@ -60,6 +60,28 @@ def get_file(path): def root(): return static_file('index.html') +@app.route('/__all_floors__.js', methods=['GET']) +def all_floors(): + ids = request.args.get('id', '').split(',') + if len(ids) == 0: + abort(404) + return None + return Response('\n'.join([get_file('project/floors/%s.js' % id) for id in ids]), mimetype = 'text/javascript') + +@app.route('/__all_animates__', methods=['GET']) +def all_animates(): + ids = request.args.get('id', '').split(',') + if len(ids) == 0: + abort(404) + return None + content = [] + for id in ids: + animate = 'project/animates/%s.animate' % id + if os.path.exists(animate): + content.append(get_file(animate)) + else: content.append('') + return '@@@~~~###~~~@@@'.join(content) + @app.route('/', methods=['GET']) def static_file(path): if os.path.isdir(path):