diff --git a/src/locales/en.json b/src/locales/en.json index aeb60cf7..647dfa40 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -262,6 +262,7 @@ "subtitle": "Select where your excel come from:", "default": "Paimon.moe Export", "takagg": "TakaGG Gacha Export", + "genshinwishes": "GenshinWishes Export", "notice": [ "This feature still in BETA please backup first by going to Setting then Export to Excel!", "Wish with the same timestamp and reward name will NOT be touched (so existing wish will not be rewritten)", @@ -270,7 +271,8 @@ ], "selectFile": { "default": "Drag & drop Paimon.moe excel file here, or click here to select", - "takagg": "Drag & drop TakaGG gacha export excel file here, or click here to select" + "takagg": "Drag & drop TakaGG gacha export excel file here, or click here to select", + "genshinwishes": "Drag & drop GenshinWishes csv file here, or click here to select" }, "processing": "Processing...", "addedOn": "Inserted on the:", diff --git a/src/routes/wish/_excelImport.svelte b/src/routes/wish/_excelImport.svelte index 3f5a19b2..3dcf4371 100644 --- a/src/routes/wish/_excelImport.svelte +++ b/src/routes/wish/_excelImport.svelte @@ -343,6 +343,100 @@ loading = false; } + async function readGenshinWishesCSV(texts) { + const lines = texts.split(/\r?\n/); + lines.shift(); + + const bannerCategories = { + 'Character Event': 'character-event', + 'Weapon Event': 'weapon-event', + Permanent: 'standard', + Novice: 'beginners', + }; + + const wishes = { + 'character-event': [], + 'weapon-event': [], + standard: [], + beginners: [], + }; + + const weapons = Object.values(weaponList); + const chars = Object.values(characters); + + for (const line of lines) { + if (line === '') continue; + + const cells = line.split(';'); + console.log(cells); + + const banner = bannerCategories[cells[0]]; + const type = cells[3].toLowerCase(); + const fullName = cells[2]; + const time = cells[5]; + + let name = ''; + if (type === 'weapon') { + const weapon = weapons.find((e) => e.name === fullName); + if (weapon === undefined) { + pushToast($t('wish.excel.errorUnknownItem'), 'error'); + error = { + banner: category, + line: index, + name: fullName, + type, + }; + step = 2; + loading = false; + throw 'unknown reward name'; + } + + name = weapon.id; + } else if (type === 'character') { + const character = chars.find((e) => e.name === fullName); + if (character === undefined) { + pushToast($t('wish.excel.errorUnknownItem'), 'error'); + error = { + banner: category, + line: index, + name: fullName, + type, + }; + step = 2; + loading = false; + throw 'unknown reward name'; + } + + name = character.id; + } + + if (name === '') { + pushToast($t('wish.excel.errorUnknownItem'), 'error'); + loading = false; + throw 'unknown reward name'; + } + + wishes[banner].push([type, time, name]); + } + + for (const [id, list] of Object.entries(wishes)) { + console.log('from csv', id, list.length); + await parseData(id, list); + } + + step = 1; + loading = false; + } + + function readCSV(file) { + const reader = new FileReader(); + reader.onload = () => { + const texts = reader.result; + readGenshinWishesCSV(texts); + }; + reader.readAsText(file); + } + async function readExcel(file) { loading = true; @@ -376,6 +470,8 @@ file.type === 'application/wps-office.xlsx' ) { readExcel(file); + } else if (file.type === 'text/csv' || file.type === 'application/vnd.ms-excel') { + readCSV(file); } else { pushToast($t('wish.excel.errorInvalidFile'), 'error'); } @@ -437,13 +533,19 @@

{$t('wish.excel.subtitle')}

-
+
+