From 00b55e90d7a9df5e7cc605edd57a8c00cf335c0c Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Tue, 11 Mar 2025 09:17:41 +0100 Subject: [PATCH] add ff1 --- dq3/dq3.ts | 204 +++++++++++++++++++++++++++-------------------------- 1 file changed, 103 insertions(+), 101 deletions(-) diff --git a/dq3/dq3.ts b/dq3/dq3.ts index b0e8bd5..9dd88c0 100644 --- a/dq3/dq3.ts +++ b/dq3/dq3.ts @@ -20,13 +20,15 @@ function getcategory(doc, category, notes) item[h] = columns[i].textContent; }); item.Notes = "" - const sup = parseInt(item.Name.split(" ").pop()); - if (!isNaN(sup)) + if (item.Name) { - item.Notes = notes[sup - 1]; - item.Name = item.Name.substr(0, item.Name.length - 2) + const sup = parseInt(item.Name.split(" ").pop()); + if (!isNaN(sup)) + { + item.Notes = notes[sup - 1]; + item.Name = item.Name.substr(0, item.Name.length - 2) + } } - item.Value = item.At || item.De; result.push(item); }); return result; @@ -34,122 +36,122 @@ function getcategory(doc, category, notes) function getnotes(doc) { + return [] const lastsup = [...doc.getElementsByTagName("sup")].pop(); return lastsup.parentElement.textContent.split("\n") .filter(i => i.length) .map(i => i.substr(3)); } -function getarmor() +async function getpage(url, tables) { - return fetch("https://mikesrpgcenter.com/dw3/armor.html") - .then(response => response.text()) - .then(html => + const result = {} + const response = await fetch(root + url) + const html = await response.text() + + const doc = getdompareser(html); + const notes = getnotes(doc); + + tables.forEach(category => { - const doc = getdompareser(html); - const notes = getnotes(doc); - ["armor", "shields", "helmets"] - .forEach(category => - { - equipment[category] = getcategory(doc, category, notes); - }); + result[category] = getcategory(doc, category, notes); }); + return result } -function getweapons() +function output(equipment) { - return fetch("https://mikesrpgcenter.com/dw3/weapons.html") - .then(response => response.text()) - .then(html => - { - const doc = getdompareser(html); - const notes = getnotes(doc); - equipment.weapons = getcategory(doc, "weapons", notes); - }); -} + const result = [] + const exclude = ["Found", "Sold", "Available", "Ft","Mr","Go"] // add unused classes/jobs -function outputcategory(category, characters) -{ - // todo : auto length - // todo: output in one string at the end - console.log("=".repeat(46)) - const columns = [ - { id: "Name", label: category.toUpperCase(), len: 21}, - { id: "Value", label: "Val", len: 4}, - { id: "Cost", label: "Cost", len: 6}, - { separator: true, label: "| "} - ] + // todo: fix footer notes + // todo: invert available X mark + // todo: remove a column if always empty - characters.forEach(char => - { - columns.push( - { - id: char.job, - label: char.name, - len: char.name.length + 1, - character : true + Object.keys(equipment).forEach(table => { + const columnsizes = {} + result.push(table.toUpperCase()) + const items = equipment[table] + + // exclude + items.forEach(item => { + exclude.forEach(name => { + delete item[name] + }) }) + + // init sizes + items.forEach(item => + { + Object.keys(item).forEach(columnname => { + columnsizes[columnname] = columnsizes[columnname] || columnname.length + columnsizes[columnname] = Math.max(columnsizes[columnname], (item[columnname] || "").length) + }) + }) + + // header + let line = "" + Object.keys(columnsizes).forEach(columnname => { + const size = columnsizes[columnname] + line += columnname + " ".repeat((Math.max(0, size - columnname.length))) + "|" + }) + result.push(line) + + // lines + items.forEach(item => { + let line = "" + Object.keys(columnsizes).forEach(columnname => { + const size = columnsizes[columnname] + const value = (item[columnname] || "").replace("\n", " ") + line += value + " ".repeat(Math.max(0, size - value.length)) + "|" + }) + result.push(line) + }) + result.push(" ") }) - // columns.push({ id: "Notes", label: "Notes", len: 6}); - - // headers - let line = ""; - columns.forEach(column => - { - let elt = column.label; - elt += " ".repeat(Math.max(0, column.len - elt.length)) - line += elt; - }) - console.log(line + "| ") - - // lines - equipment[category].forEach(item => - { - let line = ""; - let elt = ""; - columns.forEach(column => - { - if (column.separator) - { - elt = "| "; - } - else - { - elt = item[column.id]; - if (column.character) - { - elt = elt == "x" ? " " : "##" - } - elt += " ".repeat(Math.max(0, column.len - elt.length)) - } - line += elt; - }) - console.log(line + "|") - }); + console.log(result.join("\n")) } -function output() +const root = "https://mikesrpgcenter.com" +let equipment = {}; + +const dq3pages = [ + { + url: "/dw3/armor.html", + tables: ["armor", "shields", "helmets"] + }, + { + url: "/dw3/weapons.html", + tables: ["weapons"] + } +] + +const ff1pages = [ + { + url: "/ffantasy/weapons.html", + tables: ["swords", "axes", "daggers", "staffs", "hammers", "nunchucks", "miscellaneous"] + }, + { + url: "/ffantasy/armor.html", + tables: ["armor", "braceletes", "shields", "helmets", "gauntlets"] + }, + { + url: "/ffantasy/blackmagic.html", + tables: ["black_magic"] + }, + { + url: "/ffantasy/whitemagic.html", + tables: ["white_magic"] + } +] + +const pages = ff1pages +for (const index in pages) { - // todo: full name then cut to 2 char - const characters = [ - {job: "Hr", name: "Yo"}, - {job: "Sr", name: "Le"}, - {job: "Pr", name: "Je"}, - {job: "Wz", name: "Lu"} - ]; + const page = pages[index] + equipment = {...equipment, ...(await getpage(page.url, page.tables))} - console.log("Dragon Quest 3 equipment sheet"); - outputcategory("weapons", characters) - outputcategory("armor", characters) - outputcategory("shields", characters) - outputcategory("helmets", characters) } - - -var equipment = {}; - -getarmor() -.then(getweapons) -.then(output); +output(equipment) \ No newline at end of file