Skip to content

Commit eda5537

Browse files
authored
Merge pull request #180 from Fernando2603/master
fix missing skin name
2 parents fed12cc + 59e2db9 commit eda5537

File tree

3 files changed

+61
-32
lines changed

3 files changed

+61
-32
lines changed

src/ships/gallery.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ export async function fetchGallery(
107107
(node) => {
108108
let tab = <HTMLElement>node;
109109

110-
const skinName = normalizeName(tab.title);
110+
const skinName = normalizeName(tab.getAttribute("data-title"));
111111
let skinCategory;
112-
try{
112+
try {
113113
skinCategory = handleSkinCategory({ name, skinName, skinsPage });
114-
}catch(e){
115-
console.log(e)
114+
} catch (e) {
115+
console.log(e);
116116
}
117117
let image;
118118
if (tab.querySelector(".tabber__panel"))
@@ -213,7 +213,9 @@ export async function fetchGallery(
213213
)
214214
).forEach((box) =>
215215
gallery.push({
216-
description: box.querySelector(".shipart-caption, .shipgirl-art-caption, .shipgirl-caption").textContent.trim(),
216+
description: box
217+
.querySelector(".shipart-caption, .shipgirl-art-caption, .shipgirl-caption")
218+
.textContent.trim(),
217219
url: galleryThumbnailUrlToActualUrl(box.getElementsByTagName("img")[0].src),
218220
})
219221
);

src/ships/parser.ts

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const NATIONALITY: { [s: string]: string } = {
6464
106: "Venus Vacation",
6565
107: "The Idolmaster",
6666
108: "SSSS",
67+
109: "Atelier Ryza",
6768
};
6869
const kuroshiro = new Kuroshiro();
6970
const UNRELEASED = ["Tone", "Chikuma", "Pola", "Vittorio Veneto", "Kirov", "Sovetsky Soyuz"];
@@ -74,7 +75,10 @@ function findShip(id: string, name: string, nationality: string) {
7475
for (let ship of Object.values(reference)) {
7576
if (!ship.name) continue;
7677
if (
77-
(ship.name.en === name || ship.name.cn === name || ship.name.code === name || ship.code === id) &&
78+
(ship.name.en === name ||
79+
ship.name.cn === name ||
80+
ship.name.code === name ||
81+
ship.code === id) &&
7882
NATIONALITY[ship.nationality] === nationality
7983
) {
8084
id_map[id] = ship.id;
@@ -127,7 +131,9 @@ export async function parseShip(
127131
url: string
128132
): Promise<Ship> {
129133
const doc = new JSDOM(body).window.document;
130-
let tableInfo = parseTable(doc.querySelector(".mw-parser-output>.nomobile>div>div>.ship-card tbody"));
134+
let tableInfo = parseTable(
135+
doc.querySelector(".mw-parser-output>.nomobile>div>div>.ship-card tbody")
136+
);
131137
let nationality = tableInfo.Faction;
132138
let referenceShip = findShip(id, name, nationality);
133139
let ship = new Ship();
@@ -176,10 +182,16 @@ export async function parseShip(
176182
ship.slots = [null, null, null];
177183
for (let i = 0; i < 3; i++)
178184
ship.slots[i] = parseShipEQSlot(
179-
doc.querySelector(`.mw-parser-output .nomobile>div>div>.wikitable.ship-equipment tr:nth-child(${i + 3})`)
185+
doc.querySelector(
186+
`.mw-parser-output .nomobile>div>div>.wikitable.ship-equipment tr:nth-child(${i + 3})`
187+
)
180188
);
181-
ship.enhanceValue = nodeParse(doc.querySelector(".ship-enhance.wikitable td:nth-child(1)").childNodes)
182-
ship.scrapValue = nodeParse(doc.querySelector(".ship-enhance.wikitable td:nth-child(2)").childNodes)
189+
ship.enhanceValue = nodeParse(
190+
doc.querySelector(".ship-enhance.wikitable td:nth-child(1)").childNodes
191+
);
192+
ship.scrapValue = nodeParse(
193+
doc.querySelector(".ship-enhance.wikitable td:nth-child(2)").childNodes
194+
);
183195
ship.skills = parseSkills(doc.getElementById("Skills"));
184196
if (ship.rarity === "Priority" || ship.rarity === "Decisive")
185197
ship.devLevels = parseDevelopmentLevels(doc.querySelector("#Development_levels tbody"));
@@ -189,16 +201,22 @@ export async function parseShip(
189201
// This ship can be retrofited
190202
ship.retrofit = true;
191203
ship.retrofitId = 3000 + parseInt(ship.id) + "";
192-
let retroTable = doc.getElementById("Retrofit").parentElement.nextElementSibling.nextElementSibling
193-
retroTable = 'TABLE' === retroTable.nextElementSibling.tagName ?
194-
retroTable.nextElementSibling : retroTable
204+
let retroTable =
205+
doc.getElementById("Retrofit").parentElement.nextElementSibling.nextElementSibling;
206+
retroTable =
207+
"TABLE" === retroTable.nextElementSibling.tagName
208+
? retroTable.nextElementSibling
209+
: retroTable;
195210
ship.retrofitProjects = parseRetrofit(retroTable.lastElementChild);
196211
ship.retrofitHullType =
197212
doc.querySelector(".ship-card-content .card-info tr:nth-child(3)>:last-child>:last-child")
198213
?.textContent || ship.hullType;
199214
if (ship.retrofitHullType === "Light Aircraft Carrier") ship.retrofitHullType = "Light Carrier";
200215
}
201-
let obtainedFrom = parseShipObtainedFrom(doc.querySelector(".nomobile .ship-construction.wikitable tbody"), ship);
216+
let obtainedFrom = parseShipObtainedFrom(
217+
doc.querySelector(".nomobile .ship-construction.wikitable tbody"),
218+
ship
219+
);
202220
ship.construction = obtainedFrom.construction;
203221
ship.obtainedFrom = obtainedFrom.obtainedFrom;
204222
ship.misc = {
@@ -214,9 +232,13 @@ function parseTable(table: Element) {
214232
for (let i = 0; i < child.children.length; i += 2) {
215233
let title = child.children[i].textContent.replace(/\s/g, " ").trim();
216234
if (title === "Voice Actor") {
217-
218235
final[title] = {
219-
name: (child.children[i + 1].querySelector("a.text, a.extiw")?.textContent.trim() ?? (Array.from(child.children[i + 1].childNodes).filter(n=>n.nodeType===3 && n.textContent.trim())[0]?.textContent.trim())) ?? "Unknown",
236+
name:
237+
child.children[i + 1].querySelector("a.text, a.extiw")?.textContent.trim() ??
238+
Array.from(child.children[i + 1].childNodes)
239+
.filter((n) => n.nodeType === 3 && n.textContent.trim())[0]
240+
?.textContent.trim() ??
241+
"Unknown",
220242
url: child.children[i + 1].querySelector("a.text, a.extiw")?.getAttribute("href"),
221243
};
222244
} else if (title === "Illustrator")
@@ -259,7 +281,8 @@ function parseShipLimits(skill_table: Element) {
259281
function parseLimitBreak(row: Element) {
260282
let buffs = [];
261283
let rows = row.children[1].children;
262-
for (let i = 0; i < rows.length; i++) if(rows[i].textContent.trim()) buffs.push(rows[i].textContent.trim());
284+
for (let i = 0; i < rows.length; i++)
285+
if (rows[i].textContent.trim()) buffs.push(rows[i].textContent.trim());
263286
return buffs;
264287
}
265288

@@ -417,24 +440,27 @@ function parseShipEQSlot(slot: Element): Slot {
417440
return eqslot;
418441
}
419442

420-
function nodeParseKey(input: string){
421-
return {
422-
"medalOfHonor": "medal",
423-
"specializedCore": "core"
424-
}[input] ?? input
443+
function nodeParseKey(input: string) {
444+
return (
445+
{
446+
medalOfHonor: "medal",
447+
specializedCore: "core",
448+
}[input] ?? input
449+
);
425450
}
426451

427452
function nodeParse(nodes: NodeListOf<ChildNode>) {
428-
let obj: {[key:string]: number} = {};
453+
let obj: { [key: string]: number } = {};
429454
let value = 0;
430455
for (let node of nodes) {
431-
if (node.nodeType === 3 && node.textContent.trim()) value = parseInt(node.textContent)
432-
else if (node.nodeType === 1) {
433-
let el = node as Element
434-
if (el.getAttribute("title")) obj[nodeParseKey(camelize(el.getAttribute("title").trim()))] = value
435-
}
456+
if (node.nodeType === 3 && node.textContent.trim()) value = parseInt(node.textContent);
457+
else if (node.nodeType === 1) {
458+
let el = node as Element;
459+
if (el.getAttribute("title"))
460+
obj[nodeParseKey(camelize(el.getAttribute("title").trim()))] = value;
461+
}
436462
}
437-
return obj
463+
return obj;
438464
}
439465

440466
function parseStats(doc: Document): ShipStats {
@@ -474,7 +500,7 @@ function parseStats(doc: Document): ShipStats {
474500
};
475501
for (let j = 1; j < titles.length; j++) {
476502
if (!titles[j] || titles[j].trim().length === 0) continue;
477-
if(titles[j]==="antisubmarineWarfareASW") titles[j]='huntingRange'
503+
if (titles[j] === "antisubmarineWarfareASW") titles[j] = "huntingRange";
478504
if (!isStat(titles[j])) {
479505
console.log("Irregular stat" + doc.location.href);
480506
throw "parseStat " + titles[j];

src/ships/ship.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ export class Ship {
104104
stars: number;
105105
stats: ShipStats;
106106
slots: [Slot, Slot, Slot];
107-
enhanceValue: {[key:string]: number};
108-
scrapValue: {[key:string]: number};
107+
enhanceValue: { [key: string]: number };
108+
scrapValue: { [key: string]: number };
109109
skills: Skill[];
110110
skins: Skin[];
111111
gallery: GalleryItem[];
@@ -170,6 +170,7 @@ export enum SkinLimitedStatus {
170170
Unavailable = "Unavailable",
171171
EventLimited = "Event Limited",
172172
PermanentlyAvailable = "Permanently Available",
173+
PermanentEvent = "Permanent Event",
173174
Limited = "Limited",
174175
}
175176

0 commit comments

Comments
 (0)