forked from noxious/client
Changes to mapeditorcomposable, fix pencil and fill tool for tiles
Locked in, made mapeditor my bi-
This commit is contained in:
@ -1,7 +1,32 @@
|
||||
import type { Map } from '@/application/types'
|
||||
import type { Map, MapObject } from '@/application/types'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export type TeleportSettings = {
|
||||
toMapId: string
|
||||
toPositionX: number
|
||||
toPositionY: number
|
||||
toRotation: number
|
||||
}
|
||||
|
||||
const currentMap = ref<Map | null>(null)
|
||||
const active = ref(false)
|
||||
const tool = ref('move')
|
||||
const drawMode = ref('tile')
|
||||
const eraserMode = ref('tile')
|
||||
const selectedTile = ref('')
|
||||
const selectedMapObject = ref<MapObject | null>(null)
|
||||
const isTileListModalShown = ref(false)
|
||||
const isMapObjectListModalShown = ref(false)
|
||||
const isMapListModalShown = ref(false)
|
||||
const isCreateMapModalShown = ref(false)
|
||||
const isSettingsModalShown = ref(false)
|
||||
const shouldClearTiles = ref(false)
|
||||
const teleportSettings = ref<TeleportSettings>({
|
||||
toMapId: '',
|
||||
toPositionX: 0,
|
||||
toPositionY: 0,
|
||||
toRotation: 0
|
||||
})
|
||||
|
||||
export function useMapEditorComposable() {
|
||||
const loadMap = (map: Map) => {
|
||||
@ -16,16 +41,107 @@ export function useMapEditorComposable() {
|
||||
|
||||
const clearMap = () => {
|
||||
if (!currentMap.value) return
|
||||
|
||||
currentMap.value.placedMapObjects = []
|
||||
currentMap.value.mapEventTiles = []
|
||||
currentMap.value.tiles = []
|
||||
}
|
||||
|
||||
const toggleActive = () => {
|
||||
if (active.value) reset()
|
||||
active.value = !active.value
|
||||
}
|
||||
|
||||
const setTool = (newTool: string) => {
|
||||
tool.value = newTool
|
||||
}
|
||||
|
||||
const setDrawMode = (mode: string) => {
|
||||
drawMode.value = mode
|
||||
}
|
||||
|
||||
const setEraserMode = (mode: string) => {
|
||||
eraserMode.value = mode
|
||||
}
|
||||
|
||||
const setSelectedTile = (tile: string) => {
|
||||
selectedTile.value = tile
|
||||
}
|
||||
|
||||
const setSelectedMapObject = (object: MapObject) => {
|
||||
selectedMapObject.value = object
|
||||
}
|
||||
|
||||
const toggleSettingsModal = () => {
|
||||
isSettingsModalShown.value = !isSettingsModalShown.value
|
||||
}
|
||||
|
||||
const toggleMapListModal = () => {
|
||||
isMapListModalShown.value = !isMapListModalShown.value
|
||||
isCreateMapModalShown.value = false
|
||||
}
|
||||
|
||||
const toggleCreateMapModal = () => {
|
||||
isCreateMapModalShown.value = !isCreateMapModalShown.value
|
||||
}
|
||||
|
||||
const setTeleportSettings = (settings: TeleportSettings) => {
|
||||
teleportSettings.value = settings
|
||||
}
|
||||
|
||||
const triggerClearTiles = () => {
|
||||
shouldClearTiles.value = true
|
||||
}
|
||||
|
||||
const resetClearTilesFlag = () => {
|
||||
shouldClearTiles.value = false
|
||||
}
|
||||
|
||||
const reset = () => {
|
||||
tool.value = 'move'
|
||||
drawMode.value = 'tile'
|
||||
selectedTile.value = ''
|
||||
selectedMapObject.value = null
|
||||
isTileListModalShown.value = false
|
||||
isMapObjectListModalShown.value = false
|
||||
isSettingsModalShown.value = false
|
||||
isMapListModalShown.value = false
|
||||
isCreateMapModalShown.value = false
|
||||
shouldClearTiles.value = false
|
||||
}
|
||||
|
||||
return {
|
||||
// State
|
||||
currentMap,
|
||||
active,
|
||||
tool,
|
||||
drawMode,
|
||||
eraserMode,
|
||||
selectedTile,
|
||||
selectedMapObject,
|
||||
isTileListModalShown,
|
||||
isMapObjectListModalShown,
|
||||
isMapListModalShown,
|
||||
isCreateMapModalShown,
|
||||
isSettingsModalShown,
|
||||
shouldClearTiles,
|
||||
teleportSettings,
|
||||
|
||||
// Methods
|
||||
loadMap,
|
||||
updateProperty,
|
||||
clearMap
|
||||
clearMap,
|
||||
toggleActive,
|
||||
setTool,
|
||||
setDrawMode,
|
||||
setEraserMode,
|
||||
setSelectedTile,
|
||||
setSelectedMapObject,
|
||||
toggleSettingsModal,
|
||||
toggleMapListModal,
|
||||
toggleCreateMapModal,
|
||||
setTeleportSettings,
|
||||
triggerClearTiles,
|
||||
resetClearTilesFlag,
|
||||
reset
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user