diff --git a/libs/actions.js b/libs/actions.js index 6b0313a4..f08502e9 100644 --- a/libs/actions.js +++ b/libs/actions.js @@ -84,7 +84,9 @@ actions.prototype.registerAction = function (action, name, func, priority) { ////// 注销一个用户交互行为 ////// actions.prototype.unregisterAction = function (action, name) { if (!this.actions[action]) return; - this.actions[action] = this.actions[action].filter(function (x) { return x.name != name; }); + this.actions[action] = this.actions[action].filter(function (x) { + return x.name != name; + }); } ////// 执行一个用户交互行为 ////// @@ -99,8 +101,8 @@ actions.prototype.doRegisteredAction = function (action) { } actions.prototype.checkReplaying = function () { - if (core.isReplaying()&&core.status.event.id!='save' - &&(core.status.event.id||"").indexOf('book')!=0&&core.status.event.id!='viewMaps') + if (core.isReplaying() && core.status.event.id != 'save' + && (core.status.event.id || "").indexOf('book') != 0 && core.status.event.id != 'viewMaps') return true; return false; } @@ -116,70 +118,70 @@ actions.prototype.onkeyDown = function (e) { } actions.prototype._sys_onkeyDown = function (e) { - if (!core.isset(core.status.holdingKeys))core.status.holdingKeys=[]; - var isArrow={37:true,38:true,39:true,40:true}[e.keyCode] - if(isArrow && !core.status.lockControl){ - for(var ii =0;ii=49 && e.keyCode<=51) - core.setReplaySpeed(e.keyCode-48); - else if (e.keyCode==52) + else if (e.keyCode >= 49 && e.keyCode <= 51) + core.setReplaySpeed(e.keyCode - 48); + else if (e.keyCode == 52) core.setReplaySpeed(6); - else if (e.keyCode==53) + else if (e.keyCode == 53) core.setReplaySpeed(12); - else if (e.keyCode==54) + else if (e.keyCode == 54) core.setReplaySpeed(24); return true; } } actions.prototype._sys_onkeyUp = function (e) { - var isArrow={37:true,38:true,39:true,40:true}[e.keyCode] - if(isArrow && !core.status.lockControl){ - for(var ii =0;ii0) { - var pos={'x':x,'y':y}; - var pos0=core.status.stepPostfix[core.status.stepPostfix.length-1]; - var directionDistance=[pos.y-pos0.y,pos0.x-pos.x,pos0.y-pos.y,pos.x-pos0.x]; - var max=0,index=4; - for(var ii=0;ii<4;ii++){ - if(directionDistance[ii]>max){ - index=ii; - max=directionDistance[ii]; + if ((core.status.stepPostfix || []).length > 0) { + var pos = {'x': x, 'y': y}; + var pos0 = core.status.stepPostfix[core.status.stepPostfix.length - 1]; + var directionDistance = [pos.y - pos0.y, pos0.x - pos.x, pos0.y - pos.y, pos.x - pos0.x]; + var max = 0, index = 4; + for (var ii = 0; ii < 4; ii++) { + if (directionDistance[ii] > max) { + index = ii; + max = directionDistance[ii]; } } - pos=[{'x':0,'y':1},{'x':-1,'y':0},{'x':0,'y':-1},{'x':1,'y':0},false][index] - if(pos){ - pos.x+=pos0.x; - pos.y+=pos0.y; + pos = [{'x': 0, 'y': 1}, {'x': -1, 'y': 0}, {'x': 0, 'y': -1}, {'x': 1, 'y': 0}, false][index] + if (pos) { + pos.x += pos0.x; + pos.y += pos0.y; core.status.stepPostfix.push(pos); core.fillPosWithPoint(pos); } @@ -499,31 +503,35 @@ actions.prototype._sys_onup = function () { clearInterval(core.interval.onDownInterval); core.interval.onDownInterval = null; - if ((core.status.stepPostfix||[]).length == 0) return false; + if ((core.status.stepPostfix || []).length == 0) return false; var stepPostfix = []; - var direction={'0':{'1':'down','-1':'up'},'-1':{'0':'left'},'1':{'0':'right'}}; - for(var ii=1;ii=1000) { + if (!core.status.lockControl && stepPostfix.length == 0 && core.status.downTime != null && new Date() - core.status.downTime >= 1000) { this.longClick(posx, posy); } else { //posx,posy是寻路的目标点,stepPostfix是后续的移动 - this.onclick(posx,posy,stepPostfix); + this.onclick(posx, posy, stepPostfix); } - core.status.downTime=null; + core.status.downTime = null; return true; } @@ -545,7 +553,7 @@ actions.prototype.getClickLoc = function (x, y) { var left = core.dom.gameGroup.offsetLeft + statusBar.x; var top = core.dom.gameGroup.offsetTop + statusBar.y; - var loc={'x': x - left, 'y': y - top, 'size': size}; + var loc = {'x': x - left, 'y': y - top, 'size': size}; return loc; } @@ -562,72 +570,72 @@ actions.prototype._sys_onclick_lockControl = function (x, y) { this._clickCenterFly(x, y); break; case 'book': - this._clickBook(x,y); + this._clickBook(x, y); break; case 'book-detail': - this._clickBookDetail(x,y); + this._clickBookDetail(x, y); break; case 'fly': - this._clickFly(x,y); + this._clickFly(x, y); break; case 'viewMaps': - this._clickViewMaps(x,y); + this._clickViewMaps(x, y); break; case 'switchs': - this._clickSwitchs(x,y); + this._clickSwitchs(x, y); break; case 'settings': - this._clickSettings(x,y); + this._clickSettings(x, y); break; case 'shop': - this._clickShop(x,y); + this._clickShop(x, y); break; case 'selectShop': - this._clickQuickShop(x,y); + this._clickQuickShop(x, y); break; case 'equipbox': - this._clickEquipbox(x,y); + this._clickEquipbox(x, y); break; case 'toolbox': - this._clickToolbox(x,y); + this._clickToolbox(x, y); break; case 'save': case 'load': case 'replayLoad': - this._clickSL(x,y); + this._clickSL(x, y); break; case 'confirmBox': - this._clickConfirmBox(x,y); + this._clickConfirmBox(x, y); break; case 'keyBoard': - this._clickKeyBoard(x,y); + this._clickKeyBoard(x, y); break; case 'action': - this._clickAction(x,y); + this._clickAction(x, y); break; case 'text': core.drawText(); break; case 'syncSave': - this._clickSyncSave(x,y); + this._clickSyncSave(x, y); break; case 'syncSelect': - this._clickSyncSelect(x,y); + this._clickSyncSelect(x, y); break; case 'localSaveSelect': - this._clickLocalSaveSelect(x,y); + this._clickLocalSaveSelect(x, y); break; case 'storageRemove': - this._clickStorageRemove(x,y); + this._clickStorageRemove(x, y); break; case 'cursor': - this._clickCursor(x,y); + this._clickCursor(x, y); break; case 'replay': - this._clickReplay(x,y); + this._clickReplay(x, y); break; case 'gameInfo': - this._clickGameInfo(x,y); + this._clickGameInfo(x, y); break; case 'about': case 'help': @@ -639,7 +647,7 @@ actions.prototype._sys_onclick_lockControl = function (x, y) { actions.prototype._sys_onclick = function (x, y, stepPostfix) { // 寻路 - core.setAutomaticRoute(x+parseInt(core.bigmap.offsetX/32), y+parseInt(core.bigmap.offsetY/32), stepPostfix); + core.setAutomaticRoute(x + parseInt(core.bigmap.offsetX / 32), y + parseInt(core.bigmap.offsetY / 32), stepPostfix); return true; } @@ -653,36 +661,36 @@ actions.prototype._sys_onmousewheel = function (direct) { if (this.checkReplaying()) { // 滚轮控制速度 - if (direct==1) core.speedUpReplay(); - if (direct==-1) core.speedDownReplay(); + if (direct == 1) core.speedUpReplay(); + if (direct == -1) core.speedDownReplay(); return; } // 楼层飞行器 if (core.status.lockControl && core.status.event.id == 'fly') { - if (direct==1) core.ui.drawFly(this._getNextFlyFloor(1)); - if (direct==-1) core.ui.drawFly(this._getNextFlyFloor(-1)); + if (direct == 1) core.ui.drawFly(this._getNextFlyFloor(1)); + if (direct == -1) core.ui.drawFly(this._getNextFlyFloor(-1)); return; } // 怪物手册 if (core.status.lockControl && core.status.event.id == 'book') { - if (direct==1) core.ui.drawBook(core.status.event.data - 6); - if (direct==-1) core.ui.drawBook(core.status.event.data + 6); + if (direct == 1) core.ui.drawBook(core.status.event.data - 6); + if (direct == -1) core.ui.drawBook(core.status.event.data + 6); return; } // 存读档 if (core.status.lockControl && (core.status.event.id == 'save' || core.status.event.id == 'load')) { - if (direct==1) core.ui.drawSLPanel(core.status.event.data - 10); - if (direct==-1) core.ui.drawSLPanel(core.status.event.data + 10); + if (direct == 1) core.ui.drawSLPanel(core.status.event.data - 10); + if (direct == -1) core.ui.drawSLPanel(core.status.event.data + 10); return; } // 浏览地图 if (core.status.lockControl && core.status.event.id == 'viewMaps') { - if (direct==1) this._clickViewMaps(6,3); - if (direct==-1) this._clickViewMaps(6,9); + if (direct == 1) this._clickViewMaps(6, 3); + if (direct == -1) this._clickViewMaps(6, 9); return; } @@ -694,17 +702,17 @@ actions.prototype.keyDownCtrl = function () { } actions.prototype._sys_keyDownCtrl = function () { - if (core.status.event.id=='text') { + if (core.status.event.id == 'text') { core.drawText(); return true; } - if (core.status.event.id=='action' && core.status.event.data.type=='text') { + if (core.status.event.id == 'action' && core.status.event.data.type == 'text') { core.doAction(); return true; } - if (core.status.event.id=='action' && core.status.event.data.type=='sleep' + if (core.status.event.id == 'action' && core.status.event.data.type == 'sleep' && !core.status.event.data.current.noSkip) { - if (core.isset(core.timeout.sleepTimeout) && Object.keys(core.animateFrame.asyncId).length==0) { + if (core.isset(core.timeout.sleepTimeout) && Object.keys(core.animateFrame.asyncId).length == 0) { clearTimeout(core.timeout.sleepTimeout); core.timeout.sleepTimeout = null; core.doAction(); @@ -765,34 +773,34 @@ actions.prototype._sys_longClick = function (x, y, fromEvent) { // 数字键快速选择选项 actions.prototype._selectChoices = function (length, keycode, callback) { var topIndex = 6 - parseInt((length - 1) / 2); - if (keycode==13 || keycode==32 || keycode==67) { - callback(6, topIndex+core.status.event.selection); + if (keycode == 13 || keycode == 32 || keycode == 67) { + callback(6, topIndex + core.status.event.selection); } - if (keycode>=49 && keycode<=57) { - var index = keycode-49; + if (keycode >= 49 && keycode <= 57) { + var index = keycode - 49; if (index < length) { - callback(6, topIndex+index); + callback(6, topIndex + index); } } } // 上下键调整选项 actions.prototype._keyDownChoices = function (keycode) { - if (keycode==38) { + if (keycode == 38) { core.status.event.selection--; core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); } - if (keycode==40) { + if (keycode == 40) { core.status.event.selection++; core.ui.drawChoices(core.status.event.ui.text, core.status.event.ui.choices); } } ////// 点击中心对称飞行器时 -actions.prototype._clickCenterFly = function(x, y) { +actions.prototype._clickCenterFly = function (x, y) { var posX = core.status.event.data.posX, posY = core.status.event.data.posY; core.ui.closePanel(); - if (x==posX&& y==posY) { + if (x == posX && y == posY) { if (core.canUseItem('centerFly')) { core.useItem('centerFly'); } @@ -804,7 +812,7 @@ actions.prototype._clickCenterFly = function(x, y) { actions.prototype._keyUpCenterFly = function (keycode) { core.ui.closePanel(); - if (keycode==51 || keycode==13 || keycode==32 || keycode==67) { + if (keycode == 51 || keycode == 13 || keycode == 32 || keycode == 67) { if (core.canUseItem('centerFly')) { core.useItem('centerFly'); } @@ -815,7 +823,7 @@ actions.prototype._keyUpCenterFly = function (keycode) { } ////// 点击确认框时 ////// -actions.prototype._clickConfirmBox = function (x,y) { +actions.prototype._clickConfirmBox = function (x, y) { if ((x == 4 || x == 5) && y == 7 && core.isset(core.status.event.data.yes)) core.status.event.data.yes(); if ((x == 7 || x == 8) && y == 7 && core.isset(core.status.event.data.no)) @@ -824,26 +832,26 @@ actions.prototype._clickConfirmBox = function (x,y) { ////// 键盘操作确认框时 ////// actions.prototype._keyUpConfirmBox = function (keycode) { - if (keycode==37) { - core.status.event.selection=0; + if (keycode == 37) { + core.status.event.selection = 0; core.ui.drawConfirmBox(core.status.event.ui, core.status.event.data.yes, core.status.event.data.no); return; } - if (keycode==39) { - core.status.event.selection=1; + if (keycode == 39) { + core.status.event.selection = 1; core.ui.drawConfirmBox(core.status.event.ui, core.status.event.data.yes, core.status.event.data.no); return; } - if (keycode==13 || keycode==32 || keycode==67) { - if (core.status.event.selection==0 && core.isset(core.status.event.data.yes)) { - core.status.event.selection=null; + if (keycode == 13 || keycode == 32 || keycode == 67) { + if (core.status.event.selection == 0 && core.isset(core.status.event.data.yes)) { + core.status.event.selection = null; core.status.event.data.yes(); return; } - if (core.status.event.selection==1 && core.isset(core.status.event.data.no)) { - core.status.event.selection=null; + if (core.status.event.selection == 1 && core.isset(core.status.event.data.no)) { + core.status.event.selection = null; core.status.event.data.no(); return; } @@ -851,11 +859,11 @@ actions.prototype._keyUpConfirmBox = function (keycode) { } ////// 自定义事件时的点击操作 ////// -actions.prototype._clickAction = function (x,y) { - if (core.status.event.data.type=='text') { +actions.prototype._clickAction = function (x, y) { + if (core.status.event.data.type == 'text') { // 打字机效果显示全部文字 - if (core.status.event.interval!=null) { + if (core.status.event.interval != null) { core.insertAction({"type": "text", "text": core.status.event.ui, "showAll": true}); } @@ -864,17 +872,17 @@ actions.prototype._clickAction = function (x,y) { return; } - if (core.status.event.data.type=='choices') { + if (core.status.event.data.type == 'choices') { // 选项 var data = core.status.event.data.current; var choices = data.choices; - if (choices.length==0) return; + if (choices.length == 0) return; if (x >= 5 && x <= 7) { var topIndex = 6 - parseInt((choices.length - 1) / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { // 选择 - core.status.route.push("choices:"+(y-topIndex)); - core.insertAction(choices[y-topIndex].action); + core.status.route.push("choices:" + (y - topIndex)); + core.insertAction(choices[y - topIndex].action); core.doAction(); } } @@ -883,39 +891,39 @@ actions.prototype._clickAction = function (x,y) { ////// 自定义事件时,按下某个键的操作 ////// actions.prototype._keyDownAction = function (keycode) { - if (core.status.event.data.type=='choices') { + if (core.status.event.data.type == 'choices') { this._keyDownChoices(keycode); } } ////// 自定义事件时,放开某个键的操作 ////// actions.prototype._keyUpAction = function (keycode) { - if (core.status.event.data.type=='text' && (keycode==13 || keycode==32 || keycode==67)) { + if (core.status.event.data.type == 'text' && (keycode == 13 || keycode == 32 || keycode == 67)) { // 打字机效果显示全部文字 - if (core.status.event.interval!=null) { + if (core.status.event.interval != null) { core.insertAction({"type": "text", "text": core.status.event.ui, "showAll": true}); } core.doAction(); return; } - if (core.status.event.data.type=='wait') { + if (core.status.event.data.type == 'wait') { core.setFlag('type', 0); core.setFlag('keycode', keycode); - core.status.route.push("input:"+keycode); + core.status.route.push("input:" + keycode); core.doAction(); return; } - if (core.status.event.data.type=='choices') { + if (core.status.event.data.type == 'choices') { var data = core.status.event.data.current; var choices = data.choices; - if (choices.length>0) { + if (choices.length > 0) { this._selectChoices(choices.length, keycode, this._clickAction); } } } ////// 怪物手册界面的点击操作 ////// -actions.prototype._clickBook = function(x,y) { +actions.prototype._clickBook = function (x, y) { // 上一页 if ((x == 3 || x == 4) && y == 12) { core.ui.drawBook(core.status.event.data - 6); @@ -927,7 +935,7 @@ actions.prototype._clickBook = function(x,y) { return; } // 返回 - if (x>=10 && x<=12 && y==12) { + if (x >= 10 && x <= 12 && y == 12) { if (core.events.recoverEvents(core.status.event.interval)) { return; } @@ -940,9 +948,9 @@ actions.prototype._clickBook = function(x,y) { } // 怪物信息 var data = core.status.event.data; - if (core.isset(data) && y<12) { - var page=parseInt(data/6); - var index=6*page+parseInt(y/2); + if (core.isset(data) && y < 12) { + var page = parseInt(data / 6); + var index = 6 * page + parseInt(y / 2); core.ui.drawBook(index); core.ui.drawBookDetail(index); } @@ -951,18 +959,18 @@ actions.prototype._clickBook = function(x,y) { ////// 怪物手册界面时,按下某个键的操作 ////// actions.prototype._keyDownBook = function (keycode) { - if (keycode==37) core.ui.drawBook(core.status.event.data-6); - if (keycode==38) core.ui.drawBook(core.status.event.data-1); - if (keycode==39) core.ui.drawBook(core.status.event.data+6); - if (keycode==40) core.ui.drawBook(core.status.event.data+1); - if (keycode==33) core.ui.drawBook(core.status.event.data-6); - if (keycode==34) core.ui.drawBook(core.status.event.data+6); + if (keycode == 37) core.ui.drawBook(core.status.event.data - 6); + if (keycode == 38) core.ui.drawBook(core.status.event.data - 1); + if (keycode == 39) core.ui.drawBook(core.status.event.data + 6); + if (keycode == 40) core.ui.drawBook(core.status.event.data + 1); + if (keycode == 33) core.ui.drawBook(core.status.event.data - 6); + if (keycode == 34) core.ui.drawBook(core.status.event.data + 6); return; } ////// 怪物手册界面时,放开某个键的操作 ////// actions.prototype._keyUpBook = function (keycode) { - if (keycode==27 || keycode==88) { + if (keycode == 27 || keycode == 88) { if (core.events.recoverEvents(core.status.event.interval)) { return; } @@ -973,10 +981,10 @@ actions.prototype._keyUpBook = function (keycode) { else core.ui.closePanel(); return; } - if (keycode==13 || keycode==32 || keycode==67) { - var data=core.status.event.data; + if (keycode == 13 || keycode == 32 || keycode == 67) { + var data = core.status.event.data; if (core.isset(data)) { - this._clickBook(6, 2*(data%6)); + this._clickBook(6, 2 * (data % 6)); } return; } @@ -989,23 +997,23 @@ actions.prototype._clickBookDetail = function () { } ////// 楼层传送器界面时的点击操作 ////// -actions.prototype._clickFly = function(x,y) { - if ((x==10 || x==11) && y==9) core.ui.drawFly(this._getNextFlyFloor(-1)); - if ((x==10 || x==11) && y==5) core.ui.drawFly(this._getNextFlyFloor(1)); - if ((x==10 || x==11) && y==10) core.ui.drawFly(this._getNextFlyFloor(-10)); - if ((x==10 || x==11) && y==4) core.ui.drawFly(this._getNextFlyFloor(10)); - if (x>=5 && x<=7 && y==12) core.ui.closePanel(); - if (x>=0 && x<=9 && y>=3 && y<=11) +actions.prototype._clickFly = function (x, y) { + if ((x == 10 || x == 11) && y == 9) core.ui.drawFly(this._getNextFlyFloor(-1)); + if ((x == 10 || x == 11) && y == 5) core.ui.drawFly(this._getNextFlyFloor(1)); + if ((x == 10 || x == 11) && y == 10) core.ui.drawFly(this._getNextFlyFloor(-10)); + if ((x == 10 || x == 11) && y == 4) core.ui.drawFly(this._getNextFlyFloor(10)); + if (x >= 5 && x <= 7 && y == 12) core.ui.closePanel(); + if (x >= 0 && x <= 9 && y >= 3 && y <= 11) core.control.flyTo(core.floorIds[core.status.event.data]); return; } ////// 楼层传送器界面时,按下某个键的操作 ////// actions.prototype._keyDownFly = function (keycode) { - if (keycode==37) core.ui.drawFly(this._getNextFlyFloor(-10)); - else if (keycode==38) core.ui.drawFly(this._getNextFlyFloor(1)); - else if (keycode==39) core.ui.drawFly(this._getNextFlyFloor(10)); - else if (keycode==40) core.ui.drawFly(this._getNextFlyFloor(-1)); + if (keycode == 37) core.ui.drawFly(this._getNextFlyFloor(-10)); + else if (keycode == 38) core.ui.drawFly(this._getNextFlyFloor(1)); + else if (keycode == 39) core.ui.drawFly(this._getNextFlyFloor(10)); + else if (keycode == 40) core.ui.drawFly(this._getNextFlyFloor(-1)); return; } @@ -1030,15 +1038,15 @@ actions.prototype._getNextFlyFloor = function (delta, index) { ////// 楼层传送器界面时,放开某个键的操作 ////// actions.prototype._keyUpFly = function (keycode) { - if (keycode==71 || keycode==27 || keycode==88) + if (keycode == 71 || keycode == 27 || keycode == 88) core.ui.closePanel(); - if (keycode==13 || keycode==32 || keycode==67) - this._clickFly(5,5); + if (keycode == 13 || keycode == 32 || keycode == 67) + this._clickFly(5, 5); return; } ////// 查看地图界面时的点击操作 ////// -actions.prototype._clickViewMaps = function (x,y) { +actions.prototype._clickViewMaps = function (x, y) { if (!core.isset(core.status.event.data)) { core.ui.drawMaps(core.floorIds.indexOf(core.status.floorId)); return; @@ -1049,54 +1057,54 @@ actions.prototype._clickViewMaps = function (x,y) { var cx = core.status.event.data.x, cy = core.status.event.data.y; var floorId = core.floorIds[index], mw = core.floors[floorId].width, mh = core.floors[floorId].height; - if (x==0 && y==0) { + if (x == 0 && y == 0) { core.status.event.data.damage = !core.status.event.data.damage; core.ui.drawMaps(index, cx, cy); return; } - if (x==0 && y==12) { + if (x == 0 && y == 12) { core.status.event.data.paint = !core.status.event.data.paint; core.ui.drawMaps(index, cx, cy); return; } - if (x==12 && y==0) { + if (x == 12 && y == 0) { core.status.event.data.all = !core.status.event.data.all; core.ui.drawMaps(index, cx, cy); return; } - if (x>=2 && x<=10 && y<=1 && mh>13) { - core.ui.drawMaps(index, cx, cy-1); + if (x >= 2 && x <= 10 && y <= 1 && mh > 13) { + core.ui.drawMaps(index, cx, cy - 1); return; } - if (x>=2 && x<=10 && y>=11 && mh>13) { - core.ui.drawMaps(index, cx, cy+1); + if (x >= 2 && x <= 10 && y >= 11 && mh > 13) { + core.ui.drawMaps(index, cx, cy + 1); return; } - if (x<=1 && y>=2 && y<=10) { - core.ui.drawMaps(index, cx-1, cy); + if (x <= 1 && y >= 2 && y <= 10) { + core.ui.drawMaps(index, cx - 1, cy); return; } - if (x>=11 && y>=2 && y<=10) { - core.ui.drawMaps(index, cx+1, cy); + if (x >= 11 && y >= 2 && y <= 10) { + core.ui.drawMaps(index, cx + 1, cy); return; } - if(y<=4 && (mh==13 || (x>=2 && x<=10))) { + if (y <= 4 && (mh == 13 || (x >= 2 && x <= 10))) { index++; - while (index=8 && (mh==13 || (x>=2 && x<=10))) { + else if (y >= 8 && (mh == 13 || (x >= 2 && x <= 10))) { index--; - while (index>=0 && index!=now && core.status.maps[core.floorIds[index]].cannotViewMap) + while (index >= 0 && index != now && core.status.maps[core.floorIds[index]].cannotViewMap) index--; - if (index>=0) + if (index >= 0) core.ui.drawMaps(index); } - else if (x>=2 && x<=10 && y>=5 && y<=7) { + else if (x >= 2 && x <= 10 && y >= 5 && y <= 7) { core.clearMap('data'); core.ui.closePanel(); } @@ -1108,12 +1116,12 @@ actions.prototype._keyDownViewMaps = function (keycode) { var floorId = core.floorIds[core.status.event.data.index], mh = core.floors[floorId].height; - if (keycode==38||keycode==33) this._clickViewMaps(6, 3); - if (keycode==40||keycode==34) this._clickViewMaps(6, 9); - if (keycode==87 && mh>13) this._clickViewMaps(6,0); - if (keycode==65) this._clickViewMaps(0,6); - if (keycode==83 && mh>13) this._clickViewMaps(6,12); - if (keycode==68) this._clickViewMaps(12,6); + if (keycode == 38 || keycode == 33) this._clickViewMaps(6, 3); + if (keycode == 40 || keycode == 34) this._clickViewMaps(6, 9); + if (keycode == 87 && mh > 13) this._clickViewMaps(6, 0); + if (keycode == 65) this._clickViewMaps(0, 6); + if (keycode == 83 && mh > 13) this._clickViewMaps(6, 12); + if (keycode == 68) this._clickViewMaps(12, 6); return; } @@ -1124,27 +1132,27 @@ actions.prototype._keyUpViewMaps = function (keycode) { return; } - if (keycode==27 || keycode==13 || keycode==32 || (!core.isReplaying() && keycode==67)) { + if (keycode == 27 || keycode == 13 || keycode == 32 || (!core.isReplaying() && keycode == 67)) { core.clearMap('data'); core.ui.closePanel(); return; } - if (keycode==86) { + if (keycode == 86) { core.status.event.data.damage = !core.status.event.data.damage; core.ui.drawMaps(core.status.event.data); return; } - if (keycode==90) { + if (keycode == 90) { core.status.event.data.all = !core.status.event.data.all; core.ui.drawMaps(core.status.event.data); return; } - if (keycode==77) { + if (keycode == 77) { core.status.event.data.paint = !core.status.event.data.paint; core.ui.drawMaps(core.status.event.data); return; } - if (keycode==88 || (core.isReplaying() && keycode==67)) { + if (keycode == 88 || (core.isReplaying() && keycode == 67)) { if (core.isReplaying()) { core.bookReplay(); } else { @@ -1156,16 +1164,16 @@ actions.prototype._keyUpViewMaps = function (keycode) { } ////// 商店界面时的点击操作 ////// -actions.prototype._clickShop = function(x,y) { +actions.prototype._clickShop = function (x, y) { var shop = core.status.event.data.shop; var choices = shop.choices; if (x >= 5 && x <= 7) { var topIndex = 6 - parseInt(choices.length / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { + return core.events._useShop(shop, y - topIndex); } // 离开 - else if (y==topIndex+choices.length) { + else if (y == topIndex + choices.length) { core.events._exitShop(); } else return false; @@ -1175,56 +1183,60 @@ actions.prototype._clickShop = function(x,y) { ////// 商店界面时,放开某个键的操作 ////// actions.prototype._keyUpShop = function (keycode) { - if (keycode==27 || keycode==88) { + if (keycode == 27 || keycode == 88) { core.events._exitShop(); return; } - this._selectChoices(core.status.event.data.shop.choices.length+1, keycode, this._clickShop); + this._selectChoices(core.status.event.data.shop.choices.length + 1, keycode, this._clickShop); return; } ////// 快捷商店界面时的点击操作 ////// -actions.prototype._clickQuickShop = function(x, y) { - var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {return shopList[shopId].visited || !shopList[shopId].mustEnable}); +actions.prototype._clickQuickShop = function (x, y) { + var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) { + return shopList[shopId].visited || !shopList[shopId].mustEnable + }); if (x >= 5 && x <= 7) { var topIndex = 6 - parseInt(keys.length / 2); - if (y>=topIndex && y= topIndex && y < topIndex + keys.length) { var reason = core.events.canUseQuickShop(keys[y - topIndex]); if (!core.flags.enableDisabledShop && core.isset(reason)) { core.drawText(reason); return; } core.events.openShop(keys[y - topIndex], true); - if (core.status.event.id=='shop') + if (core.status.event.id == 'shop') core.status.event.data.fromList = true; } // 离开 - else if (y==topIndex+keys.length) + else if (y == topIndex + keys.length) core.ui.closePanel(); } } ////// 快捷商店界面时,放开某个键的操作 ////// actions.prototype._keyUpQuickShop = function (keycode) { - if (keycode==27 || keycode==75 || keycode==88 || keycode==86) { + if (keycode == 27 || keycode == 75 || keycode == 88 || keycode == 86) { core.ui.closePanel(); return; } - var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) {return shopList[shopId].visited || !shopList[shopId].mustEnable}); - this._selectChoices(keys.length+1, keycode, this._clickQuickShop); + var shopList = core.status.shops, keys = Object.keys(shopList).filter(function (shopId) { + return shopList[shopId].visited || !shopList[shopId].mustEnable + }); + this._selectChoices(keys.length + 1, keycode, this._clickQuickShop); return; } ////// 工具栏界面时的点击操作 ////// -actions.prototype._clickToolbox = function(x,y) { +actions.prototype._clickToolbox = function (x, y) { // 装备栏 - if (x>=10 && x<=12 && y==0) { + if (x >= 10 && x <= 12 && y == 0) { core.ui.closePanel(); core.openEquipbox(); return; } // 返回 - if (x>=10 && x<=12 && y==12) { + if (x >= 10 && x <= 12 && y == 12) { core.ui.closePanel(); return; } @@ -1232,54 +1244,55 @@ actions.prototype._clickToolbox = function(x,y) { var constantsPage = core.status.event.data.constantsPage; // 上一页 if (x == 3 || x == 4) { - if (y == 7 && toolsPage>1) { + if (y == 7 && toolsPage > 1) { core.status.event.data.toolsPage--; core.ui.drawToolbox(core.status.event.selection); } - if (y == 12 && constantsPage>1) { + if (y == 12 && constantsPage > 1) { core.status.event.data.toolsPage--; core.ui.drawToolbox(core.status.event.selection); } } // 下一页 if (x == 8 || x == 9) { - if (y == 7 && toolsPage=0) + if (index >= 0) this._clickToolboxIndex(index); } ////// 选择工具栏界面中某个Index后的操作 ////// -actions.prototype._clickToolboxIndex = function(index) { +actions.prototype._clickToolboxIndex = function (index) { var items = null; var select; - if (index<12) { - select = index + 12 * (core.status.event.data.toolsPage-1); + if (index < 12) { + select = index + 12 * (core.status.event.data.toolsPage - 1); items = Object.keys(core.status.hero.items.tools).sort(); } else { - select = index%12 + 12 * (core.status.event.data.constantsPage-1); + select = index % 12 + 12 * (core.status.event.data.constantsPage - 1); items = Object.keys(core.status.hero.items.constants).sort(); } - if (items==null) return; - if (select>=items.length) return; - var itemId=items[select]; - if (itemId==core.status.event.data.selectId) { + if (items == null) return; + if (select >= items.length) return; + var itemId = items[select]; + if (itemId == core.status.event.data.selectId) { core.events.tryUseItem(itemId); } else { @@ -1296,79 +1309,79 @@ actions.prototype._keyDownToolbox = function (keycode) { var index = core.status.event.selection; var toolsPage = core.status.event.data.toolsPage; var constantsPage = core.status.event.data.constantsPage; - var toolsTotalPage = Math.ceil(tools.length/12); - var constantsTotalPage = Math.ceil(constants.length/12); - var toolsLastIndex = toolsPage 1) { core.status.event.data.toolsPage--; index = 11; } else return; // 第一页不向前翻 } - else if (index==12) { + else if (index == 12) { if (constantsPage == 1) { - if (toolsTotalPage==0) return; + if (toolsTotalPage == 0) return; core.status.event.data.toolsPage = toolsTotalPage; - index = (tools.length+11)%12; + index = (tools.length + 11) % 12; } else { core.status.event.data.constantsPage--; index = 23; } } - else index -= 1 ; + else index -= 1; this._clickToolboxIndex(index); return; } - if (keycode==38) { // up - if (index>=12&&index<=17) { // 进入tools - if (toolsTotalPage==0) return; - if (toolsLastIndex>=6) index = Math.min(toolsLastIndex, index-6); - else index = Math.min(toolsLastIndex, index-12); + if (keycode == 38) { // up + if (index >= 12 && index <= 17) { // 进入tools + if (toolsTotalPage == 0) return; + if (toolsLastIndex >= 6) index = Math.min(toolsLastIndex, index - 6); + else index = Math.min(toolsLastIndex, index - 12); } - else if (index<6) return; // 第一行没有向上 + else if (index < 6) return; // 第一行没有向上 else index -= 6; this._clickToolboxIndex(index); return; } - if (keycode==39) { // right - if (toolsPage 5) nextIndex = Math.min(toolsLastIndex, index + 6); - else index+=6; + else index += 6; } - if (nextIndex==null && index<=11) { + if (nextIndex == null && index <= 11) { if (constantsTotalPage == 0) return; - nextIndex = Math.min(index+6, constantsLastIndex); + nextIndex = Math.min(index + 6, constantsLastIndex); } - if (nextIndex==null && index<=17) { - if (constantsLastIndex > 17) nextIndex = Math.min(constantsLastIndex, index+6); + if (nextIndex == null && index <= 17) { + if (constantsLastIndex > 17) nextIndex = Math.min(constantsLastIndex, index + 6); } - if (nextIndex!=null) { + if (nextIndex != null) { this._clickToolboxIndex(nextIndex); } return; @@ -1377,33 +1390,33 @@ actions.prototype._keyDownToolbox = function (keycode) { ////// 工具栏界面时,放开某个键的操作 ////// actions.prototype._keyUpToolbox = function (keycode) { - if (keycode==81){ + if (keycode == 81) { core.ui.closePanel(); core.openEquipbox(); return; } - if (keycode==84 || keycode==27 || keycode==88) { + if (keycode == 84 || keycode == 27 || keycode == 88) { core.ui.closePanel(); return; } if (!core.isset(core.status.event.data)) return; - if (keycode==13 || keycode==32 || keycode==67) { + if (keycode == 13 || keycode == 32 || keycode == 67) { this._clickToolboxIndex(core.status.event.selection); return; } } ////// 装备栏界面时的点击操作 ////// -actions.prototype._clickEquipbox = function(x,y) { +actions.prototype._clickEquipbox = function (x, y) { // 道具栏 - if (x>=10 && x<=12 && y==0) { + if (x >= 10 && x <= 12 && y == 0) { core.ui.closePanel(); core.openToolbox(); return; } // 返回 - if (x>=10 && x<=12 && y==12) { + if (x >= 10 && x <= 12 && y == 12) { core.ui.closePanel(); return; } @@ -1413,7 +1426,7 @@ actions.prototype._clickEquipbox = function(x,y) { // 上一页 if ((x == 3 || x == 4) && y == 12) { - if (page>1) { + if (page > 1) { core.status.event.data.page--; core.ui.drawEquipbox(core.status.event.selection); } @@ -1421,44 +1434,44 @@ actions.prototype._clickEquipbox = function(x,y) { } // 下一页 if ((x == 8 || x == 9) && y == 12) { - var lastPage = Math.ceil(Object.keys(core.status.hero.items.equips).length/12); - if (page=0) { - if (index<12) index = parseInt(index/2); + if (index >= 0) { + if (index < 12) index = parseInt(index / 2); this._clickEquipboxIndex(index); } } ////// 选择装备栏界面中某个Index后的操作 ////// -actions.prototype._clickEquipboxIndex = function(index) { - if (index<6) { - if (index>=core.status.globalAttribute.equipName.length) return; - if (index==core.status.event.selection && core.isset(core.status.hero.equipment[index])) { +actions.prototype._clickEquipboxIndex = function (index) { + if (index < 6) { + if (index >= core.status.globalAttribute.equipName.length) return; + if (index == core.status.event.selection && core.isset(core.status.hero.equipment[index])) { core.unloadEquip(index); - core.status.route.push("unEquip:"+index); + core.status.route.push("unEquip:" + index); } } - else if (index>=12) { - var equips = Object.keys(core.status.hero.items.equips||{}).sort(); - if (index==core.status.event.selection) { - var equipId = equips[index-12 + (core.status.event.data.page-1)*12]; + else if (index >= 12) { + var equips = Object.keys(core.status.hero.items.equips || {}).sort(); + if (index == core.status.event.selection) { + var equipId = equips[index - 12 + (core.status.event.data.page - 1) * 12]; core.loadEquip(equipId); - core.status.route.push("equip:"+equipId); + core.status.route.push("equip:" + equipId); } - } + } core.ui.drawEquipbox(index); } @@ -1470,12 +1483,12 @@ actions.prototype._keyDownEquipbox = function (keycode) { var ownEquipment = Object.keys(core.status.hero.items.equips).sort(); var index = core.status.event.selection; var page = core.status.event.data.page; - var totalPage = Math.ceil(ownEquipment.length/12); - var totalLastIndex = 12+(page 1) { core.status.event.data.page--; index = 23; @@ -1488,47 +1501,47 @@ actions.prototype._keyDownEquipbox = function (keycode) { this._clickEquipboxIndex(index); return; } - if (keycode==38) { // up - if (index<3) return; - else if (index<6) index -= 3; + if (keycode == 38) { // up + if (index < 3) return; + else if (index < 6) index -= 3; else if (index < 18) { - index = parseInt((index-12)/2); - if (equipCapacity>3) index = Math.min(equipCapacity-1, index + 3); - else index = Math.min(equipCapacity-1, index); + index = parseInt((index - 12) / 2); + if (equipCapacity > 3) index = Math.min(equipCapacity - 1, index + 3); + else index = Math.min(equipCapacity - 1, index); } else index -= 6; this._clickEquipboxIndex(index); return; } - if (keycode==39) { // right - if (page3) index = Math.min(index+3, equipCapacity-1); + if (keycode == 40) { // down + if (index < 3) { + if (equipCapacity > 3) index = Math.min(index + 3, equipCapacity - 1); else { if (totalPage == 0) return; - index = Math.min(2*index+1+12, totalLastIndex); + index = Math.min(2 * index + 1 + 12, totalLastIndex); } } else if (index < 6) { if (totalPage == 0) return; - index = Math.min(2*(index-3)+1+12, totalLastIndex); + index = Math.min(2 * (index - 3) + 1 + 12, totalLastIndex); } else if (index < 18) - index = Math.min(index+6, totalLastIndex); + index = Math.min(index + 6, totalLastIndex); else return; this._clickEquipboxIndex(index); return; @@ -1537,45 +1550,45 @@ actions.prototype._keyDownEquipbox = function (keycode) { ////// 装备栏界面时,放开某个键的操作 ////// actions.prototype._keyUpEquipbox = function (keycode, altKey) { - if (altKey && keycode>=48 && keycode<=57) { - core.items.quickSaveEquip(keycode-48); + if (altKey && keycode >= 48 && keycode <= 57) { + core.items.quickSaveEquip(keycode - 48); return; } - if (keycode==84){ + if (keycode == 84) { core.ui.closePanel(); core.openToolbox(); return; } - if (keycode==81 || keycode==27 || keycode==88) { + if (keycode == 81 || keycode == 27 || keycode == 88) { core.ui.closePanel(); return; } if (!core.isset(core.status.event.data.selectId)) return; - if (keycode==13 || keycode==32 || keycode==67) { + if (keycode == 13 || keycode == 32 || keycode == 67) { this._clickEquipboxIndex(core.status.event.selection); return; } } ////// 存读档界面时的点击操作 ////// -actions.prototype._clickSL = function(x,y) { +actions.prototype._clickSL = function (x, y) { - var index=core.status.event.data; - var page = parseInt(index/10), offset=index%10; + var index = core.status.event.data; + var page = parseInt(index / 10), offset = index % 10; // 上一页 if ((x == 3 || x == 4) && y == 12) { - core.ui.drawSLPanel(10*(page-1)+offset); + core.ui.drawSLPanel(10 * (page - 1) + offset); return; } // 下一页 if ((x == 8 || x == 9) && y == 12) { - core.ui.drawSLPanel(10*(page+1)+offset); + core.ui.drawSLPanel(10 * (page + 1) + offset); return; } // 返回 - if (x>=10 && x<=12 && y==12) { + if (x >= 10 && x <= 12 && y == 12) { if (core.events.recoverEvents(core.status.event.interval)) { return; } @@ -1586,42 +1599,42 @@ actions.prototype._clickSL = function(x,y) { return; } // 删除 - if (x>=0 && x<=2 && y==12) { + if (x >= 0 && x <= 2 && y == 12) { - if (core.status.event.id=='save') { - core.status.event.selection=!core.status.event.selection; + if (core.status.event.id == 'save') { + core.status.event.selection = !core.status.event.selection; core.ui.drawSLPanel(index); } else { - var index = parseInt(prompt("请输入读档编号"))||0; - if (index>0) { + var index = parseInt(prompt("请输入读档编号")) || 0; + if (index > 0) { core.doSL(index, core.status.event.id); } } return; } - var id=null; - if (y>=1 && y<=4) { - if (x>=1 && x<=3) id = "autoSave"; - if (x>=5 && x<=7) id = 5*page+1; - if (x>=9 && x<=11) id = 5*page+2; + var id = null; + if (y >= 1 && y <= 4) { + if (x >= 1 && x <= 3) id = "autoSave"; + if (x >= 5 && x <= 7) id = 5 * page + 1; + if (x >= 9 && x <= 11) id = 5 * page + 2; } - if (y>=7 && y<=10) { - if (x>=1 && x<=3) id = 5*page+3; - if (x>=5 && x<=7) id = 5*page+4; - if (x>=9 && x<=11) id = 5*page+5; + if (y >= 7 && y <= 10) { + if (x >= 1 && x <= 3) id = 5 * page + 3; + if (x >= 5 && x <= 7) id = 5 * page + 4; + if (x >= 9 && x <= 11) id = 5 * page + 5; } - if (id!=null) { - if (core.status.event.selection) { + if (id != null) { + if (core.status.event.selection) { if (id == 'autoSave') { core.drawTip("无法删除自动存档!"); } else { // core.removeLocalStorage("save"+id); - core.removeLocalForage("save"+id, function() { + core.removeLocalForage("save" + id, function () { core.ui.drawSLPanel(index, true); - }, function() { + }, function () { core.drawTip("无法删除存档!"); }) } @@ -1633,53 +1646,53 @@ actions.prototype._clickSL = function(x,y) { } ////// 存读档界面时,按下某个键的操作 ////// -actions.prototype._keyDownSL = function(keycode) { +actions.prototype._keyDownSL = function (keycode) { - var index=core.status.event.data; - var page = parseInt(index/10), offset=index%10; + var index = core.status.event.data; + var page = parseInt(index / 10), offset = index % 10; - if (keycode==37) { // left - if (offset==0) { - core.ui.drawSLPanel(10*(page-1) + 5); + if (keycode == 37) { // left + if (offset == 0) { + core.ui.drawSLPanel(10 * (page - 1) + 5); } else { core.ui.drawSLPanel(index - 1); } return; } - if (keycode==38) { // up - if (offset<3) { - core.ui.drawSLPanel(10*(page-1) + offset + 3); + if (keycode == 38) { // up + if (offset < 3) { + core.ui.drawSLPanel(10 * (page - 1) + offset + 3); } else { core.ui.drawSLPanel(index - 3); } return; } - if (keycode==39) { // right - if (offset==5) { - core.ui.drawSLPanel(10*(page+1)+1); + if (keycode == 39) { // right + if (offset == 5) { + core.ui.drawSLPanel(10 * (page + 1) + 1); } else { core.ui.drawSLPanel(index + 1); } return; } - if (keycode==40) { // down - if (offset>=3) { - core.ui.drawSLPanel(10*(page+1) + offset - 3); + if (keycode == 40) { // down + if (offset >= 3) { + core.ui.drawSLPanel(10 * (page + 1) + offset - 3); } else { core.ui.drawSLPanel(index + 3); } return; } - if (keycode==33) { // PAGEUP - core.ui.drawSLPanel(10*(page-1) + offset); + if (keycode == 33) { // PAGEUP + core.ui.drawSLPanel(10 * (page - 1) + offset); return; } - if (keycode==34) { // PAGEDOWN - core.ui.drawSLPanel(10*(page+1) + offset); + if (keycode == 34) { // PAGEDOWN + core.ui.drawSLPanel(10 * (page + 1) + offset); return; } } @@ -1687,10 +1700,10 @@ actions.prototype._keyDownSL = function(keycode) { ////// 存读档界面时,放开某个键的操作 ////// actions.prototype._keyUpSL = function (keycode) { - var index=core.status.event.data; - var page = parseInt(index/10), offset=index%10; + var index = core.status.event.data; + var page = parseInt(index / 10), offset = index % 10; - if (keycode==27 || keycode==88 || (core.status.event.id == 'save' && keycode==83) || (core.status.event.id == 'load' && keycode==68)) { + if (keycode == 27 || keycode == 88 || (core.status.event.id == 'save' && keycode == 83) || (core.status.event.id == 'load' && keycode == 68)) { if (core.events.recoverEvents(core.status.event.interval)) { return; } @@ -1700,32 +1713,32 @@ actions.prototype._keyUpSL = function (keycode) { } return; } - if (keycode==13 || keycode==32 || keycode==67) { - if (offset==0) { + if (keycode == 13 || keycode == 32 || keycode == 67) { + if (offset == 0) { core.doSL("autoSave", core.status.event.id); } else { - core.doSL(5*page+offset, core.status.event.id); + core.doSL(5 * page + offset, core.status.event.id); } return; } - if (keycode==69 && core.status.event.id == 'load') { // E - var index = parseInt(prompt("请输入读档编号"))||0; - if (index>0) { + if (keycode == 69 && core.status.event.id == 'load') { // E + var index = parseInt(prompt("请输入读档编号")) || 0; + if (index > 0) { core.doSL(index, core.status.event.id); } return; } - if (keycode==46) { - if (offset==0) { + if (keycode == 46) { + if (offset == 0) { core.drawTip("无法删除自动存档!"); } else { // core.removeLocalStorage("save"+(5*page+offset)); // core.ui.drawSLPanel(index); - core.removeLocalForage("save"+(5*page+offset), function() { + core.removeLocalForage("save" + (5 * page + offset), function () { core.ui.drawSLPanel(index, true); - }, function() { + }, function () { core.drawTip("无法删除存档!"); }) } @@ -1733,12 +1746,12 @@ actions.prototype._keyUpSL = function (keycode) { } ////// 系统设置界面时的点击操作 ////// -actions.prototype._clickSwitchs = function (x,y) { - if (x<5 || x>7) return; +actions.prototype._clickSwitchs = function (x, y) { + if (x < 5 || x > 7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { + var selection = y - topIndex; switch (selection) { case 0: core.triggerBgm(); @@ -1750,25 +1763,25 @@ actions.prototype._clickSwitchs = function (x,y) { core.ui.drawSwitchs(); break; case 2: - core.flags.displayEnemyDamage=!core.flags.displayEnemyDamage; + core.flags.displayEnemyDamage = !core.flags.displayEnemyDamage; core.updateDamage(); core.setLocalStorage('enemyDamage', core.flags.displayEnemyDamage); core.ui.drawSwitchs(); break; case 3: - core.flags.displayCritical=!core.flags.displayCritical; + core.flags.displayCritical = !core.flags.displayCritical; core.updateDamage(); core.setLocalStorage('critical', core.flags.displayCritical); core.ui.drawSwitchs(); break; case 4: - core.flags.displayExtraDamage=!core.flags.displayExtraDamage; + core.flags.displayExtraDamage = !core.flags.displayExtraDamage; core.updateDamage(); core.setLocalStorage('extraDamage', core.flags.displayExtraDamage); core.ui.drawSwitchs(); break; case 5: - core.platform.useLocalForage=!core.platform.useLocalForage; + core.platform.useLocalForage = !core.platform.useLocalForage; core.setLocalStorage('useLocalForage', core.platform.useLocalForage); core.control.getSaveIndexes(function (indexes) { core.saves.ids = indexes; @@ -1786,7 +1799,7 @@ actions.prototype._clickSwitchs = function (x,y) { core.ui.drawSwitchs(); break; case 8: - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawSettings(); break; } @@ -1795,8 +1808,8 @@ actions.prototype._clickSwitchs = function (x,y) { ////// 系统设置界面时,放开某个键的操作 ////// actions.prototype._keyUpSwitchs = function (keycode) { - if (keycode==27 || keycode==88) { - core.status.event.selection=0; + if (keycode == 27 || keycode == 88) { + core.status.event.selection = 0; core.ui.drawSettings(); return; } @@ -1804,16 +1817,16 @@ actions.prototype._keyUpSwitchs = function (keycode) { } ////// 系统菜单栏界面时的点击事件 ////// -actions.prototype._clickSettings = function (x,y) { - if (x<5 || x>7) return; +actions.prototype._clickSettings = function (x, y) { + if (x < 5 || x > 7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { + var selection = y - topIndex; switch (selection) { case 0: - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawSwitchs(); break; case 1: @@ -1828,20 +1841,20 @@ actions.prototype._clickSettings = function (x,y) { core.ui.drawPaint(); break; case 4: - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawSyncSave(); break; case 5: - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawGameInfo(); break; case 6: - core.status.event.selection=1; + core.status.event.selection = 1; core.ui.drawConfirmBox("你确定要返回标题页面吗?", function () { core.ui.closePanel(); core.restart(); }, function () { - core.status.event.selection=3; + core.status.event.selection = 3; core.ui.drawSettings(); }); break; @@ -1855,7 +1868,7 @@ actions.prototype._clickSettings = function (x,y) { ////// 系统菜单栏界面时,放开某个键的操作 ////// actions.prototype._keyUpSettings = function (keycode) { - if (keycode==27 || keycode==88) { + if (keycode == 27 || keycode == 88) { core.ui.closePanel(); return; } @@ -1863,32 +1876,32 @@ actions.prototype._keyUpSettings = function (keycode) { } ////// 同步存档界面时的点击操作 ////// -actions.prototype._clickSyncSave = function (x,y) { - if (x<5 || x>7) return; +actions.prototype._clickSyncSave = function (x, y) { + if (x < 5 || x > 7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { + var selection = y - topIndex; switch (selection) { case 0: // core.syncSave("save"); - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawSyncSelect(); break; case 1: core.syncLoad(); break; case 2: - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawLocalSaveSelect(); break; case 3: core.readFile(function (obj) { - if (obj.name!=core.firstData.name) { + if (obj.name != core.firstData.name) { alert("存档和游戏不一致!"); return; } - if (obj.version!=core.firstData.version) { + if (obj.version != core.firstData.version) { alert("游戏版本不一致!"); return; } @@ -1896,30 +1909,30 @@ actions.prototype._clickSyncSave = function (x,y) { alert("无效的存档!"); return; } - var data=obj.data; + var data = obj.data; if (data instanceof Array) { core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?", function () { - for (var i=1;i<=5*(main.savePages||30);i++) { - if (i<=data.length) { - core.setLocalForage("save"+i, data[i-1]); + for (var i = 1; i <= 5 * (main.savePages || 30); i++) { + if (i <= data.length) { + core.setLocalForage("save" + i, data[i - 1]); } else { if (core.saves.ids[i]) - core.removeLocalForage("save"+i); + core.removeLocalForage("save" + i); } } core.ui.closePanel(); core.drawText("读取成功!\n你的本地所有存档均已被覆盖。"); }, function () { - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawSyncSave(); }) } else { // core.setLocalStorage("save"+core.saves.saveIndex, data); - core.setLocalForage("save"+core.saves.saveIndex, data, function() { - core.drawText("同步成功!\n单存档已覆盖至存档"+core.saves.saveIndex); + core.setLocalForage("save" + core.saves.saveIndex, data, function () { + core.drawText("同步成功!\n单存档已覆盖至存档" + core.saves.saveIndex); }) } }, function () { @@ -1927,7 +1940,7 @@ actions.prototype._clickSyncSave = function (x,y) { }); break; case 4: - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawReplay(); break; case 5: @@ -1935,7 +1948,7 @@ actions.prototype._clickSyncSave = function (x,y) { core.drawText("\t[系统提示]调试模式下无法下载录像"); break; } - core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5route", JSON.stringify({ + core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route", JSON.stringify({ 'name': core.firstData.name, 'hard': core.status.hard, 'seed': core.getFlag('__seed__'), @@ -1943,11 +1956,11 @@ actions.prototype._clickSyncSave = function (x,y) { })); break; case 6: - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawStorageRemove(); break; case 7: - core.status.event.selection=4; + core.status.event.selection = 4; core.ui.drawSettings(); break; @@ -1958,8 +1971,8 @@ actions.prototype._clickSyncSave = function (x,y) { ////// 同步存档界面时,放开某个键的操作 ////// actions.prototype._keyUpSyncSave = function (keycode) { - if (keycode==27 || keycode==88) { - core.status.event.selection=2; + if (keycode == 27 || keycode == 88) { + core.status.event.selection = 2; core.ui.drawSettings(); return; } @@ -1968,11 +1981,11 @@ actions.prototype._keyUpSyncSave = function (keycode) { ////// 同步存档选择界面时的点击操作 ////// actions.prototype._clickSyncSelect = function (x, y) { - if (x<5 || x>7) return; + if (x < 5 || x > 7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; switch (selection) { case 0: @@ -1982,7 +1995,7 @@ actions.prototype._clickSyncSelect = function (x, y) { core.syncSave(); break; case 2: - core.status.event.selection=0; + core.status.event.selection = 0; core.ui.drawSyncSave(); break; } @@ -1991,8 +2004,8 @@ actions.prototype._clickSyncSelect = function (x, y) { ////// 同步存档选择界面时,放开某个键的操作 ////// actions.prototype._keyUpSyncSelect = function (keycode) { - if (keycode==27 || keycode==88) { - core.status.event.selection=0; + if (keycode == 27 || keycode == 88) { + core.status.event.selection = 0; core.ui.drawSettings(); return; } @@ -2000,36 +2013,36 @@ actions.prototype._keyUpSyncSelect = function (keycode) { } ////// 存档下载界面时的点击操作 ////// -actions.prototype._clickLocalSaveSelect = function (x,y) { - if (x<5 || x>7) return; +actions.prototype._clickLocalSaveSelect = function (x, y) { + if (x < 5 || x > 7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; - if (selection<2) { - core.control.getSaves(selection==0?null:core.saves.saveIndex, function(saves) { + if (selection < 2) { + core.control.getSaves(selection == 0 ? null : core.saves.saveIndex, function (saves) { if (core.isset(saves)) { var content = { "name": core.firstData.name, "version": core.firstData.version, "data": saves } - core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5save", JSON.stringify(content)); + core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5save", JSON.stringify(content)); } }) } } - core.status.event.selection=2; + core.status.event.selection = 2; core.ui.drawSyncSave(); } ////// 存档下载界面时,放开某个键的操作 ////// actions.prototype._keyUpLocalSaveSelect = function (keycode) { - if (keycode==27 || keycode==88) { - core.status.event.selection=0; + if (keycode == 27 || keycode == 88) { + core.status.event.selection = 0; core.ui.drawSettings(); return; } @@ -2038,12 +2051,12 @@ actions.prototype._keyUpLocalSaveSelect = function (keycode) { ////// 存档删除界面时的点击操作 ////// actions.prototype._clickStorageRemove = function (x, y) { - if (x<5 || x>7) return; + if (x < 5 || x > 7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; switch (selection) { case 0: @@ -2067,10 +2080,10 @@ actions.prototype._clickStorageRemove = function (x, y) { if (core.platform.useLocalForage) { core.ui.drawWaiting("正在清空,请稍后..."); Object.keys(core.saves.ids).forEach(function (v) { - if (v!=0) - core.removeLocalForage("save"+v); + if (v != 0) + core.removeLocalForage("save" + v); }); - core.removeLocalForage("autoSave", function() { + core.removeLocalForage("autoSave", function () { core.saves.autosave.data = null; core.saves.autosave.updated = false; core.ui.closePanel(); @@ -2081,8 +2094,8 @@ actions.prototype._clickStorageRemove = function (x, y) { } else { Object.keys(core.saves.ids).forEach(function (v) { - if (v!=0) - core.removeLocalStorage("save"+v); + if (v != 0) + core.removeLocalStorage("save" + v); }); core.removeLocalStorage("autoSave"); core.saves.autosave.data = null; @@ -2093,7 +2106,7 @@ actions.prototype._clickStorageRemove = function (x, y) { } break; case 2: - core.status.event.selection=6; + core.status.event.selection = 6; core.ui.drawSyncSave(); break; } @@ -2102,8 +2115,8 @@ actions.prototype._clickStorageRemove = function (x, y) { ////// 存档删除界面时,放开某个键的操作 ////// actions.prototype._keyUpStorageRemove = function (keycode) { - if (keycode==27 || keycode==88) { - core.status.event.selection=5; + if (keycode == 27 || keycode == 88) { + core.status.event.selection = 5; core.ui.drawSyncSave(); return; } @@ -2112,30 +2125,28 @@ actions.prototype._keyUpStorageRemove = function (keycode) { ////// 回放选择界面时的点击操作 ////// actions.prototype._clickReplay = function (x, y) { - if (x<5 || x>7) return; + if (x < 5 || x > 7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; switch (selection) { - case 0: - { - core.ui.closePanel(); - core.startGame(core.status.hard, core.getFlag('__seed__'), core.clone(core.status.route)); - break; - } - case 1: - { - core.status.event.id = 'replayLoad'; - core.status.event.selection = null; - core.ui.clearLastEvent(); - var saveIndex = core.saves.saveIndex; - var page=parseInt((saveIndex-1)/5), offset=saveIndex-5*page; - core.ui.drawSLPanel(10*page+offset); - break; - } + case 0: { + core.ui.closePanel(); + core.startGame(core.status.hard, core.getFlag('__seed__'), core.clone(core.status.route)); + break; + } + case 1: { + core.status.event.id = 'replayLoad'; + core.status.event.selection = null; + core.ui.clearLastEvent(); + var saveIndex = core.saves.saveIndex; + var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page; + core.ui.drawSLPanel(10 * page + offset); + break; + } case 2: core.chooseReplayFile(); break; @@ -2144,7 +2155,7 @@ actions.prototype._clickReplay = function (x, y) { core.drawText("\t[系统提示]调试模式下无法下载录像"); break; } - core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5route", JSON.stringify({ + core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route", JSON.stringify({ 'name': core.firstData.name, 'hard': core.status.hard, 'seed': core.getFlag('__seed__'), @@ -2161,7 +2172,7 @@ actions.prototype._clickReplay = function (x, y) { ////// 回放选择界面时,放开某个键的操作 ////// actions.prototype._keyUpReplay = function (keycode) { - if (keycode==27 || keycode==88) { + if (keycode == 27 || keycode == 88) { core.ui.closePanel(); return; } @@ -2170,12 +2181,12 @@ actions.prototype._keyUpReplay = function (keycode) { ////// 游戏信息界面时的点击操作 ////// actions.prototype._clickGameInfo = function (x, y) { - if (x<5 || x>7) return; + if (x < 5 || x > 7) return; var choices = core.status.event.ui.choices; var topIndex = 6 - parseInt((choices.length - 1) / 2); - if (y>=topIndex && y= topIndex && y < topIndex + choices.length) { var selection = y - topIndex; switch (selection) { case 0: @@ -2190,11 +2201,11 @@ actions.prototype._clickGameInfo = function (x, y) { break; case 2: if (core.platform.isPC) { - window.open("/score.php?name="+core.firstData.name+"&num=10", "_blank"); + window.open("/score.php?name=" + core.firstData.name + "&num=10", "_blank"); } else { if (confirm("即将离开本塔,跳转至本塔评论页面,确认?")) { - window.location.href = "/score.php?name="+core.firstData.name+"&num=10"; + window.location.href = "/score.php?name=" + core.firstData.name + "&num=10"; } } break; @@ -2206,12 +2217,12 @@ actions.prototype._clickGameInfo = function (x, y) { break; case 5: if (core.platform.isPC) - window.open(core.firstData.name+".zip"); + window.open(core.firstData.name + ".zip"); else - window.location.href = core.firstData.name+".zip"; + window.location.href = core.firstData.name + ".zip"; break; case 6: - core.status.event.selection=5; + core.status.event.selection = 5; core.ui.drawSettings(); break; } @@ -2220,7 +2231,7 @@ actions.prototype._clickGameInfo = function (x, y) { ////// 游戏信息界面时,放开某个键的操作 ////// actions.prototype._keyUpGameInfo = function (keycode) { - if (keycode==27 || keycode==88) { + if (keycode == 27 || keycode == 88) { core.ui.closePanel(); return; } @@ -2229,102 +2240,103 @@ actions.prototype._keyUpGameInfo = function (keycode) { ////// “虚拟键盘”界面时的点击操作 ////// actions.prototype._clickKeyBoard = function (x, y) { - if (y==3 && x>=1 && x<=11) { + if (y == 3 && x >= 1 && x <= 11) { core.ui.closePanel(); - core.keyUp(112+x-1); // F1-F12: 112-122 + core.keyUp(112 + x - 1); // F1-F12: 112-122 } - if (y==3 && x==12) { + if (y == 3 && x == 12) { var val = prompt(); - if (val!=null) { + if (val != null) { try { eval(val); } - catch (e) {} + catch (e) { + } } } - if (y==4 && x>=1 && x<=10) { + if (y == 4 && x >= 1 && x <= 10) { core.ui.closePanel(); - core.keyUp(x==10?48:48+x); // 1-9: 49-57; 0: 48 + core.keyUp(x == 10 ? 48 : 48 + x); // 1-9: 49-57; 0: 48 } // 字母 var lines = [ - ["Q","W","E","R","T","Y","U","I","O","P"], - ["A","S","D","F","G","H","J","K","L"], - ["Z","X","C","V","B","N","M"], + ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"], + ["A", "S", "D", "F", "G", "H", "J", "K", "L"], + ["Z", "X", "C", "V", "B", "N", "M"], ]; - if (y==5 && x>=1 && x<=10) { + if (y == 5 && x >= 1 && x <= 10) { core.ui.closePanel(); - core.keyUp(lines[0][x-1].charCodeAt(0)); + core.keyUp(lines[0][x - 1].charCodeAt(0)); } - if (y==6 && x>=1 && x<=9) { + if (y == 6 && x >= 1 && x <= 9) { core.ui.closePanel(); - core.keyUp(lines[1][x-1].charCodeAt(0)); + core.keyUp(lines[1][x - 1].charCodeAt(0)); } - if (y==7 && x>=1 && x<=7) { + if (y == 7 && x >= 1 && x <= 7) { core.ui.closePanel(); - core.keyUp(lines[2][x-1].charCodeAt(0)); + core.keyUp(lines[2][x - 1].charCodeAt(0)); } - if (y==8 && x>=1 && x<=11) { + if (y == 8 && x >= 1 && x <= 11) { core.ui.closePanel(); - if (x==1) core.keyUp(189); // - - if (x==2) core.keyUp(187); // = - if (x==3) core.keyUp(219); // [ - if (x==4) core.keyUp(221); // ] - if (x==5) core.keyUp(220); // \ - if (x==6) core.keyUp(186); // ; - if (x==7) core.keyUp(222); // ' - if (x==8) core.keyUp(188); // , - if (x==9) core.keyUp(190); // . - if (x==10) core.keyUp(191); // / - if (x==11) core.keyUp(192); // ` + if (x == 1) core.keyUp(189); // - + if (x == 2) core.keyUp(187); // = + if (x == 3) core.keyUp(219); // [ + if (x == 4) core.keyUp(221); // ] + if (x == 5) core.keyUp(220); // \ + if (x == 6) core.keyUp(186); // ; + if (x == 7) core.keyUp(222); // ' + if (x == 8) core.keyUp(188); // , + if (x == 9) core.keyUp(190); // . + if (x == 10) core.keyUp(191); // / + if (x == 11) core.keyUp(192); // ` } - if (y==9 && x>=1 && x<=10) { + if (y == 9 && x >= 1 && x <= 10) { core.ui.closePanel(); - if (x==1) core.keyUp(27); // ESC - if (x==2) core.keyUp(9); // TAB - if (x==3) core.keyUp(20); // CAPS - if (x==4) core.keyUp(16); // SHIFT - if (x==5) core.keyUp(17); // CTRL - if (x==6) core.keyUp(18); // ALT - if (x==7) core.keyUp(32); // SPACE - if (x==8) core.keyUp(8); // BACKSPACE - if (x==9) core.keyUp(13); // ENTER - if (x==10) core.keyUp(46); // DEL + if (x == 1) core.keyUp(27); // ESC + if (x == 2) core.keyUp(9); // TAB + if (x == 3) core.keyUp(20); // CAPS + if (x == 4) core.keyUp(16); // SHIFT + if (x == 5) core.keyUp(17); // CTRL + if (x == 6) core.keyUp(18); // ALT + if (x == 7) core.keyUp(32); // SPACE + if (x == 8) core.keyUp(8); // BACKSPACE + if (x == 9) core.keyUp(13); // ENTER + if (x == 10) core.keyUp(46); // DEL } - if (y==10 && x>=9 && x<=11) + if (y == 10 && x >= 9 && x <= 11) core.ui.closePanel(); } ////// 光标界面时的点击操作 ////// -actions.prototype._clickCursor = function (x,y) { - if (x==core.status.automaticRoute.cursorX && y==core.status.automaticRoute.cursorY) { +actions.prototype._clickCursor = function (x, y) { + if (x == core.status.automaticRoute.cursorX && y == core.status.automaticRoute.cursorY) { core.ui.closePanel(); - core.onclick(x,y,[]); + core.onclick(x, y, []); return; } - core.status.automaticRoute.cursorX=x; - core.status.automaticRoute.cursorY=y; + core.status.automaticRoute.cursorX = x; + core.status.automaticRoute.cursorY = y; core.ui.drawCursor(); } ////// 光标界面时,按下某个键的操作 ////// actions.prototype._keyDownCursor = function (keycode) { - if (keycode==37) { // left + if (keycode == 37) { // left core.status.automaticRoute.cursorX--; core.ui.drawCursor(); return; } - if (keycode==38) { // up + if (keycode == 38) { // up core.status.automaticRoute.cursorY--; core.ui.drawCursor(); return; } - if (keycode==39) { // right + if (keycode == 39) { // right core.status.automaticRoute.cursorX++; core.ui.drawCursor(); return; } - if (keycode==40) { // down + if (keycode == 40) { // down core.status.automaticRoute.cursorY++; core.ui.drawCursor(); return; @@ -2333,11 +2345,11 @@ actions.prototype._keyDownCursor = function (keycode) { ////// 光标界面时,放开某个键的操作 ////// actions.prototype._keyUpCursor = function (keycode) { - if (keycode==27 || keycode==88) { + if (keycode == 27 || keycode == 88) { core.ui.closePanel(); return; } - if (keycode==13 || keycode==32 || keycode==67 || keycode==69) { + if (keycode == 13 || keycode == 32 || keycode == 67 || keycode == 69) { core.ui.closePanel(); core.onclick(core.status.automaticRoute.cursorX, core.status.automaticRoute.cursorY, []); return; @@ -2347,8 +2359,8 @@ actions.prototype._keyUpCursor = function (keycode) { ////// 绘图相关 ////// actions.prototype._ondownPaint = function (x, y) { - x+=core.bigmap.offsetX; - y+=core.bigmap.offsetY; + x += core.bigmap.offsetX; + y += core.bigmap.offsetY; if (!core.status.event.data.erase) { core.dymCanvas.paint.beginPath(); core.dymCanvas.paint.moveTo(x, y); @@ -2358,14 +2370,14 @@ actions.prototype._ondownPaint = function (x, y) { } actions.prototype._onmovePaint = function (x, y) { - if (core.status.event.data.x==null) return; - x+=core.bigmap.offsetX; - y+=core.bigmap.offsetY; + if (core.status.event.data.x == null) return; + x += core.bigmap.offsetX; + y += core.bigmap.offsetY; if (core.status.event.data.erase) { - core.clearMap('paint', x-10, y-10, 20, 20); + core.clearMap('paint', x - 10, y - 10, 20, 20); return; } - var midx = (core.status.event.data.x+x)/2, midy = (core.status.event.data.y+y)/2; + var midx = (core.status.event.data.x + x) / 2, midy = (core.status.event.data.y + y) / 2; core.dymCanvas.paint.quadraticCurveTo(midx, midy, x, y); core.dymCanvas.paint.stroke(); core.status.event.data.x = x; @@ -2384,7 +2396,7 @@ actions.prototype.setPaintMode = function (mode) { else if (mode == 'erase') core.status.event.data.erase = true; else return; - core.drawTip("进入"+(core.status.event.data.erase?"擦除":"绘图")+"模式"); + core.drawTip("进入" + (core.status.event.data.erase ? "擦除" : "绘图") + "模式"); } actions.prototype.clearPaint = function () { @@ -2399,7 +2411,7 @@ actions.prototype.savePaint = function () { if (core.isset(core.paint[floorId])) data[floorId] = lzw_decode(core.paint[floorId]); } - core.download(core.firstData.name+".h5paint", JSON.stringify({ + core.download(core.firstData.name + ".h5paint", JSON.stringify({ 'name': core.firstData.name, 'paint': data })); @@ -2407,7 +2419,7 @@ actions.prototype.savePaint = function () { actions.prototype.loadPaint = function () { core.readFile(function (obj) { - if (obj.name!=core.firstData.name) { + if (obj.name != core.firstData.name) { alert("绘图文件和游戏不一致!"); return; } @@ -2424,7 +2436,7 @@ actions.prototype.loadPaint = function () { core.clearMap('paint'); var value = core.paint[core.status.floorId]; if (core.isset(value)) value = lzw_decode(value).split(","); - core.utils.decodeCanvas(value, 32*core.bigmap.width, 32*core.bigmap.height); + core.utils.decodeCanvas(value, 32 * core.bigmap.width, 32 * core.bigmap.height); core.drawImage('paint', core.bigmap.tempCanvas.canvas, 0, 0); core.drawTip("读取绘图文件成功"); @@ -2441,7 +2453,7 @@ actions.prototype.exitPaint = function () { } actions.prototype._keyUpPaint = function (keycode) { - if (keycode==27 || keycode==88 || keycode==77 || keycode==13 || keycode==32 || keycode==67) { + if (keycode == 27 || keycode == 88 || keycode == 77 || keycode == 13 || keycode == 32 || keycode == 67) { this.exitPaint(); return; } diff --git a/libs/core.js b/libs/core.js index b314eebc..a61b6f6a 100644 --- a/libs/core.js +++ b/libs/core.js @@ -172,9 +172,9 @@ function core() { 'textAttribute': { 'position': "center", "offset": 0, - "title": [255,215,0,1], - "background": [0,0,0,0.85], - "text": [255,255,255,1], + "title": [255, 215, 0, 1], + "background": [0, 0, 0, 0.85], + "text": [255, 255, 255, 1], "titlefont": 22, "textfont": 16, "bold": false, @@ -242,7 +242,7 @@ core.prototype.init = function (coreData, callback) { core.material.enemys = core.enemys.getEnemys(); core.material.icons = core.icons.getIcons(); - core.platform.isOnline = location.protocol.indexOf("http")==0; + core.platform.isOnline = location.protocol.indexOf("http") == 0; if (core.platform.isOnline) { window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext; try { @@ -256,10 +256,10 @@ core.prototype.init = function (coreData, callback) { } ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"].forEach(function (t) { - if (navigator.userAgent.indexOf(t)>=0) { - if (t=='iPhone' || t=='iPad' || t=='iPod') core.platform.isIOS = true; - if (t=='Android') core.platform.isAndroid=true; - core.platform.isPC=false; + if (navigator.userAgent.indexOf(t) >= 0) { + if (t == 'iPhone' || t == 'iPad' || t == 'iPod') core.platform.isIOS = true; + if (t == 'Android') core.platform.isAndroid = true; + core.platform.isPC = false; } }); @@ -270,8 +270,8 @@ core.prototype.init = function (coreData, callback) { core.platform.supportCopy = false; } - var chrome=/Chrome\/(\d+)\./i.exec(navigator.userAgent); - if (core.isset(chrome) && parseInt(chrome[1])>=50) + var chrome = /Chrome\/(\d+)\./i.exec(navigator.userAgent); + if (core.isset(chrome) && parseInt(chrome[1]) >= 50) core.platform.isChrome = true; core.platform.isSafari = /Safari/i.test(navigator.userAgent) && !/Chrome/i.test(navigator.userAgent); core.platform.isQQ = /QQ/i.test(navigator.userAgent); @@ -279,26 +279,41 @@ core.prototype.init = function (coreData, callback) { core.platform.useLocalForage = core.getLocalStorage('useLocalForage', !core.platform.isIOS); if (core.platform.useLocalForage) { try { - core.setLocalForage("__test__", lzw_encode("__test__"), function() { + core.setLocalForage("__test__", lzw_encode("__test__"), function () { try { - core.getLocalForage("__test__", null, function(data) { + core.getLocalForage("__test__", null, function (data) { try { - if (lzw_decode(data)!="__test__") { + if (lzw_decode(data) != "__test__") { console.log("localForage unsupported!"); - core.platform.useLocalForage=false; + core.platform.useLocalForage = false; } else { console.log("localForage supported!") core.removeLocalForage("__test__"); } } - catch (e) {main.log(e); core.platform.useLocalForage=false;} - }, function(e) {main.log(e); core.platform.useLocalForage=false;}) + catch (e) { + main.log(e); + core.platform.useLocalForage = false; + } + }, function (e) { + main.log(e); + core.platform.useLocalForage = false; + }) } - catch (e) {main.log(e); core.platform.useLocalForage=false;} - }, function(e) {main.log(e); core.platform.useLocalForage=false;}) + catch (e) { + main.log(e); + core.platform.useLocalForage = false; + } + }, function (e) { + main.log(e); + core.platform.useLocalForage = false; + }) + } + catch (e) { + main.log(e); + core.platform.useLocalForage = false; } - catch (e) {main.log(e); core.platform.useLocalForage=false;} } core.platform.extendKeyboard = core.getLocalStorage("extendKeyboard", false); @@ -316,7 +331,7 @@ core.prototype.init = function (coreData, callback) { // 先从存储中读取BGM状态 core.musicStatus.bgmStatus = core.getLocalStorage('bgmStatus', true); - if (!core.platform.isPC && (navigator.connection||{}).type!='wifi') + if (!core.platform.isPC && (navigator.connection || {}).type != 'wifi') core.musicStatus.bgmStatus = false; core.musicStatus.soundStatus = core.getLocalStorage('soundStatus', true); @@ -336,7 +351,7 @@ core.prototype.init = function (coreData, callback) { core.animateFrame.weather.fog.src = "project/images/fog.png"; core.material.images.keyboard = new Image(); - core.material.images.keyboard.onerror = function () { + core.material.images.keyboard.onerror = function () { core.material.images.keyboard = null; } core.material.images.keyboard.src = "project/images/keyboard.png"; @@ -351,14 +366,14 @@ core.prototype.init = function (coreData, callback) { core.loader._load(function () { // 设置勇士高度 - core.material.icons.hero.height = core.material.images.hero.height/4; + core.material.icons.hero.height = core.material.images.hero.height / 4; // 行走图 core.control.updateHeroIcon(); core.initStatus.maps = core.maps.initMaps(core.floorIds); core.setRequestAnimationFrame(); - if (main.mode=='play') + if (main.mode == 'play') core.events.initGame(); if (core.isset(functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.plugins)) { @@ -396,13 +411,13 @@ core.prototype._forwardFunc = function (name, funcname) { } if (core[funcname]) { - console.error("ERROR: Cannot forward function "+funcname+" from "+name+"!"); + console.error("ERROR: Cannot forward function " + funcname + " from " + name + "!"); return; } var parameterInfo = /^\s*function\s*[\w_$]*\(([\w_,$\s]*)\)\s*\{/.exec(core[name][funcname].toString()); - var parameters = (parameterInfo==null?"":parameterInfo[1]).replace(/\s*/g, '').replace(/,/g, ', '); + var parameters = (parameterInfo == null ? "" : parameterInfo[1]).replace(/\s*/g, '').replace(/,/g, ', '); // core[funcname] = new Function(parameters, "return core."+name+"."+funcname+"("+parameters+");"); - eval("core."+funcname+" = function ("+parameters+") {\n\treturn core."+name+"."+funcname+"("+parameters+");\n}"); + eval("core." + funcname + " = function (" + parameters + ") {\n\treturn core." + name + "." + funcname + "(" + parameters + ");\n}"); } /** diff --git a/libs/data.js b/libs/data.js index b11f91cf..e833cf37 100644 --- a/libs/data.js +++ b/libs/data.js @@ -4,13 +4,13 @@ function data() { this._init(); } -data.prototype._init = function() { +data.prototype._init = function () { this.firstData = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData; this.values = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.values; this.flags = data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.flags; //delete(data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d); } -data.prototype.getFirstData = function() { +data.prototype.getFirstData = function () { return core.clone(this.firstData); } \ No newline at end of file diff --git a/libs/enemys.js b/libs/enemys.js index c6ea882c..35d11e09 100644 --- a/libs/enemys.js +++ b/libs/enemys.js @@ -8,8 +8,10 @@ function enemys() { enemys.prototype._init = function () { this.enemys = enemys_fcae963b_31c9_42b4_b48c_bb48d09f3f80; this.enemydata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.enemys; - if (main.mode=='play') { - this.enemydata.hasSpecial = function (a, b) {return core.enemys.hasSpecial(a, b)}; + if (main.mode == 'play') { + this.enemydata.hasSpecial = function (a, b) { + return core.enemys.hasSpecial(a, b) + }; for (var enemyId in this.enemys) { this.enemys[enemyId].id = enemyId; } @@ -54,9 +56,9 @@ enemys.prototype.getSpecialText = function (enemy) { var special = enemy.special; var text = []; - var specials=this.getSpecials(); + var specials = this.getSpecials(); if (core.isset(specials)) { - for (var i=0;inextInfo.damage) { + if (nextInfo == null || (typeof nextInfo == 'number')) break; + if (pre > nextInfo.damage) { pre = nextInfo.damage; - list.push([atk-hero_atk, info.damage-nextInfo.damage]); - if (nextInfo.damage<=0 && !core.flags.enableNegativeDamage) break; - if (list.length>=number) break; + list.push([atk - hero_atk, info.damage - nextInfo.damage]); + if (nextInfo.damage <= 0 && !core.flags.enableNegativeDamage) break; + if (list.length >= number) break; } } - if (list.length==0) list.push([0,0]); + if (list.length == 0) list.push([0, 0]); return list; } @@ -211,51 +213,51 @@ enemys.prototype._nextCriticals_useBinarySearch = function (enemy, info, number, var list = []; var calNext = function (currAtk, maxAtk) { var start = Math.floor(currAtk), end = Math.floor(maxAtk); - if (start>end) return null; + if (start > end) return null; - while (startnextInfo.damage) end = mid; - else start = mid+1; + if (pre > nextInfo.damage) end = mid; + else start = mid + 1; } var nextInfo = core.enemys.getDamageInfo(enemy, {"atk": start}, x, y, floorId); - return nextInfo==null||(typeof nextInfo == 'number')||nextInfo.damage>=pre?null:[start,nextInfo.damage]; + return nextInfo == null || (typeof nextInfo == 'number') || nextInfo.damage >= pre ? null : [start, nextInfo.damage]; } var currAtk = hero_atk; while (true) { - var next = calNext(currAtk+1, mon_hp+mon_def, pre); + var next = calNext(currAtk + 1, mon_hp + mon_def, pre); if (next == null) break; currAtk = next[0]; pre = next[1]; - list.push([currAtk-hero_atk, info.damage-pre]); - if (pre<=0 && !core.flags.enableNegativeDamage) break; - if (list.length>=number) break; + list.push([currAtk - hero_atk, info.damage - pre]); + if (pre <= 0 && !core.flags.enableNegativeDamage) break; + if (list.length >= number) break; } - if (list.length==0) list.push([0,0]); + if (list.length == 0) list.push([0, 0]); return list; } enemys.prototype._nextCriticals_useTurn = function (enemy, info, number, x, y, floorId) { var mon_hp = info.mon_hp, hero_atk = core.status.hero.atk, mon_def = info.mon_def, turn = info.turn; var list = [], pre = null; - for (var t = turn-1;t>=1;t--) { - var nextAtk = Math.ceil(mon_hp/t) + mon_def; + for (var t = turn - 1; t >= 1; t--) { + var nextAtk = Math.ceil(mon_hp / t) + mon_def; // 装备提升比例的计算临界 nextAtk = Math.ceil(nextAtk / core.getFlag('__atk_buff__', 1)); - if (nextAtk<=hero_atk) break; - if (nextAtk!=pre) { + if (nextAtk <= hero_atk) break; + if (nextAtk != pre) { var nextInfo = this.getDamageInfo(enemy, {"atk": nextAtk}, x, y, floorId); - if (nextInfo==null || (typeof nextInfo == 'number')) break; - list.push([nextAtk-hero_atk,Math.floor(info.damage-nextInfo.damage)]); - if (nextInfo.damage<=0 && !core.flags.enableNegativeDamage) break; + if (nextInfo == null || (typeof nextInfo == 'number')) break; + list.push([nextAtk - hero_atk, Math.floor(info.damage - nextInfo.damage)]); + if (nextInfo.damage <= 0 && !core.flags.enableNegativeDamage) break; pre = nextAtk; } - if (list.length>=number) + if (list.length >= number) break; } - if (list.length==0) list.push([0,0]); + if (list.length == 0) list.push([0, 0]); return list; } @@ -265,7 +267,7 @@ enemys.prototype.getDefDamage = function (enemy, k, x, y, floorId) { k = k || 1; var nowDamage = this.calDamage(enemy, null, x, y, floorId); var nextDamage = this.calDamage(enemy, {"def": core.status.hero.def + k}, x, y, floorId); - if (nowDamage == null || nextDamage ==null) return "???"; + if (nowDamage == null || nextDamage == null) return "???"; return nowDamage - nextDamage; } @@ -275,7 +277,7 @@ enemys.prototype.getEnemyInfo = function (enemy, hero, x, y, floorId) { } ////// 获得战斗伤害信息(实际伤害计算函数) ////// -enemys.prototype.getDamageInfo = function(enemy, hero, x, y, floorId) { +enemys.prototype.getDamageInfo = function (enemy, hero, x, y, floorId) { // 移动到了脚本编辑 - getDamageInfo中 if (typeof enemy == 'string') enemy = core.material.enemys[enemy]; return this.enemydata.getDamageInfo(enemy, hero, x, y, floorId); @@ -298,12 +300,12 @@ enemys.prototype.updateEnemys = function () { ////// 获得当前楼层的怪物列表 ////// enemys.prototype.getCurrentEnemys = function (floorId) { - floorId=floorId||core.status.floorId; + floorId = floorId || core.status.floorId; var enemys = [], used = {}; var mapBlocks = core.status.maps[floorId].blocks; for (var b = 0; b < mapBlocks.length; b++) { if (core.isset(mapBlocks[b].event) && !mapBlocks[b].disable - && mapBlocks[b].event.cls.indexOf('enemy')==0) { + && mapBlocks[b].event.cls.indexOf('enemy') == 0) { this._getCurrentEnemys_addEnemy(mapBlocks[b].event.id, enemys, used, floorId); } } @@ -324,15 +326,15 @@ enemys.prototype._getCurrentEnemys_getEnemy = function (enemyId) { enemys.prototype._getCurrentEnemys_addEnemy = function (enemyId, enemys, used, floorId) { var enemy = this._getCurrentEnemys_getEnemy(enemyId); - if (enemy==null || used[enemy.id]) return; + if (enemy == null || used[enemy.id]) return; var enemyInfo = this.getEnemyInfo(enemy, null, null, null, floorId); var specialText = core.enemys.getSpecialText(enemy); - if (specialText.length>=3) specialText = "多属性..."; + if (specialText.length >= 3) specialText = "多属性..."; else specialText = specialText.join(" "); var critical = this.nextCriticals(enemy, 1, null, null, floorId); - if (critical.length>0) critical=critical[0]; + if (critical.length > 0) critical = critical[0]; var e = core.clone(enemy); for (var x in enemyInfo) { @@ -342,7 +344,7 @@ enemys.prototype._getCurrentEnemys_addEnemy = function (enemyId, enemys, used, f e.damage = this.getDamage(enemy, null, null, floorId); e.critical = critical[0]; e.criticalDamage = critical[1]; - e.defDamage = this.getDefDamage(enemy,1,null,null,floorId); + e.defDamage = this.getDefDamage(enemy, 1, null, null, floorId); enemys.push(e); used[enemy.id] = true; } diff --git a/libs/events.js b/libs/events.js index 3bda1f7b..4dae39cf 100644 --- a/libs/events.js +++ b/libs/events.js @@ -21,10 +21,10 @@ events.prototype.initGame = function () { ////// 游戏开始事件 ////// events.prototype.startGame = function (hard, seed, route, callback) { - main.dom.levelChooseButtons.style.display='none'; - main.dom.startButtonGroup.style.display='none'; + main.dom.levelChooseButtons.style.display = 'none'; + main.dom.startButtonGroup.style.display = 'none'; - if (main.mode!='play') return; + if (main.mode != 'play') return; // 无动画的开始游戏 if (core.flags.startUsingCanvas || core.isset(route)) { @@ -84,7 +84,7 @@ events.prototype._startGame_upload = function () { formData.append('type', 'people'); formData.append('name', core.firstData.name); formData.append('version', core.firstData.version); - formData.append('platform', core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":""); + formData.append('platform', core.platform.isPC ? "PC" : core.platform.isAndroid ? "Android" : core.platform.isIOS ? "iOS" : ""); formData.append('hard', core.encodeBase64(core.status.hard)); formData.append('hardCode', core.getFlag('hard', 0)); formData.append('base64', 1); @@ -141,7 +141,7 @@ events.prototype._gameOver_confirmUpload = function (ending, norank) { return; } core.ui.drawConfirmBox("你想记录你的ID和成绩吗?", function () { - var username = main.isCompetition?"":prompt("请输入你的ID:", core.getCookie('id')||""); + var username = main.isCompetition ? "" : prompt("请输入你的ID:", core.getCookie('id') || ""); core.events._gameOver_doUpload(username, ending, norank); }, function () { if (main.isCompetition) @@ -160,9 +160,9 @@ events.prototype._gameOver_doUpload = function (username, ending, norank) { formData.append('type', 'score'); formData.append('name', core.firstData.name); formData.append('version', core.firstData.version); - formData.append('platform', core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":""); + formData.append('platform', core.platform.isPC ? "PC" : core.platform.isAndroid ? "Android" : core.platform.isIOS ? "iOS" : ""); formData.append('hard', core.encodeBase64(core.status.hard)); - formData.append('username', core.encodeBase64(username||"")); + formData.append('username', core.encodeBase64(username || "")); formData.append('ending', core.encodeBase64(ending)); formData.append('lv', core.status.hero.lv); formData.append('hp', Math.min(hp, Math.pow(2, 63))); @@ -172,9 +172,9 @@ events.prototype._gameOver_doUpload = function (username, ending, norank) { formData.append('money', core.status.hero.money); formData.append('experience', core.status.hero.experience); formData.append('steps', core.status.hero.steps); - formData.append('norank', norank||0); + formData.append('norank', norank || 0); formData.append('seed', core.getFlag('__seed__')); - formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime/1000)); + formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime / 1000)); formData.append('route', core.encodeRoute(core.status.route)); formData.append('base64', 1); @@ -183,7 +183,7 @@ events.prototype._gameOver_doUpload = function (username, ending, norank) { else core.http("POST", "/games/upload.php", formData); - setTimeout(function() { + setTimeout(function () { core.events._gameOver_confirmDownload(ending); }, 200); } @@ -198,7 +198,7 @@ events.prototype._gameOver_confirmDownload = function (ending) { 'seed': core.getFlag('__seed__'), 'route': core.encodeRoute(core.status.route) } - core.download(core.firstData.name+"_"+core.formatDate2(new Date())+".h5route", JSON.stringify(obj)); + core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route", JSON.stringify(obj)); core.events._gameOver_askRate(ending); }, function () { core.events._gameOver_askRate(ending); @@ -214,11 +214,11 @@ events.prototype._gameOver_askRate = function (ending) { core.ui.closePanel(); core.ui.drawConfirmBox("恭喜通关本塔,你想进行评分吗?", function () { if (core.platform.isPC) { - window.open("/score.php?name="+core.firstData.name+"&num=10", "_blank"); + window.open("/score.php?name=" + core.firstData.name + "&num=10", "_blank"); core.restart(); } else { - window.location.href = "/score.php?name="+core.firstData.name+"&num=10"; + window.location.href = "/score.php?name=" + core.firstData.name + "&num=10"; } }, function () { core.restart(); @@ -241,9 +241,9 @@ events.prototype.unregisterSystemEvent = function (type) { ////// 执行一个系统事件 ////// events.prototype.doSystemEvent = function (type, data, callback) { if (this.systemEvents[type]) this.systemEvents[type](data, callback); - else if (this["_sys_"+type]) this["_sys_"+type](data, callback); + else if (this["_sys_" + type]) this["_sys_" + type](data, callback); else { - main.log("未知的系统事件: "+type+"!"); + main.log("未知的系统事件: " + type + "!"); if (callback) callback(); } } @@ -263,7 +263,7 @@ events.prototype._trigger = function (x, y) { if (trigger == 'ski') core.status.isSkiing = true; // 转换楼层能否穿透 - if (trigger=='changeFloor' && !noPass && this._trigger_ignoreChangeFloor(block)) + if (trigger == 'changeFloor' && !noPass && this._trigger_ignoreChangeFloor(block)) return; core.status.automaticRoute.moveDirectly = false; this.doSystemEvent(trigger, block, function () { @@ -276,17 +276,17 @@ events.prototype._trigger = function (x, y) { events.prototype._trigger_ignoreChangeFloor = function (block) { var able = core.flags.ignoreChangeFloor; if (core.isset(block.event.data) && core.isset(block.event.data.ignoreChangeFloor)) - able=block.event.data.ignoreChangeFloor; + able = block.event.data.ignoreChangeFloor; if (able) { if (core.isReplaying()) { - if (core.status.replay.toReplay[0]=='no') { + if (core.status.replay.toReplay[0] == 'no') { core.status.replay.toReplay.shift(); core.status.route.push("no"); return true; } } else if (core.status.automaticRoute.autoHeroMove - || core.status.automaticRoute.autoStep0) floorId = core.floorIds[index-1]; - else floorId=core.status.floorId; + var index = core.floorIds.indexOf(core.status.floorId); + if (index > 0) floorId = core.floorIds[index - 1]; + else floorId = core.status.floorId; } else if (floorId == ':next') { - var index=core.floorIds.indexOf(core.status.floorId); - if (index0) + if (number > 0) core.setBlock(number, ex, ey); } } @@ -715,9 +715,9 @@ events.prototype.unregisterEvent = function (type) { events.prototype.doEvent = function (data, x, y, prefix) { var type = data.type; if (this.actions[type]) this.actions[type](data, x, y, prefix); - else if (this["_action_"+type]) this["_action_"+type](data, x, y, prefix); + else if (this["_action_" + type]) this["_action_" + type](data, x, y, prefix); else { - core.insertAction("未知的自定义事件: "+type+"!"); + core.insertAction("未知的自定义事件: " + type + "!"); core.doAction(); } } @@ -730,7 +730,7 @@ events.prototype.doEvents = function (list, x, y, callback) { } this.setEvents(list, x, y, callback); // 停止勇士 - core.waitHeroToStop(function() { + core.waitHeroToStop(function () { core.lockControl(); core.doAction(); }); @@ -747,7 +747,7 @@ events.prototype.setEvents = function (list, x, y, callback) { } ////// 执行当前自定义事件列表中的下一个事件 ////// -events.prototype.doAction = function() { +events.prototype.doAction = function () { // 清空boxAnimate和UI层 core.status.boxAnimateObjs = []; clearInterval(core.status.event.interval); @@ -757,7 +757,7 @@ events.prototype.doAction = function() { if (this._doAction_finishEvents()) return; // 当前点坐标和前缀 var x = core.status.event.data.x, y = core.status.event.data.y; - var prefix = [core.status.floorId||"f", core.isset(x)?x:"x", core.isset(y)?y:"y"].join("@"); + var prefix = [core.status.floorId || "f", core.isset(x) ? x : "x", core.isset(y) ? y : "y"].join("@"); var current = core.status.event.data.list[0]; if (this._popEvents(current, prefix)) return; // 当前要执行的事件 @@ -772,7 +772,7 @@ events.prototype.doAction = function() { events.prototype._doAction_finishEvents = function () { // 事件处理完毕 - if (core.status.event.data.list.length==0) { + if (core.status.event.data.list.length == 0) { var callback = core.status.event.data.callback; core.ui.closePanel(); if (core.isset(callback)) @@ -851,7 +851,7 @@ events.prototype.__action_getLoc = function (loc, x, y, prefix) { x = core.calValue(loc[0], prefix); y = core.calValue(loc[1], prefix); } - return [x,y]; + return [x, y]; } events.prototype.__action_getHeroLoc = function (loc, prefix) { @@ -897,17 +897,17 @@ events.prototype._action_comment = function (data, x, y, prefix) { events.prototype._action_setText = function (data, x, y, prefix) { ["position", "offset", "bold", "titlefont", "textfont", "time"].forEach(function (t) { - if (core.isset(data[t])) core.status.textAttribute[t]=data[t]; + if (core.isset(data[t])) core.status.textAttribute[t] = data[t]; }); ["background", "title", "text"].forEach(function (t) { - if (core.isset(data[t]) && (data[t] instanceof Array) && data[t].length>=3) { - if (data[t].length==3) data[t].push(1); - core.status.textAttribute[t]=data[t]; + if (core.isset(data[t]) && (data[t] instanceof Array) && data[t].length >= 3) { + if (data[t].length == 3) data[t].push(1); + core.status.textAttribute[t] = data[t]; } - if (t=='background' && core.isset(data[t])) { + if (t == 'background' && core.isset(data[t])) { var img = core.material.images.images[data[t]]; - if (core.isset(img) && img.width==192 && img.height==128) { - core.status.textAttribute[t]=data[t]; + if (core.isset(img) && img.width == 192 && img.height == 128) { + core.status.textAttribute[t] = data[t]; } } }); @@ -922,7 +922,7 @@ events.prototype._action_tip = function (data, x, y, prefix) { events.prototype._action_show = function (data, x, y, prefix) { data.loc = this.__action_getLoc2D(data.loc, x, y, prefix); - if (data.time>0 && !(data.floorId && data.floorId != core.status.floorId)) { + if (data.time > 0 && !(data.floorId && data.floorId != core.status.floorId)) { this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, 'show', data.time); } else { @@ -935,7 +935,7 @@ events.prototype._action_show = function (data, x, y, prefix) { events.prototype._action_hide = function (data, x, y, prefix) { data.loc = this.__action_getLoc2D(data.loc, x, y, prefix); - if (data.time>0 && !(data.floorId && data.floorId != core.status.floorId)) { + if (data.time > 0 && !(data.floorId && data.floorId != core.status.floorId)) { data.loc.forEach(function (t) { core.hideBlock(t[0], t[1], data.floorId); }); @@ -943,7 +943,7 @@ events.prototype._action_hide = function (data, x, y, prefix) { } else { data.loc.forEach(function (t) { - core.removeBlock(t[0],t[1],data.floorId) + core.removeBlock(t[0], t[1], data.floorId) }); core.doAction(); } @@ -1016,7 +1016,7 @@ events.prototype._action_jumpHero = function (data, x, y, prefix) { events.prototype._action_changeFloor = function (data, x, y, prefix) { var loc = this.__action_getHeroLoc(data.loc, prefix); var heroLoc = {x: loc[0], y: loc[1], direction: data.direction}; - core.changeFloor(data.floorId || core.status.floorId, null, heroLoc, data.time, function() { + core.changeFloor(data.floorId || core.status.floorId, null, heroLoc, data.time, function () { core.lockControl(); core.doAction(); }); @@ -1071,7 +1071,7 @@ events.prototype._action_setFg = function (data, x, y, prefix) { core.doAction(); } else { - core.setFg(data.color, data.time, function() { + core.setFg(data.color, data.time, function () { core.setFlag('__color__', data.color || null); core.doAction(); }); @@ -1113,7 +1113,7 @@ events.prototype._action_useItem = function (data, x, y, prefix) { core.useItem(data.id, true, core.doAction); } else { - core.drawTip("当前无法使用"+((core.material.items[data.id]||{}).name||"未知道具")); + core.drawTip("当前无法使用" + ((core.material.items[data.id] || {}).name || "未知道具")); core.doAction(); } } @@ -1163,7 +1163,7 @@ events.prototype._action_insert = function (data, x, y, prefix) { else { var loc = this.__action_getLoc(data.loc, x, y, prefix); var floorId = data.floorId || core.status.floorId; - var event = core.floors[floorId].events[loc[0]+","+loc[1]]; + var event = core.floors[floorId].events[loc[0] + "," + loc[1]]; if (core.isset(event)) { if (core.isset(event.data)) event = event.data; this.insertAction(event); @@ -1208,7 +1208,7 @@ events.prototype._action_stopSound = function (data, x, y, prefix) { } events.prototype._action_setVolume = function (data, x, y, prefix) { - data.value = core.clamp(parseInt(data.value)/100, 0, 1); + data.value = core.clamp(parseInt(data.value) / 100, 0, 1); core.setFlag("__volume__", data.value); this.__action_doAsyncFunc(data.async, this.setVolume, data.value, data.time || 0); } @@ -1251,7 +1251,7 @@ events.prototype._action_setHeroIcon = function (data, x, y, prefix) { events.prototype._action_input = function (data, x, y, prefix) { var value = this.__action_getInput(data.text, false); if (value == null) return; - value = Math.abs(parseInt(value)||0); + value = Math.abs(parseInt(value) || 0); core.status.route.push("input:" + value); core.setFlag("input", value); core.doAction(); @@ -1266,19 +1266,19 @@ events.prototype._action_input2 = function (data, x, y, prefix) { } events.prototype.__action_getInput = function (hint, isText) { - var value, prefix = isText?"input2:":"input:"; + var value, prefix = isText ? "input2:" : "input:"; if (core.isReplaying()) { var action = core.status.replay.toReplay.shift(); try { - if (action.indexOf(prefix)!=0) - throw new Error("录像文件出错!当前需要一个 "+prefix+" 项,实际为 "+action); + if (action.indexOf(prefix) != 0) + throw new Error("录像文件出错!当前需要一个 " + prefix + " 项,实际为 " + action); if (isText) value = core.decodeBase64(action.substring(7)); else value = parseInt(action.substring(6)); } catch (e) { main.log(e); core.stopReplay(); - core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type":"exit"}]); + core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]); core.doAction(); return null; } @@ -1286,7 +1286,7 @@ events.prototype.__action_getInput = function (hint, isText) { else { core.interval.onDownInterval = 'tmp'; value = prompt(core.replaceText(hint)); - if (!core.isset(value)) value=""; + if (!core.isset(value)) value = ""; } return value; } @@ -1316,18 +1316,18 @@ events.prototype._action_choices = function (data, x, y, prefix) { var action = core.status.replay.toReplay.shift(), index; // --- 忽略可能的turn事件 if (action == 'turn') action = core.status.replay.toReplay.shift(); - if (action.indexOf("choices:")==0 && ((index=parseInt(action.substring(8)))>=0) && index= 0) && index < data.choices.length) { + core.status.event.selection = index; setTimeout(function () { - core.status.route.push("choices:"+index); + core.status.route.push("choices:" + index); core.insertAction(data.choices[index].action); core.doAction(); }, 750 / Math.max(1, core.status.replay.speed)) } else { - main.log("录像文件出错!当前需要一个 choices: 项,实际为 "+action); + main.log("录像文件出错!当前需要一个 choices: 项,实际为 " + action); core.stopReplay(); - core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type":"exit"}]); + core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]); core.doAction(); return; } @@ -1370,8 +1370,8 @@ events.prototype._action_lose = function (data, x, y, prefix) { events.prototype._action_function = function (data, x, y, prefix) { var func = data["function"]; try { - if (typeof func == "string" && func.indexOf("function")==0) { - eval('('+func+')()'); + if (typeof func == "string" && func.indexOf("function") == 0) { + eval('(' + func + ')()'); } } catch (e) { main.log(e); @@ -1406,24 +1406,24 @@ events.prototype._action_vibrate = function (data, x, y, prefix) { } events.prototype._action_sleep = function (data, x, y, prefix) { - core.timeout.sleepTimeout = setTimeout(function() { + core.timeout.sleepTimeout = setTimeout(function () { core.timeout.sleepTimeout = null; core.doAction(); - }, core.isReplaying()?Math.min(data.time, 20):data.time); + }, core.isReplaying() ? Math.min(data.time, 20) : data.time); } events.prototype._action_wait = function (data, x, y, prefix) { if (core.isReplaying()) { var code = core.status.replay.toReplay.shift(); - if (code.indexOf("input:")==0) { + if (code.indexOf("input:") == 0) { var value = parseInt(code.substring(6)); - core.status.route.push("input:"+value); + core.status.route.push("input:" + value); this.__action_wait_getValue(value); } else { - main.log("录像文件出错!当前需要一个 input: 项,实际为 "+code); + main.log("录像文件出错!当前需要一个 input: 项,实际为 " + code); core.stopReplay(); - core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type":"exit"}]); + core.insertAction(["录像文件出错,请在控制台查看报错信息。", {"type": "exit"}]); } core.doAction(); return; @@ -1515,7 +1515,7 @@ events.prototype._action_exit = function (data, x, y, prefix) { events.prototype.follow = function (name) { core.status.hero.followers = core.status.hero.followers || []; if (core.isset(core.material.images.images[name]) - && core.material.images.images[name].width==128) { + && core.material.images.images[name].width == 128) { core.status.hero.followers.push({"img": name}); core.control.gatherFollowers(); core.clearMap('hero'); @@ -1594,8 +1594,8 @@ events.prototype._setValue_setFlag = function (name, value) { } events.prototype._setValue_setSwitch = function (name, value, prefix) { - if (name.indexOf("switch:") !==0 ) return; - core.setFlag((prefix||"f@x@y")+"@"+data.name.substring(7), value); + if (name.indexOf("switch:") !== 0) return; + core.setFlag((prefix || "f@x@y") + "@" + data.name.substring(7), value); } ////// 数值增减 ////// @@ -1613,11 +1613,11 @@ events.prototype.setFloorInfo = function (name, value, floorId, prefix) { ////// 设置全塔属性 ////// events.prototype.setGlobalAttribute = function (name, value) { if (typeof value == 'string') { - if ((value.charAt(0)=='"' && value.charAt(value.length-1)=='"') - || (value.charAt(0)=="'" && value.charAt(value.length-1)=="'")) - value = value.substring(1, value.length-1); + if ((value.charAt(0) == '"' && value.charAt(value.length - 1) == '"') + || (value.charAt(0) == "'" && value.charAt(value.length - 1) == "'")) + value = value.substring(1, value.length - 1); // --- 检查 [] - if (value.charAt(0) == '[' && value.charAt(value.length-1)==']') + if (value.charAt(0) == '[' && value.charAt(value.length - 1) == ']') value = eval(value); } core.status.globalAttribute[name] = value; @@ -1647,7 +1647,7 @@ events.prototype.showImage = function (code, image, x, y, dw, dh, opacityVal, ti } var zIndex = code + 100; time = time || 0; - var name = "image"+ zIndex; + var name = "image" + zIndex; var ctx = core.createCanvas(name, x, y, image.width * dw, image.height * dh, zIndex); ctx.drawImage(image, 0, 0, image.width * dw, image.height * dh); if (time == 0) { @@ -1678,7 +1678,7 @@ events.prototype.hideImage = function (code, time, callback) { events.prototype.moveImage = function (code, to, opacityVal, time, callback) { time = time || 1000; to = to || []; - var name = "image"+ (code+100); + var name = "image" + (code + 100); if (!core.dymCanvas[name]) { if (callback) callback(); return; @@ -1699,16 +1699,16 @@ events.prototype.moveImage = function (code, to, opacityVal, time, callback) { }, callback) } -events.prototype._moveImage_moving = function(name, moveInfo, callback) { +events.prototype._moveImage_moving = function (name, moveInfo, callback) { var per_time = 10, step = 0, steps = parseInt(moveInfo.time / 10); var fromX = moveInfo.fromX, fromY = moveInfo.fromY, toX = moveInfo.toX, toY = moveInfo.toY, opacity = moveInfo.opacity, toOpacity = moveInfo.toOpacity; var currX = fromX, currY = fromY, currOpacity = opacity; var animate = setInterval(function () { step++; - currOpacity = opacity + (toOpacity-opacity)*step/steps; - currX = parseInt(fromX + (toX-fromX)*step/steps); - currY = parseInt(fromY + (toY-fromY)*step/steps); + currOpacity = opacity + (toOpacity - opacity) * step / steps; + currX = parseInt(fromX + (toX - fromX) * step / steps); + currY = parseInt(fromY + (toY - fromY) * step / steps); core.setOpacity(name, currOpacity); core.relocateCanvas(name, currX, currY); if (step == steps) { @@ -1728,7 +1728,7 @@ events.prototype.setVolume = function (value, time, callback) { if (core.musicStatus.playingBgm) core.material.bgms[core.musicStatus.playingBgm].volume = value; } - if (!core.isset(time) || time<100) { + if (!core.isset(time) || time < 100) { set(value); if (callback) callback(); return; @@ -1737,8 +1737,8 @@ events.prototype.setVolume = function (value, time, callback) { var per_time = 10, step = 0, steps = parseInt(time / per_time); var fade = setInterval(function () { step++; - set(currVolume+(value-currVolume)*step/steps); - if (step>=steps) { + set(currVolume + (value - currVolume) * step / steps); + if (step >= steps) { delete core.animateFrame.asyncId[fade]; clearInterval(fade); if (callback) callback(); @@ -1748,19 +1748,19 @@ events.prototype.setVolume = function (value, time, callback) { } ////// 画面震动 ////// -events.prototype.vibrate = function(time, callback) { +events.prototype.vibrate = function (time, callback) { if (core.isReplaying()) { if (callback) callback(); return; } - if (!core.isset(time) || time<1000) time=1000; + if (!core.isset(time) || time < 1000) time = 1000; // --- 将time调整为500的倍数(上整),不然会出错 time = Math.ceil(time / 500) * 500; - var shakeInfo = { duration: time * 3 / 50, speed: 5, power: 5, direction: 1, shake: 0 }; - var animate=setInterval(function(){ + var shakeInfo = {duration: time * 3 / 50, speed: 5, power: 5, direction: 1, shake: 0}; + var animate = setInterval(function () { core.events._vibrate_update(shakeInfo); core.control.addGameCanvasTranslate(shakeInfo.shake, 0); - if(shakeInfo.duration===0) { + if (shakeInfo.duration === 0) { delete core.animateFrame.asyncId[animate]; clearInterval(animate); if (callback) callback(); @@ -1771,33 +1771,33 @@ events.prototype.vibrate = function(time, callback) { } events.prototype._vibrate_update = function (shakeInfo) { - if(shakeInfo.duration >= 1 || shakeInfo.shake != 0){ + if (shakeInfo.duration >= 1 || shakeInfo.shake != 0) { var delta = (shakeInfo.power * shakeInfo.speed * shakeInfo.direction) / 10.0; - if(shakeInfo.duration <= 1 && shakeInfo.shake * (shakeInfo.shake + delta) < 0){ + if (shakeInfo.duration <= 1 && shakeInfo.shake * (shakeInfo.shake + delta) < 0) { shakeInfo.shake = 0; - }else{ + } else { shakeInfo.shake += delta; } - if(shakeInfo.shake > shakeInfo.power * 2){ + if (shakeInfo.shake > shakeInfo.power * 2) { shakeInfo.direction = -1; } - if(shakeInfo.shake < - shakeInfo.power * 2){ + if (shakeInfo.shake < -shakeInfo.power * 2) { shakeInfo.direction = 1; } - if(shakeInfo.duration >= 1){ + if (shakeInfo.duration >= 1) { shakeInfo.duration -= 1 } } } ////// 打开一个全局商店 ////// -events.prototype.openShop = function(shopId, needVisited) { +events.prototype.openShop = function (shopId, needVisited) { var shop = core.status.shops[shopId]; shop.times = shop.times || 0; if (shop.commonTimes) shop.times = core.getFlag('commonTimes', 0); if (needVisited && !shop.visited) { if (!core.flags.enableDisabledShop) { - if (shop.times==0) core.drawTip("该商店尚未开启"); + if (shop.times == 0) core.drawTip("该商店尚未开启"); else core.drawTip("该商店已失效"); return; } @@ -1817,9 +1817,9 @@ events.prototype._useShop = function (shop, index) { return false; } var use = shop.use, choice = shop.choices[index]; - var times = shop.times, need = core.calValue(choice.need||shop.need, null, null, times); + var times = shop.times, need = core.calValue(choice.need || shop.need, null, null, times); if (need > core.getStatus(use)) { - core.drawTip("你的"+(use=='money'?"金币":"经验")+"不足"); + core.drawTip("你的" + (use == 'money' ? "金币" : "经验") + "不足"); return false; } core.status.event.selection = index; @@ -1834,8 +1834,8 @@ events.prototype._useShop = function (shop, index) { } events.prototype._exitShop = function () { - if (core.status.event.data.actions.length>0) { - core.status.route.push("shop:"+core.status.event.data.id+":"+core.status.event.data.actions.join("")); + if (core.status.event.data.actions.length > 0) { + core.status.route.push("shop:" + core.status.event.data.id + ":" + core.status.event.data.actions.join("")); } core.status.event.data.actions = []; core.status.boxAnimateObjs = []; @@ -1851,7 +1851,7 @@ events.prototype.disableQuickShop = function (shopId) { } ////// 能否使用快捷商店 ////// -events.prototype.canUseQuickShop = function(shopId) { +events.prototype.canUseQuickShop = function (shopId) { return this.eventdata.canUseQuickShop(shopId); } @@ -1861,7 +1861,7 @@ events.prototype.setHeroIcon = function (name, noDraw) { if (!img || img.width != 128) return; core.setFlag("heroIcon", name); core.material.images.hero.onload = function () { - core.material.icons.hero.height = img.height/4; + core.material.icons.hero.height = img.height / 4; core.control.updateHeroIcon(name); if (!noDraw) core.drawHero(); } @@ -1876,35 +1876,35 @@ events.prototype.checkLvUp = function () { if (next == null) break; actions = actions.concat(next); } - if (actions.length>0) core.insertAction(actions); + if (actions.length > 0) core.insertAction(actions); } events.prototype._checkLvUp_check = function () { if (!core.flags.enableLevelUp || !core.isset(core.firstData.levelUp) - || core.status.hero.lv>=core.firstData.levelUp.length) return null; + || core.status.hero.lv >= core.firstData.levelUp.length) return null; // 计算下一个所需要的数值 - var next = (core.firstData.levelUp[core.status.hero.lv]||{}); + var next = (core.firstData.levelUp[core.status.hero.lv] || {}); var need = core.calValue(next.need); if (!core.isset(need)) return null; - if (core.status.hero.experience>=need) { + if (core.status.hero.experience >= need) { // 升级 core.status.hero.lv++; if (next.clear) core.status.hero.experience -= need; - return next.action||[]; + return next.action || []; } return null; } ////// 尝试使用道具 ////// -events.prototype.tryUseItem = function(itemId) { +events.prototype.tryUseItem = function (itemId) { core.ui.closePanel(); - if (itemId=='book') return core.openBook(false); - if (itemId=='fly') return core.useFly(false); - if (itemId=='centerFly') return core.ui.drawCenterFly(); + if (itemId == 'book') return core.openBook(false); + if (itemId == 'fly') return core.useFly(false); + if (itemId == 'centerFly') return core.ui.drawCenterFly(); - if (core.canUseItem(itemId))core.useItem(itemId); - else core.drawTip("当前无法使用"+core.material.items[itemId].name); + if (core.canUseItem(itemId)) core.useItem(itemId); + else core.drawTip("当前无法使用" + core.material.items[itemId].name); } ////// 使用炸弹/圣锤后的事件 ////// @@ -1929,9 +1929,9 @@ events.prototype.uploadCurrent = function (username) { formData.append('type', 'score'); formData.append('name', core.firstData.name); formData.append('version', core.firstData.version); - formData.append('platform', core.platform.isPC?"PC":core.platform.isAndroid?"Android":core.platform.isIOS?"iOS":""); + formData.append('platform', core.platform.isPC ? "PC" : core.platform.isAndroid ? "Android" : core.platform.isIOS ? "iOS" : ""); formData.append('hard', core.encodeBase64(core.status.hard)); - formData.append('username', core.encodeBase64(username||"current")); + formData.append('username', core.encodeBase64(username || "current")); formData.append('lv', core.status.hero.lv); formData.append('hp', Math.min(core.status.hero.hp, Math.pow(2, 63))); formData.append('atk', core.status.hero.atk); @@ -1941,7 +1941,7 @@ events.prototype.uploadCurrent = function (username) { formData.append('experience', core.status.hero.experience); formData.append('steps', core.status.hero.steps); formData.append('seed', core.getFlag('__seed__')); - formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime/1000)); + formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime / 1000)); formData.append('route', core.encodeRoute(core.status.route)); formData.append('deler', 'current'); formData.append('base64', 1); diff --git a/libs/icons.js b/libs/icons.js index db33f828..12b78828 100644 --- a/libs/icons.js +++ b/libs/icons.js @@ -26,14 +26,14 @@ icons.prototype.getClsFromId = function (id) { } icons.prototype._getAnimateFrames = function (cls, useOriginValue) { - if (cls=='enemys' || cls=='npcs') { + if (cls == 'enemys' || cls == 'npcs') { return 2; } if (cls == 'animates' || cls == 'enemy48') { return 4; } if (cls == 'npc48') { - return useOriginValue? 4 : 1; + return useOriginValue ? 4 : 1; } return 1; } @@ -55,9 +55,9 @@ icons.prototype.getTilesetOffset = function (id) { for (var i in core.tilesets) { var imgName = core.tilesets[i]; var img = core.material.images.tilesets[imgName]; - var width = Math.floor(img.width/32), height = Math.floor(img.height/32); - if (id>=startOffset && id= startOffset && id < startOffset + width * height) { + var x = (id - startOffset) % width, y = parseInt((id - startOffset) / width); return {"image": imgName, "x": x, "y": y}; } startOffset += this.tilesetStartOffset; diff --git a/libs/items.js b/libs/items.js index 708acd6a..ce3ee753 100644 --- a/libs/items.js +++ b/libs/items.js @@ -22,7 +22,7 @@ items.prototype.getItems = function () { } ////// “即捡即用类”道具的使用效果 ////// -items.prototype.getItemEffect = function(itemId, itemNum) { +items.prototype.getItemEffect = function (itemId, itemNum) { var itemCls = core.material.items[itemId].cls; // 消耗品 if (itemCls === 'items') { @@ -44,14 +44,14 @@ items.prototype.getItemEffect = function(itemId, itemNum) { } ////// “即捡即用类”道具的文字提示 ////// -items.prototype.getItemEffectTip = function(itemId) { +items.prototype.getItemEffectTip = function (itemId) { var itemCls = core.material.items[itemId].cls; // 消耗品 if (itemCls === 'items') { var ratio = parseInt(core.status.thisMap.item_ratio) || 1; if (itemId in this.itemEffectTip) { try { - return eval(this.itemEffectTip[itemId])||""; + return eval(this.itemEffectTip[itemId]) || ""; } catch (e) { main.log(e); return ""; @@ -72,7 +72,7 @@ items.prototype.useItem = function (itemId, noRoute, callback) { // 执行完毕 this._afterUseItem(itemId); // 记录路线 - if (!noRoute) core.status.route.push("item:"+itemId); + if (!noRoute) core.status.route.push("item:" + itemId); if (core.isset(callback)) callback(); } @@ -91,9 +91,9 @@ items.prototype._useItemEffect = function (itemId) { items.prototype._afterUseItem = function (itemId) { // 道具使用完毕:删除 var itemCls = core.material.items[itemId].cls; - if (itemCls=='tools') + if (itemCls == 'tools') core.status.hero.items[itemCls][itemId]--; - if (core.status.hero.items[itemCls][itemId]<=0) + if (core.status.hero.items[itemCls][itemId] <= 0) delete core.status.hero.items[itemCls][itemId]; if (!core.status.event.id) { @@ -130,8 +130,8 @@ items.prototype.itemCount = function (itemId) { if (!core.isset(core.status.hero)) return 0; if (!core.isset(itemId) || !core.isset(core.material.items[itemId])) return 0; var itemCls = core.material.items[itemId].cls; - if (itemCls=="items") return 0; - return core.status.hero.items[itemCls][itemId]||0; + if (itemCls == "items") return 0; + return core.status.hero.items[itemCls][itemId] || 0; } ////// 是否存在某个物品 ////// @@ -144,9 +144,9 @@ items.prototype.hasEquip = function (itemId) { if (!core.isset(core.status.hero)) return null; if (!core.isset(itemId)) return null; - if (!core.isset((core.material.items[itemId]||{}).equip)) return null; + if (!core.isset((core.material.items[itemId] || {}).equip)) return null; - for (var i in core.status.hero.equipment||[]) + for (var i in core.status.hero.equipment || []) if (core.status.hero.equipment[i] == itemId) return true; return false @@ -155,7 +155,7 @@ items.prototype.hasEquip = function (itemId) { ////// 获得某个装备类型的当前装备 ////// items.prototype.getEquip = function (equipType) { if (!core.isset(core.status.hero)) return null; - return (core.status.hero.equipment||[])[equipType]||null; + return (core.status.hero.equipment || [])[equipType] || null; } ////// 设置某个物品的个数 ////// @@ -169,7 +169,7 @@ items.prototype.setItem = function (itemId, itemNum) { } core.status.hero.items[itemCls][itemId] = itemNum; if (core.status.hero.items[itemCls][itemId] <= 0) { - if (itemCls!='keys') delete core.status.hero.items[itemCls][itemId]; + if (itemCls != 'keys') delete core.status.hero.items[itemCls][itemId]; else core.status.hero.items[itemCls][itemId] = 0; } core.updateStatusBar(); @@ -181,9 +181,9 @@ items.prototype.removeItem = function (itemId, itemNum) { if (!core.isset(itemNum)) itemNum = 1; if (!core.hasItem(itemId)) return false; var itemCls = core.material.items[itemId].cls; - core.status.hero.items[itemCls][itemId]-=itemNum; + core.status.hero.items[itemCls][itemId] -= itemNum; if (core.status.hero.items[itemCls][itemId] <= 0) { - if (itemCls!='keys') delete core.status.hero.items[itemCls][itemId]; + if (itemCls != 'keys') delete core.status.hero.items[itemCls][itemId]; else core.status.hero.items[itemCls][itemId] = 0; } core.updateStatusBar(); @@ -206,11 +206,11 @@ items.prototype.addItem = function (itemId, itemNum) { } core.status.hero.items[itemCls][itemId] += itemNum; if (core.status.hero.items[itemCls][itemId] <= 0) { - if (itemCls!='keys') delete core.status.hero.items[itemCls][itemId]; + if (itemCls != 'keys') delete core.status.hero.items[itemCls][itemId]; else core.status.hero.items[itemCls][itemId] = 0; } // 永久道具只能有一个 - if (itemCls == 'constants' && core.status.hero.items[itemCls][itemId]>1) + if (itemCls == 'constants' && core.status.hero.items[itemCls][itemId] > 1) core.status.hero.items[itemCls][itemId] = 1; core.updateStatusBar(); } @@ -227,7 +227,7 @@ items.prototype.getEquipTypeById = function (equipId) { items.prototype.getEquipTypeByName = function (name) { var names = core.status.globalAttribute.equipName; for (var i = 0; i < names.length; ++i) { - if (names[i] === name && !core.isset((core.status.hero.equipment||[])[i])) { + if (names[i] === name && !core.isset((core.status.hero.equipment || [])[i])) { return i; } } @@ -237,7 +237,7 @@ items.prototype.getEquipTypeByName = function (name) { // 当前能否撞上某装备 items.prototype.canEquip = function (equipId, hint) { // 装备是否合法 - var equip = core.material.items[equipId]||{}; + var equip = core.material.items[equipId] || {}; if (!core.isset(equip.equip)) { if (hint) core.drawTip("不合法的装备!"); return false; @@ -245,16 +245,16 @@ items.prototype.canEquip = function (equipId, hint) { // 是否拥有该装备 if (!core.hasItem(equipId) && !core.hasEquip(equipId)) { - if (hint) core.drawTip("你当前没有"+equip.name+",无法换装"); + if (hint) core.drawTip("你当前没有" + equip.name + ",无法换装"); return false; } // 可装备条件 var condition = this.equipCondition[equipId]; - if (core.isset(condition) && condition.length>0) { + if (core.isset(condition) && condition.length > 0) { try { if (!eval(condition)) { - if (hint) core.drawTip("当前不可换上"+equip.name); + if (hint) core.drawTip("当前不可换上" + equip.name); return false; } } @@ -278,7 +278,7 @@ items.prototype.loadEquip = function (equipId, callback) { var loadEquip = core.material.items[equipId] || {}; var type = this.getEquipTypeById(equipId); if (type < 0) { - core.drawTip("当前没有"+loadEquip.equip.type+"的空位!"); + core.drawTip("当前没有" + loadEquip.equip.type + "的空位!"); if (core.isset(callback)) callback(); return; } @@ -304,17 +304,17 @@ items.prototype.compareEquipment = function (compareEquipId, beComparedEquipId) var compareAtk = 0, compareDef = 0, compareMdef = 0; if (core.isset(compareEquipId)) { var compareEquip = core.material.items[compareEquipId]; - compareAtk += (compareEquip.equip||{}).atk || 0; - compareDef += (compareEquip.equip||{}).def || 0; - compareMdef += (compareEquip.equip||{}).mdef || 0; + compareAtk += (compareEquip.equip || {}).atk || 0; + compareDef += (compareEquip.equip || {}).def || 0; + compareMdef += (compareEquip.equip || {}).mdef || 0; } if (core.isset(beComparedEquipId)) { var beComparedEquip = core.material.items[beComparedEquipId]; - compareAtk -= (beComparedEquip.equip||{}).atk || 0; - compareDef -= (beComparedEquip.equip||{}).def || 0; - compareMdef -= (beComparedEquip.equip||{}).mdef || 0; + compareAtk -= (beComparedEquip.equip || {}).atk || 0; + compareDef -= (beComparedEquip.equip || {}).def || 0; + compareMdef -= (beComparedEquip.equip || {}).mdef || 0; } - return {"atk":compareAtk,"def":compareDef,"mdef":compareMdef}; + return {"atk": compareAtk, "def": compareDef, "mdef": compareMdef}; } ////// 实际换装的效果 ////// @@ -324,7 +324,7 @@ items.prototype._loadEquipEffect = function (equipId, unloadEquipId, isPercentag if (isPercentage) { for (var v in result) - core.addFlag('__'+v+'_buff__', result[v]/100); + core.addFlag('__' + v + '_buff__', result[v] / 100); } else { for (var v in result) @@ -350,16 +350,16 @@ items.prototype._realLoadEquip = function (type, loadId, unloadId, callback) { core.playSound('equip.mp3'); // --- 实际换装 - this._loadEquipEffect(loadId, unloadId, loadPercentage==null?unloadPercentage:loadPercentage); + this._loadEquipEffect(loadId, unloadId, loadPercentage == null ? unloadPercentage : loadPercentage); // --- 加减 if (loadId) core.removeItem(loadId); if (unloadId) core.addItem(unloadId); - core.status.hero.equipment[type] = loadId||null; + core.status.hero.equipment[type] = loadId || null; // --- 提示 - if (loadId) core.drawTip("已装备上"+loadEquip.name, core.material.icons.items[loadId]); - else if (unloadId) core.drawTip("已卸下"+unloadEquip.name, core.material.icons.items[unloadId]); + if (loadId) core.drawTip("已装备上" + loadEquip.name, core.material.icons.items[loadId]); + else if (unloadId) core.drawTip("已卸下" + unloadEquip.name, core.material.icons.items[unloadId]); if (core.isset(callback)) callback(); } @@ -370,38 +370,38 @@ items.prototype.quickSaveEquip = function (index) { var saveEquips = core.getFlag("saveEquips", []); saveEquips[index] = core.clone(core.status.hero.equipment); core.setFlag("saveEquips", saveEquips); - core.drawTip("已保存"+index+"号套装"); + core.drawTip("已保存" + index + "号套装"); } ////// 读取装备 ////// items.prototype.quickLoadEquip = function (index) { var current = core.getFlag("saveEquips", [])[index]; if (!core.isset(current)) { - core.drawTip(index+"号套装不存在"); + core.drawTip(index + "号套装不存在"); return; } // 检查所有的装备 var equipSize = core.status.globalAttribute.equipName.length; - for (var i=0;i 32*32*3000) { - console.warn("警告!"+imgName+"上的图块素材个数大于3000!"); + if (img.width * img.height > 32 * 32 * 3000) { + console.warn("警告!" + imgName + "上的图块素材个数大于3000!"); } } callback(); @@ -99,12 +99,12 @@ loader.prototype._loadTilesets = function (callback) { } loader.prototype.loadImages = function (names, toSave, callback) { - if (!core.isset(names) || names.length==0) { + if (!core.isset(names) || names.length == 0) { if (core.isset(callback)) callback(); return; } var items = 0; - for (var i=0;i=0) { + if (index >= 0) { core.musicStatus.cachedBgms.splice(index, 1); } else { @@ -267,7 +267,9 @@ loader.prototype._preloadBgm = function (bgm) { loader.prototype.freeBgm = function (name) { if (!core.isset(core.material.bgms[name])) return; // 从cachedBgms中删除 - core.musicStatus.cachedBgms = core.musicStatus.cachedBgms.filter(function (t) {return t!=name; }); + core.musicStatus.cachedBgms = core.musicStatus.cachedBgms.filter(function (t) { + return t != name; + }); // 清掉缓存 core.material.bgms[name].removeAttribute("src"); core.material.bgms[name].load(); diff --git a/libs/utils.js b/libs/utils.js index 969cb745..9cb77897 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -18,7 +18,7 @@ function utils() { utils.prototype._init = function () { // 定义Object.assign if (typeof Object.assign != "function") { - Object.assign = function(target, varArgs) { // .length of function is 2 + Object.assign = function (target, varArgs) { // .length of function is 2 if (target == null) { // TypeError if undefined or null throw new TypeError('Cannot convert undefined or null to object'); } @@ -41,7 +41,7 @@ utils.prototype._init = function () { }; } if (typeof String.prototype.endsWith != "function") { - String.prototype.endsWith = function(search, this_len) { + String.prototype.endsWith = function (search, this_len) { if (this_len === undefined || this_len > this.length) { this_len = this.length; } @@ -63,10 +63,10 @@ utils.prototype.replaceText = function (text, need, times) { utils.prototype.calValue = function (value, prefix, need, times) { if (!core.isset(value)) return value; if (typeof value === 'string') { - value=value.replace(/status:([\w\d_]+)/g, "core.getStatus('$1')"); - value=value.replace(/item:([\w\d_]+)/g, "core.itemCount('$1')"); - value=value.replace(/flag:([\w\d_]+)/g, "core.getFlag('$1', 0)"); - value=value.replace(/switch:([\w\d_]+)/g, "core.getFlag('"+(prefix||"global")+"@$1', 0)"); + value = value.replace(/status:([\w\d_]+)/g, "core.getStatus('$1')"); + value = value.replace(/item:([\w\d_]+)/g, "core.itemCount('$1')"); + value = value.replace(/flag:([\w\d_]+)/g, "core.getFlag('$1', 0)"); + value = value.replace(/switch:([\w\d_]+)/g, "core.getFlag('" + (prefix || "global") + "@$1', 0)"); return eval(value); } if (value instanceof Function) { @@ -76,27 +76,27 @@ utils.prototype.calValue = function (value, prefix, need, times) { } ////// 字符串自动换行的分割 ////// -utils.prototype.splitLines = function(canvas, text, maxLength, font) { +utils.prototype.splitLines = function (canvas, text, maxLength, font) { if (core.isset(font)) core.setFont(canvas, font); var contents = []; var last = 0; - for (var i=0;imaxLength) { + if (core.isset(maxLength) && width > maxLength) { contents.push(text.substring(last, i)); - last=i; + last = i; } } } @@ -105,7 +105,7 @@ utils.prototype.splitLines = function(canvas, text, maxLength, font) { } ////// 向某个数组前插入另一个数组或元素 ////// -utils.prototype.unshift = function (a,b) { +utils.prototype.unshift = function (a, b) { if (!(a instanceof Array) || !core.isset(b)) return; if (b instanceof Array) { core.clone(b).reverse().forEach(function (e) { @@ -117,7 +117,7 @@ utils.prototype.unshift = function (a,b) { } ////// 向某个数组后插入另一个数组或元素 ////// -utils.prototype.push = function (a,b) { +utils.prototype.push = function (a, b) { if (!(a instanceof Array) || !core.isset(b)) return; if (b instanceof Array) { core.clone(b).forEach(function (e) { @@ -129,21 +129,21 @@ utils.prototype.push = function (a,b) { } ////// 设置本地存储 ////// -utils.prototype.setLocalStorage = function(key, value) { +utils.prototype.setLocalStorage = function (key, value) { try { if (!core.isset(value)) { this.removeLocalStorage(key); return; } - var str = JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function(chr) { + var str = JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function (chr) { return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4) }); var compressed = lzw_encode(str); // test if we can save to localStorage localStorage.setItem("__tmp__", compressed); - if (lzw_decode(localStorage.getItem("__tmp__"))==str) { + if (lzw_decode(localStorage.getItem("__tmp__")) == str) { localStorage.setItem(core.firstData.name + "_" + key, compressed); } else { @@ -169,29 +169,33 @@ utils.prototype.decompress = function (value) { if (core.isset(output) && output.length > 0) return JSON.parse(output); } - catch (e) {} + catch (e) { + } try { var output = LZString.decompress(value); if (core.isset(output) && output.length > 0) return JSON.parse(output); } - catch (e) {} + catch (e) { + } try { return JSON.parse(value); } - catch (e) {main.log(e);} + catch (e) { + main.log(e); + } return null; } ////// 获得本地存储 ////// -utils.prototype.getLocalStorage = function(key, defaultValue) { - var res = this.decompress(localStorage.getItem(core.firstData.name+"_"+key)); - return res==null?defaultValue:res; +utils.prototype.getLocalStorage = function (key, defaultValue) { + var res = this.decompress(localStorage.getItem(core.firstData.name + "_" + key)); + return res == null ? defaultValue : res; } ////// 移除本地存储 ////// utils.prototype.removeLocalStorage = function (key) { - localStorage.removeItem(core.firstData.name+"_"+key); + localStorage.removeItem(core.firstData.name + "_" + key); if (key == 'autoSave') delete core.saves.ids[0]; else if (/^save\d+$/.test(key)) delete core.saves.ids[parseInt(key.substring(4))]; } @@ -214,10 +218,10 @@ utils.prototype.setLocalForage = function (key, value, successCallback, errorCal } // Save to localforage - var compressed = lzw_encode(JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function(chr) { + var compressed = lzw_encode(JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function (chr) { return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4) })); - localforage.setItem(core.firstData.name+"_"+key, compressed, function (err) { + localforage.setItem(core.firstData.name + "_" + key, compressed, function (err) { if (core.isset(err)) { if (core.isset(errorCallback)) errorCallback(err); } @@ -232,14 +236,14 @@ utils.prototype.setLocalForage = function (key, value, successCallback, errorCal utils.prototype.getLocalForage = function (key, defaultValue, successCallback, errorCallback) { if (!core.platform.useLocalForage) { - var value=this.getLocalStorage(key, defaultValue); + var value = this.getLocalStorage(key, defaultValue); if (core.isset(successCallback)) { successCallback(value); } return; } - localforage.getItem(core.firstData.name+"_"+key, function (err, value) { + localforage.getItem(core.firstData.name + "_" + key, function (err, value) { if (core.isset(err)) { if (core.isset(errorCallback)) errorCallback(err); } @@ -247,7 +251,7 @@ utils.prototype.getLocalForage = function (key, defaultValue, successCallback, e if (!core.isset(successCallback)) return; if (core.isset(value)) { var res = core.utils.decompress(value); - successCallback(res==null?defaultValue:res); + successCallback(res == null ? defaultValue : res); return; } successCallback(defaultValue); @@ -263,7 +267,7 @@ utils.prototype.removeLocalForage = function (key, successCallback, errorCallbac return; } - localforage.removeItem(core.firstData.name+"_"+key, function (err) { + localforage.removeItem(core.firstData.name + "_" + key, function (err) { if (core.isset(err)) { if (core.isset(errorCallback)) errorCallback(err); } @@ -280,13 +284,13 @@ utils.prototype.clone = function (data) { if (!core.isset(data)) return data; // date if (data instanceof Date) { - var copy=new Date(); + var copy = new Date(); copy.setTime(data.getTime()); return copy; } // array if (data instanceof Array) { - var copy=[]; + var copy = []; // for (var i=0;i=one.val) { - var v = x/one.val; - return c + v.toFixed(Math.max(0, Math.floor(3-Math.log10(v+1)))) + one.c; + if (x >= one.val) { + var v = x / one.val; + return c + v.toFixed(Math.max(0, Math.floor(3 - Math.log10(v + 1)))) + one.c; } } else { - if (x>=10*one.val) { - var v = x/one.val; - return c + v.toFixed(Math.max(0, Math.floor(4-Math.log10(v+1)))) + one.c; + if (x >= 10 * one.val) { + var v = x / one.val; + return c + v.toFixed(Math.max(0, Math.floor(4 - Math.log10(v + 1)))) + one.c; } } } - return c+x; + return c + x; } ////// 数组转RGB ////// utils.prototype.arrayToRGB = function (color) { - var nowR = this.clamp(parseInt(color[0]),0,255), nowG = this.clamp(parseInt(color[1]),0,255), - nowB = this.clamp(parseInt(color[2]),0,255); - return "#"+((1<<24)+(nowR<<16)+(nowG<<8)+nowB).toString(16).slice(1); + var nowR = this.clamp(parseInt(color[0]), 0, 255), nowG = this.clamp(parseInt(color[1]), 0, 255), + nowB = this.clamp(parseInt(color[2]), 0, 255); + return "#" + ((1 << 24) + (nowR << 16) + (nowG << 8) + nowB).toString(16).slice(1); } utils.prototype.arrayToRGBA = function (color) { - if (!this.isset(color[3])) color[3]=1; - var nowR = this.clamp(parseInt(color[0]),0,255), nowG = this.clamp(parseInt(color[1]),0,255), - nowB = this.clamp(parseInt(color[2]),0,255), nowA = this.clamp(parseFloat(color[3]),0,1); - return "rgba("+nowR+","+nowG+","+nowB+","+nowA+")"; + if (!this.isset(color[3])) color[3] = 1; + var nowR = this.clamp(parseInt(color[0]), 0, 255), nowG = this.clamp(parseInt(color[1]), 0, 255), + nowB = this.clamp(parseInt(color[2]), 0, 255), nowA = this.clamp(parseFloat(color[3]), 0, 1); + return "rgba(" + nowR + "," + nowG + "," + nowB + "," + nowA + ")"; } ////// 加密路线 ////// utils.prototype.encodeRoute = function (route) { - var ans="", lastMove = "", cnt=0; + var ans = "", lastMove = "", cnt = 0; route.forEach(function (t) { - if (t=='up' || t=='down' || t=='left' || t=='right') { - if (t!=lastMove && cnt>0) { - ans+=lastMove.substring(0,1).toUpperCase(); - if (cnt>1) ans+=cnt; - cnt=0; + if (t == 'up' || t == 'down' || t == 'left' || t == 'right') { + if (t != lastMove && cnt > 0) { + ans += lastMove.substring(0, 1).toUpperCase(); + if (cnt > 1) ans += cnt; + cnt = 0; } - lastMove=t; + lastMove = t; cnt++; } else { - if (cnt>0) { - ans+=lastMove.substring(0,1).toUpperCase(); - if (cnt>1) ans+=cnt; - cnt=0; + if (cnt > 0) { + ans += lastMove.substring(0, 1).toUpperCase(); + if (cnt > 1) ans += cnt; + cnt = 0; } ans += core.utils._encodeRoute_encodeOne(t); } }); - if (cnt>0) { - ans+=lastMove.substring(0,1).toUpperCase(); - if (cnt>1) ans+=cnt; + if (cnt > 0) { + ans += lastMove.substring(0, 1).toUpperCase(); + if (cnt > 1) ans += cnt; } return LZString.compressToBase64(ans); } utils.prototype._encodeRoute_id2number = function (id) { var number = core.maps.getNumberById(id); - return number==0?id:number; + return number == 0 ? id : number; } utils.prototype._encodeRoute_encodeOne = function (t) { - if (t.indexOf('item:')==0) - return "I"+this._encodeRoute_id2number(t.substring(5))+":"; - else if (t.indexOf('unEquip:')==0) - return "u"+t.substring(8); - else if (t.indexOf('equip:')==0) - return "e"+this._encodeRoute_id2number(t.substring(6))+":"; - else if (t.indexOf('fly:')==0) - return "F"+t.substring(4)+":"; - else if (t.indexOf('choices:')==0) - return "C"+t.substring(8); - else if (t.indexOf('shop:')==0) - return "S"+t.substring(5); - else if (t=='turn') + if (t.indexOf('item:') == 0) + return "I" + this._encodeRoute_id2number(t.substring(5)) + ":"; + else if (t.indexOf('unEquip:') == 0) + return "u" + t.substring(8); + else if (t.indexOf('equip:') == 0) + return "e" + this._encodeRoute_id2number(t.substring(6)) + ":"; + else if (t.indexOf('fly:') == 0) + return "F" + t.substring(4) + ":"; + else if (t.indexOf('choices:') == 0) + return "C" + t.substring(8); + else if (t.indexOf('shop:') == 0) + return "S" + t.substring(5); + else if (t == 'turn') return 'T'; - else if (t.indexOf('turn:')==0) - return "t"+t.substring(5).substring(0,1).toUpperCase()+":"; - else if (t=='getNext') + else if (t.indexOf('turn:') == 0) + return "t" + t.substring(5).substring(0, 1).toUpperCase() + ":"; + else if (t == 'getNext') return 'G'; - else if (t.indexOf('input:')==0) - return "P"+t.substring(6); - else if (t.indexOf('input2:')==0) - return "Q"+t.substring(7)+":"; - else if (t=='no') + else if (t.indexOf('input:') == 0) + return "P" + t.substring(6); + else if (t.indexOf('input2:') == 0) + return "Q" + t.substring(7) + ":"; + else if (t == 'no') return 'N'; - else if (t.indexOf('move:')==0) - return "M"+t.substring(5); - else if (t.indexOf('key:')==0) - return 'K'+t.substring(4); - else if (t.indexOf('random:')==0) - return 'X'+t.substring(7); + else if (t.indexOf('move:') == 0) + return "M" + t.substring(5); + else if (t.indexOf('key:') == 0) + return 'K' + t.substring(4); + else if (t.indexOf('random:') == 0) + return 'X' + t.substring(7); return ''; } @@ -476,7 +480,8 @@ utils.prototype.decodeRoute = function (route) { if (core.isset(v) && /^[a-zA-Z0-9+\/=:]*$/.test(v)) { route = v; } - } catch (e) {} + } catch (e) { + } var decodeObj = {route: route, index: 0, ans: []}; while (decodeObj.index < decodeObj.route.length) { @@ -486,18 +491,18 @@ utils.prototype.decodeRoute = function (route) { } utils.prototype._decodeRoute_getNumber = function (decodeObj, noparse) { - var num=""; - while (decodeObj.index0) { + var na = core.clone(a), nb = core.clone(b); + while (nb.length > 0) { if (na.shift() != nb.shift()) return null; } return na; } utils.prototype.inArray = function (array, element) { - return this.isset(array) && (array instanceof Array) && array.indexOf(element)>=0; + return this.isset(array) && (array instanceof Array) && array.indexOf(element) >= 0; } utils.prototype.clamp = function (x, a, b) { - var min=Math.min(a, b), max=Math.max(a, b); - return Math.min(Math.max(x||0, min), max); + var min = Math.min(a, b), max = Math.max(a, b); + return Math.min(Math.max(x || 0, min), max); } utils.prototype.getCookie = function (name) { var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); - return match?match[2]:null; + return match ? match[2] : null; } utils.prototype.expandMoveSteps = function (steps) { - var moveSteps=[]; + var moveSteps = []; steps.forEach(function (e) { - if (typeof e=="string") { + if (typeof e == "string") { moveSteps.push(e); } else { @@ -581,7 +622,7 @@ utils.prototype.expandMoveSteps = function (steps) { moveSteps.push(e.direction) } else { - for (var i=0;i\/?]*$/.test(value); - var style = 'font-style: ' + (italic?'italic':'normal') + '; '; + var style = 'font-style: ' + (italic ? 'italic' : 'normal') + '; '; // 判定是否需要缩放 var length = this.strlen(value) || 1; - style += 'font-size: ' + Math.min(1, 7/length) + 'em; '; + style += 'font-size: ' + Math.min(1, 7 / length) + 'em; '; if (core.isset(css)) style += css; core.statusBar[name].innerHTML = "" + value + ""; } @@ -620,7 +661,7 @@ utils.prototype.encodeBase64 = function (str) { ////// Base64解密 ////// utils.prototype.decodeBase64 = function (str) { - return decodeURIComponent(atob(str).split('').map(function(c) { + return decodeURIComponent(atob(str).split('').map(function (c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); } @@ -628,19 +669,19 @@ utils.prototype.decodeBase64 = function (str) { ////// 任意进制转换 ////// utils.prototype.convertBase = function (str, fromBase, toBase) { var map = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]\\|:;<>,.?/"; - if (fromBase==toBase) return str; - var len = str.length, ans=""; + if (fromBase == toBase) return str; + var len = str.length, ans = ""; var t = []; - for (var i=0;i0) { - for (var i=len; i>=1; i--) { - t[i-1]+=t[i]%toBase*fromBase; - t[i]=parseInt(t[i]/toBase); + for (var i = 0; i < len; i++) t[i] = map.indexOf(str.charAt(i)); + t[len] = 0; + while (len > 0) { + for (var i = len; i >= 1; i--) { + t[i - 1] += t[i] % toBase * fromBase; + t[i] = parseInt(t[i] / toBase); } - ans+=map.charAt(t[0]%toBase); - t[0]=parseInt(t[0]/toBase); - while (len>0 && t[len-1]==0) len--; + ans += map.charAt(t[0] % toBase); + t[0] = parseInt(t[0] / toBase); + while (len > 0 && t[len - 1] == 0) len--; } return ans; } @@ -649,21 +690,21 @@ utils.prototype.rand = function (num) { var rand = core.getFlag('__rand__'); rand = this.__next_rand(rand); core.setFlag('__rand__', rand); - var ans = rand/2147483647; - if (core.isset(num) && num>0) - return Math.floor(ans*num); + var ans = rand / 2147483647; + if (core.isset(num) && num > 0) + return Math.floor(ans * num); return ans; } ////// 生成随机数(录像方法) ////// utils.prototype.rand2 = function (num) { - num = num||2147483648; + num = num || 2147483648; var value; if (core.isReplaying()) { var action = core.status.replay.toReplay.shift(); - if (action.indexOf("random:")==0 ) { - value=parseInt(action.substring(7)); + if (action.indexOf("random:") == 0) { + value = parseInt(action.substring(7)); } else { core.stopReplay(); @@ -672,14 +713,14 @@ utils.prototype.rand2 = function (num) { } } else { - value = Math.floor(Math.random()*num); + value = Math.floor(Math.random() * num); } - core.status.route.push("random:"+value); + core.status.route.push("random:" + value); return value; } utils.prototype.__init_seed = function () { - var rand = new Date().getTime()%34834795 + 3534; + var rand = new Date().getTime() % 34834795 + 3534; rand = this.__next_rand(rand); rand = this.__next_rand(rand); rand = this.__next_rand(rand); @@ -688,8 +729,8 @@ utils.prototype.__init_seed = function () { } utils.prototype.__next_rand = function (_rand) { - _rand=(_rand%127773)*16807-~~(_rand/127773)*2836; - _rand+=_rand<0?2147483647:0; + _rand = (_rand % 127773) * 16807 - ~~(_rand / 127773) * 2836; + _rand += _rand < 0 ? 2147483647 : 0; return _rand; } @@ -712,24 +753,24 @@ utils.prototype.readFile = function (success, error, readType) { } // Step 1: 如果不支持FileReader,直接不支持 - if (core.platform.fileReader==null) { + if (core.platform.fileReader == null) { alert("当前浏览器不支持FileReader!"); if (core.isset(error)) error(); return; } - if (core.platform.fileInput==null) { + if (core.platform.fileInput == null) { core.platform.fileInput = document.createElement("input"); core.platform.fileInput.style.opacity = 0; core.platform.fileInput.type = 'file'; core.platform.fileInput.onchange = function () { var files = core.platform.fileInput.files; - if (files.length==0) { + if (files.length == 0) { if (core.isset(core.platform.errorCallback)) core.platform.errorCallback(); return; } - if(!readType)core.platform.fileReader.readAsText(core.platform.fileInput.files[0]); + if (!readType) core.platform.fileReader.readAsText(core.platform.fileInput.files[0]); else core.platform.fileReader.readAsDataURL(core.platform.fileInput.files[0]); core.platform.fileInput.value = ''; } @@ -740,14 +781,14 @@ utils.prototype.readFile = function (success, error, readType) { ////// 读取文件完毕 ////// utils.prototype.readFileContent = function (content) { - var obj=null; - if(content.slice(0,4)==='data'){ + var obj = null; + if (content.slice(0, 4) === 'data') { if (core.isset(core.platform.successCallback)) core.platform.successCallback(content); return; } try { - obj=JSON.parse(content); + obj = JSON.parse(content); if (core.isset(obj)) { if (core.isset(core.platform.successCallback)) core.platform.successCallback(obj); @@ -807,14 +848,14 @@ utils.prototype.download = function (filename, content) { alert("你当前使用的是Safari浏览器,不支持直接下载文件。\n即将打开一个新窗口为应下载内容,请自行全选复制然后创建空白文件并粘贴。"); var blob = new Blob([content], {type: 'text/plain;charset=utf-8'}); var href = window.URL.createObjectURL(blob); - var opened=window.open(href, "_blank"); + var opened = window.open(href, "_blank"); window.URL.revokeObjectURL(href); return; } // Step 4: 下载 var blob = new Blob([content], {type: 'text/plain;charset=utf-8'}); - if(window.navigator.msSaveOrOpenBlob) { + if (window.navigator.msSaveOrOpenBlob) { window.navigator.msSaveBlob(blob, filename); } else { @@ -868,7 +909,7 @@ utils.prototype.copy = function (data) { ////// 动画显示某对象 ////// utils.prototype.show = function (obj, speed, callback) { obj.style.display = 'block'; - if (!core.isset(speed) && main.mode!='play') { + if (!core.isset(speed) && main.mode != 'play') { obj.style.opacity = 1; if (core.isset(callback)) callback(); return; @@ -889,7 +930,7 @@ utils.prototype.show = function (obj, speed, callback) { ////// 动画使某对象消失 ////// utils.prototype.hide = function (obj, speed, callback) { - if (!core.isset(speed) || main.mode!='play'){ + if (!core.isset(speed) || main.mode != 'play') { obj.style.display = 'none'; if (core.isset(callback)) callback(); return; @@ -918,16 +959,16 @@ utils.prototype.encodeCanvas = function (ctx) { ctx.imageSmoothingEnabled = false; var imgData = ctx.getImageData(0, 0, width, height); - for (var i=0;i threshold - || window.outerHeight - zoom*window.innerHeight > threshold; + var zoom = Math.min(window.outerWidth / window.innerWidth, window.outerHeight / window.innerHeight); + return window.outerWidth - zoom * window.innerWidth > threshold + || window.outerHeight - zoom * window.innerHeight > threshold; } utils.prototype.hashCode = function (obj) { @@ -977,8 +1018,8 @@ utils.prototype.hashCode = function (obj) { var hash = 0, i, chr; if (obj.length === 0) return hash; for (i = 0; i < obj.length; i++) { - chr = obj.charCodeAt(i); - hash = ((hash << 5) - hash) + chr; + chr = obj.charCodeAt(i); + hash = ((hash << 5) - hash) + chr; hash |= 0; } return hash; @@ -1011,20 +1052,20 @@ utils.prototype.same = function (a, b) { utils.prototype._export = function (floorIds) { if (!core.isset(floorIds)) floorIds = [core.status.floorId]; - else if (floorIds=='all') floorIds = core.clone(core.floorIds); + else if (floorIds == 'all') floorIds = core.clone(core.floorIds); else if (typeof floorIds == 'string') floorIds = [floorIds]; var monsterMap = {}; // map - var content = floorIds.length+"\n13 13\n\n"; + var content = floorIds.length + "\n13 13\n\n"; floorIds.forEach(function (floorId) { var arr = core.maps.getMapArray(core.status.maps[floorId].blocks, 13, 13); content += arr.map(function (x) { // check monster x.forEach(function (t) { var block = core.maps.initBlock(null, null, t); - if (block.event.cls.indexOf("enemy")==0) { + if (block.event.cls.indexOf("enemy") == 0) { monsterMap[t] = block.event.id; } }) @@ -1034,7 +1075,9 @@ utils.prototype._export = function (floorIds) { // values content += ["redJewel", "blueJewel", "greenJewel", "redPotion", "bluePotion", - "yellowPotion", "greenPotion", "sword1", "shield1"].map(function (x) {return core.values[x]}).join(" ") + "\n\n"; + "yellowPotion", "greenPotion", "sword1", "shield1"].map(function (x) { + return core.values[x] + }).join(" ") + "\n\n"; // monster content += Object.keys(monsterMap).length + "\n"; @@ -1059,26 +1102,26 @@ utils.prototype.http = function (type, url, formData, success, error, mimeType, xhr.overrideMimeType(mimeType); if (core.isset(responseType)) xhr.responseType = responseType; - xhr.onload = function(e) { - if (xhr.status==200) { + xhr.onload = function (e) { + if (xhr.status == 200) { if (core.isset(success)) { success(xhr.response); } } else { if (core.isset(error)) - error("HTTP "+xhr.status); + error("HTTP " + xhr.status); } }; xhr.onabort = function () { if (core.isset(error)) error("Abort"); } - xhr.ontimeout = function() { + xhr.ontimeout = function () { if (core.isset(error)) error("Timeout"); } - xhr.onerror = function() { + xhr.onerror = function () { if (core.isset(error)) error("Error on Connection"); } @@ -1096,8 +1139,8 @@ function lzw_encode(s) { var currChar; var phrase = data[0]; var code = 256; - for (var i=1; i 1 ? dict[phrase] : phrase.charCodeAt(0)); dict[phrase + currChar] = code; code++; - phrase=currChar; + phrase = currChar; } } out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0)); - for (var i=0; i