Almost finalised refactoring
This commit is contained in:
@ -15,16 +15,16 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { type Map } from '@/application/types'
|
||||
import MapEventTiles from '@/components/gameMaster/mapEditor/mapPartials/MapEventTiles.vue'
|
||||
import MapObjects from '@/components/gameMaster/mapEditor/mapPartials/MapObjects.vue'
|
||||
import MapTiles from '@/components/gameMaster/mapEditor/mapPartials/MapTiles.vue'
|
||||
import MapList from '@/components/gameMaster/mapEditor/partials/MapList.vue'
|
||||
import MapSettings from '@/components/gameMaster/mapEditor/partials/MapSettings.vue'
|
||||
import ObjectList from '@/components/gameMaster/mapEditor/partials/ObjectList.vue'
|
||||
import TeleportModal from '@/components/gameMaster/mapEditor/partials/TeleportModal.vue'
|
||||
import TileList from '@/components/gameMaster/mapEditor/partials/TileList.vue'
|
||||
// Components
|
||||
import Toolbar from '@/components/gameMaster/mapEditor/partials/Toolbar.vue'
|
||||
import MapList from '@/components/gameMaster/mapEditor/partials/MapList.vue'
|
||||
import MapSettings from '@/components/gameMaster/mapEditor/partials/MapSettings.vue'
|
||||
import MapEventTiles from '@/components/gameMaster/mapEditor/mapPartials/MapEventTiles.vue'
|
||||
import MapObjects from '@/components/gameMaster/mapEditor/mapPartials/MapObjects.vue'
|
||||
import MapTiles from '@/components/gameMaster/mapEditor/mapPartials/MapTiles.vue'
|
||||
import { useGameStore } from '@/stores/gameStore'
|
||||
import { useMapEditorStore } from '@/stores/mapEditorStore'
|
||||
import { onUnmounted, ref } from 'vue'
|
||||
@ -38,7 +38,7 @@ function clear() {
|
||||
if (!mapEditorStore.map) return
|
||||
|
||||
// Clear objects, event tiles and tiles
|
||||
mapEditorStore.map.mapObjects = []
|
||||
mapEditorStore.map.placedMapObjects = []
|
||||
mapEditorStore.map.mapEventTiles = []
|
||||
mapEditorStore.triggerClearTiles()
|
||||
}
|
||||
@ -55,14 +55,14 @@ function save() {
|
||||
pvp: mapEditorStore.map.pvp,
|
||||
mapEffects: mapEditorStore.map.mapEffects.map(({ id, mapId, effect, strength }) => ({ id, mapId, effect, strength })),
|
||||
mapEventTiles: mapEditorStore.map.mapEventTiles.map(({ id, mapId, type, positionX, positionY, teleport }) => ({ id, mapId, type, positionX, positionY, teleport })),
|
||||
mapObjects: mapEditorStore.map.mapObjects.map(({ id, mapId, objectId, depth, isRotated, positionX, positionY }) => ({ id, mapId, objectId, depth, isRotated, positionX, positionY }))
|
||||
placedMapObjects: mapEditorStore.map.placedMapObjects.map(({ id, mapId, objectId, depth, isRotated, positionX, positionY }) => ({ id, mapId, objectId, depth, isRotated, positionX, positionY }))
|
||||
}
|
||||
|
||||
if (mapEditorStore.isSettingsModalShown) {
|
||||
mapEditorStore.toggleSettingsModal()
|
||||
}
|
||||
|
||||
gameStore.connection?.emit('gm:map_editor:map:update', data, (response: Map) => {
|
||||
gameStore.connection?.emit('gm:map:update', data, (response: Map) => {
|
||||
mapEditorStore.setMap(response)
|
||||
})
|
||||
}
|
||||
|
@ -6,8 +6,8 @@
|
||||
<script setup lang="ts">
|
||||
import type { PlacedMapObject as MapObjectT } from '@/application/types'
|
||||
import { uuidv4 } from '@/application/utilities'
|
||||
import SelectedMapObject from '@/components/gameMaster/mapEditor/partials/SelectedMapObject.vue'
|
||||
import MapObject from '@/components/gameMaster/mapEditor/mapPartials/MapObject.vue'
|
||||
import SelectedMapObject from '@/components/gameMaster/mapEditor/partials/SelectedMapObject.vue'
|
||||
import { getTile } from '@/composables/mapComposable'
|
||||
import { useMapEditorStore } from '@/stores/mapEditorStore'
|
||||
import { useScene } from 'phavuer'
|
||||
@ -65,7 +65,7 @@ function pencil(pointer: Phaser.Input.Pointer) {
|
||||
}
|
||||
|
||||
// Add new object to mapObjects
|
||||
mapEditorStore.map.mapObjects = mapEditorStore.map.mapObjects.concat(newObject as MapObjectT)
|
||||
mapEditorStore.map.placedMapObjects = mapEditorStore.map.placedMapObjects.concat(newObject as MapObjectT)
|
||||
}
|
||||
|
||||
function eraser(pointer: Phaser.Input.Pointer) {
|
||||
@ -92,11 +92,11 @@ function eraser(pointer: Phaser.Input.Pointer) {
|
||||
if (!tile) return
|
||||
|
||||
// Check if object already exists on position
|
||||
const existingObject = mapEditorStore.map.mapObjects.find((object) => object.positionX === tile.x && object.positionY === tile.y)
|
||||
const existingObject = mapEditorStore.map.placedMapObjects.find((object) => object.positionX === tile.x && object.positionY === tile.y)
|
||||
if (!existingObject) return
|
||||
|
||||
// Remove existing object
|
||||
mapEditorStore.map.mapObjects = mapEditorStore.map.mapObjects.filter((object) => object.id !== existingObject.id)
|
||||
mapEditorStore.map.placedMapObjects = mapEditorStore.map.placedMapObjects.filter((object) => object.id !== existingObject.id)
|
||||
}
|
||||
|
||||
function objectPicker(pointer: Phaser.Input.Pointer) {
|
||||
@ -123,7 +123,7 @@ function objectPicker(pointer: Phaser.Input.Pointer) {
|
||||
if (!tile) return
|
||||
|
||||
// Check if object already exists on position
|
||||
const existingObject = mapEditorStore.map.mapObjects.find((object) => object.positionX === tile.x && object.positionY === tile.y)
|
||||
const existingObject = mapEditorStore.map.placedMapObjects.find((object) => object.positionX === tile.x && object.positionY === tile.y)
|
||||
if (!existingObject) return
|
||||
|
||||
// Select the object
|
||||
@ -134,7 +134,7 @@ function moveMapObject(id: string) {
|
||||
// Check if map is set
|
||||
if (!mapEditorStore.map) return
|
||||
|
||||
movingMapObject.value = mapEditorStore.map.mapObjects.find((object) => object.id === id) as MapObjectT
|
||||
movingMapObject.value = mapEditorStore.map.placedMapObjects.find((object) => object.id === id) as MapObjectT
|
||||
|
||||
function handlePointerMove(pointer: Phaser.Input.Pointer) {
|
||||
if (!movingMapObject.value) return
|
||||
@ -160,7 +160,7 @@ function rotateMapObject(id: string) {
|
||||
// Check if map is set
|
||||
if (!mapEditorStore.map) return
|
||||
|
||||
mapEditorStore.map.mapObjects = mapEditorStore.map.mapObjects.map((object) => {
|
||||
mapEditorStore.map.placedMapObjects = mapEditorStore.map.placedMapObjects.map((object) => {
|
||||
if (object.id === id) {
|
||||
return {
|
||||
...object,
|
||||
@ -175,7 +175,7 @@ function deleteMapObject(id: string) {
|
||||
// Check if map is set
|
||||
if (!mapEditorStore.map) return
|
||||
|
||||
mapEditorStore.map.mapObjects = mapEditorStore.map.mapObjects.filter((object) => object.id !== id)
|
||||
mapEditorStore.map.placedMapObjects = mapEditorStore.map.placedMapObjects.filter((object) => object.id !== id)
|
||||
selectedMapObject.value = null
|
||||
}
|
||||
|
||||
@ -210,7 +210,8 @@ watch(
|
||||
(newObjects) => {
|
||||
if (!mapEditorStore.map) return
|
||||
|
||||
const updatedMapObjects = mapEditorStore.map.mapObjects.map((mapObject) => {
|
||||
console.log(mapEditorStore.map.placedMapObjects)
|
||||
const updatedMapObjects = mapEditorStore.map.placedMapObjects.map((mapObject) => {
|
||||
const updatedObject = newObjects.find((obj) => obj.id === mapObject.object.id)
|
||||
if (updatedObject) {
|
||||
return {
|
||||
|
@ -50,7 +50,7 @@ const width = ref(0)
|
||||
const height = ref(0)
|
||||
|
||||
function submit() {
|
||||
gameStore.connection.emit('gm:map_editor:map:create', { name: name.value, width: width.value, height: height.value }, (response: Map[]) => {
|
||||
gameStore.connection.emit('gm:mapObject:create', { name: name.value, width: width.value, height: height.value }, (response: Map[]) => {
|
||||
mapEditorStore.setMapList(response)
|
||||
})
|
||||
mapEditorStore.toggleCreateMapModal()
|
||||
|
@ -41,20 +41,20 @@ onMounted(async () => {
|
||||
})
|
||||
|
||||
function fetchMaps() {
|
||||
gameStore.connection?.emit('gm:map_editor:map:list', {}, (response: Map[]) => {
|
||||
gameStore.connection?.emit('gm:mapObject:list', {}, (response: Map[]) => {
|
||||
mapEditorStore.setMapList(response)
|
||||
})
|
||||
}
|
||||
|
||||
function loadMap(id: number) {
|
||||
gameStore.connection?.emit('gm:map_editor:map:request', { mapId: id }, (response: Map) => {
|
||||
gameStore.connection?.emit('gm:mapObject:request', { mapId: id }, (response: Map) => {
|
||||
mapEditorStore.setMap(response)
|
||||
})
|
||||
mapEditorStore.toggleMapListModal()
|
||||
}
|
||||
|
||||
function deleteMap(id: number) {
|
||||
gameStore.connection?.emit('gm:map_editor:map:delete', { mapId: id }, () => {
|
||||
gameStore.connection?.emit('gm:mapObject:delete', { mapId: id }, () => {
|
||||
fetchMaps()
|
||||
})
|
||||
}
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import config from '@/application/config'
|
||||
import type { Object, PlacedMapObject } from '@/application/types'
|
||||
import type { MapObject, PlacedMapObject } from '@/application/types'
|
||||
import Modal from '@/components/utilities/Modal.vue'
|
||||
import { useGameStore } from '@/stores/gameStore'
|
||||
import { useMapEditorStore } from '@/stores/mapEditorStore'
|
||||
@ -77,8 +77,8 @@ const toggleTag = (tag: string) => {
|
||||
|
||||
onMounted(async () => {
|
||||
isModalOpen.value = true
|
||||
gameStore.connection?.emit('gm:object:list', {}, (response: Object[]) => {
|
||||
mapEditorStore.setObjectList(response)
|
||||
gameStore.connection?.emit('gm:mapObject:list', {}, (response: MapObject[]) => {
|
||||
mapEditorStore.setMapObjectList(response)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
@ -52,7 +52,7 @@ const gameStore = useGameStore()
|
||||
onMounted(fetchMaps)
|
||||
|
||||
function fetchMaps() {
|
||||
gameStore.connection?.emit('gm:map_editor:map:list', {}, (response: Map[]) => {
|
||||
gameStore.connection?.emit('gm:mapObject:list', {}, (response: Map[]) => {
|
||||
mapEditorStore.setMapList(response)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user