Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AUTOID = false;
- re_room = /^R\s*\{\s*(\d+)\}\s*\{\s*(\d+)\}\s*\{\s*\<(\d+)\>\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{\s*([0-9\.]+)\}/;
- re_exit = /^E\s*\{\s*(\d+)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{\s*(\d+)\}\s*\{(.*)\}\s*\{(.*)\}/;
- function loadTTMap(filepath) {
- jmc.parse(jmc.CommandChar + "mapper clear");
- jmc.parse(jmc.CommandChar + "mapper add direction {north,n} 0 1 0 {south,s}");
- jmc.parse(jmc.CommandChar + "mapper add direction {east,e} 1 0 0 {west,w}");
- jmc.parse(jmc.CommandChar + "mapper add direction {up,u} 1 1 0 {down,d}");
- var stream = new ActiveXObject("ADODB.Stream");
- stream.CharSet = "utf-8";
- stream.Open();
- stream.LoadFromFile(filepath);
- var lines = stream.ReadText().split('\n');
- stream.Close();
- var rooms = {};
- var match;
- if (AUTOID) {
- for (var i = 0; i < lines.length; i++) {
- var line = lines[i];
- if ((match = re_room.exec(line)) != null) {
- match[6] = '';
- jmc.parse(jmc.CommandChar + "mapper autoid {" + match[4] + "} {" + match[6] + "} {} PrimaryId");
- var secondary = match[1];
- var primary = jmc.GetVar("PrimaryId");
- if (primary.indexOf('.') >= 0)
- primary = primary.substr(0, primary.indexOf('.'));
- var id = primary + "." + secondary;
- rooms[match[1]] = id;
- }
- }
- }
- var rooms_count = 0;
- var last_room_id = 0;
- for (var i = 0; i < lines.length; i++) {
- var line = lines[i];
- if ((match = re_room.exec(line)) != null) {
- var id = AUTOID ? rooms[match[1]] : match[1];
- if (AUTOID) {
- match[6] = '';
- match[7] = '';
- }
- jmc.parse(jmc.CommandChar + "mapper add room " + id + " {" + match[4] + "} {" + match[6] + "} {" + match[7] + "} {" + match[8] + "} {" + match[9] + "}");
- last_room_id = id;
- rooms_count++;
- } else if ((match = re_exit.exec(line)) != null) {
- var id = AUTOID ? rooms[match[1]] : match[1];
- jmc.parse(jmc.CommandChar + "mapper add exit " + last_room_id + " {" + match[2] + "} " + id);
- }
- }
- jmc.showme("Rooms loaded: " + rooms_count);
- }
- /* usage:
- - copy importTTMap.js to ./settings
- - copy tt-map to ./tt.map
- - set AUTOID = true in case tt-map contains real vnums (e.g. from MSDP)
- - execute in jmc:
- #use importTTMap.js
- #scri loadTTMap("tt.map")
- #mapper write tt.map
- */
Add Comment
Please, Sign In to add comment