Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: query cargo in hr #65

Merged
merged 1 commit into from
Dec 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions src/entries/HrCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,37 @@ import { Char } from "../widgets/HrCalculator/utils";

const ele = document.querySelector("#root");

function init(): Source[] {
return (
Array.from(
document.querySelector("#filter-data")?.children || [],
) as HTMLElement[]
)
.filter((v) => {
return v.dataset.obtain_method?.split(", ").includes("公开招募");
})
.map((v) => {
const temp: Source = {
profession: v.dataset.profession!,
position: v.dataset.position!,
rarity: Number.parseInt(v.dataset.rarity!),
tag: v.dataset.tag?.split(" ") || [],
zh: v.dataset.zh!,
subset: [],
obtainMethod: v.dataset.obtain_method?.split(", ") || [],
};
const char = Char.fromSource(temp);
temp.subset = char.bitmap.getSubSet();
return Object.freeze(temp);
});
async function init() {
const resp = await fetch(
`/api.php?${new URLSearchParams({
action: "cargoquery",
format: "json",
tables: "chara,char_obatin",
limit: "5000",
fields:
"chara.profession,chara.position,chara.rarity,chara.tag,chara.cn,char_obatin.obtainMethod",
where: 'char_obatin.obtainMethod like "%公开招募%" AND chara.charIndex>0',
join_on: "chara._pageName=char_obatin._pageName",
})}`,
);
const json = await resp.json();
const source = json.cargoquery.map((obj: any) => {
const v = obj.title;
const temp: Source = {
profession: v.profession!,
position: v.position!,
rarity: Number.parseInt(v.rarity!),
tag: v.tag?.split(" ") || [],
zh: v.cn!,
subset: [],
obtainMethod: v.obtainMethod?.split(" ") || [],
};
const char = Char.fromSource(temp);
temp.subset = char.bitmap.getSubSet();
return Object.freeze(temp);
});
console.log(source);
if (ele) createApp(HrCalculator, { source }).mount(ele);
else console.error("data-item or ele not found", ele);
}

const source = init();
console.log(source);
if (ele) createApp(HrCalculator, { source }).mount(ele);
else console.error("data-item or ele not found", ele);
init();