Skip to content

Commit

Permalink
character to map
Browse files Browse the repository at this point in the history
  • Loading branch information
chadluo committed Oct 6, 2024
1 parent 292c9be commit b4e1646
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 99 deletions.
13 changes: 9 additions & 4 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
formatName,
weekdays,
} from "./i18n";
import { characters } from "./models/characters";
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";
Expand Down Expand Up @@ -59,7 +59,7 @@ export function renderQTableContent(
): string {
switch (type) {
case TYPE_CHARACTER: {
const character = characters.find((c) => c.id === id);
const character = characters[id as CharacterId];
return character == null
? ""
: renderQTableRows(
Expand Down Expand Up @@ -221,7 +221,10 @@ function byEnemy(enemy: string): Map<Material, OfMaterial[]> {
}
map.set(m, [
...(map.get(m) ?? []),
...filterForMaterial([...characters, ...weapons], material),
...filterForMaterial(
[...Object.values(characters), ...weapons],
material
),
]);
return map;
}, new Map<Material, OfMaterial[]>());
Expand All @@ -239,7 +242,9 @@ export function byDomain(
map.set(
m,
filterForMaterial(
domain?.type === TYPE_WEAPON_DOMAIN ? weapons : characters,
domain?.type === TYPE_WEAPON_DOMAIN
? weapons
: Object.values(characters),
material
)
);
Expand Down
9 changes: 6 additions & 3 deletions src/components/characters_table.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { TYPE_CHARACTER, renderLink } from "../base";
import { hasBookmarks } from "../bookmarks";
import { DELIMITER, formatName, type I18nObject } from "../i18n";
import { characters, type Character } from "../models/characters";
import { DELIMITER, type I18nObject, formatName } from "../i18n";
import { type Character, characters } from "../models/characters";

const title: I18nObject = { en: "Characters", "zh-CN": "角色" };

export class CharactersTable extends HTMLElement {
constructor() {
super();
const byRarity = Map.groupBy(characters, ({ rarity }) => rarity);
const byRarity = Map.groupBy(
Object.values(characters),
({ rarity }) => rarity
);
const rarities = Array.from(byRarity.keys()).sort().reverse();
this.innerHTML = `<details class="section" ${hasBookmarks() ? "" : "open"}>
<summary>🦸 ${formatName(title)}</summary>
Expand Down
Loading

0 comments on commit b4e1646

Please sign in to comment.