utils.js v2.6
This commit is contained in:
parent
3fb6d09796
commit
9739612132
191
libs/utils.js
191
libs/utils.js
@ -397,16 +397,49 @@ utils.prototype.arrayToRGBA = function (color) {
|
|||||||
return "rgba("+nowR+","+nowG+","+nowB+","+nowA+")";
|
return "rgba("+nowR+","+nowG+","+nowB+","+nowA+")";
|
||||||
}
|
}
|
||||||
|
|
||||||
////// 加密路线 //////
|
utils.prototype._encodeRoute_id2number = function (id) {
|
||||||
utils.prototype.encodeRoute = function (route) {
|
|
||||||
var ans="";
|
|
||||||
var lastMove = "", cnt=0;
|
|
||||||
|
|
||||||
var id2number = function (id) {
|
|
||||||
var number = core.maps.getNumberById(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')
|
||||||
|
return 'T';
|
||||||
|
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')
|
||||||
|
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);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
////// 加密路线 //////
|
||||||
|
utils.prototype.encodeRoute = function (route) {
|
||||||
|
var ans="", lastMove = "", cnt=0;
|
||||||
|
|
||||||
route.forEach(function (t) {
|
route.forEach(function (t) {
|
||||||
if (t=='up' || t=='down' || t=='left' || t=='right') {
|
if (t=='up' || t=='down' || t=='left' || t=='right') {
|
||||||
if (t!=lastMove && cnt>0) {
|
if (t!=lastMove && cnt>0) {
|
||||||
@ -423,50 +456,70 @@ utils.prototype.encodeRoute = function (route) {
|
|||||||
if (cnt>1) ans+=cnt;
|
if (cnt>1) ans+=cnt;
|
||||||
cnt=0;
|
cnt=0;
|
||||||
}
|
}
|
||||||
if (t.indexOf('item:')==0)
|
ans += core.utils._encodeRoute_encodeOne(t);
|
||||||
ans+="I"+id2number(t.substring(5))+":";
|
|
||||||
else if (t.indexOf('unEquip:')==0)
|
|
||||||
ans+="u"+t.substring(8);
|
|
||||||
else if (t.indexOf('equip:')==0)
|
|
||||||
ans+="e"+id2number(t.substring(6))+":";
|
|
||||||
else if (t.indexOf('fly:')==0)
|
|
||||||
ans+="F"+t.substring(4)+":";
|
|
||||||
else if (t.indexOf('choices:')==0)
|
|
||||||
ans+="C"+t.substring(8);
|
|
||||||
else if (t.indexOf('shop:')==0)
|
|
||||||
ans+="S"+t.substring(5);
|
|
||||||
else if (t=='turn')
|
|
||||||
ans+='T';
|
|
||||||
else if (t.indexOf('turn:')==0)
|
|
||||||
ans+="t"+t.substring(5).substring(0,1).toUpperCase()+":";
|
|
||||||
else if (t=='getNext')
|
|
||||||
ans+='G';
|
|
||||||
else if (t.indexOf('input:')==0)
|
|
||||||
ans+="P"+t.substring(6);
|
|
||||||
else if (t.indexOf('input2:')==0)
|
|
||||||
ans+="Q"+t.substring(7)+":";
|
|
||||||
else if (t=='no')
|
|
||||||
ans+='N';
|
|
||||||
else if (t.indexOf('move:')==0)
|
|
||||||
ans+="M"+t.substring(5);
|
|
||||||
else if (t.indexOf('key:')==0)
|
|
||||||
ans+='K'+t.substring(4);
|
|
||||||
else if (t.indexOf('random:')==0)
|
|
||||||
ans+='X'+t.substring(7);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (cnt>0) {
|
if (cnt>0) {
|
||||||
ans+=lastMove.substring(0,1).toUpperCase();
|
ans+=lastMove.substring(0,1).toUpperCase();
|
||||||
if (cnt>1) ans+=cnt;
|
if (cnt>1) ans+=cnt;
|
||||||
}
|
}
|
||||||
// return ans;
|
|
||||||
// 压缩
|
|
||||||
return LZString.compressToBase64(ans);
|
return LZString.compressToBase64(ans);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.prototype._decodeRoute_getNumber = function (decodeObj, noparse) {
|
||||||
|
var num="";
|
||||||
|
while (decodeObj.index<decodeObj.route.length && !isNaN(decodeObj.route.charAt(decodeObj.index))) {
|
||||||
|
num+=decodeObj.route.charAt(decodeObj.index++);
|
||||||
|
}
|
||||||
|
if (num.length==0) num="1";
|
||||||
|
return core.isset(noparse)?num:parseInt(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.prototype._decodeRoute_getString = function (decodeObj) {
|
||||||
|
var str="";
|
||||||
|
while (decodeObj.index<decodeObj.route.length && decodeObj.route.charAt(decodeObj.index)!=':') {
|
||||||
|
str+=decodeObj.route.charAt(decodeObj.index++);
|
||||||
|
}
|
||||||
|
decodeObj.index++;
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.prototype._decodeRoute_number2id = function (number) {
|
||||||
|
if (/^\d+$/.test(number)) {
|
||||||
|
var info = core.maps.blocksInfo[number];
|
||||||
|
if (core.isset(info)) return info.id;
|
||||||
|
}
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
|
||||||
|
var nxt=(c=='I'|| c=='e' ||c=='F'||c=='S'||c=='Q'||c=='t')?
|
||||||
|
this._decodeRoute_getString(decodeObj):this._decodeRoute_getNumber(decodeObj);
|
||||||
|
|
||||||
|
var mp = {"U": "up", "D": "down", "L": "left", "R": "right"};
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
case "U": case "D": case "L": case "R": for (var i=0;i<nxt;i++) decodeObj.ans.push(mp[c]); break;
|
||||||
|
case "I": decodeObj.ans.push("item:"+this._decodeRoute_number2id(nxt)); break;
|
||||||
|
case "u": decodeObj.ans.push("unEquip:"+nxt); break;
|
||||||
|
case "e": decodeObj.ans.push("equip:"+this._decodeRoute_number2id(nxt)); break;
|
||||||
|
case "F": decodeObj.ans.push("fly:"+nxt); break;
|
||||||
|
case "C": decodeObj.ans.push("choices:"+nxt); break;
|
||||||
|
case "S": decodeObj.ans.push("shop:"+nxt+":"+this._decodeRoute_getNumber(decodeObj, true)); break;
|
||||||
|
case "T": decodeObj.ans.push("turn"); break;
|
||||||
|
case "t": decodeObj.ans.push("turn:"+mp[nxt]); break;
|
||||||
|
case "G": decodeObj.ans.push("getNext"); break;
|
||||||
|
case "P": decodeObj.ans.push("input:"+nxt); break;
|
||||||
|
case "Q": decodeObj.ans.push("input2:"+nxt); break;
|
||||||
|
case "N": decodeObj.ans.push("no"); break;
|
||||||
|
case "M": ++decodeObj.index; ans.push("move:"+nxt+":"+this._decodeRoute_getNumber(decodeObj)); break;
|
||||||
|
case "K": decodeObj.ans.push("key:"+nxt); break;
|
||||||
|
case "X": decodeObj.ans.push("random:"+nxt); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////// 解密路线 //////
|
////// 解密路线 //////
|
||||||
utils.prototype.decodeRoute = function (route) {
|
utils.prototype.decodeRoute = function (route) {
|
||||||
|
|
||||||
if (!core.isset(route)) return route;
|
if (!core.isset(route)) return route;
|
||||||
|
|
||||||
// 解压缩
|
// 解压缩
|
||||||
@ -477,63 +530,11 @@ utils.prototype.decodeRoute = function (route) {
|
|||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
var ans=[], index=0;
|
var decodeObj = {route: route, index: 0, ans: []};
|
||||||
|
while (decodeObj.index < decodeObj.route.length) {
|
||||||
var getNumber = function (noparse) {
|
this._decodeRoute_decodeOne(decodeObj, decodeObj.route.charAt(decodeObj.index++));
|
||||||
var num="";
|
|
||||||
while (index<route.length && !isNaN(route.charAt(index))) {
|
|
||||||
num+=route.charAt(index++);
|
|
||||||
}
|
}
|
||||||
if (num.length==0) num="1";
|
return decodeObj.ans;
|
||||||
return core.isset(noparse)?num:parseInt(num);
|
|
||||||
}
|
|
||||||
var getString = function () {
|
|
||||||
var str="";
|
|
||||||
while (index<route.length && route.charAt(index)!=':') {
|
|
||||||
str+=route.charAt(index++);
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
var mp = {
|
|
||||||
"U": "up",
|
|
||||||
"D": "down",
|
|
||||||
"L": "left",
|
|
||||||
"R": "right"
|
|
||||||
}
|
|
||||||
|
|
||||||
var number2id = function (nxt) {
|
|
||||||
if (/^\d+$/.test(nxt)) {
|
|
||||||
var info = core.maps.blocksInfo[nxt];
|
|
||||||
if (core.isset(info)) return info.id;
|
|
||||||
}
|
|
||||||
return nxt;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (index<route.length) {
|
|
||||||
var c=route.charAt(index++);
|
|
||||||
var nxt=(c=='I'|| c=='e' ||c=='F'||c=='S'||c=='Q'||c=='t')?getString():getNumber();
|
|
||||||
|
|
||||||
switch (c) {
|
|
||||||
case "U": case "D": case "L": case "R": for (var i=0;i<nxt;i++) ans.push(mp[c]); break;
|
|
||||||
case "I":ans.push("item:"+number2id(nxt)); break;
|
|
||||||
case "u": ans.push("unEquip:"+nxt); break;
|
|
||||||
case "e": ans.push("equip:"+number2id(nxt)); break;
|
|
||||||
case "F": ans.push("fly:"+nxt); break;
|
|
||||||
case "C": ans.push("choices:"+nxt); break;
|
|
||||||
case "S": ans.push("shop:"+nxt+":"+getNumber(true)); break;
|
|
||||||
case "T": ans.push("turn"); break;
|
|
||||||
case "t": ans.push("turn:"+mp[nxt]); break;
|
|
||||||
case "G": ans.push("getNext"); break;
|
|
||||||
case "P": ans.push("input:"+nxt); break;
|
|
||||||
case "Q": ans.push("input2:"+nxt); break;
|
|
||||||
case "N": ans.push("no"); break;
|
|
||||||
case "M": ++index; ans.push("move:"+nxt+":"+getNumber()); break;
|
|
||||||
case "K": ans.push("key:"+nxt); break;
|
|
||||||
case "X": ans.push("random:"+nxt); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ans;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////// 判断某对象是否不为undefined也不会null //////
|
////// 判断某对象是否不为undefined也不会null //////
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user