Skip to content

Commit

Permalink
lib: support poe1 and 2 schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
SnosMe committed Dec 6, 2024
1 parent 92b8a4d commit 7d3bfd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pathofexile-dat",
"version": "10.0.0",
"version": "11.0.0",
"type": "module",
"bin": "./dist/cli/run.js",
"exports": {
Expand All @@ -14,7 +14,7 @@
},
"dependencies": {
"ooz-wasm": "^2.0.0",
"pathofexile-dat-schema": "^5.0.0"
"pathofexile-dat-schema": "^6.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
Expand Down
20 changes: 13 additions & 7 deletions lib/src/cli/export-tables.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SCHEMA_URL, SCHEMA_VERSION, SchemaFile } from 'pathofexile-dat-schema'
import { SCHEMA_URL, SCHEMA_VERSION, SchemaFile, ValidFor } from 'pathofexile-dat-schema'
import type { ExportConfig } from './ExportConfig.js'
import { FileLoader } from './bundle-loaders.js'
import { Header, getHeaderLength } from '../dat/header.js'
Expand All @@ -7,8 +7,6 @@ import { readColumn } from '../dat/reader.js'
import * as fs from 'fs/promises'
import * as path from 'path'

let schema: SchemaFile

const TRANSLATIONS = [
{ name: 'English', path: 'Data' },
{ name: 'French', path: 'Data/French' },
Expand All @@ -30,7 +28,7 @@ export async function exportTables (
if (!config.tables?.length) return

console.log('Loading schema for dat files')
schema = await (await fetch(SCHEMA_URL)).json()
const schema = await (await fetch(SCHEMA_URL)).json()
if (schema.version !== SCHEMA_VERSION) {
console.error('Schema has format not compatible with this package. Check for "pathofexile-dat" updates.')
process.exit(1)
Expand All @@ -48,7 +46,7 @@ export async function exportTables (
for (const target of config.tables) {
console.log(`Exporting table "${tr.path}/${target.name}"`)
const datFile = readDatFile('.datc64', await loader.getFileContents(`${tr.path}/${target.name}.datc64`))
const headers = importHeaders(target.name, datFile)
const headers = importHeaders(target.name, datFile, config, schema)
.filter(hdr => target.columns.includes(hdr.name))

for (const column of target.columns) {
Expand Down Expand Up @@ -89,10 +87,18 @@ interface NamedHeader extends Header {
name: string
}

function importHeaders (name: string, datFile: DatFile): NamedHeader[] {
function importHeaders (
name: string,
datFile: DatFile,
config: ExportConfig,
schema: SchemaFile
): NamedHeader[] {
const headers = [] as NamedHeader[]

const sch = schema.tables.find(s => s.name === name)!
const validFor = (config.patch?.startsWith('4.') || config.steam?.includes('Path of Exile 2'))
? ValidFor.PoE2
: ValidFor.PoE1
const sch = schema.tables.find(s => s.name === name && s.validFor === validFor)!
let offset = 0
for (const column of sch.columns) {
headers.push({
Expand Down

0 comments on commit 7d3bfd5

Please sign in to comment.