Update character list from wish history

- close #36
pull/1/head
Made Baruna 2021-04-19 01:12:31 +08:00
parent 086ed376eb
commit d14fe3f972
4 changed files with 167 additions and 45 deletions

View File

@ -1,38 +0,0 @@
import { getAccountPrefix } from "../stores/account";
import { readSave, updateSave } from "../stores/saveManager";
const bannerCategories = ['beginners', 'standard', 'character-event', 'weapon-event'];
function readLocalData(path) {
const prefix = getAccountPrefix();
const data = readSave(`${prefix}${path}`);
if (data !== null) {
const counterData = JSON.parse(data);
const pullData = counterData.pulls || [];
return pullData;
}
return null;
}
export function processCharacters() {
const characters = {};
for (const id of bannerCategories) {
const data = readLocalData(`wish-counter-${id}`);
if (data === null) continue;
for (const item of data) {
if (item.type === 'character') {
if (characters[item.id] === undefined) {
characters[item.id] = 0;
}
characters[item.id]++;
}
}
}
const prefix = getAccountPrefix();
updateSave(`${prefix}characters`, JSON.stringify(characters));
}

View File

@ -17,7 +17,7 @@
import Icon from '../../components/Icon.svelte';
import Button from '../../components/Button.svelte';
import { getAccountPrefix } from '../../stores/account';
import { readSave } from '../../stores/saveManager';
import { readSave, updateSave } from '../../stores/saveManager';
import { characters } from '../../data/characters';
import { itemGroup } from '../../data/itemGroup';
@ -26,6 +26,44 @@
let constellationDiv;
const defaultChars = {
amber: {
default: 1,
wish: 0,
manual: 0,
},
kaeya: {
default: 1,
wish: 0,
manual: 0,
},
lisa: {
default: 1,
wish: 0,
manual: 0,
},
traveler_geo: {
default: 1,
wish: 0,
manual: 0,
},
traveler_anemo: {
default: 1,
wish: 0,
manual: 0,
},
barbara: {
default: 1,
wish: 0,
manual: 0,
},
xiangling: {
default: 1,
wish: 0,
manual: 0,
},
};
const numberFormat = Intl.NumberFormat('en', {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
@ -36,6 +74,7 @@
const book = itemGroup[bookId];
const materials = character.ascension[1].items;
let chars = {};
let constellationCount = -1;
let manualCount = 0;
let editConstallation = false;
@ -49,11 +88,12 @@
const data = readSave(`${prefix}characters`);
if (data !== null) {
const constellation = JSON.parse(data);
chars = constellation;
if (constellation[id]) {
constellationCount = constellationCount[id].default + constellationCount[id].wish - 1;
manualCount = constellationCount[id].manual;
constellationCount = constellation[id].default + constellation[id].wish - 1;
manualCount = constellation[id].manual;
} else {
constellationCount = 0;
constellationCount = -1;
}
}
}
@ -64,6 +104,27 @@
function saveConstellationCount() {
editConstallation = false;
if (chars[id]) {
chars[id].manual = manualCount;
} else if (defaultChars[id]) {
chars[id] = {
...defaultChars[id],
manual: manualCount,
};
} else {
chars[id] = {
default: 0,
wish: 0,
manual: manualCount,
};
}
if (chars[id].default + chars[id].wish + chars[id].manual === 0) {
delete chars[id];
}
const prefix = getAccountPrefix();
updateSave(`${prefix}characters`, JSON.stringify(chars));
}
function scrollToView(view) {

View File

@ -8,7 +8,7 @@
import { characters } from '../../data/characters';
import { getAccountPrefix } from '../../stores/account';
import { readSave } from '../../stores/saveManager';
import { readSave, updateSave } from '../../stores/saveManager';
let sortBy = '';
let sortOrder = false;
@ -71,12 +71,82 @@
}
}
function processWishes() {
const chars = {
amber: {
default: 1,
wish: 0,
manual: 0,
},
kaeya: {
default: 1,
wish: 0,
manual: 0,
},
lisa: {
default: 1,
wish: 0,
manual: 0,
},
traveler_geo: {
default: 1,
wish: 0,
manual: 0,
},
traveler_anemo: {
default: 1,
wish: 0,
manual: 0,
},
barbara: {
default: 1,
wish: 0,
manual: 0,
},
xiangling: {
default: 1,
wish: 0,
manual: 0,
},
};
const bannerCategories = ['beginners', 'standard', 'character-event', 'weapon-event'];
const prefix = getAccountPrefix();
for (const id of bannerCategories) {
const data = readSave(`${prefix}wish-counter-${id}`);
if (data !== null) {
showConstellation = true;
const counterData = JSON.parse(data);
const pullData = counterData.pulls || [];
for (const pull of pullData) {
if (pull.type === 'character') {
if (chars[pull.id] === undefined) {
chars[pull.id] = {
default: 0,
wish: 0,
manual: 0,
};
}
chars[pull.id].wish++;
}
}
}
}
if (showConstellation) {
constellation = chars;
updateSave(`${prefix}characters`, JSON.stringify(chars));
}
}
function getConstellation() {
const prefix = getAccountPrefix();
const data = readSave(`${prefix}characters`);
if (data !== null) {
constellation = JSON.parse(data);
showConstellation = true;
} else {
processWishes();
}
}
@ -144,7 +214,7 @@
>
{#if constellation[id]}
<span class="mx-1 text-white text-xs font-semibold">
C{Math.min(constellation[id] - 1, 6)}
C{Math.max(0, (constellation[id].default + constellation[id].wish + constellation[id].manual) - 1)}
</span>
{/if}
<img class="w-4 h-4" src={`/images/elements/${char.element.id}.png`} alt={char.element.name} />

View File

@ -9,7 +9,7 @@
import { bannerTypes } from '../../data/bannerTypes';
import { getAccountPrefix } from '../../stores/account';
import { readSave, updateTime, fromRemote } from '../../stores/saveManager';
import { readSave, updateTime, fromRemote, updateSave } from '../../stores/saveManager';
import SummaryItem from './_summaryItem.svelte';
import Icon from '../../components/Icon.svelte';
import { mdiEarth } from '@mdi/js';
@ -43,6 +43,18 @@
monthlyData = {};
// collected characters stuff
let updateCollectedCharacters = false;
let collectedCharacters = {};
const collectedCharactersData = readSave(`${prefix}characters`);
if (collectedCharactersData !== null) {
collectedCharacters = JSON.parse(collectedCharactersData);
for (const collectedId of Object.keys(collectedCharacters)) {
collectedCharacters[collectedId].wish = 0;
}
updateCollectedCharacters = true;
}
for (let type of types) {
const path = `wish-counter-${type.id}`;
const data = readSave(`${prefix}${path}`);
@ -70,6 +82,19 @@
rarity = characters[pull.id].rarity;
itemName = characters[pull.id].name;
currentType = 'character';
// collected characters stuff
if (updateCollectedCharacters) {
if (collectedCharacters[pull.id]) {
collectedCharacters[pull.id].wish += 1;
} else {
collectedCharacters[pull.id] = {
default: 0,
manual: 0,
wish: 1,
};
}
}
} else if (pull.type === 'weapon') {
rarity = weaponList[pull.id].rarity;
itemName = weaponList[pull.id].name;
@ -134,6 +159,10 @@
}
}
if (updateCollectedCharacters) {
updateSave(`${prefix}characters`, JSON.stringify(collectedCharacters));
}
console.log(avg);
loading = false;
}