Advertisement
Guest User

Untitled

a guest
Aug 26th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { BlockData } from './BlockData';
  2. import { BiomeData } from './BiomeData';
  3.  
  4. import gameDataJSON from '../../data/gamedata.json';
  5. import blockDataJSON from '../../data/blockdata.json';
  6. import biomeDataJSON from '../../data/biomedata.json';
  7.  
  8. export class GameData {
  9.     public blockSize: number;
  10.     public renderDistance: number;
  11.     public chunkSize:  {
  12.         width: number,
  13.         height: number
  14.     }
  15.  
  16.     public blocks: {[key: string]: BlockData} = {};
  17.     public biomes: {[key: string]: BiomeData} = {};
  18.  
  19.     private classes: any = {
  20.         BlockData,
  21.         BiomeData
  22.     };
  23.  
  24.     constructor() {
  25.         let gameData: any = (<any>gameDataJSON);
  26.  
  27.         this.blockSize = gameData.blockSize;
  28.         this.renderDistance = gameData.renderDistance;
  29.         this.chunkSize = gameData.chunkSize;
  30.  
  31.         this.setData(this.blocks, blockDataJSON, 'BlockData');
  32.         this.setData(this.biomes, biomeDataJSON, 'BiomeData');
  33.     }
  34.  
  35.     private setData = (array: any, json: any, className: string): void => {
  36.         let data: any = (<any>json);
  37.  
  38.         for (let key in data) {
  39.             array[key] = new this.classes[className](data[key]);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement