mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
97 lines
2.9 KiB
TypeScript
97 lines
2.9 KiB
TypeScript
import { defineStore } from 'pinia'
|
||
import type {
|
||
Planet,
|
||
Player,
|
||
BuildQueueItem,
|
||
FleetMission,
|
||
BattleResult,
|
||
SpyReport,
|
||
Officer,
|
||
SpiedNotification,
|
||
NPCActivityNotification,
|
||
IncomingFleetAlert,
|
||
MissileAttack,
|
||
AchievementStats,
|
||
AchievementProgress,
|
||
WebDAVConfig
|
||
} from '@/types/game'
|
||
import { TechnologyType, OfficerType } from '@/types/game'
|
||
import { initializeAchievementStats, initializeAchievements } from '@/logic/achievementLogic'
|
||
import type { Locale } from '@/locales'
|
||
import pkg from '../../package.json'
|
||
import { encryptData, decryptData } from '@/utils/crypto'
|
||
|
||
export const useGameStore = defineStore('game', {
|
||
state: () => ({
|
||
gameTime: Date.now(),
|
||
isPaused: false,
|
||
gameSpeed: 1,
|
||
player: {
|
||
id: 'player1',
|
||
name: '',
|
||
planets: [] as Planet[],
|
||
technologies: {} as Record<TechnologyType, number>,
|
||
officers: {} as Record<OfficerType, Officer>,
|
||
researchQueue: [] as BuildQueueItem[],
|
||
waitingResearchQueue: [],
|
||
fleetMissions: [] as FleetMission[],
|
||
missileAttacks: [] as MissileAttack[],
|
||
battleReports: [] as BattleResult[],
|
||
spyReports: [] as SpyReport[],
|
||
spiedNotifications: [] as SpiedNotification[],
|
||
npcActivityNotifications: [] as NPCActivityNotification[],
|
||
missionReports: [],
|
||
incomingFleetAlerts: [] as IncomingFleetAlert[],
|
||
giftNotifications: [],
|
||
giftRejectedNotifications: [],
|
||
points: 0,
|
||
isGMEnabled: false, // 明确设置 GM 模式默认为 false
|
||
lastVersionCheckTime: 0, // 最后一次检查版本的时间戳,默认为0
|
||
achievementStats: initializeAchievementStats() as AchievementStats,
|
||
achievements: initializeAchievements() as Record<string, AchievementProgress>
|
||
} as Player,
|
||
currentPlanetId: '',
|
||
isDark: '',
|
||
locale: 'zh-CN' as Locale,
|
||
notificationSettings: {
|
||
browser: false,
|
||
inApp: true,
|
||
suppressInFocus: false,
|
||
types: {
|
||
construction: true,
|
||
research: true,
|
||
unlock: true
|
||
}
|
||
},
|
||
webdavConfig: null as WebDAVConfig | null
|
||
}),
|
||
actions: {
|
||
async requestBrowserPermission(): Promise<boolean> {
|
||
if (!('Notification' in window)) return false
|
||
|
||
if (Notification.permission === 'granted') return true
|
||
|
||
const permission = await Notification.requestPermission()
|
||
return permission === 'granted'
|
||
}
|
||
},
|
||
getters: {
|
||
currentPlanet(): Planet | undefined {
|
||
return this.player.planets.find(p => p.id === this.currentPlanetId)
|
||
},
|
||
getMoonForPlanet(): (planetId: string) => Planet | undefined {
|
||
return (planetId: string) => {
|
||
return this.player.planets.find(p => p.parentPlanetId === planetId && p.isMoon)
|
||
}
|
||
}
|
||
},
|
||
persist: {
|
||
key: pkg.name,
|
||
storage: localStorage,
|
||
serializer: {
|
||
serialize: state => encryptData(state),
|
||
deserialize: value => decryptData(value)
|
||
}
|
||
}
|
||
})
|