tianheng 发表于 2009-1-7 11:31:16

帖个js转换zmud格式alias的东东,方便mushclient初学者

帖个js转换zmud格式alias的东东,方便mushclient初学者
var pathArray = {"e" : "w", "east" : "west", "eu" : "wd", "eastup" : "westdown",
"ed" : "wu", "eastdown" : "westup", "w" : "e", "west" : "east",
"wu" : "ed", "westup" : "eastdown", "wd" : "eu", "westdown" : "eastup",
"s" : "n", "south" : "north", "su" : "nd", "southup" : "northdown",
"sd" : "nu", "southdown" : "northup", "n" : "s", "north" : "south",
"nu" : "sd", "northup" : "southdown", "nd" : "su", "northdown" : "southup",
"u" : "d", "up" : "down", "d" : "u", "down" : "up", "se" : "nw",
"southeast" : "northwest", "sw" : "ne", "southwest" : "northeast",
"ne" : "sw", "northeast" : "southwest", "nw" : "se", "northwest" : "southeast",
"enter" : "out", "out" : "enter"};
/**路径中默认可以识别的方向和行为**/
var pa = {"n":"north","s":"south","e":"east","w":"west","u":"up","d":"down",
"c":"close","o":"open","l":"look","k":"unlock"};
/**显示消息**/
function show(obj) {
var shell = new ActiveXObject("WScript.Shell");
shell.Popup(obj);
}
/**处理zMud格式的alias**/
function alias(aliastr) {
var a = aliastr.toLowerCase();
var name = "", path = "";
if (a.indexOf("#alias") != -1) {
name = a.substring(7,a.indexOf("{") - 1);
path = a.substring(a.indexOf("{") + 1,a.indexOf("}"));
}
var ary = path.split(";");
var tp = "";
for (i = 0; i < ary.length; i++) {
var regExp0 = /#(\d{1,})(\s*)(.*)/;
var regExp2 = /do(\s*)(\d{1,})(\s*)(.*)/;
var regExp1 = /#wa(\s*)(\d{1,})/;
if (regExp1.test(ary)) {
} else if (regExp0.test(ary)) {
   var reg = regExp0.exec(ary);
   var n = RegExp.$1;
   var s = RegExp.$3;
   tp += n + parseStr(s);
} else if (regExp2.test(ary)) {
   var reg = regExp2.exec(ary);
   var n = RegExp.$2;
   var s = RegExp.$4;
   tp += n + parseStr(s);
} else {
   tp += parseStr(ary);
}
}
function parseStr(str) {
var tmp = "";
var t = pathArray;
if (t != undefined) {
   if (pa != undefined) {
    tmp = str;
   } else {
    tmp = "(" + str + "/" + t + ")";
   }
} else {
   tmp = "(" + str + ")";
}
return tmp;
}
return tp;
}
eval(show(alias("#alias baituo {n;w;do 2 ask qian about 白驼山;give qian 1 gold;#2 sw;#wa 1000;do 5 d}")));欢迎大家指正!

[ 本帖最后由 tianheng 于 2009-1-7 04:17 PM 编辑 ]

tianheng 发表于 2009-1-7 11:32:28

测试用的alias是为了测试乱写的

tianheng 发表于 2009-1-7 11:34:01

var regExp0 = /#(\d{1,})(\s*)(.*)/;
var regExp2 = /do(\s*)(\d{1,})(\s*)(.*)/;
感觉这两个可以合并为一个,但不知道怎么弄。

tianheng 发表于 2009-1-7 16:15:28

