UNPKG

@runejs/filestore

Version:

Tools for managing the RuneJS filestore.

77 lines (76 loc) 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Filestore = exports.getFileName = exports.fileNames = void 0; const data_1 = require("./data"); const file_index_1 = require("./file-index"); const util_1 = require("./util"); const stores_1 = require("./stores"); const getFileName = (nameHash) => { return exports.fileNames[nameHash.toString()] || nameHash.toString(); }; exports.getFileName = getFileName; class Filestore { filestoreDir; configDir; binaryStore; configStore; fontStore; jingleStore; modelStore; musicStore; regionStore; soundStore; spriteStore; widgetStore; textureStore; channels; indexes = new Map(); constructor(filestoreDir, options) { this.filestoreDir = filestoreDir; this.configDir = options?.configDir || filestoreDir; this.channels = (0, data_1.loadFilestore)(filestoreDir); exports.fileNames = (0, util_1.getFileNames)(this.configDir); this.binaryStore = new stores_1.BinaryStore(this); this.configStore = new stores_1.ConfigStore(this); this.fontStore = new stores_1.FontStore(this); this.jingleStore = new stores_1.JingleStore(this); this.modelStore = new stores_1.ModelStore(this); this.musicStore = new stores_1.MusicStore(this); this.regionStore = new stores_1.RegionStore(this, options?.xteas); this.soundStore = new stores_1.SoundStore(this); this.spriteStore = new stores_1.SpriteStore(this); this.widgetStore = new stores_1.WidgetStore(this); this.textureStore = new stores_1.TextureStore(this); this.fontStore.loadFonts(); } /** * Fetches the specified File Index. * @param indexId The string or numberic ID of the File Index to find. */ getIndex(inputIndexId) { let indexId = inputIndexId; if (typeof indexId !== 'number') { indexId = file_index_1.indexIdMap[indexId]; } if (!this.indexes.has(indexId)) { const archiveIndex = new file_index_1.FileIndex(indexId, this.channels); archiveIndex.decodeIndex(); this.indexes.set(indexId, archiveIndex); return archiveIndex; } return this.indexes.get(indexId); } get itemStore() { return this.configStore?.itemStore; } get varbitStore() { return this.configStore?.varbitStore; } get npcStore() { return this.configStore?.npcStore; } get objectStore() { return this.configStore?.objectStore; } } exports.Filestore = Filestore;