diff --git a/src/lib/clientdb/ClientDb.ts b/src/lib/clientdb/ClientDb.ts index ce8ef95..c15f2a7 100644 --- a/src/lib/clientdb/ClientDb.ts +++ b/src/lib/clientdb/ClientDb.ts @@ -1,6 +1,7 @@ import { IoSource, IoStream, openStream } from '@wowserhq/io'; import ClientDbRecord from './ClientDbRecord.js'; import * as dbIo from './io.js'; +import { DB_LOCALE } from './const.js'; interface Constructor { new (...args: any[]): T; @@ -8,6 +9,7 @@ interface Constructor { class ClientDb { #RecordClass: Constructor; + #locale: DB_LOCALE; #minId = 0xfffffff; #maxId = 0; @@ -17,8 +19,9 @@ class ClientDb { #records: T[]; #recordsById: Record; - constructor(RecordClass: Constructor) { + constructor(RecordClass: Constructor, locale = DB_LOCALE.LOCALE_ENUS) { this.#RecordClass = RecordClass; + this.#locale = locale; } get records() { @@ -37,7 +40,7 @@ class ClientDb { const recordsById = {}; for (let i = 0; i < this.#recordCount; i++) { - const record = new this.#RecordClass().load(stream, stringBlockStream); + const record = new this.#RecordClass().load(stream, stringBlockStream, this.#locale); this.#minId = record.id < this.#minId ? record.id : this.#minId; this.#maxId = record.id > this.#maxId ? record.id : this.#maxId; @@ -92,4 +95,4 @@ class ClientDb { } export default ClientDb; -export { ClientDb }; +export { ClientDb, DB_LOCALE }; diff --git a/src/lib/clientdb/ClientDbRecord.ts b/src/lib/clientdb/ClientDbRecord.ts index 51b9b8c..174fa90 100644 --- a/src/lib/clientdb/ClientDbRecord.ts +++ b/src/lib/clientdb/ClientDbRecord.ts @@ -1,5 +1,6 @@ import { IoStream, IoType } from '@wowserhq/io'; import * as dbIo from './io.js'; +import { DB_LOCALE } from './const.js'; class ClientDbRecord { id: number; @@ -10,15 +11,15 @@ class ClientDbRecord { this.#recordIo = recordIo; } - load(stream: IoStream, stringBlock: IoStream) { + load(stream: IoStream, stringBlock: IoStream, locale: DB_LOCALE) { const record = this.#recordIo.read(stream); for (const [key, value] of Object.entries(record)) { if (key.endsWith('.locstring')) { - const strings = this.#readLocString(value as number[], stringBlock); + const string = this.#readLocString(value as number[], stringBlock, locale); const normalizedKey = key.replace('.locstring', ''); - this[normalizedKey] = strings; + this[normalizedKey] = string; } else { this[key] = value; } @@ -27,22 +28,18 @@ class ClientDbRecord { return this; } - #readLocString(value: number[], stringBlock: IoStream) { + #readLocString(value: number[], stringBlock: IoStream, locale: DB_LOCALE) { // All values before last are offsets in the string block const offsets = value.slice(0, -1); // Last value is flags const flags = value.at(-1); - const strings: string[] = []; + // Read locale-specific string + stringBlock.offset = offsets[locale]; + const localeString = dbIo.string.read(stringBlock); - for (const offset of offsets) { - stringBlock.offset = offset; - const string = dbIo.string.read(stringBlock); - strings.push(string); - } - - return strings; + return localeString; } } diff --git a/src/lib/clientdb/const.ts b/src/lib/clientdb/const.ts new file mode 100644 index 0000000..fa851ad --- /dev/null +++ b/src/lib/clientdb/const.ts @@ -0,0 +1,13 @@ +enum DB_LOCALE { + LOCALE_ENUS = 0, + LOCALE_KOKR, + LOCALE_FRFR, + LOCALE_DEDE, + LOCALE_ZHCN, + LOCALE_ZHTW, + LOCALE_ESES, + LOCALE_ESMX, + LOCALE_RURU, +} + +export { DB_LOCALE }; diff --git a/src/lib/clientdb/record/AreaTableRecord.ts b/src/lib/clientdb/record/AreaTableRecord.ts index 1b1597a..54bc841 100644 --- a/src/lib/clientdb/record/AreaTableRecord.ts +++ b/src/lib/clientdb/record/AreaTableRecord.ts @@ -32,7 +32,7 @@ class AreaTableRecord extends ClientDbRecord { zoneMusic: number; introSound: number; explorationLevel: number; - areaName: string[]; + areaName: string; factionGroupMask: number; liquidTypeId: number[]; minElevation: number; diff --git a/src/spec/clientdb/ClientDb.spec.ts b/src/spec/clientdb/ClientDb.spec.ts index 5c0bc36..a5ab25a 100644 --- a/src/spec/clientdb/ClientDb.spec.ts +++ b/src/spec/clientdb/ClientDb.spec.ts @@ -18,7 +18,7 @@ describe('ClientDb', () => { const record = dbc.getRecordByIndex(1); expect(record.id).toBe(2); - expect(record.areaName[0]).toBe('Longshore'); + expect(record.areaName).toBe('Longshore'); expect(record.minElevation).toBe(-500); }); });