迁移
This commit is contained in:
@@ -34,6 +34,7 @@ export interface IConfigEquip {
|
||||
export interface IConfigOath {
|
||||
id: string;
|
||||
adaptation: number;
|
||||
upgrade: number[];
|
||||
}
|
||||
|
||||
export interface IConfigEmblem {
|
||||
@@ -107,6 +108,7 @@ const defaultAvatarConfig = {
|
||||
const createDefaultOathConfig = (): IConfigOath => ({
|
||||
id: "",
|
||||
adaptation: 0,
|
||||
upgrade: [0, 0, 0, 0],
|
||||
});
|
||||
|
||||
const defaultOathConfig = createDefaultOathConfig();
|
||||
@@ -118,22 +120,24 @@ const createDefaultEmblemConfig = (): IConfigEmblem => ({
|
||||
|
||||
const defaultEmblemConfig = createDefaultEmblemConfig();
|
||||
|
||||
const createDefaultConfig = (): IConfig => ({
|
||||
skills: {},
|
||||
equips: {},
|
||||
oaths: {},
|
||||
oathSkill: "1",
|
||||
jades: {},
|
||||
avatar: {},
|
||||
sundry: {},
|
||||
bindAwake: 50,
|
||||
DSB: false,
|
||||
BUFF: false,
|
||||
options: {},
|
||||
avatarLink: "",
|
||||
emblems: {},
|
||||
});
|
||||
|
||||
export const useConfigStore = defineStore("configStore", () => {
|
||||
const config = ref<IConfig>({
|
||||
skills: {},
|
||||
equips: {},
|
||||
oaths: {},
|
||||
oathSkill: "1",
|
||||
jades: {},
|
||||
avatar: {},
|
||||
sundry: {},
|
||||
bindAwake: 50,
|
||||
DSB: false,
|
||||
BUFF: false,
|
||||
options: {},
|
||||
avatarLink: "",
|
||||
emblems: {},
|
||||
});
|
||||
const config = ref<IConfig>(createDefaultConfig());
|
||||
|
||||
const skillCountConfig = ref<IResultSkillCount[]>([]);
|
||||
const changeSourceLogs = ref<IChangeSourceLog[]>([]);
|
||||
@@ -142,32 +146,22 @@ export const useConfigStore = defineStore("configStore", () => {
|
||||
const infoStore = useInfoStore();
|
||||
const alter = infoStore.infos?.alter;
|
||||
|
||||
// A character with no persisted data must start clean instead of inheriting the last role's
|
||||
// in-memory configuration or skill-count overrides.
|
||||
config.value = createDefaultConfig();
|
||||
skillCountConfig.value = [];
|
||||
|
||||
if (alter) {
|
||||
const localConfig = localStorage.getItem(`dcalc/${alter}/config`);
|
||||
const localSkillConfig = localStorage.getItem(`dcalc/${alter}/config/skillCount`);
|
||||
if (localConfig) {
|
||||
config.value = JSON.parse(localConfig);
|
||||
try {
|
||||
if (localConfig) config.value = JSON.parse(localConfig) as IConfig;
|
||||
if (localSkillConfig) skillCountConfig.value = JSON.parse(localSkillConfig) as IResultSkillCount[];
|
||||
} catch {
|
||||
// Ignore malformed legacy browser data and continue with the current schema defaults.
|
||||
config.value = createDefaultConfig();
|
||||
skillCountConfig.value = [];
|
||||
}
|
||||
if (localSkillConfig) {
|
||||
skillCountConfig.value = JSON.parse(localSkillConfig);
|
||||
}
|
||||
}
|
||||
if (!config.value) {
|
||||
config.value = {
|
||||
skills: {},
|
||||
equips: {},
|
||||
oaths: {},
|
||||
oathSkill: "1",
|
||||
jades: {},
|
||||
avatar: {},
|
||||
sundry: {},
|
||||
bindAwake: 50,
|
||||
DSB: false,
|
||||
BUFF: false,
|
||||
options: {},
|
||||
avatarLink: "",
|
||||
emblems: {},
|
||||
};
|
||||
}
|
||||
if (!config.value?.equips) config.value.equips = {};
|
||||
if (!config.value?.skills) config.value.skills = {};
|
||||
@@ -205,6 +199,8 @@ export const useConfigStore = defineStore("configStore", () => {
|
||||
config.value &&
|
||||
!config.value?.oaths.hasOwnProperty(p) &&
|
||||
(config.value.oaths[p.toString()] = createDefaultOathConfig());
|
||||
const oath = config.value.oaths[p.toString()];
|
||||
if (oath && !Array.isArray(oath.upgrade)) oath.upgrade = [0, 0, 0, 0];
|
||||
});
|
||||
|
||||
infoStore.options.forEach((option) => {
|
||||
@@ -310,6 +306,7 @@ export const useConfigStore = defineStore("configStore", () => {
|
||||
chooseEqu,
|
||||
skillCountConfig,
|
||||
defaultEqusConfig,
|
||||
createDefaultConfig,
|
||||
defaultAvatarConfig,
|
||||
defaultOathConfig,
|
||||
createDefaultOathConfig,
|
||||
|
||||
@@ -163,9 +163,17 @@ export const useInfoStore = defineStore("infoStore", () => {
|
||||
|
||||
const createCharacter = async (alter: string, equVersion?: string) => {
|
||||
const time = new Date().getTime();
|
||||
alter_token.value = btoa(JSON.stringify({ alter, equVersion, time }));
|
||||
infos.value = await api.characterInfo();
|
||||
const token = btoa(JSON.stringify({ alter, equVersion, time }));
|
||||
alter_token.value = token;
|
||||
const nextInfos = await api.characterInfo();
|
||||
|
||||
// Navigation can start another character request before this one returns. In that case the
|
||||
// latest Alter-Token owns the store and this response must not overwrite it.
|
||||
if (alter_token.value !== token) return false;
|
||||
|
||||
infos.value = nextInfos;
|
||||
useConfigStore().loadConfig();
|
||||
return true;
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user