Advertisement
jargon

Roe2Js :: "load game data.js"

Jul 2nd, 2024 (edited)
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var default_entity_stats = [];
  2. var default_action_stats = [];
  3.  
  4. var entityLayers = [];
  5. var entityRoster = [];
  6.  
  7. var actionRoster = [];
  8.  
  9. var full_entity_stats = [];
  10. var full_map = [];
  11.  
  12. loadDefaultEntities();
  13. loadDefaultActions();
  14.  
  15. function loadDefaultEntities() {
  16.   try {
  17.     // Load entity layers and default stats
  18.     entityLayers = loadJSONDirect('/test dictionary/scripts/json/gamevars/entityRoster.json');
  19.     default_entity_stats['____'] = loadJSONDirect('/test dictionary/scripts/json/gamevars/default stats.json');
  20.    
  21.     // Iterate over entity layers
  22.     for (let layer = 0; layer < entityLayers.length; layer++) {
  23.       entityRoster = entityLayers[layer];
  24.  
  25.       for (let index = 0; index < entityRoster.length; index++) {
  26.         const entityName = entityRoster[index];
  27.         const entityShortName = entityName.substring(0, 4);
  28.         const filePath = `/test dictionary/scripts/json/gamevars/entities/${entityShortName}.json`;
  29.  
  30.         // Load entity stats
  31.         const entityStats = loadJSONDirect(filePath);
  32.         if (entityStats && entityStats[entityShortName]) {
  33.           if (!default_entity_stats[entityName]) {
  34.             default_entity_stats[entityName] = {};
  35.           }
  36.           default_entity_stats[entityName].stats = entityStats[entityShortName].stats;
  37.         }
  38.       }
  39.     }
  40.   } catch (error) {
  41.     console.error('Error loading default entities:', error);
  42.   }
  43. }
  44.  
  45. function loadDefaultActions() {
  46.   try {
  47.     // Load action roster
  48.     actionRoster = loadJSONDirect('/test dictionary/scripts/json/gamevars/actionRoster.json');
  49.  
  50.     for (let index = 0; index < actionRoster.length; index++) {
  51.       const actionName = actionRoster[index];
  52.       const actionShortName = actionName.substring(0, 4);
  53.       const url = `/test dictionary/scripts/json/gamevars/actions/${actionShortName}.json`;
  54.  
  55.       // Load action stats
  56.       const actionStats = loadJSONDirect(url);
  57.       if (actionStats) {
  58.         default_action_stats[actionShortName] = actionStats;
  59.       }
  60.     }
  61.   } catch (error) {
  62.     console.error('Error loading default actions:', error);
  63.   }
  64. }
  65.  
  66. function loadMap() {
  67.   try {
  68.     // Load the raw map data
  69.     const rawMap = loadJSONDirect('/test dictionary/scripts/json/maps/demo.json');
  70.    
  71.     full_map = create3DArrayBlock('____', 0, rawMap.length - 1, 0, rawMap[0].length - 1, 0, layers.gui);
  72.     full_entity_stats = create3DArrayBlock([], 0, rawMap.length - 1, 0, rawMap[0].length - 1, 0, layers.gui);
  73.  
  74.     for (let y = 0; y < rawMap[0].length; y++) {
  75.       for (let x = 0; x < rawMap.length; x++) {
  76.         for (let z = 0; z < layers.gui; z++) {
  77.           const mapCell = rawMap[x][y][z];
  78.           const mapCellShortName = mapCell.substring(0, 4);
  79.           full_map[x][y][z] = mapCellShortName;
  80.  
  81.           if (default_entity_stats[mapCellShortName]) {
  82.             full_entity_stats[x][y][z] = default_entity_stats[mapCellShortName];
  83.           } else {
  84.             full_entity_stats[x][y][z] = default_entity_stats['____'];
  85.           }
  86.         }
  87.       }
  88.     }
  89.  
  90.     cx = randInt(0, full_map.length - 1);
  91.     cy = randInt(0, full_map[0].length - 1);
  92.   } catch (error) {
  93.     console.error('Error loading map:', error);
  94.   }
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement