|
5 | 5 | EnemyLevel, |
6 | 6 | MapPart, |
7 | 7 | Reward, |
| 8 | + MapDrop, |
8 | 9 | StarConditions, |
9 | 10 | } from "./chapter"; |
10 | 11 | import { camelize } from "../utils"; |
@@ -61,10 +62,10 @@ export function parseChapter(doc: Document, index: number, names: any) { |
61 | 62 | jp: names[index + "-" + i] ? names[index + "-" + i].jp : null, |
62 | 63 | }, |
63 | 64 | normal: hasHardMode |
64 | | - ? parseMap(boxes[(i-1)*2], index + "-" + i) |
| 65 | + ? parseMap(boxes[(i - 1) * 2], index + "-" + i) |
65 | 66 | : parseMap(boxes[i - 1], index + "-" + i), |
66 | 67 | hard: hasHardMode |
67 | | - ? parseMap(boxes[(i-1)*2+1], index + "-" + i) |
| 68 | + ? parseMap(boxes[(i - 1) * 2 + 1], index + "-" + i) |
68 | 69 | : null, |
69 | 70 | }; |
70 | 71 | } |
@@ -198,7 +199,7 @@ function parseAirSuprem(div: Element): AirSupremacy { |
198 | 199 | parity: parseInt(div.childNodes[8].textContent.replace(/[^\d]+/g, "")), |
199 | 200 | superiority: parseInt(div.childNodes[10].textContent.replace(/[^\d]+/g, "")), |
200 | 201 | supremacy: parseInt(div.childNodes[12].textContent.replace(/[^\d]+/g, "")) |
201 | | - }:{ |
| 202 | + } : { |
202 | 203 | actual: parseInt(div.childNodes[1].textContent.replace(/[^\d]+/g, "")), |
203 | 204 | superiority: parseInt(div.childNodes[6].textContent.replace(/[^\d]+/g, "")), |
204 | 205 | supremacy: parseInt(div.childNodes[8].textContent.replace(/[^\d]+/g, "")), |
@@ -261,10 +262,31 @@ function parseStatsRestriction(div: Element) { |
261 | 262 | return restrictions; |
262 | 263 | } |
263 | 264 |
|
264 | | -function parseMapDrops(div: Element): string[] { |
265 | | - let rewards: string[] = []; |
| 265 | +const MAP_DROP_REGEX = /^\s*(?<amm>(?<min>\d+)[-–](?<max>\d+)|\d+)x? (?<reward>[^,;.]+)(?:[,;.]|$)/ |
| 266 | +function parseMapDrops(div: Element): MapDrop[] { |
| 267 | + let rewards: MapDrop[] = []; |
| 268 | + let type: 'summary' | 'clear' | 'chance' = 'summary' |
| 269 | + let buf = ""; |
| 270 | + let m: RegExpMatchArray | null = null; |
266 | 271 | div.childNodes.forEach((n) => { |
267 | | - if (n.nodeType === 3) rewards.push(n.textContent.replace(",", "").trim()); |
| 272 | + if (n.textContent === "Clear bonus:") return type = "clear"; |
| 273 | + if (n.textContent === "Chance of getting:") return type = "chance"; |
| 274 | + if (type === "summary") { |
| 275 | + if (n.nodeType === 3) rewards.push(n.textContent.replace(",", "").trim()); |
| 276 | + } else { |
| 277 | + buf.push(n?.firstChild?.alt ?? n?.firstChild?.title ?? n?.alt ?? n?.title) |
| 278 | + let m = buf.match(MAP_DROP_REGEX) |
| 279 | + if (m) { |
| 280 | + buf = buf.slice(m[0].length) |
| 281 | + rewards.push({ |
| 282 | + min: m.groups?.min ? parseInt(m.groups?.min) : undefined, |
| 283 | + max: m.groups?.max ? parseInt(m.groups?.max) : undefined, |
| 284 | + amm: !(m.groups?.min && m.groups?.max) ? m.groups?.amm : undefined, |
| 285 | + item: m.groups?.reward, |
| 286 | + guaranteed: type === "clear" |
| 287 | + }) |
| 288 | + } |
| 289 | + } |
268 | 290 | }); |
269 | 291 | return rewards; |
270 | 292 | } |
|
0 commit comments