@rhyster/wow-casc-dbc 2.1.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1687,6 +1687,7 @@ class DBDParser {
1687
1687
  __publicField(this, "wdc");
1688
1688
  __publicField(this, "definitions", /* @__PURE__ */ new Map());
1689
1689
  __publicField(this, "columns", []);
1690
+ __publicField(this, "cache", /* @__PURE__ */ new Map());
1690
1691
  this.wdc = wdc;
1691
1692
  }
1692
1693
  async init() {
@@ -1761,6 +1762,9 @@ class DBDParser {
1761
1762
  return this.wdc.getAllIDs();
1762
1763
  }
1763
1764
  getRowData(id) {
1765
+ if (this.cache.has(id)) {
1766
+ return structuredClone(this.cache.get(id));
1767
+ }
1764
1768
  const row = this.wdc.getRowData(id);
1765
1769
  if (!row) {
1766
1770
  return void 0;
@@ -1804,8 +1808,19 @@ class DBDParser {
1804
1808
  data[column.name] = cell.string;
1805
1809
  }
1806
1810
  } else if (column.type === "float") {
1807
- assert__default(typeof cell.data === "number", `Invalid data type for float column ${column.name}`);
1808
- data[column.name] = castFloat(cell.data, srcSize, srcSigned);
1811
+ if (column.arraySize) {
1812
+ assert__default(typeof cell.data === "bigint", `Invalid data type for float array column ${column.name}`);
1813
+ const values = [];
1814
+ const castBuffer = Buffer.from(cell.data.toString(16).padStart(8 * column.arraySize, "0"), "hex");
1815
+ for (let i = 0; i < column.arraySize; i += 1) {
1816
+ const value = castBuffer.readFloatLE(i * 4);
1817
+ values.push(Math.round(value * 100) / 100);
1818
+ }
1819
+ data[column.name] = values;
1820
+ } else {
1821
+ assert__default(typeof cell.data === "number", `Invalid data type for float column ${column.name}`);
1822
+ data[column.name] = castFloat(cell.data, srcSize, srcSigned);
1823
+ }
1809
1824
  } else if (typeof cell.data === "number") {
1810
1825
  data[column.name] = castIntegerBySize(
1811
1826
  cell.data,
@@ -1890,7 +1905,8 @@ class DBDParser {
1890
1905
  }
1891
1906
  });
1892
1907
  }
1893
- return data;
1908
+ this.cache.set(id, data);
1909
+ return structuredClone(data);
1894
1910
  }
1895
1911
  }
1896
1912
 
package/dist/index.d.cts CHANGED
@@ -224,6 +224,7 @@ declare class DBDParser {
224
224
  readonly wdc: WDCReader;
225
225
  readonly definitions: Map<string, string>;
226
226
  columns: Column[];
227
+ private cache;
227
228
  private constructor();
228
229
  private init;
229
230
  static parse(wdc: WDCReader): Promise<DBDParser>;
package/dist/index.d.mts CHANGED
@@ -224,6 +224,7 @@ declare class DBDParser {
224
224
  readonly wdc: WDCReader;
225
225
  readonly definitions: Map<string, string>;
226
226
  columns: Column[];
227
+ private cache;
227
228
  private constructor();
228
229
  private init;
229
230
  static parse(wdc: WDCReader): Promise<DBDParser>;
package/dist/index.d.ts CHANGED
@@ -224,6 +224,7 @@ declare class DBDParser {
224
224
  readonly wdc: WDCReader;
225
225
  readonly definitions: Map<string, string>;
226
226
  columns: Column[];
227
+ private cache;
227
228
  private constructor();
228
229
  private init;
229
230
  static parse(wdc: WDCReader): Promise<DBDParser>;
package/dist/index.mjs CHANGED
@@ -1675,6 +1675,7 @@ class DBDParser {
1675
1675
  __publicField(this, "wdc");
1676
1676
  __publicField(this, "definitions", /* @__PURE__ */ new Map());
1677
1677
  __publicField(this, "columns", []);
1678
+ __publicField(this, "cache", /* @__PURE__ */ new Map());
1678
1679
  this.wdc = wdc;
1679
1680
  }
1680
1681
  async init() {
@@ -1749,6 +1750,9 @@ class DBDParser {
1749
1750
  return this.wdc.getAllIDs();
1750
1751
  }
1751
1752
  getRowData(id) {
1753
+ if (this.cache.has(id)) {
1754
+ return structuredClone(this.cache.get(id));
1755
+ }
1752
1756
  const row = this.wdc.getRowData(id);
1753
1757
  if (!row) {
1754
1758
  return void 0;
@@ -1792,8 +1796,19 @@ class DBDParser {
1792
1796
  data[column.name] = cell.string;
1793
1797
  }
1794
1798
  } else if (column.type === "float") {
1795
- assert(typeof cell.data === "number", `Invalid data type for float column ${column.name}`);
1796
- data[column.name] = castFloat(cell.data, srcSize, srcSigned);
1799
+ if (column.arraySize) {
1800
+ assert(typeof cell.data === "bigint", `Invalid data type for float array column ${column.name}`);
1801
+ const values = [];
1802
+ const castBuffer = Buffer.from(cell.data.toString(16).padStart(8 * column.arraySize, "0"), "hex");
1803
+ for (let i = 0; i < column.arraySize; i += 1) {
1804
+ const value = castBuffer.readFloatLE(i * 4);
1805
+ values.push(Math.round(value * 100) / 100);
1806
+ }
1807
+ data[column.name] = values;
1808
+ } else {
1809
+ assert(typeof cell.data === "number", `Invalid data type for float column ${column.name}`);
1810
+ data[column.name] = castFloat(cell.data, srcSize, srcSigned);
1811
+ }
1797
1812
  } else if (typeof cell.data === "number") {
1798
1813
  data[column.name] = castIntegerBySize(
1799
1814
  cell.data,
@@ -1878,7 +1893,8 @@ class DBDParser {
1878
1893
  }
1879
1894
  });
1880
1895
  }
1881
- return data;
1896
+ this.cache.set(id, data);
1897
+ return structuredClone(data);
1882
1898
  }
1883
1899
  }
1884
1900
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhyster/wow-casc-dbc",
3
- "version": "2.1.1",
3
+ "version": "2.3.0",
4
4
  "description": "Fetch World of Warcraft data files from CASC and parse DBC/DB2 files.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -40,16 +40,16 @@
40
40
  "@types/async": "^3.2.24",
41
41
  "@types/cli-progress": "^3.11.5",
42
42
  "@types/jest": "^29.5.12",
43
- "@types/node": "^20.11.30",
44
- "@typescript-eslint/eslint-plugin": "^7.4.0",
45
- "@typescript-eslint/parser": "^7.4.0",
43
+ "@types/node": "^20.12.7",
44
+ "@typescript-eslint/eslint-plugin": "^7.7.1",
45
+ "@typescript-eslint/parser": "^7.7.1",
46
46
  "eslint": "^8.57.0",
47
47
  "eslint-config-airbnb-base": "^15.0.0",
48
48
  "eslint-config-airbnb-typescript": "^18.0.0",
49
49
  "jest": "^29.7.0",
50
50
  "ts-jest": "^29.1.2",
51
51
  "ts-node": "^10.9.2",
52
- "typescript": "^5.4.3",
52
+ "typescript": "^5.4.5",
53
53
  "unbuild": "^2.0.0"
54
54
  },
55
55
  "dependencies": {