Commit 1b32d903 authored by Chunchi Che's avatar Chunchi Che

feat: download ydk

parent e1541134
Pipeline #23063 passed with stages
in 12 minutes and 37 seconds
...@@ -163,7 +163,7 @@ const DeckUploader: React.FC<{ onLoaded: (deck: IDeck) => void }> = ({ ...@@ -163,7 +163,7 @@ const DeckUploader: React.FC<{ onLoaded: (deck: IDeck) => void }> = ({
) )
) { ) {
// YDK解析成功 // YDK解析成功
onLoaded({ deckName: file.name, ...deck }); onLoaded({ deckName: file.name.replace(/\.ydk/g, ""), ...deck });
} else { } else {
alert(`${file.name}解析失败,请检查格式是否正确。`); alert(`${file.name}解析失败,请检查格式是否正确。`);
setUploadState("ERROR"); setUploadState("ERROR");
......
...@@ -43,7 +43,12 @@ import { DeckSelect } from "./DeckSelect"; ...@@ -43,7 +43,12 @@ import { DeckSelect } from "./DeckSelect";
import { Filter } from "./Filter"; import { Filter } from "./Filter";
import styles from "./index.module.scss"; import styles from "./index.module.scss";
import { editDeckStore } from "./store"; import { editDeckStore } from "./store";
import { editingDeckToIDeck, iDeckToEditingDeck, type Type } from "./utils"; import {
downloadDeckAsYDK,
editingDeckToIDeck,
iDeckToEditingDeck,
type Type,
} from "./utils";
export const loader: LoaderFunction = async () => { export const loader: LoaderFunction = async () => {
// 必须先加载卡组,不然页面会崩溃 // 必须先加载卡组,不然页面会崩溃
...@@ -97,7 +102,12 @@ export const Component: React.FC = () => { ...@@ -97,7 +102,12 @@ export const Component: React.FC = () => {
setSelectedDeck(deckStore.get(name) ?? deckStore.decks[0]) setSelectedDeck(deckStore.get(name) ?? deckStore.decks[0])
} }
onDelete={async (name) => await deckStore.delete(name)} onDelete={async (name) => await deckStore.delete(name)}
onDownload={(id) => console.log(id)} onDownload={(name) => {
const deck = deckStore.get(name);
if (deck) {
downloadDeckAsYDK(deck);
}
}}
onAdd={() => console.log("add")} onAdd={() => console.log("add")}
/> />
</ScrollableArea> </ScrollableArea>
......
...@@ -35,3 +35,26 @@ export const compareCards = (a: CardMeta, b: CardMeta): number => { ...@@ -35,3 +35,26 @@ export const compareCards = (a: CardMeta, b: CardMeta): number => {
if (aType !== bType) return aType - bType; if (aType !== bType) return aType - bType;
return a.id - b.id; return a.id - b.id;
}; };
/** 下载卡组YDK文件 **/
export function downloadDeckAsYDK(deck: IDeck) {
const lines: string[] = [];
lines.push("#created by neos");
lines.push("#main");
lines.push(...deck.main.map((cardId) => cardId.toString()));
lines.push("#extra");
lines.push(...deck.extra.map((cardId) => cardId.toString()));
lines.push("!side");
lines.push(...deck.side.map((cardId) => cardId.toString()));
const text = lines.join("\n");
const blob = new Blob([text], { type: "text/plain" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = deck.deckName + ".ydk";
a.click();
URL.revokeObjectURL(url);
}
...@@ -78,11 +78,13 @@ export const Component: React.FC = () => { ...@@ -78,11 +78,13 @@ export const Component: React.FC = () => {
title="竞技匹配" title="竞技匹配"
desc="与世界上其他玩家在线匹配,您的排名将实时显示在排行榜上。" desc="与世界上其他玩家在线匹配,您的排名将实时显示在排行榜上。"
icon={<IconFont type="icon-battle" size={32} />} icon={<IconFont type="icon-battle" size={32} />}
onClick={() => alert("开发中,敬请期待")}
/> />
<Mode <Mode
title="休闲匹配" title="休闲匹配"
desc="使用任意卡组进行对战,将胜负暂且搁置,尽情享受决斗的乐趣。" desc="使用任意卡组进行对战,将胜负暂且搁置,尽情享受决斗的乐趣。"
icon={<IconFont type="icon-coffee" size={28} />} icon={<IconFont type="icon-coffee" size={28} />}
onClick={() => alert("开发中,敬请期待")}
/> />
<Mode <Mode
title="单人模式" title="单人模式"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment