Files
Exiled-Exchange-2/dataParser/stats.ts
Kvan7 835e43a166 v0.1.4 (#166)
* Fix #132

* Features/python script update (#143)

This closes the following issues:

- #67 
- #68 
- #69 
- #70 
- #110 
- #111 
- #112 
- #139

* [Parse Error] - Dualstring bow #60

* Adds starting for localization

* tests yay, this is terrible Add junit tests :( #74

* revert tests cause they were really terrible

* bump gitignore so i dont lose files

* Features/pseudo-pseudo (#93)

* uhhhhhhhhhhhh, maybe pseudo will get support before GGG

* psesudo only ele

* remove git ignored files

* fix ignore

* working tree

* update parser #67

* bump

* more stuff

* maybe working new desc parsing

* Description parser

* Maybe?

* update

* add ko and cmn-Hant

* Add items and pseudo

* push to main

* force utf-16

* moving data

* uh, miss typed a utf 8 for a utf 16

* revert cause that was worse

* Features/moreLocalizationFixes (#148)

* change data files

* ru client strings

* Revert to search by translated name

REVERT THIS LATER ONCE COPY ADVANCED DESC IS BACK

* ru ko and cmn-Hant parse correctly now

* Change Exalted orb to Perfect Jewelers orb

May change again, but just found out about sidekick and since their program was made before creating this, I'm not going to add conflict of logos.

* change from jewelers to div, didn't like how it looked in ui

* Update README

* Update README.md

* Update README.md

* Revert "change from jewelers to div, didn't like how it looked in ui"

This reverts commit b11d33353d.

* Update README.md

* Update localization for PoE2 #66

Functional. Missing some base types in some languages but will make separate issue

* move .ds_store to ds_store (just unhide)

* Builtin browser opens while disabled in settings #103

* [Not Recognized Modifier] - +2 Charm Slots #137

* Remove calls to poeprices for now

* Version Bump to v0.1.4

* Move store and rename

* file move error

* lint + update app_i18n

* [PoE2] Item gets pinned in-game with CTRL+D (auto-hide on) #124

* add fix to pull-json

* final lint fix
2024-12-24 12:45:31 -06:00

126 lines
3.7 KiB
TypeScript

import { Stat } from "./data/interfaces-apt";
import { Stats } from "./vendor/client/tables/index";
import * as fs from "node:fs";
import * as path from "node:path";
import { API_STATS } from "./vendor/trade-api";
import { StatEntry } from "./vendor/trade-api/index-interfaces";
export function makeGeneratorStats(): (lang: string) => Stat[] {
const stats = API_STATS();
const statsFlattened = stats.flatMap((s) => s.entries);
const addStatId = (s: StatEntry) => {
return {
...s,
statId: s.id.substring(s.type.length + 1),
statIdNumber: s.id.substring(s.type.length + 1 + 5) as unknown as number,
};
};
const statsWithStatId = statsFlattened.map(addStatId);
const statsGroupedByStatId = statsWithStatId.reduce(
(acc, curr) => {
const statId = curr.statId;
if (acc[statId]) {
acc[statId].push(curr);
} else {
acc[statId] = [curr];
}
return acc;
},
{} as Record<string, StatEntry[]>,
);
const FormatRef = (ref: string) => {
// Get all parts of string in [ ]
let outString = "";
for (let i = 0; i < ref.length; i++) {
if (ref[i] === "[") {
i++;
let localOutString = "";
while (ref[i] !== "]") {
if (ref[i] === "|") {
localOutString = "";
} else {
localOutString += ref[i];
}
i++;
}
outString += localOutString;
} else {
outString += ref[i];
}
}
return outString;
};
return (lang: string) => {
const statsArray: Stat[] = [];
for (const statId in statsGroupedByStatId) {
const statEntries = statsGroupedByStatId[statId];
const combinedStat = {
ref: FormatRef(statEntries[0].text),
better: 0,
matchers: [{ string: "StatMatcher" }],
trade: {
ids: {
...(statEntries.filter((e) => e.type == "explicit").length > 0 && {
explicit: statEntries
.filter((e) => e.type == "explicit")
.map((e) => e.id),
}),
...(statEntries.filter((e) => e.type == "implicit").length > 0 && {
implicit: statEntries
.filter((e) => e.type == "implicit")
.map((e) => e.id),
}),
...(statEntries.filter((e) => e.type == "fractured").length > 0 && {
fractured: statEntries
.filter((e) => e.type == "fractured")
.map((e) => e.id),
}),
...(statEntries.filter((e) => e.type == "scourge").length > 0 && {
scourge: statEntries
.filter((e) => e.type == "scourge")
.map((e) => e.id),
}),
...(statEntries.filter((e) => e.type == "crafted").length > 0 && {
crafted: statEntries
.filter((e) => e.type == "crafted")
.map((e) => e.id),
}),
...(statEntries.filter((e) => e.type == "pseudo").length > 0 && {
pseudo: statEntries
.filter((e) => e.type == "pseudo")
.map((e) => e.id),
}),
},
},
};
statsArray.push(combinedStat);
}
return statsArray;
};
}
(async function main() {
const generators = [makeGeneratorStats()];
for (const lang of ["en"]) {
const items = generators.flatMap((g) => g(lang));
items.sort((a, b) => a.ref.localeCompare(b.ref));
const jsonLines = Array.from(
new Set(items.map((item) => JSON.stringify(item))),
);
const filePath = path.join(__dirname, "data", lang, "stats.ndjson");
fs.writeFileSync(filePath, jsonLines.join("\n") + "\n");
}
})();