156 lines
3.2 KiB
TypeScript
156 lines
3.2 KiB
TypeScript
// deno
|
|
import { DOMParser } from 'https://deno.land/x/deno_dom/deno-dom-wasm.ts'
|
|
|
|
function getdompareser(html)
|
|
{
|
|
const parser = new DOMParser();
|
|
return parser.parseFromString(html, "text/html");
|
|
}
|
|
|
|
function getcategory(doc, category, notes)
|
|
{
|
|
const result = [];
|
|
const items = [...doc.getElementById(category).nextSibling.nextSibling.nextSibling.firstChild.children[0].children];
|
|
const header = [...items.shift().children].map(h => h.textContent);
|
|
items.forEach(elt => {
|
|
const item = {};
|
|
const columns = [...elt.children];
|
|
header.forEach( (h,i) =>
|
|
{
|
|
item[h] = columns[i].textContent;
|
|
});
|
|
item.Notes = ""
|
|
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;
|
|
}
|
|
|
|
function getnotes(doc)
|
|
{
|
|
const lastsup = [...doc.getElementsByTagName("sup")].pop();
|
|
return lastsup.parentElement.textContent.split("\n")
|
|
.filter(i => i.length)
|
|
.map(i => i.substr(3));
|
|
}
|
|
|
|
function getarmor()
|
|
{
|
|
return fetch("https://mikesrpgcenter.com/dw3/armor.html")
|
|
.then(response => response.text())
|
|
.then(html =>
|
|
{
|
|
const doc = getdompareser(html);
|
|
const notes = getnotes(doc);
|
|
["armor", "shields", "helmets"]
|
|
.forEach(category =>
|
|
{
|
|
equipment[category] = getcategory(doc, category, notes);
|
|
});
|
|
});
|
|
}
|
|
|
|
function getweapons()
|
|
{
|
|
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);
|
|
});
|
|
}
|
|
|
|
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: "| "}
|
|
]
|
|
|
|
characters.forEach(char =>
|
|
{
|
|
columns.push(
|
|
{
|
|
id: char.job,
|
|
label: char.name,
|
|
len: char.name.length + 1,
|
|
character : true
|
|
})
|
|
})
|
|
|
|
// 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 + "|")
|
|
});
|
|
}
|
|
|
|
function output()
|
|
{
|
|
// 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"}
|
|
];
|
|
|
|
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);
|
|
|