Skip to content

Commit

Permalink
weapon to map
Browse files Browse the repository at this point in the history
  • Loading branch information
chadluo committed Oct 6, 2024
1 parent b4e1646 commit 596a873
Show file tree
Hide file tree
Showing 4 changed files with 411 additions and 202 deletions.
8 changes: 4 additions & 4 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { type CharacterId, characters } from "./models/characters";
import { type Domain, bosses, domains, enemies } from "./models/enemies";
import { type Material, materials } from "./models/materials";
import { weapons } from "./models/weapons";
import { type WeaponId, weapons } from "./models/weapons";
import { findRecents } from "./version";

export type Region =
Expand Down Expand Up @@ -72,7 +72,7 @@ export function renderQTableContent(
);
}
case TYPE_WEAPON: {
const weapon = weapons.find((w) => w.id === id);
const weapon = weapons[id as WeaponId];
return weapon == null
? ""
: renderQTableRows(
Expand Down Expand Up @@ -222,7 +222,7 @@ function byEnemy(enemy: string): Map<Material, OfMaterial[]> {
map.set(m, [
...(map.get(m) ?? []),
...filterForMaterial(
[...Object.values(characters), ...weapons],
[...Object.values(characters), ...Object.values(weapons)],
material
),
]);
Expand All @@ -243,7 +243,7 @@ export function byDomain(
m,
filterForMaterial(
domain?.type === TYPE_WEAPON_DOMAIN
? weapons
? Object.values(weapons)
: Object.values(characters),
material
)
Expand Down
19 changes: 12 additions & 7 deletions src/components/weapons_table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,35 @@ const title: I18nObject = { en: "Weapons", "zh-CN": "武器" };
export class WeaponsTable extends HTMLElement {
constructor() {
super();
const byRarity = Map.groupBy(weapons, ({ rarity }) => rarity);
const byRarity = Map.groupBy(
Object.values(weapons),
({ rarity }) => rarity
);
const rarities = Array.from(byRarity.keys()).sort().reverse();
this.innerHTML = `<details class="section" ${hasBookmarks() ? "" : "open"}>
<summary>🗡️ ${formatName(title)}</summary><table class="ctable">
${rarities
.map((rarity) => {
const ws2: Map<Category, Weapon[]> = Map.groupBy(
byRarity.get(rarity) || [],
({ category }) => category,
({ category }) => category
);
const categories = Array.from(ws2.keys());
return `<tr><th rowspan="${categories.length}">${"⭐".repeat(rarity)}</th>
return `<tr><th rowspan="${categories.length}">${"⭐".repeat(
rarity
)}</th>
<td>${this.formatWeaponIcon(categories[0])}${ws2
.get(categories[0])
?.map((w) => renderLink(w.id, TYPE_WEAPON, w.name))
.join(formatName(DELIMITER))}</td></tr>
.get(categories[0])
?.map((w) => renderLink(w.id, TYPE_WEAPON, w.name))
.join(formatName(DELIMITER))}</td></tr>
${categories
.slice(1)
.map(
(category) =>
`<tr><td>${this.formatWeaponIcon(category)}${ws2
.get(category)
?.map((c) => renderLink(c.id, TYPE_WEAPON, c.name))
.join(formatName(DELIMITER))}</td></tr>`,
.join(formatName(DELIMITER))}</td></tr>`
)
.join("")}`;
})
Expand Down
Loading

0 comments on commit 596a873

Please sign in to comment.