UNPKG

puzzlescript

Version:

Play PuzzleScript games in your terminal!

53 lines 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LookupHelper = void 0; class LookupHelper { constructor() { this._allSoundEffects = new Map(); this._allObjects = new Map(); this._allLegendTiles = new Map(); this._allLevelChars = new Map(); } _addToHelper(map, key, value) { if (map.has(key)) { throw new Error(`ERROR: Duplicate object is defined named "${key}". They are case-sensitive!`); } map.set(key, value); } addSoundEffect(key, soundEffect) { this._addToHelper(this._allSoundEffects, key.toLowerCase(), soundEffect); } addToAllObjects(gameObject) { this._addToHelper(this._allObjects, gameObject.getName().toLowerCase(), gameObject); } addToAllLegendTiles(legendTile) { this._addToHelper(this._allLegendTiles, legendTile.spriteNameOrLevelChar.toLowerCase(), legendTile); } addObjectToAllLevelChars(levelChar, gameObject) { this._addToHelper(this._allLegendTiles, levelChar.toLowerCase(), gameObject); this._addToHelper(this._allLevelChars, levelChar.toLowerCase(), gameObject); } addLegendToAllLevelChars(legendTile) { this._addToHelper(this._allLevelChars, legendTile.spriteNameOrLevelChar.toLowerCase(), legendTile); } lookupObjectOrLegendTile(source, key) { key = key.toLowerCase(); const value = this._allObjects.get(key) || this._allLegendTiles.get(key); if (!value) { throw new Error(`ERROR: Could not look up "${key}". Has it been defined in the Objects section or the Legend section?`); } return value; } lookupByLevelChar(key) { const value = this._allLevelChars.get(key.toLowerCase()); if (!value) { throw new Error(`ERROR: Could not look up "${key}" in the levelChars map. Has it been defined in the Objects section or the Legend section?`); } return value; } lookupSoundEffect(key) { return this._allSoundEffects.get(key.toLowerCase()); } } exports.LookupHelper = LookupHelper; //# sourceMappingURL=lookup.js.map