init
This commit is contained in:
15
src/helper/exportDataBattle.ts
Normal file
15
src/helper/exportDataBattle.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { BattleDataStateJson } from "@/types/mics";
|
||||
|
||||
export const exportBattleData = (
|
||||
data: BattleDataStateJson,
|
||||
filename = 'battle_data.json'
|
||||
) => {
|
||||
const dataStr = JSON.stringify(data, null, 2);
|
||||
const blob = new Blob([dataStr], { type: 'application/json' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
19
src/helper/getNameChar.ts
Normal file
19
src/helper/getNameChar.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { AvatarType } from "@/types";
|
||||
|
||||
|
||||
export function getNameChar(locale: string, data: AvatarType | undefined): string {
|
||||
if (!data) {
|
||||
return ""
|
||||
}
|
||||
let text = data.lang.get(locale) ?? "";
|
||||
if (!text) {
|
||||
text = data.lang.get("en") ?? "";
|
||||
}
|
||||
if (Number(data.id) % 2 === 0 && Number(data.id) > 8000) {
|
||||
text = `Female ${data.damageType} MC`
|
||||
} else if (Number(data.id) > 8000) {
|
||||
text = `Male ${data.damageType} MC`
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
21
src/helper/importDataBattle.ts
Normal file
21
src/helper/importDataBattle.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { BattleDataStateJson } from "@/types/mics";
|
||||
|
||||
export const importBattleData = (file: File, loadBattleDataFromJSON: (data: BattleDataStateJson) => void) => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
try {
|
||||
const result = reader.result as string;
|
||||
const parsed = JSON.parse(result) as BattleDataStateJson;
|
||||
loadBattleDataFromJSON(parsed);
|
||||
resolve();
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
};
|
||||
reader.onerror = () => reject(reader.error);
|
||||
reader.readAsText(file);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
3
src/helper/index.ts
Normal file
3
src/helper/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from "./getNameChar"
|
||||
export * from "./exportDataBattle"
|
||||
export * from "./importDataBattle"
|
||||
Reference in New Issue
Block a user