Renamed zone > map
This commit is contained in:
134
src/stores/mapEditorStore.ts
Normal file
134
src/stores/mapEditorStore.ts
Normal file
@ -0,0 +1,134 @@
|
||||
import type { Object, Tile, Map, MapEffect, PlacedMapObject } from '@/application/types'
|
||||
import { useGameStore } from '@/stores/gameStore'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export type TeleportSettings = {
|
||||
toMapId: number
|
||||
toPositionX: number
|
||||
toPositionY: number
|
||||
toRotation: number
|
||||
}
|
||||
|
||||
export const useMapEditorStore = defineStore('mapEditor', {
|
||||
state: () => {
|
||||
return {
|
||||
active: false,
|
||||
map: null as Map | null,
|
||||
tool: 'move',
|
||||
drawMode: 'tile',
|
||||
eraserMode: 'tile',
|
||||
mapList: [] as Map[],
|
||||
tileList: [] as Tile[],
|
||||
objectList: [] as Object[],
|
||||
selectedTile: '',
|
||||
selectedObject: null as Object | null,
|
||||
isTileListModalShown: false,
|
||||
isObjectListModalShown: false,
|
||||
isMapListModalShown: false,
|
||||
isCreateMapModalShown: false,
|
||||
isSettingsModalShown: false,
|
||||
shouldClearTiles: false,
|
||||
mapSettings: {
|
||||
name: '',
|
||||
width: 0,
|
||||
height: 0,
|
||||
pvp: false,
|
||||
mapEffects: [] as MapEffect[]
|
||||
},
|
||||
teleportSettings: {
|
||||
toMapId: 0,
|
||||
toPositionX: 0,
|
||||
toPositionY: 0,
|
||||
toRotation: 0
|
||||
} as TeleportSettings
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
toggleActive() {
|
||||
const gameStore = useGameStore()
|
||||
if (!this.active) gameStore.connection?.emit('map:character:leave')
|
||||
if (this.active) this.reset()
|
||||
this.active = !this.active
|
||||
},
|
||||
setMap(map: Map | null) {
|
||||
this.map = map
|
||||
},
|
||||
setMapName(name: string) {
|
||||
this.mapSettings.name = name
|
||||
},
|
||||
setMapWidth(width: number) {
|
||||
this.mapSettings.width = width
|
||||
},
|
||||
setMapHeight(height: number) {
|
||||
this.mapSettings.height = height
|
||||
},
|
||||
setMapPvp(pvp: boolean) {
|
||||
if (!this.map) return
|
||||
this.map.pvp = pvp
|
||||
},
|
||||
setMapEffects(mapEffects: MapEffect[]) {
|
||||
if (!this.map) return
|
||||
this.mapSettings.mapEffects = mapEffects
|
||||
},
|
||||
setTool(tool: string) {
|
||||
this.tool = tool
|
||||
},
|
||||
setDrawMode(mode: string) {
|
||||
this.drawMode = mode
|
||||
},
|
||||
setEraserMode(mode: string) {
|
||||
this.eraserMode = mode
|
||||
},
|
||||
setMapList(maps: Map[]) {
|
||||
this.mapList = maps
|
||||
},
|
||||
setTileList(tiles: Tile[]) {
|
||||
this.tileList = tiles
|
||||
},
|
||||
setObjectList(objects: Object[]) {
|
||||
this.objectList = objects
|
||||
},
|
||||
setSelectedTile(tile: string) {
|
||||
this.selectedTile = tile
|
||||
},
|
||||
setSelectedObject(object: Object) {
|
||||
this.selectedObject = object
|
||||
},
|
||||
toggleSettingsModal() {
|
||||
this.isSettingsModalShown = !this.isSettingsModalShown
|
||||
},
|
||||
toggleMapListModal() {
|
||||
this.isMapListModalShown = !this.isMapListModalShown
|
||||
this.isCreateMapModalShown = false
|
||||
},
|
||||
toggleCreateMapModal() {
|
||||
this.isCreateMapModalShown = !this.isCreateMapModalShown
|
||||
},
|
||||
setTeleportSettings(teleportSettings: TeleportSettings) {
|
||||
this.teleportSettings = teleportSettings
|
||||
},
|
||||
triggerClearTiles() {
|
||||
this.shouldClearTiles = true
|
||||
},
|
||||
|
||||
resetClearTilesFlag() {
|
||||
this.shouldClearTiles = false
|
||||
},
|
||||
reset(resetMap = false) {
|
||||
if (resetMap) this.map = null
|
||||
this.mapList = []
|
||||
this.tileList = []
|
||||
this.objectList = []
|
||||
this.tool = 'move'
|
||||
this.drawMode = 'tile'
|
||||
this.selectedTile = ''
|
||||
this.selectedObject = null
|
||||
this.isTileListModalShown = false
|
||||
this.isObjectListModalShown = false
|
||||
this.isSettingsModalShown = false
|
||||
this.isMapListModalShown = false
|
||||
this.isCreateMapModalShown = false
|
||||
this.shouldClearTiles = false
|
||||
}
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user