junebug12851/pokered-save-editor

View on GitHub
src/app/data/gameData.service.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { Injectable } from '@angular/core';
import { utils } from './../utils/utils';
 
declare var window: {
require: any;
};
 
/**
* Represents a single game data file
*/
class GameData {
constructor(name: string) {
this.data = window.require(utils.getPath(`/assets/data/${name}.json`));
}
 
public data: any;
}
 
/**
* Looks up game data on demand in the game data folder and index and caches
* it for use
*/
@Injectable({
providedIn: 'root'
})
export class GameDataService {
 
protected cache: {
[key: string]: GameData
} = {};
 
Declaration of instance method not allowed after declaration of instance field. Instead, this should come at the beginning of the class/interface.
file(name: string) {
if (this.cache[name] === undefined) {
this.cache[name] = new GameData(name);
}
 
return this.cache[name];
}
}