呵呵,精华了。修改了下,可以批量转换文件中的#alias。调用方法为:/myaddalias("x:/pkuxkx_path.txt");
var pathArray = {"e" : "w", "east" : "west", "eu" : "wd", "eastup" : "westdown",
"ed" : "wu", "eastdown" : "westup", "w" : "e", "west" : "east",
"wu" : "ed", "westup" : "eastdown", "wd" : "eu", "westdown" : "eastup",
"s" : "n", "south" : "north", "su" : "nd", "southup" : "northdown",
"sd" : "nu", "southdown" : "northup", "n" : "s", "north" : "south",
"nu" : "sd", "northup" : "southdown", "nd" : "su", "northdown" : "southup",
"u" : "d", "up" : "down", "d" : "u", "down" : "up", "se" : "nw",
"southeast" : "northwest", "sw" : "ne", "southwest" : "northeast",
"ne" : "sw", "northeast" : "southwest", "nw" : "se", "northwest" : "southeast",
"enter" : "out", "out" : "enter"};
/**路径中默认可以识别的方向和行为**/
var pa = {"n":"north","s":"south","e":"east","w":"west","u":"up","d":"down",
"c":"close","o":"open","l":"look","k":"unlock"};
/**显示消息**/
function show(obj) {
var shell = new ActiveXObject("WScript.Shell");
shell.Popup(obj);
}
/**处理zMud格式的alias**/
function alias(aliastr) {
var a = aliastr.toLowerCase();
var name = "", path = "";
if (a.indexOf("#alias") != -1) {
name = a.substring(7,a.indexOf("{") - 1);
path = a.substring(a.indexOf("{") + 1,a.indexOf("}"));
}
var ary = path.split(";");
var tp = "";
for (i = 0; i < ary.length; i++) {
var regExp0 = /#(\d{1,})(\s*)(.*)/;
var regExp2 = /do(\s*)(\d{1,})(\s*)(.*)/;
var regExp1 = /#wa(\s*)(\d{1,})/;
if (regExp1.test(ary)) {
} else if (regExp0.test(ary)) {
   var reg = regExp0.exec(ary);
   var n = RegExp.$1;
   var s = RegExp.$3;
   tp += n + parseStr(s);
} else if (regExp2.test(ary)) {
   var reg = regExp2.exec(ary);
   var n = RegExp.$2;
   var s = RegExp.$4;
   tp += n + parseStr(s);
} else {
   tp += parseStr(ary);
}
}
function parseStr(str) {
var tmp = "";
var t = pathArray;
if (t != undefined) {
   if (pa != undefined) {
    tmp = str;
   } else {
    tmp = "(" + str + "/" + t + ")";
   }
} else {
   tmp = "(" + str + ")";
}
return tmp;
}
return tp;
}
//eval(show(alias("#alias baituo {n;w;do 2 ask qian about 白驼山;give qian 1 gold;#2 sw;#wa 1000;do 5 d}")));
/**处理zMud格式的alias**/
function alias(aliastr) {
var a = aliastr.toLowerCase();
var name = "", path = "";
if (a.indexOf("#alias") != -1) {
name = a.substring(7,a.indexOf("{") - 1);
path = a.substring(a.indexOf("{") + 1,a.indexOf("}"));
}
var ary = path.split(";");
var tp = "";
for (i = 0; i < ary.length; i++) {
var regExp0 = /#(\d{1,})(\s*)(.*)/;
var regExp2 = /do(\s*)(\d{1,})(\s*)(.*)/;
var regExp1 = /#wa(\s*)(\d{1,})/;
if (regExp1.test(ary)) {
} else if (regExp0.test(ary)) {
   var reg = regExp0.exec(ary);
   var n = RegExp.$1;
   var s = RegExp.$3;
   tp += n + parseStr(s);
} else if (regExp2.test(ary)) {
   var reg = regExp2.exec(ary);
   var n = RegExp.$2;
   var s = RegExp.$4;
   tp += n + parseStr(s);
} else {
   tp += parseStr(ary);
}
}
function parseStr(str) {
var tmp = "";
var t = pathArray;
if (t != undefined) {
   if (pa != undefined) {
    tmp = str;
   } else {
    tmp = "(" + str + "/" + t + ")";
   }
} else {
   tmp = "(" + str + ")";
}
return tmp;
}
note(name + " = " + tp);
addalias(name, name, tp, 1|32|1024|2048, "");
//return tp;
}
function myaddalias(file) {
try {
var fso, rf, r;
var ForReading = 1, ForWriting = 2, ForAppending = 8;
fso = new ActiveXObject("Scripting.FileSystemObject");
rf = fso.OpenTextFile(file, ForReading);
while (!rf.AtEndOfStream) {
   r = rf.ReadLine();
   if (trim(r) != "") {
    alias(r);
   }
}
rf.close();
note("ok!");
}
catch (e) {
}
}

附件更新过了!

[ 本帖最后由 tianheng 于 2009-1-7 04:18 PM 编辑 ]

bfmgqy 发表于 2009-1-8 12:57:45

发一个mush版的插件,北侠常用路径的插件,和zmud的差不多,很像
页: [1]
查看完整版本: 帖个js转换zmud格式alias的东东,方便mushclient初学者