-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
191 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
libs/* | ||
!libs/TipHooker-1.0 | ||
!libs/StatLogic | ||
.release | ||
.vscode | ||
libs/* | ||
!libs/TipHooker-1.0 | ||
!libs/StatLogic | ||
.release | ||
.vscode | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#!/usr/bin/env node | ||
|
||
import { argv } from 'node:process' | ||
import * as https from 'node:https' | ||
import { parse } from 'csv-parse' | ||
import * as fs from 'node:fs' | ||
|
||
let product = argv[2] | ||
if(!product) { | ||
product = "wow_classic_ptr" | ||
console.log(`Product not specified, using ${product}`) | ||
} | ||
|
||
let rawVersionData = await new Promise((resolve) => { | ||
https.get("https://wago.tools/api/builds", (res) => { | ||
let data = '' | ||
res.on('data', (chunk) => data += chunk) | ||
|
||
res.on('end', () => { | ||
resolve(data) | ||
}) | ||
}) | ||
}) | ||
const versionData = JSON.parse(rawVersionData) | ||
const version = versionData[product][0].version | ||
console.log(`Latest ${product} version: ${version}`) | ||
|
||
// InventoryTypes that can contain a mix of Armor and Bonus Armor | ||
// https://warcraft.wiki.gg/wiki/Enum.InventoryType | ||
const InventoryTypeSlots = { | ||
1: "HEADSLOT", | ||
3: "SHOULDERSLOT", | ||
5: "CHESTSLOT", | ||
6: "WAISTSLOT", | ||
7: "LEGSSLOT", | ||
8: "FEETSLOT", | ||
9: "WRISTSLOT", | ||
10: "HANDSSLOT", | ||
14: "SECONDARYHANDSLOT", | ||
16: "BACKSLOT", | ||
20: "CHESTSLOT", | ||
} | ||
|
||
// https://warcraft.wiki.gg/wiki/Enum.ItemQuality | ||
const ItemQualities = { | ||
0: "Enum.ItemQuality.Poor", | ||
1: "Enum.ItemQuality.Standard", // in-game doesn't match wiki | ||
2: "Enum.ItemQuality.Good", // in-game doesn't match wiki | ||
3: "Enum.ItemQuality.Rare", | ||
4: "Enum.ItemQuality.Epic", | ||
5: "Enum.ItemQuality.Legendary", | ||
6: "Enum.ItemQuality.Artifact", | ||
7: "Enum.ItemQuality.Heirloom", | ||
8: "Enum.ItemQuality.WoWToken", | ||
} | ||
|
||
const items = {} | ||
await new Promise((resolve) => { | ||
const csvStream = parse({ | ||
columns: true, | ||
}).on('readable', () => { | ||
let item; | ||
while ((item = csvStream.read()) !== null) { | ||
if(item.QualityModifier > 0 ) { | ||
items[item.ID] = { | ||
Quality: ItemQualities[item.OverallQualityID], | ||
Slot: InventoryTypeSlots[item.InventoryType], | ||
Armor: item.Resistances_0, | ||
ItemLevel: item.ItemLevel | ||
} | ||
} | ||
} | ||
}).on('end', () => { | ||
resolve() | ||
}) | ||
|
||
const filter = Object.keys(InventoryTypeSlots).join("|") | ||
const url = `https://wago.tools/db2/ItemSparse/csv?version=${version}&filter[InventoryType]=${filter}&sort[QualityModifier]=desc` | ||
https.get(url, (res) => { | ||
res.pipe(csvStream) | ||
}) | ||
}) | ||
|
||
console.log("Parsed ItemSparse.db2") | ||
|
||
// https://warcraft.wiki.gg/wiki/ItemType#4:_Armor | ||
const ItemArmorSubclasses = { | ||
1: "Enum.ItemArmorSubclass.Cloth", | ||
2: "Enum.ItemArmorSubclass.Leather", | ||
3: "Enum.ItemArmorSubclass.Mail", | ||
4: "Enum.ItemArmorSubclass.Plate", | ||
6: "Enum.ItemArmorSubclass.Shield", | ||
} | ||
|
||
await new Promise((resolve) => { | ||
const csvStream = parse({ | ||
columns: true | ||
}).on('readable', () => { | ||
let item; | ||
while ((item = csvStream.read()) !== null) { | ||
if(items[item.ID]) { | ||
const subclass = ItemArmorSubclasses[item.SubclassID] | ||
if(subclass) { | ||
items[item.ID].SubclassID = subclass | ||
} else { | ||
delete items[item.ID] | ||
} | ||
} | ||
} | ||
}).on('end', () => { | ||
resolve() | ||
}) | ||
|
||
const filter = Object.keys(items).join("|") | ||
const url = `https://wago.tools/db2/Item/csv?version=${version}&filter[ID]=${filter}` | ||
https.get(url, (res) => { | ||
res.pipe(csvStream) | ||
}) | ||
}) | ||
|
||
console.log("Parsed Item.db2") | ||
|
||
const baseArmor = {} | ||
for(const item of Object.values(items)) { | ||
let quality = baseArmor[item.Quality] ||= {} | ||
let slot = quality[item.Slot] ||= {} | ||
let subclass = slot[item.SubclassID] ||= {} | ||
subclass[item.ItemLevel] = item.Armor | ||
} | ||
|
||
let data = "addon.baseArmorTable = {\n" | ||
const indent = "\t" | ||
const generateLua = function(obj, level) { | ||
level ||= 1 | ||
for(const [key, value] of Object.entries(obj)) { | ||
if(typeof(value) === "object") { | ||
data = data.concat(indent.repeat(level), "[", key, "] = {\n") | ||
generateLua(value, level + 1) | ||
data = data.concat(indent.repeat(level), "},\n") | ||
} else { | ||
data = data.concat(indent.repeat(level), "[", key, "] = ", value, ",\n") | ||
} | ||
} | ||
} | ||
generateLua(baseArmor) | ||
data = data + "}\n" | ||
|
||
const filename = `Bonus_Armor_${version}.lua` | ||
fs.writeFileSync(filename, data) | ||
console.log(`Wrote ${filename}`) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "generatebasearmor", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "GenerateBaseArmor.mjs", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "GPL-2.0", | ||
"dependencies": { | ||
"csv-parse": "^5.5.2" | ||
} | ||
} |