mirror of
https://github.com/MadeBaruna/paimon-moe.git
synced 2025-01-05 18:26:56 +01:00
Update excel import
This commit is contained in:
parent
e9347e17dc
commit
8e01ec7cd0
4 changed files with 76 additions and 40 deletions
|
@ -141,7 +141,8 @@ async function addWishHistory(workbook) {
|
|||
{ header: 'Pity', width: 4, style: { alignment: { horizontal: 'center' } } },
|
||||
{ header: '#Roll', width: 7, style: { alignment: { horizontal: 'center' } } },
|
||||
{ header: 'Group', width: 7, style: { alignment: { horizontal: 'center' } } },
|
||||
{ header: 'Banner', width: 24 },
|
||||
{ header: 'Banner', width: 30 },
|
||||
{ header: 'Part', width: 9 },
|
||||
// { header: 'Icon', width: 5.5 },
|
||||
];
|
||||
|
||||
|
@ -175,10 +176,11 @@ async function addWishHistory(workbook) {
|
|||
pull.at,
|
||||
groupCount,
|
||||
pull.code === '400' ? bannersDual[pull.banner.fullName][1].name : pull.banner.name,
|
||||
pull.code === '400' ? 'Wish 2' : '',
|
||||
]);
|
||||
|
||||
const bgColor = pull.striped ? 'ffeeeeee' : 'ffffffff';
|
||||
for (let i = 1; i <= 8; i++) {
|
||||
for (let i = 1; i <= 9; i++) {
|
||||
row.getCell(i).fill = {
|
||||
type: 'pattern',
|
||||
pattern: 'solid',
|
||||
|
|
|
@ -364,7 +364,8 @@
|
|||
"This feature is still in BETA! Please make a backup first by going to the Settings menu then Export to Excel.",
|
||||
"Wishes with the same timestamp and reward name will NOT be touched (existing wishes will not be rewritten)",
|
||||
"This feature will only append and prepend wishes (nothing will be inserted in the middle of the list)",
|
||||
"Currently, the importer can only support excel files with an ENGLISH reward name"
|
||||
"Currently, the importer can only support excel files with an ENGLISH reward name",
|
||||
"Please change the website language first according to your excel file language"
|
||||
],
|
||||
"selectFile": {
|
||||
"default": "Drag & drop Paimon.moe excel file here, or click here to select",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<script>
|
||||
import { t } from 'svelte-i18n';
|
||||
import { t, dictionary, locale } from 'svelte-i18n';
|
||||
import { Workbook, ValueType } from 'exceljs';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
|
@ -103,20 +103,34 @@
|
|||
const { path, data } = await readLocalData(id);
|
||||
const { append, prepend } = added[id];
|
||||
|
||||
const beginning = prepend.map((e) => ({
|
||||
id: e[2],
|
||||
time: e[1],
|
||||
type: e[0],
|
||||
pity: 0,
|
||||
manualInput: true,
|
||||
}));
|
||||
const end = append.map((e) => ({
|
||||
id: e[2],
|
||||
time: e[1],
|
||||
type: e[0],
|
||||
pity: 0,
|
||||
manualInput: true,
|
||||
}));
|
||||
const beginning = prepend.map((e) => {
|
||||
const d = {
|
||||
id: e[2],
|
||||
time: e[1],
|
||||
type: e[0],
|
||||
pity: 0,
|
||||
manualInput: true,
|
||||
};
|
||||
|
||||
if (e[3] !== undefined) {
|
||||
d.code = e[3];
|
||||
}
|
||||
return d;
|
||||
});
|
||||
const end = append.map((e) => {
|
||||
const d = {
|
||||
id: e[2],
|
||||
time: e[1],
|
||||
type: e[0],
|
||||
pity: 0,
|
||||
manualInput: true,
|
||||
};
|
||||
|
||||
if (e[3] !== undefined) {
|
||||
d.code = e[3];
|
||||
}
|
||||
return d;
|
||||
});
|
||||
|
||||
const combined = [...beginning, ...data, ...end];
|
||||
|
||||
|
@ -210,6 +224,7 @@
|
|||
const type = row.getCell(1).text.toLowerCase();
|
||||
let time = row.getCell(3);
|
||||
const fullName = row.getCell(2).text;
|
||||
const wish2 = row.getCell(9).text === 'Wish 2';
|
||||
|
||||
if (time.type === ValueType.Date) {
|
||||
time = dayjs.utc(time.value).format('YYYY-MM-DD HH:mm:ss');
|
||||
|
@ -258,7 +273,11 @@
|
|||
throw 'unknown reward name';
|
||||
}
|
||||
|
||||
wishes.push([type, time, name]);
|
||||
const w = [type, time, name];
|
||||
if (wish2) {
|
||||
w[3] = '400';
|
||||
}
|
||||
wishes.push(w);
|
||||
});
|
||||
|
||||
console.log('from excel', category, wishes.length);
|
||||
|
@ -270,24 +289,41 @@
|
|||
}
|
||||
|
||||
async function readGachaExportExcel(workbook) {
|
||||
const bannerCategories = {
|
||||
'character-event': 'Character Event Wish',
|
||||
'weapon-event': 'Weapon Event Wish',
|
||||
standard: 'Permanent Wish',
|
||||
beginners: 'Novice Wishes',
|
||||
};
|
||||
const itemNames = {};
|
||||
for (const [k, v] of Object.entries($dictionary[$locale])) {
|
||||
itemNames[v] = k;
|
||||
}
|
||||
console.log(itemNames);
|
||||
|
||||
const bannerCategories = ['character-event', 'weapon-event', 'standard', 'beginners'];
|
||||
const bannerCodes = ['301', '302', '200', '100'];
|
||||
|
||||
const weapons = Object.values(weaponList);
|
||||
const chars = Object.values(characters);
|
||||
|
||||
for (const [id, category] of Object.entries(bannerCategories)) {
|
||||
const sheet = workbook.getWorksheet(category);
|
||||
const typeWeaponTranslate = $t('wish.detail.weapon');
|
||||
const typeCharacterTranslate = $t('wish.detail.character');
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const sheet = workbook.worksheets[i];
|
||||
const id = bannerCategories[i];
|
||||
let code = bannerCodes[i];
|
||||
const wishes = [];
|
||||
sheet.eachRow((row, index) => {
|
||||
if (index === 1) return;
|
||||
const type = row.getCell(3).text.toLowerCase();
|
||||
const typeRaw = row.getCell(3).text;
|
||||
let type = typeRaw;
|
||||
if (typeWeaponTranslate === typeRaw) {
|
||||
type = 'weapon';
|
||||
} else if (typeCharacterTranslate === typeRaw) {
|
||||
type = 'character';
|
||||
}
|
||||
|
||||
let time = row.getCell(1);
|
||||
const fullName = row.getCell(2).text;
|
||||
const fullName = itemNames[row.getCell(2).text];
|
||||
if (i === 0) {
|
||||
code = row.getCell(7).text.indexOf('2') > -1 ? '400' : '301';
|
||||
}
|
||||
|
||||
if (time.type === ValueType.Date) {
|
||||
time = dayjs.utc(time.value).format('YYYY-MM-DD HH:mm:ss');
|
||||
|
@ -299,9 +335,9 @@
|
|||
if (type === 'weapon') {
|
||||
const weapon = weapons.find((e) => e.name === fullName);
|
||||
if (weapon === undefined) {
|
||||
pushToast($t('wish.excel.errorUnknownItem'), 'error');
|
||||
pushToast($t('wish.excel.errorUnknownItem') + ` [${id} ${type} ${index}: ${fullName}]`, 'error');
|
||||
error = {
|
||||
banner: category,
|
||||
banner: id,
|
||||
line: index,
|
||||
name: fullName,
|
||||
type,
|
||||
|
@ -315,7 +351,7 @@
|
|||
} else if (type === 'character') {
|
||||
const character = chars.find((e) => e.name === fullName);
|
||||
if (character === undefined) {
|
||||
pushToast($t('wish.excel.errorUnknownItem'), 'error');
|
||||
pushToast($t('wish.excel.errorUnknownItem') + ` [${id} ${type} ${index}: ${fullName}]`, 'error');
|
||||
error = {
|
||||
banner: category,
|
||||
line: index,
|
||||
|
@ -331,15 +367,15 @@
|
|||
}
|
||||
|
||||
if (name === '') {
|
||||
pushToast($t('wish.excel.errorUnknownItem'), 'error');
|
||||
pushToast($t('wish.excel.errorUnknownItem') + ` [${id} ${type} ${index}: ${fullName}]`, 'error');
|
||||
loading = false;
|
||||
throw 'unknown reward name';
|
||||
}
|
||||
|
||||
wishes.push([type, time, name]);
|
||||
wishes.push([type, time, name, code]);
|
||||
});
|
||||
|
||||
console.log('from excel', category, wishes.length);
|
||||
console.log('from excel', id, wishes.length);
|
||||
await parseData(id, wishes);
|
||||
}
|
||||
|
||||
|
@ -619,7 +655,7 @@
|
|||
<li class="text-red-300">{$t('wish.excel.notice.0')}</li>
|
||||
<li class="text-white">{$t('wish.excel.notice.1')}</li>
|
||||
<li class="text-white">{$t('wish.excel.notice.2')}</li>
|
||||
<li class="text-white">{$t('wish.excel.notice.3')}</li>
|
||||
<li class="text-white">{$t('wish.excel.notice.4')}</li>
|
||||
</ol>
|
||||
</div>
|
||||
<p class="text-gray-200 mb-2">{$t('wish.excel.subtitle')}</p>
|
||||
|
|
|
@ -7,10 +7,7 @@ const IMAGE_CACHE = `cacheimg${IMAGE_CACHE_VER}`;
|
|||
|
||||
const IMAGE_URL = `${self.location.origin}/images/`;
|
||||
|
||||
const changelog = [
|
||||
'Update sumeru commission achievement checklist',
|
||||
'Add character & weapons release timeline (Database > Character Reruns)',
|
||||
];
|
||||
const changelog = ['Update excel import to support other language', 'Update character guides'];
|
||||
|
||||
const channel = new BroadcastChannel('paimonmoe-sw');
|
||||
|
||||
|
|
Loading…
Reference in a new issue