client/src/stores/zoneEditorStore.ts

129 lines
3.3 KiB
TypeScript

import { defineStore } from 'pinia'
import { useGameStore } from '@/stores/gameStore'
import type { Zone, Object, Tile, ZoneObject, ZoneEffects } from '@/types'
export type TeleportSettings = {
toZoneId: number
toPositionX: number
toPositionY: number
toRotation: number
}
export const useZoneEditorStore = defineStore('zoneEditor', {
state: () => {
return {
active: true,
zone: null as Zone | null,
tool: 'move',
drawMode: 'tile',
eraserMode: 'tile',
zoneList: [] as Zone[],
tileList: [] as Tile[],
objectList: [] as Object[],
selectedTile: null as Tile | null,
selectedObject: null as Object | null,
objectDepth: 0,
isTileListModalShown: false,
isObjectListModalShown: false,
isZoneListModalShown: false,
isCreateZoneModalShown: false,
isSettingsModalShown: false,
zoneSettings: {
name: '',
width: 0,
height: 0,
pvp: false,
effects: [] as ZoneEffects[]
},
teleportSettings: {
toZoneId: 0,
toPositionX: 0,
toPositionY: 0,
toRotation: 0
} as TeleportSettings
}
},
actions: {
toggleActive() {
const gameStore = useGameStore()
if (!this.active) gameStore.connection?.emit('zone:character:leave')
if (this.active) this.reset()
this.active = !this.active
},
setZone(zone: Zone | null) {
this.zone = zone
},
setZoneName(name: string) {
this.zoneSettings.name = name
},
setZoneWidth(width: number) {
this.zoneSettings.width = width
},
setZoneHeight(height: number) {
this.zoneSettings.height = height
},
setZonePvp(pvp: boolean) {
if (!this.zone) return
this.zone.pvp = pvp
},
setZoneEffects(zoneEffects: ZoneEffects) {
if (!this.zone) return
this.zone.zoneEffects = zoneEffects
},
setTool(tool: string) {
this.tool = tool
},
setDrawMode(mode: string) {
this.drawMode = mode
},
setEraserMode(mode: string) {
this.eraserMode = mode
},
setZoneList(zones: Zone[]) {
this.zoneList = zones
},
setTileList(tiles: Tile[]) {
this.tileList = tiles
},
setObjectList(objects: Object[]) {
this.objectList = objects
},
setSelectedTile(tile: Tile) {
this.selectedTile = tile
},
setSelectedObject(object: any) {
this.selectedObject = object
},
setObjectDepth(depth: number) {
this.objectDepth = depth
},
toggleSettingsModal() {
this.isSettingsModalShown = !this.isSettingsModalShown
},
toggleZoneListModal() {
this.isZoneListModalShown = !this.isZoneListModalShown
this.isCreateZoneModalShown = false
},
toggleCreateZoneModal() {
this.isCreateZoneModalShown = !this.isCreateZoneModalShown
},
setTeleportSettings(teleportSettings: TeleportSettings) {
this.teleportSettings = teleportSettings
},
reset(resetZone = false) {
if (resetZone) this.zone = null
this.zoneList = []
this.tileList = []
this.objectList = []
this.tool = 'move'
this.drawMode = 'tile'
this.selectedTile = null
this.selectedObject = null
this.objectDepth = 0
this.isSettingsModalShown = false
this.isZoneListModalShown = false
this.isCreateZoneModalShown = false
}
}
})