This commit is contained in:
quenousimporte 2025-03-11 09:17:41 +01:00
parent d86718c420
commit 00b55e90d7
1 changed files with 103 additions and 101 deletions

View File

@ -20,13 +20,15 @@ function getcategory(doc, category, notes)
item[h] = columns[i].textContent; item[h] = columns[i].textContent;
}); });
item.Notes = "" item.Notes = ""
if (item.Name)
{
const sup = parseInt(item.Name.split(" ").pop()); const sup = parseInt(item.Name.split(" ").pop());
if (!isNaN(sup)) if (!isNaN(sup))
{ {
item.Notes = notes[sup - 1]; item.Notes = notes[sup - 1];
item.Name = item.Name.substr(0, item.Name.length - 2) item.Name = item.Name.substr(0, item.Name.length - 2)
} }
item.Value = item.At || item.De; }
result.push(item); result.push(item);
}); });
return result; return result;
@ -34,122 +36,122 @@ function getcategory(doc, category, notes)
function getnotes(doc) function getnotes(doc)
{ {
return []
const lastsup = [...doc.getElementsByTagName("sup")].pop(); const lastsup = [...doc.getElementsByTagName("sup")].pop();
return lastsup.parentElement.textContent.split("\n") return lastsup.parentElement.textContent.split("\n")
.filter(i => i.length) .filter(i => i.length)
.map(i => i.substr(3)); .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 doc = getdompareser(html);
const notes = getnotes(doc); const notes = getnotes(doc);
["armor", "shields", "helmets"]
.forEach(category => tables.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") const result = []
.then(response => response.text()) const exclude = ["Found", "Sold", "Available", "Ft","Mr","Go"] // add unused classes/jobs
.then(html =>
{
const doc = getdompareser(html);
const notes = getnotes(doc);
equipment.weapons = getcategory(doc, "weapons", notes);
});
}
function outputcategory(category, characters) // todo: fix footer notes
{ // todo: invert available X mark
// todo : auto length // todo: remove a column if always empty
// 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: "| "}
]
characters.forEach(char => Object.keys(equipment).forEach(table => {
{ const columnsizes = {}
columns.push( result.push(table.toUpperCase())
{ const items = equipment[table]
id: char.job,
label: char.name, // exclude
len: char.name.length + 1, items.forEach(item => {
character : true exclude.forEach(name => {
delete item[name]
}) })
}) })
// columns.push({ id: "Notes", label: "Notes", len: 6}); // init sizes
items.forEach(item =>
// headers
let line = "";
columns.forEach(column =>
{ {
let elt = column.label; Object.keys(item).forEach(columnname => {
elt += " ".repeat(Math.max(0, column.len - elt.length)) columnsizes[columnname] = columnsizes[columnname] || columnname.length
line += elt; columnsizes[columnname] = Math.max(columnsizes[columnname], (item[columnname] || "").length)
}) })
console.log(line + "| ") })
// 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 // lines
equipment[category].forEach(item => items.forEach(item => {
{ let line = ""
let line = ""; Object.keys(columnsizes).forEach(columnname => {
let elt = ""; const size = columnsizes[columnname]
columns.forEach(column => const value = (item[columnname] || "").replace("\n", " ")
{ line += value + " ".repeat(Math.max(0, size - value.length)) + "|"
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 + "|") result.push(line)
}); })
result.push(" ")
})
console.log(result.join("\n"))
} }
function output() const root = "https://mikesrpgcenter.com"
let equipment = {};
const dq3pages = [
{ {
// todo: full name then cut to 2 char url: "/dw3/armor.html",
const characters = [ tables: ["armor", "shields", "helmets"]
{job: "Hr", name: "Yo"}, },
{job: "Sr", name: "Le"}, {
{job: "Pr", name: "Je"}, url: "/dw3/weapons.html",
{job: "Wz", name: "Lu"} 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)
{
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)
} }
output(equipment)
var equipment = {};
getarmor()
.then(getweapons)
.then(output);