add ff1
This commit is contained in:
parent
d86718c420
commit
00b55e90d7
dq3
204
dq3/dq3.ts
204
dq3/dq3.ts
|
@ -20,13 +20,15 @@ function getcategory(doc, category, notes)
|
||||||
item[h] = columns[i].textContent;
|
item[h] = columns[i].textContent;
|
||||||
});
|
});
|
||||||
item.Notes = ""
|
item.Notes = ""
|
||||||
const sup = parseInt(item.Name.split(" ").pop());
|
if (item.Name)
|
||||||
if (!isNaN(sup))
|
|
||||||
{
|
{
|
||||||
item.Notes = notes[sup - 1];
|
const sup = parseInt(item.Name.split(" ").pop());
|
||||||
item.Name = item.Name.substr(0, item.Name.length - 2)
|
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);
|
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")
|
const result = {}
|
||||||
.then(response => response.text())
|
const response = await fetch(root + url)
|
||||||
.then(html =>
|
const html = await response.text()
|
||||||
|
|
||||||
|
const doc = getdompareser(html);
|
||||||
|
const notes = getnotes(doc);
|
||||||
|
|
||||||
|
tables.forEach(category =>
|
||||||
{
|
{
|
||||||
const doc = getdompareser(html);
|
result[category] = getcategory(doc, category, notes);
|
||||||
const notes = getnotes(doc);
|
|
||||||
["armor", "shields", "helmets"]
|
|
||||||
.forEach(category =>
|
|
||||||
{
|
|
||||||
equipment[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]
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 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});
|
console.log(result.join("\n"))
|
||||||
|
|
||||||
// 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()
|
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 page = pages[index]
|
||||||
const characters = [
|
equipment = {...equipment, ...(await getpage(page.url, page.tables))}
|
||||||
{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);
|
|
||||||
|
|
||||||
|
output(equipment)
|
Loading…
Reference in New Issue