mirror of
https://github.com/unanmed/HumanBreak.git
synced 2026-11-07 13:14:30 +08:00
Deploying to gh-pages from @ 8ec41d634a 🚀
This commit is contained in:
1 parent
350603e640
commit
ce9c2d075f
2 files changed
+39
-185
No files matched your search
Vendored
+1
-1
@@ -11,7 +11,7 @@
|
||||
"use strict";(function(){var ignoreInJump={event:["X20007","X20001","X20006","X20014","X20010","X20007"],bg:["X20037","X20038","X20039","X20045","X20047","X20053","X20054","X20055","X20067","X20068","X20075","X20076"]};var jumpIgnoreFloor=["MT31","snowTown"];function jumpSkill(){if(core.status.floorId.startsWith("tower"))return core.drawTip("\u5F53\u65E0\u6CD5\u4F7F\u7528\u8BE5\u6280\u80FD");if(jumpIgnoreFloor.includes(core.status.floorId)||flags.onChase){return core.drawTip("\u5F53\u524D\u697C\u5C42\u65E0\u6CD5\u4F7F\u7528\u8BE5\u6280\u80FD")}if(!flags.skill2)return;if(!flags["jump_"+core.status.floorId])flags["jump_"+core.status.floorId]=0;if(core.status.floorId=="MT14"&&flags["jump_"+core.status.floorId]==2&&!flags.MT14Jump){if(!(core.status.hero.loc.x===77&&core.status.hero.loc.y===5&&core.status.hero.loc.direction==="right")){return core.drawTip("\u8BE5\u5730\u56FE\u8FD8\u6709\u4E00\u4E2A\u5FC5\u8DF3\u7684\u5730\u65B9\uFF0C\u4F60\u8FD8\u6CA1\u6709\u8DF3")}else flags.MT14Jump=true}if(flags["jump_"+core.status.floorId]>=3)return core.drawTip("\u5F53\u524D\u5730\u56FE\u4F7F\u7528\u6B21\u6570\u5DF2\u7528\u5B8C");var direction=core.status.hero.loc.direction;var loc=core.status.hero.loc;var checkLoc={};switch(direction){case"up":checkLoc.x=loc.x;checkLoc.y=loc.y-1;break;case"right":checkLoc.x=loc.x+1;checkLoc.y=loc.y;break;case"down":checkLoc.x=loc.x;checkLoc.y=loc.y+1;break;case"left":checkLoc.x=loc.x-1;checkLoc.y=loc.y;break;}var cls=core.getBlockCls(checkLoc.x,checkLoc.y);var noPass=core.noPass(checkLoc.x,checkLoc.y);var id=core.getBlockId(checkLoc.x,checkLoc.y)||"";var bgId=core.getBlockByNumber(core.getBgNumber(checkLoc.x,checkLoc.y)).event.id||"";if(!noPass||cls=="items"||id.startsWith("X")&&!ignoreInJump.event.includes(id)||bgId.startsWith("X")&&!ignoreInJump.bg.includes(bgId))return core.drawTip("\u5F53\u524D\u65E0\u6CD5\u4F7F\u7528\u6280\u80FD");if(noPass&&!(cls=="enemys"||cls=="enemy48")){var toLoc=checkNoPass(direction,checkLoc.x,checkLoc.y,true);if(!toLoc)return;core.autosave();if(flags.chapter<=1)core.status.hero.hp-=200*flags.hard;core.updateStatusBar();flags["jump_"+core.status.floorId]++;if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose("\u4F60\u8DF3\u6B7B\u4E86")}core.playSound("015-Jump01.ogg");core.insertAction([{type:"jumpHero",loc:[toLoc.x,toLoc.y],time:500}])}if(cls=="enemys"||cls=="enemy48"){var firstNoPass=checkNoPass(direction,checkLoc.x,checkLoc.y,false);if(!firstNoPass)return;core.autosave();if(flags.chapter<=1)core.status.hero.hp-=200*flags.hard;core.updateStatusBar();flags["jump_"+core.status.floorId]++;if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose("\u4F60\u8DF3\u6B7B\u4E86")}core.playSound("015-Jump01.ogg");core.insertAction([{type:"jump",from:[checkLoc.x,checkLoc.y],to:[firstNoPass.x,firstNoPass.y],time:500,keep:true}])}function checkNoPass(direction,x,y,startNo){if(!startNo)startNo=false;switch(direction){case"up":y--;break;case"right":x++;break;case"down":y++;break;case"left":x--;break;}if(x>core.status.thisMap.width-1||y>core.status.thisMap.height-1||x<0||y<0)return core.drawTip("\u5F53\u524D\u65E0\u6CD5\u4F7F\u7528\u6280\u80FD");var id=core.getBlockId(x,y)||"";if(core.getBgNumber(x,y))var bgId=core.getBlockByNumber(core.getBgNumber(x,y)).event.id||"";else var bgId="";if(core.noPass(x,y)||core.getBlockCls(x,y)=="items"||id.startsWith("X")&&!ignoreInJump.event.includes(id)||bgId.startsWith("X")&&!ignoreInJump.bg.includes(bgId)||core.getBlockCls(x,y)=="animates")return checkNoPass(direction,x,y,true);if(!startNo)return checkNoPass(direction,x,y,false);return{x:x,y:y}}}core.plugin.skillEffects={jumpSkill:jumpSkill}})();
|
||||
"use strict";(function(){var stage=1,hp=10000,seconds=0,boomLocs=[],heroHp;function initTowerBoss(){stage=1;hp=10000;seconds=0;heroHp=core.status.hero.hp;dynamicChangeHp(0,10000,10000);autoFixRouteBoss(true);core.insertAction([{type:"sleep",time:1000,noSkip:true}]);setTimeout(bossCore,1000)}function autoFixRouteBoss(isStart){var route=core.status.route;if(isStart){flags.startFix=route.length-1;return}route.splice(flags.startFix);route.push("choices:0");delete flags.startFix}function healthBar(now,total){var nowLength=now/total*476;var color=[255*2-now/total*2*255,now/total*2*255,0,1];if(!core.dymCanvas.healthBar)core.createCanvas("healthBar",0,0,480,16,140);else core.clearMap("healthBar");core.fillRect("healthBar",0,0,480,16,"#bbbbbb");var style=document.getElementById("healthBar").getContext("2d");style.shadowColor="rgba(0, 0, 0, 0.8)";style.shadowBlur=5;style.shadowOffsetX=10;style.shadowOffsetY=5;style.filter="blur(1px)";core.fillRect("healthBar",2,2,nowLength,12,color);style.shadowColor="rgba(0, 0, 0, 0.5)";style.shadowOffsetX=0;style.shadowOffsetY=0;core.strokeRect("healthBar",1,1,478,14,"#ffffff",2);style.shadowColor="rgba(0, 0, 0, 1)";style.shadowBlur=3;style.shadowOffsetX=2;style.shadowOffsetY=1;style.filter="none";core.fillText("healthBar",now+"/"+total,5,13.5,"#ffffff","16px normal")}function dynamicChangeHp(from,to,total){var frame=0,speed=(to-from)/50,now=from;var interval=window.setInterval(function(){frame++;if(frame==50){clearInterval(interval);healthBar(to,total)}now+=speed;healthBar(now,total)},20)}function skipWord(words,x,y,time){x=x||0;y=y||16;time=time||3000;if(!core.dymCanvas.words)core.createCanvas("words",x,y,480,24,135);else core.clearMap("words");if(flags.wordsTimeOut)clearTimeout(flags.wordsTimeOut);dynamicCurtain(y,y+24,time/3);var style=document.getElementById("words").getContext("2d");style.shadowColor="rgba(0, 0, 0, 1)";style.shadowBlur=3;style.shadowOffsetX=2;style.shadowOffsetY=1;skip1(0);function skip1(now){if(parseInt(now)>=words.length){flags.wordsTimeOut=setTimeout(function(){core.deleteCanvas("words");core.deleteCanvas("wordsBg")},time);return}var frame=0,blur=2,nx=4+now*24;var skip2=window.setInterval(function(){blur-=0.4;frame++;core.clearMap("words",nx,0,24,24);style.filter="blur("+blur+"px)";core.fillText("words",words[now],nx,20,"#ffffff","22px normal");if(frame==5){clearInterval(skip2);skip1(now+1)}},20)}}function dynamicCurtain(from,to,time,width){width=width||480;if(!core.dymCanvas.wordsBg)core.createCanvas("wordsBg",0,from,width,24,130);else core.clearMap("wordsBg");time/=1000;var ny=from,frame=0,a=2*(to-from)/Math.pow(time*50,2),speed=a*time*50;var style=document.getElementById("wordsBg").getContext("2d");style.shadowColor="rgba(0, 0, 0, 0.8)";var wordsInterval=window.setInterval(function(){frame++;speed-=a;ny+=speed;core.clearMap("wordsBg");style.shadowBlur=8;style.shadowOffsetY=2;core.fillRect("wordsBg",0,0,width,ny-from,[180,180,180,0.7]);style.shadowBlur=3;style.shadowOffsetY=0;core.strokeRect("wordsBg",1,1,width-2,ny-from-2,[255,255,255,0.7],2);if(frame>=time*50){clearInterval(wordsInterval);core.clearMap("wordsBg");style.shadowBlur=8;style.shadowOffsetY=2;core.fillRect("wordsBg",0,0,width,to-from,[180,180,180,0.7]);style.shadowBlur=3;style.shadowOffsetY=0;core.strokeRect("wordsBg",1,1,width-2,ny-from-2,[255,255,255,0.7],2)}},20)}function attackBoss(){if(flags.canAttack)return;if(Math.random()<0.8)return;if(hp>3500){var nx=Math.floor(Math.random()*13+1),ny=Math.floor(Math.random()*13+1)}else if(hp>2000){var nx=Math.floor(Math.random()*11+2),ny=Math.floor(Math.random()*11+2)}else if(hp>1000){var nx=Math.floor(Math.random()*9+3),ny=Math.floor(Math.random()*9+3)}else{var nx=Math.floor(Math.random()*7+4),ny=Math.floor(Math.random()*7+4)}flags.canAttack=true;if(!core.dymCanvas.attackBoss)core.createCanvas("attackBoss",0,0,480,480,35);else core.clearMap("attackBoss");var style=document.getElementById("attackBoss").getContext("2d");var frame1=0,blur=3,scale=2,speed=0.04,a=0.0008;var atkAnimate=window.setInterval(function(){core.clearMap("attackBoss");frame1++;speed-=a;scale-=speed;blur-=0.06;style.filter="blur("+blur+"px)";core.strokeCircle("attackBoss",nx*32+16,ny*32+16,16*scale,[255,150,150,0.7],4);core.fillCircle("attackBoss",nx*32+16,ny*32+16,3*scale,[255,150,150,0.7]);if(frame1==50){clearInterval(atkAnimate);core.clearMap("attactkBoss");style.filter="none";core.strokeCircle("attackBoss",nx*32+16,ny*32+16,16,[255,150,150,0.7],4);core.fillCircle("attackBoss",nx*32+16,ny*32+16,3,[255,150,150,0.7])}},20);var frame2=0;var atkBoss=window.setInterval(function(){frame2++;var x=core.status.hero.loc.x,y=core.status.hero.loc.y;if(frame2>100){setTimeout(function(){delete flags.canAttack},4000);clearInterval(atkBoss);core.deleteCanvas("attackBoss");return}if(nx==x&&ny==y){setTimeout(function(){delete flags.canAttack},4000);dynamicChangeHp(hp,hp-500,10000);hp-=500;clearInterval(atkBoss);core.deleteCanvas("attackBoss");if(hp>3500)core.drawAnimate("hand",7,1);else if(hp>2Line truncated
|
||||
"use strict";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_x,_r,_arr=[],_n=!0,_d=!1;try{if(_x=(_i=_i.call(arr)).next,0===i){if(Object(_i)!==_i)return;_n=!1}else for(;!(_n=(_s=_x.call(_i)).done)&&(_arr.push(_s.value),_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{if(!_n&&null!=_i["return"]&&(_r=_i["return"](),Object(_r)!==_r))return}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}(function(){control.prototype.checkBlock=function(forceMockery){var x=core.getHeroLoc("x"),y=core.getHeroLoc("y"),loc=x+","+y;var damage=core.status.checkBlock.damage[loc];if(damage){if(!main.replayChecking)core.addPop((x-core.bigmap.offsetX/32)*32+12,(y-core.bigmap.offsetY/32)*32+20,-damage.toString());core.status.hero.hp-=damage;var text=Object.keys(core.status.checkBlock.type[loc]||{}).join("\uFF0C")||"\u4F24\u5BB3";core.drawTip("\u53D7\u5230"+text+damage+"\u70B9");core.drawHeroAnimate("zone");this._checkBlock_disableQuickShop();core.status.hero.statistics.extraDamage+=damage;if(core.status.hero.hp<=0){core.status.hero.hp=0;core.updateStatusBar();core.events.lose();return}else{core.updateStatusBar()}}this._checkBlock_repulse(core.status.checkBlock.repulse[loc]);checkMockery(loc,forceMockery)};control.prototype.moveHero=function(direction,callback){if(core.status.heroMoving!=0)return;if(core.isset(direction))core.setHeroLoc("direction",direction);var nx=core.nextX();var ny=core.nextY();if(core.status.checkBlock.mockery["".concat(nx,",").concat(ny)]){core.autosave()}if(callback)return this.moveAction(callback);this._moveHero_moving()};function checkMockery(loc,force){if(core.status.lockControl&&!force)return;var mockery=core.status.checkBlock.mockery[loc];if(mockery){mockery.sort(function(a,b){return a[0]===b[0]?a[1]-b[1]:a[0]-b[0]});var action=[];var _mockery$=_slicedToArray(mockery[0],2),tx=_mockery$[0],ty=_mockery$[1];var _core$status$hero$loc=core.status.hero.loc,x=_core$status$hero$loc.x,y=_core$status$hero$loc.y;var dir=x>tx?"left":x<tx?"right":y>ty?"up":"down";var _core$utils$scan$dir=core.utils.scan[dir],dx=_core$utils$scan$dir.x,dy=_core$utils$scan$dir.y;action.push({type:"changePos",direction:dir});var blocks=core.getMapBlocksObj();while(1){x+=dx;y+=dy;var block=blocks["".concat(x,",").concat(y)];if(block){block.event.cls==="";if(["animates","autotile","tileset","npcs","npc48"].includes(block.event.cls)){action.push({type:"hide",loc:[[x,y]],remove:true,time:0},{type:"function","function":"function() { core.removeGlobalAnimate(".concat(x,", ").concat(y,") }")},{type:"animate",name:"hand",loc:[x,y],async:true})}if(block.event.cls.startsWith("enemy")){action.push({type:"moveAction"})}}action.push({type:"moveAction"});if(x===tx&&y===ty)break}action.push({type:"function","function":"function() { core.checkBlock(true); }"});action.push({type:"stopAsync"});core.insertAction(action)}}})();
|
||||
"use strict";function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||_typeof(obj)!=="object"&&typeof obj!=="function"){return{"default":obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj["default"]=obj;if(cache){cache.set(obj,newObj)}return newObj}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_x,_r,_arr=[],_n=!0,_d=!1;try{if(_x=(_i=_i.call(arr)).next,0===i){if(Object(_i)!==_i)return;_n=!1}else for(;!(_n=(_s=_x.call(_i)).done)&&(_arr.push(_s.value),_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{if(!_n&&null!=_i["return"]&&(_r=_i["return"](),Object(_r)!==_r))return}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _regeneratorRuntime(){"use strict";_regeneratorRuntime=function _regeneratorRuntime(){return exports};var exports={},Op=Object.prototype,hasOwn=Op.hasOwnProperty,defineProperty=Object.defineProperty||function(obj,key,desc){obj[key]=desc.value},$Symbol="function"==typeof Symbol?Symbol:{},iteratorSymbol=$Symbol.iterator||"@@iterator",asyncIteratorSymbol=$Symbol.asyncIterator||"@@asyncIterator",toStringTagSymbol=$Symbol.toStringTag||"@@toStringTag";function define(obj,key,value){return Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}),obj[key]}try{define({},"")}catch(err){define=function define(obj,key,value){return obj[key]=value}}function wrap(innerFn,outerFn,self,tryLocsList){var protoGenerator=outerFn&&outerFn.prototype instanceof Generator?outerFn:Generator,generator=Object.create(protoGenerator.prototype),context=new Context(tryLocsList||[]);return defineProperty(generator,"_invoke",{value:makeInvokeMethod(innerFn,self,context)}),generator}function tryCatch(fn,obj,arg){try{return{type:"normal",arg:fn.call(obj,arg)}}catch(err){return{type:"throw",arg:err}}}exports.wrap=wrap;var ContinueSentinel={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}var IteratorPrototype={};define(IteratorPrototype,iteratorSymbol,function(){return this});var getProto=Object.getPrototypeOf,NativeIteratorPrototype=getProto&&getProto(getProto(values([])));NativeIteratorPrototype&&NativeIteratorPrototype!==Op&&hasOwn.call(NativeIteratorPrototype,iteratorSymbol)&&(IteratorPrototype=NativeIteratorPrototype);var Gp=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(IteratorPrototype);function defineIteratorMethods(prototype){["next","throw","return"].forEach(function(method){define(prototype,method,function(arg){return this._invoke(method,arg)})})}function AsyncIterator(generator,PromiseImpl){function invoke(method,arg,resolve,reject){var record=tryCatch(generator[method],generator,arg);if("throw"!==record.type){var result=record.arg,value=result.value;return value&&"object"==_typeof(value)&&hasOwn.call(value,"__await")?PromiseImpl.resolve(value.__await).then(function(value){invoke("next",value,resolve,reject)},function(err){invoke("throw",err,resolve,reject)}):ProLine truncated
|
||||
"use strict";function _typeof(obj){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||_typeof(obj)!=="object"&&typeof obj!=="function"){return{"default":obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj["default"]=obj;if(cache){cache.set(obj,newObj)}return newObj}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_x,_r,_arr=[],_n=!0,_d=!1;try{if(_x=(_i=_i.call(arr)).next,0===i){if(Object(_i)!==_i)return;_n=!1}else for(;!(_n=(_s=_x.call(_i)).done)&&(_arr.push(_s.value),_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{if(!_n&&null!=_i["return"]&&(_r=_i["return"](),Object(_r)!==_r))return}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}function _regeneratorRuntime(){"use strict";_regeneratorRuntime=function _regeneratorRuntime(){return exports};var exports={},Op=Object.prototype,hasOwn=Op.hasOwnProperty,defineProperty=Object.defineProperty||function(obj,key,desc){obj[key]=desc.value},$Symbol="function"==typeof Symbol?Symbol:{},iteratorSymbol=$Symbol.iterator||"@@iterator",asyncIteratorSymbol=$Symbol.asyncIterator||"@@asyncIterator",toStringTagSymbol=$Symbol.toStringTag||"@@toStringTag";function define(obj,key,value){return Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}),obj[key]}try{define({},"")}catch(err){define=function define(obj,key,value){return obj[key]=value}}function wrap(innerFn,outerFn,self,tryLocsList){var protoGenerator=outerFn&&outerFn.prototype instanceof Generator?outerFn:Generator,generator=Object.create(protoGenerator.prototype),context=new Context(tryLocsList||[]);return defineProperty(generator,"_invoke",{value:makeInvokeMethod(innerFn,self,context)}),generator}function tryCatch(fn,obj,arg){try{return{type:"normal",arg:fn.call(obj,arg)}}catch(err){return{type:"throw",arg:err}}}exports.wrap=wrap;var ContinueSentinel={};function Generator(){}function GeneratorFunction(){}function GeneratorFunctionPrototype(){}var IteratorPrototype={};define(IteratorPrototype,iteratorSymbol,function(){return this});var getProto=Object.getPrototypeOf,NativeIteratorPrototype=getProto&&getProto(getProto(values([])));NativeIteratorPrototype&&NativeIteratorPrototype!==Op&&hasOwn.call(NativeIteratorPrototype,iteratorSymbol)&&(IteratorPrototype=NativeIteratorPrototype);var Gp=GeneratorFunctionPrototype.prototype=Generator.prototype=Object.create(IteratorPrototype);function defineIteratorMethods(prototype){["next","throw","return"].forEach(function(method){define(prototype,method,function(arg){return this._invoke(method,arg)})})}function AsyncIterator(generator,PromiseImpl){function invoke(method,arg,resolve,reject){var record=tryCatch(generator[method],generator,arg);if("throw"!==record.type){var result=record.arg,value=result.value;return value&&"object"==_typeof(value)&&hasOwn.call(value,"__await")?PromiseImpl.resolve(value.__await).then(function(value){invoke("next",value,resolve,reject)},function(err){invoke("throw",err,resolve,reject)}):ProLine truncated
|
||||
"use strict";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_x,_r,_arr=[],_n=!0,_d=!1;try{if(_x=(_i=_i.call(arr)).next,0===i){if(Object(_i)!==_i)return;_n=!1}else for(;!(_n=(_s=_x.call(_i)).done)&&(_arr.push(_s.value),_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{if(!_n&&null!=_i["return"]&&(_r=_i["return"](),Object(_r)!==_r))return}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}(function(){var _core$plugin$study=core.plugin.study,studySkill=_core$plugin$study.studySkill,canStudySkill=_core$plugin$study.canStudySkill;var replayableSettings=["autoSkill"];core.registerReplayAction("settings",function(name){if(!name.startsWith("set:"))return false;var _name$split=name.split(":"),_name$split2=_slicedToArray(_name$split,3),setting=_name$split2[1],value=_name$split2[2];var v=eval(value);if(typeof v!=="boolean")return false;if(!replayableSettings.includes(setting))return false;flags[setting]=v;core.replay();return true});core.registerReplayAction("upgradeSkill",function(name){if(!name.startsWith("skill:"))return false;var skill=parseInt(name.slice(6));core.plugin.skillTree.upgradeSkill(skill);core.replay();return true});core.registerReplayAction("study",function(name){if(!name.startsWith("study:"))return false;var _name$slice$split$map=name.slice(6).split(",").map(function(v){return parseInt(v)}),_name$slice$split$map2=_slicedToArray(_name$slice$split$map,3),num=_name$slice$split$map2[0],x=_name$slice$split$map2[1],y=_name$slice$split$map2[2];if(!canStudySkill(num))return false;var id=core.getBlockId(x,y);var enemy=core.getEnemyInfo(id,void 0,x,y);if(!enemy.special.includes(num))return false;studySkill(enemy,num);core.replay();return true});var shopOpened=false;var openedShopId="";core.registerReplayAction("openShop",function(name){if(!name.startsWith("openShop:"))return false;openedShopId=name.slice(9);shopOpened=true;core.replay();return true});core.registerReplayAction("buy",function(name){var _flags,_flags$itemShop,_flags$itemShop2,_openedShopId,_flags$itemShop2$_ope,_flags$itemShop$opene,_flags$itemShop$opene2;if(!name.startsWith("buy:")&&!name.startsWith("sell:"))return false;if(!shopOpened)return false;if(!openedShopId)return false;var _name$split$map=name.split(":").map(function(v){return /^\d+$/.test(v)?parseInt(v):v}),_name$split$map2=_slicedToArray(_name$split$map,3),type=_name$split$map2[0],id=_name$split$map2[1],num=_name$split$map2[2];var shop=core.status.shops[id];var item=shop.choices.find(function(v){return v.id===id});if(!item)return false;(_flags$itemShop=(_flags=flags).itemShop)!==null&&_flags$itemShop!==void 0?_flags$itemShop:_flags.itemShop={};(_flags$itemShop2$_ope=(_flags$itemShop2=flags.itemShop)[_openedShopId=openedShopId])!==null&&_flags$itemShop2$_ope!==void 0?_flags$itemShop2$_ope:_flags$itemShop2[_openedShopId]={};(_flags$itemShop$opene2=(_flags$itemShop$opene=flags.itemShop[openedShopId])[id])!==null&&_flags$itemShop$opene2!==void 0?_flags$itemShop$opene2:_flags$itemShop$opene[id]=0;if(num>item.number-flags.itemShop[openedShopId][id]){return false}var cost=0;if(type==="buy"){cost=item.money*num}else{cost=-item.sell*num}if(cost>core.status.hero.money)return false;core.status.hero.money-=cost;flags.itemShop[openedShopId][id]+=type==="buy"?num:-num;core.replay();return true});core.registerReplayAction("closeShop",function(name){if(name!=="closeShop")return false;if(!shopOpened)return false;shopOpened=false;openedShopId="";core.replay();return true})})();
|
||||
"use strict";function _createForOfIteratorHelper(o,allowArrayLike){var it=typeof Symbol!=="undefined"&&o[Symbol.iterator]||o["@@iterator"];if(!it){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;var F=function F(){};return{s:F,n:function n(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]}},e:function e(_e2){throw _e2},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var normalCompletion=true,didErr=false,err;return{s:function s(){it=it.call(o)},n:function n(){var step=it.next();normalCompletion=step.done;return step},e:function e(_e3){didErr=true;err=_e3},f:function f(){try{if(!normalCompletion&&it["return"]!=null)it["return"]()}finally{if(didErr)throw err}}}}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_x,_r,_arr=[],_n=!0,_d=!1;try{if(_x=(_i=_i.call(arr)).next,0===i){if(Object(_i)!==_i)return;_n=!1}else for(;!(_n=(_s=_x.call(_i)).done)&&(_arr.push(_s.value),_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{if(!_n&&null!=_i["return"]&&(_r=_i["return"](),Object(_r)!==_r))return}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}(function(){var levels=[];var skills={chapter1:[{index:0,title:"\u529B\u91CF",desc:["\u529B\u91CF\u5C31\u662F\u6839\u672C\uFF01\u53EF\u4EE5\u901A\u8FC7\u667A\u6167\u589E\u52A0\u529B\u91CF\uFF0C\u6BCF\u7EA7\u589E\u52A02\u70B9\u653B\u51FB\u3002"],consume:"10 * level + 10",front:[],loc:[1,2],max:10,effect:["\u653B\u51FB + ${level * 2}"]},{index:1,title:"\u81F4\u547D\u4E00\u51FB",desc:["\u7206\u53D1\u51FA\u5168\u90E8\u529B\u91CF\u653B\u51FB\u654C\u4EBA\uFF0C\u6BCF\u7EA7\u589E\u52A05\u70B9\u989D\u5916\u653B\u51FB\u3002"],consume:"30 * level + 30",front:[[0,5]],loc:[2,1],max:10,effect:["\u989D\u5916\u653B\u51FB + ${level * 5}"]},{index:2,title:"\u65AD\u706D\u4E4B\u5203",desc:["<span style=\"color: gold\">\u4E3B\u52A8\u6280\u80FD\uFF0C\u5FEB\u6377\u952E1</span>\uFF0C","\u5F00\u542F\u540E\u4F1A\u5728\u6218\u6597\u65F6\u4F1A\u989D\u5916\u589E\u52A0\u4E00\u5B9A\u91CF\u7684\u653B\u51FB\uFF0C\u4F46\u540C\u65F6\u51CF\u5C11\u4E00\u5B9A\u91CF\u7684\u9632\u5FA1\u3002"],consume:"200 * level + 400",front:[[1,5]],loc:[4,1],max:5,effect:["\u589E\u52A0${level * 10}%\u653B\u51FB\uFF0C\u51CF\u5C11${level * 10}%\u9632\u5FA1"]},{index:3,title:"\u575A\u97E7",desc:["\u7531\u667A\u6167\u8F6C\u5316\u51FA\u575A\u97E7\uFF01\u6BCF\u7EA7\u589E\u52A02\u70B9\u9632\u5FA1"],consume:"10 * level + 10",front:[],loc:[1,4],max:10,effect:["\u9632\u5FA1 + ${level * 2}"]},{index:4,title:"\u56DE\u6625",desc:["\u8BA9\u667A\u6167\u5316\u4E3A\u6CBB\u6108\u4E4B\u6CC9\u6C34\uFF01\u6BCF\u7EA7\u589E\u52A01\u70B9\u751F\u547D\u56DE\u590D"],consume:"20 * level + 20",front:[[3,5]],loc:[2,5],max:25,effect:["\u751F\u547D\u56DE\u590D + ${level}"]},{index:5,title:"\u6CBB\u6108\u4E4B\u6CC9",desc:["\u8BA9\u751F\u547D\u53D8\u5F97\u66F4\u591A\u4E00\u4E9B\u5427\uFF01\u6BCF\u540350\u74F6\u8840\u74F6\u5C31\u589E\u52A0\u5F53\u524D\u751F\u547D\u56DE\u590D10%\u7684\u751F\u547D\u56DE\u590D"],consume:"1500",front:[[4,25]],loc:[4,5],max:1,effect:["50\u74F6\u884010%\u751F\u547D\u56DE\u590D"]},{index:6,title:"\u575A\u56FA\u4E4B\u76FE",desc:["\u8BA9\u62A4\u7532\u66F4\u52A0\u575A\u786C\u4E00\u4E9B\u5427\uFF01\u6BCF\u7EA7\u589E\u52A010\u70B9\u9632\u5FA1"],consume:"50 + level * 50",front:[[3,5]],loc:[2,3],max:10,effect:["\u9632\u5FA1 + ${level * 10}"]},{index:7,title:"\u65E0\u4E0A\u4E4B\u76FE",desc:["<span style=\"color: #dd4\">\u7B2C\u4E00\u7AE0\u7EC8\u6781\u6280\u80FD</span>\uFF0C\u6218\u6597\u65F6\u667A\u6167\u4F1A\u5145\u5F53\u7B49\u91CF\u62A4\u76FE"],consume:"2500",front:[[6,10],[5,1],[2,2]],loc:[5,3],max:1,effect:["\u6218\u6597\u65F6\u667A\u6167\u4F1A\u5145\u5F53\u62A4\u76FE"]}],chapter2:[{index:8,title:"\u950B\u5229",desc:["\u8BA9\u5251\u53D8\u5F97\u66F4\u52A0\u950B\u5229\uFF01\u6BCF\u7EA7\u4F7F\u653B\u51FB\u589E\u52A01%\uFF08buff\u5F0F\u589E\u52A0\uFLine truncated
|
||||
"use strict";function _createForOfIteratorHelper(o,allowArrayLike){var it=typeof Symbol!=="undefined"&&o[Symbol.iterator]||o["@@iterator"];if(!it){if(Array.isArray(o)||(it=_unsupportedIterableToArray(o))||allowArrayLike&&o&&typeof o.length==="number"){if(it)o=it;var i=0;var F=function F(){};return{s:F,n:function n(){if(i>=o.length)return{done:true};return{done:false,value:o[i++]}},e:function e(_e2){throw _e2},f:F}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var normalCompletion=true,didErr=false,err;return{s:function s(){it=it.call(o)},n:function n(){var step=it.next();normalCompletion=step.done;return step},e:function e(_e3){didErr=true;err=_e3},f:function f(){try{if(!normalCompletion&&it["return"]!=null)it["return"]()}finally{if(didErr)throw err}}}}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_unsupportedIterableToArray(arr,i)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen)}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i<len;i++)arr2[i]=arr[i];return arr2}function _iterableToArrayLimit(arr,i){var _i=null==arr?null:"undefined"!=typeof Symbol&&arr[Symbol.iterator]||arr["@@iterator"];if(null!=_i){var _s,_e,_x,_r,_arr=[],_n=!0,_d=!1;try{if(_x=(_i=_i.call(arr)).next,0===i){if(Object(_i)!==_i)return;_n=!1}else for(;!(_n=(_s=_x.call(_i)).done)&&(_arr.push(_s.value),_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{if(!_n&&null!=_i["return"]&&(_r=_i["return"](),Object(_r)!==_r))return}finally{if(_d)throw _e}}return _arr}}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr}(function(){function drawHalo(ctx,onMap){if(main.replayChecking)return;if(!core.getLocalStorage("showHalo",true))return;var halo=core.status.checkBlock.halo;ctx.save();for(var _i=0,_Object$entries=Object.entries(halo);_i<_Object$entries.length;_i++){var _Object$entries$_i=_slicedToArray(_Object$entries[_i],2),loc=_Object$entries$_i[0],range=_Object$entries$_i[1];var _loc$split$map=loc.split(",").map(function(v){return parseInt(v)}),_loc$split$map2=_slicedToArray(_loc$split$map,2),x=_loc$split$map2[0],y=_loc$split$map2[1];var _iterator=_createForOfIteratorHelper(range),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var r=_step.value;var _r$split=r.split(":"),_r$split2=_slicedToArray(_r$split,4),type=_r$split2[0],value=_r$split2[1],color=_r$split2[2],border=_r$split2[3];if(type==="square"){var n=parseInt(value);var _r2=Math.floor(n/2);var left=x-_r2,right=x+_r2,top=y-_r2,bottom=y+_r2;if(onMap&&core.bigmap.v2){left-=core.bigmap.posX;top-=core.bigmap.posY;right-=core.bigmap.posX;bottom-=core.bigmap.posY;if(right<-1||left>core._PX_/32+1||top<-1||bottom>core._PY_/32+1){continue}}ctx.fillStyle=color;ctx.strokeStyle=border!==null&&border!==void 0?border:color;ctx.lineWidth=1;ctx.globalAlpha=0.1;ctx.fillRect(left*32,top*32,n*32,n*32);ctx.globalAlpha=0.6;ctx.strokeRect(left*32,top*32,n*32,n*32)}}}catch(err){_iterator.e(err)}finally{_iterator.f()}}ctx.restore()}core.plugin.halo={drawHalo:drawHalo}})();
|
||||
+38
-184
@@ -44,6 +44,7 @@ next();
|
||||
let repStart;
|
||||
|
||||
const listenedFloors = [];
|
||||
const listenedPlugins = [];
|
||||
|
||||
// ----- GET file
|
||||
|
||||
@@ -172,6 +173,7 @@ async function writeFile(req, res) {
|
||||
const value = /&value=[^]+/.exec(data)[0].slice(7);
|
||||
await fs.writeFile(dir, value, { encoding: type });
|
||||
testWatchFloor(name);
|
||||
testWatchPlugin(name);
|
||||
if (name.endsWith('project/events.js')) doDeclaration('events', value);
|
||||
if (name.endsWith('project/items.js')) doDeclaration('items', value);
|
||||
if (name.endsWith('project/maps.js')) doDeclaration('maps', value);
|
||||
@@ -332,7 +334,7 @@ async function watch() {
|
||||
watchOneFloor(v.slice(15));
|
||||
});
|
||||
|
||||
// 脚本编辑 及 插件 热重载
|
||||
// 脚本编辑 热重载
|
||||
const scripts = await extract('project/functions.js', 'project/plugins.js');
|
||||
scripts.forEach(v => {
|
||||
const dir = path.resolve(__dirname, v);
|
||||
@@ -343,6 +345,12 @@ async function watch() {
|
||||
});
|
||||
});
|
||||
|
||||
// 插件热重载
|
||||
const plugins = await extract('project/plugin/*.js');
|
||||
plugins.forEach(v => {
|
||||
watchOnePlugin(v.slice(15));
|
||||
});
|
||||
|
||||
// 数据热重载
|
||||
const datas = (await extract('project/*.js')).filter(
|
||||
v => !v.endsWith('functions.js') && !v.endsWith('plugins.js')
|
||||
@@ -370,6 +378,19 @@ function testWatchFloor(url) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否是楼层文件并进行监听
|
||||
* @param {string} url 要测试的路径
|
||||
*/
|
||||
function testWatchPlugin(url) {
|
||||
if (/project(\/|\\)plugin(\/|\\).*\.js/.test(url)) {
|
||||
const f = url.slice(15);
|
||||
if (!listenedFloors.includes(f.slice(0, -3))) {
|
||||
watchOnePlugin(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听一个楼层文件
|
||||
* @param {string} file 要监听的文件
|
||||
@@ -386,6 +407,22 @@ function watchOneFloor(file) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听一个楼层文件
|
||||
* @param {string} file 要监听的文件
|
||||
*/
|
||||
function watchOnePlugin(file) {
|
||||
if (!/.*\.js/.test(file)) return;
|
||||
const f = file.slice(0, -3);
|
||||
listenedFloors.push(file.slice(0, -3));
|
||||
fss.watchFile(`project/plugin/${file}`, { interval: 500 }, () => {
|
||||
const plugin = f;
|
||||
if (hotReloadData.includes(`@@plugin:${plugin}`)) return;
|
||||
hotReloadData += `@@plugin:${plugin}`;
|
||||
console.log(`plugin hot reload: ${plugin}`);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改部分文件后重新加载及热重载
|
||||
* @param {http.IncomingMessage} req
|
||||
@@ -411,189 +448,6 @@ function reload(req, res, hot = false) {
|
||||
});
|
||||
}
|
||||
|
||||
// ----- replay debugger
|
||||
|
||||
/**
|
||||
* 录像调试
|
||||
* @param {http.IncomingMessage} req
|
||||
* @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res
|
||||
*/
|
||||
function replay(req, res) {
|
||||
req.on('data', async chunk => {
|
||||
if (chunk.toString() === 'test' && !replayed) {
|
||||
replayed = true;
|
||||
try {
|
||||
await fs.mkdir(path.resolve(__dirname, '_replay'));
|
||||
await fs.mkdir(path.resolve(__dirname, '_replay/status'));
|
||||
await fs.mkdir(path.resolve(__dirname, '_replay/save'));
|
||||
} catch {}
|
||||
|
||||
try {
|
||||
await fs.readFile(
|
||||
path.resolve(__dirname, '_replay/.info'),
|
||||
'utf-8'
|
||||
);
|
||||
} catch {
|
||||
await fs.writeFile(
|
||||
path.resolve(__dirname, '_replay/.info'),
|
||||
`{
|
||||
"cnt": 0
|
||||
}`,
|
||||
'utf-8'
|
||||
);
|
||||
}
|
||||
const data = fss.readFileSync(
|
||||
path.resolve(__dirname, '_replay/.info'),
|
||||
'utf-8'
|
||||
);
|
||||
repStart = Number(JSON.parse(data).cnt);
|
||||
console.log(`服务器录像调试模块已开始服务`);
|
||||
}
|
||||
});
|
||||
|
||||
req.on('end', () => {
|
||||
res.end();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取未占用的状态栏位
|
||||
* @param {http.IncomingMessage} req
|
||||
* @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res
|
||||
*/
|
||||
async function replayCnt() {
|
||||
const data = `{
|
||||
"cnt": ${++repStart}
|
||||
}`;
|
||||
fss.writeFileSync(path.resolve(__dirname, '_replay/.info'), data, 'utf-8');
|
||||
|
||||
return repStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入
|
||||
* @param {http.IncomingMessage} req
|
||||
* @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res
|
||||
*/
|
||||
async function replayWrite(req, res) {
|
||||
const data = await getPostData(req);
|
||||
const n = await replayCnt();
|
||||
|
||||
if (isNaN(n)) res.end('@error');
|
||||
|
||||
await Promise.all([
|
||||
fs.writeFile(
|
||||
path.resolve(__dirname, '_replay/.info'),
|
||||
`{
|
||||
"cnt": ${n + 1}
|
||||
}`,
|
||||
'utf-8'
|
||||
),
|
||||
fs.writeFile(
|
||||
path.resolve(__dirname, `_replay/status/${n}.rep`),
|
||||
data,
|
||||
'utf-8'
|
||||
)
|
||||
]);
|
||||
|
||||
res.end(n.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 比对录像与本地数据
|
||||
* @param {http.IncomingMessage} req
|
||||
* @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res
|
||||
*/
|
||||
async function replayCheck(req, res) {
|
||||
const ans = await getPostData(req);
|
||||
const [n, data] = ans.split('@-|-@');
|
||||
|
||||
const local = (
|
||||
await fs.readFile(
|
||||
path.resolve(__dirname, `_replay/status/${n}.rep`),
|
||||
'utf-8'
|
||||
)
|
||||
)
|
||||
.split('@---@')
|
||||
.map(v => JSON.parse(v));
|
||||
const rep = data.split('@---@').map(v => JSON.parse(v));
|
||||
|
||||
if (local.length !== rep.length) return res.end('false');
|
||||
|
||||
const check = (a, b) => {
|
||||
if (a === b) return true;
|
||||
if (typeof a !== typeof b) return false;
|
||||
if (typeof a === 'object' && a !== null) {
|
||||
for (const j in a) {
|
||||
if (j === 'statistics' || j === 'timeout') continue; // 忽略统计信息
|
||||
const aa = a[j];
|
||||
const bb = b[j];
|
||||
if (!check(aa, bb)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
typeof a === 'boolean' ||
|
||||
typeof a === 'number' ||
|
||||
typeof a === 'string' ||
|
||||
typeof a === 'symbol' ||
|
||||
typeof a === 'undefined' ||
|
||||
typeof a === 'bigint' ||
|
||||
a === null
|
||||
) {
|
||||
return a === b;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
for (let i = 0; i < local.length; i++) {
|
||||
const a = local[i];
|
||||
const b = rep[i];
|
||||
if (!check(a, b)) return res.end('false');
|
||||
}
|
||||
|
||||
res.end('true');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地属性
|
||||
* @param {http.IncomingMessage} req
|
||||
* @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res
|
||||
*/
|
||||
async function replayGet(req, res, dir) {
|
||||
const ans = Number(await getPostData(req));
|
||||
|
||||
const data = await fs.readFile(
|
||||
path.resolve(__dirname, `_replay/${dir}/${ans}.rep`)
|
||||
);
|
||||
res.end(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 录像回放存档
|
||||
* @param {http.IncomingMessage} req
|
||||
* @param {http.ServerResponse<http.IncomingMessage> & {req: http.IncomingMessage;}} res
|
||||
*/
|
||||
async function replaySave(req, res) {
|
||||
const data = await getPostData(req);
|
||||
const [cnt, save] = data.split('@-|-@');
|
||||
|
||||
if (isNaN(Number(cnt))) {
|
||||
console.log('Invalid input of save cnt');
|
||||
res.end('@error: 不合法的录像存档信息');
|
||||
}
|
||||
|
||||
await fs.writeFile(
|
||||
path.resolve(__dirname, `_replay/save/${cnt}.rep`),
|
||||
save,
|
||||
'utf-8'
|
||||
);
|
||||
|
||||
res.end('success');
|
||||
}
|
||||
|
||||
// ----- declaration
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user