黑暗武士初步实现
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { useInfoStore } from './info'
|
||||
import api from '@/api'
|
||||
import type { IEquipment } from '@/api/info/type'
|
||||
import type { IEquipment, ISkill } from '@/api/info/type'
|
||||
import type { IResultSkillCount } from '@/api/calc/type'
|
||||
// | '上衣'
|
||||
// | '头肩'
|
||||
@@ -42,6 +42,11 @@ export interface IConfigEmblem {
|
||||
items: string[]
|
||||
}
|
||||
|
||||
export interface ISkillShortcuts {
|
||||
shortcuts: string[]
|
||||
combos: string[][]
|
||||
}
|
||||
|
||||
export interface IConfig {
|
||||
skills: Record<string, { lv: number; vp: number; up: number }>
|
||||
equips: Record<string, IConfigEquip>
|
||||
@@ -73,6 +78,7 @@ export interface IConfig {
|
||||
options: Record<string, number>
|
||||
avatarLink: string
|
||||
emblems: Record<string, IConfigEmblem>
|
||||
skillShortcuts: ISkillShortcuts
|
||||
}
|
||||
|
||||
const defaultEqusConfig = {
|
||||
@@ -113,6 +119,39 @@ const createDefaultEmblemConfig = (): IConfigEmblem => ({
|
||||
|
||||
const defaultEmblemConfig = createDefaultEmblemConfig()
|
||||
|
||||
const createDefaultSkillShortcuts = (): ISkillShortcuts => ({
|
||||
shortcuts: Array.from({ length: 6 }, () => ''),
|
||||
combos: Array.from({ length: 6 }, () => Array.from({ length: 5 }, () => '')),
|
||||
})
|
||||
|
||||
const normalizeSkillShortcuts = (
|
||||
arrangement?: Partial<ISkillShortcuts>,
|
||||
skills: ISkill[] = [],
|
||||
): ISkillShortcuts => {
|
||||
const validSkillIds = new Set(skills.map((skill) => skill.id.toString()))
|
||||
const skillIdByUuid = new Map(skills.map((skill) => [skill.uuid, skill.id.toString()]))
|
||||
const normalizeSkillId = (value: unknown) => {
|
||||
const key =
|
||||
typeof value === 'number' ? value.toString() : typeof value === 'string' ? value : ''
|
||||
if (!key) return ''
|
||||
return validSkillIds.has(key) ? key : (skillIdByUuid.get(key) ?? '')
|
||||
}
|
||||
|
||||
return {
|
||||
shortcuts: Array.from({ length: 6 }, (_, index) =>
|
||||
normalizeSkillId(arrangement?.shortcuts?.[index]),
|
||||
),
|
||||
combos: Array.from({ length: 6 }, (_, column) => {
|
||||
const combo = Array.from({ length: 5 }, (_, stage) =>
|
||||
normalizeSkillId(arrangement?.combos?.[column]?.[stage]),
|
||||
)
|
||||
const firstEmptyStage = combo.findIndex((skillId) => !skillId)
|
||||
if (firstEmptyStage >= 0) combo.fill('', firstEmptyStage)
|
||||
return combo
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
export const useConfigStore = defineStore('configStore', () => {
|
||||
const config = ref<IConfig>({
|
||||
skills: {},
|
||||
@@ -128,6 +167,7 @@ export const useConfigStore = defineStore('configStore', () => {
|
||||
options: {},
|
||||
avatarLink: '',
|
||||
emblems: {},
|
||||
skillShortcuts: createDefaultSkillShortcuts(),
|
||||
})
|
||||
|
||||
const skillCountConfig = ref<IResultSkillCount[]>([])
|
||||
@@ -161,6 +201,7 @@ export const useConfigStore = defineStore('configStore', () => {
|
||||
options: {},
|
||||
avatarLink: '',
|
||||
emblems: {},
|
||||
skillShortcuts: createDefaultSkillShortcuts(),
|
||||
}
|
||||
}
|
||||
if (!config.value?.equips) config.value.equips = {}
|
||||
@@ -172,6 +213,10 @@ export const useConfigStore = defineStore('configStore', () => {
|
||||
if (!config.value?.options) config.value.options = {}
|
||||
if (!config.value?.oaths) config.value.oaths = {}
|
||||
if (!config.value?.emblems) config.value.emblems = {}
|
||||
config.value.skillShortcuts = normalizeSkillShortcuts(
|
||||
config.value.skillShortcuts,
|
||||
infoStore.skills,
|
||||
)
|
||||
|
||||
const part = [...infoStore.parts, '宠物', '副武器'].filter(
|
||||
(a) => !config.value?.equips.hasOwnProperty(a),
|
||||
@@ -291,5 +336,6 @@ export const useConfigStore = defineStore('configStore', () => {
|
||||
createDefaultOathConfig,
|
||||
defaultEmblemConfig,
|
||||
createDefaultEmblemConfig,
|
||||
createDefaultSkillShortcuts,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user