Guest User

importTTMap.js

a guest
Oct 10th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. AUTOID = false;
  3.  
  4. re_room = /^R\s*\{\s*(\d+)\}\s*\{\s*(\d+)\}\s*\{\s*\<(\d+)\>\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{\s*([0-9\.]+)\}/;
  5. re_exit = /^E\s*\{\s*(\d+)\}\s*\{(.*)\}\s*\{(.*)\}\s*\{\s*(\d+)\}\s*\{(.*)\}\s*\{(.*)\}/;
  6.  
  7. function loadTTMap(filepath) {
  8.     jmc.parse(jmc.CommandChar + "mapper clear");
  9.    
  10.     jmc.parse(jmc.CommandChar + "mapper add direction {north,n} 0 1 0 {south,s}");
  11.     jmc.parse(jmc.CommandChar + "mapper add direction {east,e} 1 0 0 {west,w}");
  12.     jmc.parse(jmc.CommandChar + "mapper add direction {up,u} 1 1 0 {down,d}");
  13.    
  14.     var stream = new ActiveXObject("ADODB.Stream");
  15.     stream.CharSet = "utf-8";
  16.     stream.Open();
  17.     stream.LoadFromFile(filepath);
  18.     var lines = stream.ReadText().split('\n');
  19.     stream.Close();
  20.    
  21.     var rooms = {};
  22.     var match;
  23.     if (AUTOID) {
  24.         for (var i = 0; i < lines.length; i++) {
  25.             var line = lines[i];
  26.             if ((match = re_room.exec(line)) != null) {
  27.                 match[6] = '';
  28.                 jmc.parse(jmc.CommandChar + "mapper autoid {" + match[4] + "} {" + match[6] + "} {} PrimaryId");
  29.                 var secondary = match[1];
  30.                 var primary = jmc.GetVar("PrimaryId");
  31.                 if (primary.indexOf('.') >= 0)
  32.                     primary = primary.substr(0, primary.indexOf('.'));
  33.                 var id = primary + "." + secondary;
  34.                 rooms[match[1]] = id;
  35.             }
  36.         }
  37.     }
  38.     var rooms_count = 0;
  39.     var last_room_id = 0;
  40.     for (var i = 0; i < lines.length; i++) {
  41.         var line = lines[i];
  42.         if ((match = re_room.exec(line)) != null) {
  43.             var id = AUTOID ? rooms[match[1]] : match[1];
  44.             if (AUTOID) {
  45.                 match[6] = '';
  46.                 match[7] = '';
  47.             }
  48.             jmc.parse(jmc.CommandChar + "mapper add room " + id + " {" + match[4] + "} {" + match[6] + "} {" + match[7] + "} {" + match[8] + "} {" + match[9] + "}");
  49.             last_room_id = id;
  50.             rooms_count++;
  51.         } else if ((match = re_exit.exec(line)) != null) {
  52.             var id = AUTOID ? rooms[match[1]] : match[1];
  53.             jmc.parse(jmc.CommandChar + "mapper add exit " + last_room_id + " {" + match[2] + "} " + id);
  54.         }
  55.     }
  56.     jmc.showme("Rooms loaded: " + rooms_count);
  57. }
  58.  
  59. /* usage:
  60.    - copy importTTMap.js to ./settings
  61.    - copy tt-map to ./tt.map
  62.    - set AUTOID = true in case tt-map contains real vnums (e.g. from MSDP)
  63.    - execute in jmc:
  64.      #use importTTMap.js
  65.      #scri loadTTMap("tt.map")
  66.      #mapper write tt.map
  67. */
Add Comment
Please, Sign In to add comment