diff --git a/package-lock.json b/package-lock.json index d5ccded..ffab0d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2535,9 +2535,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.87", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.87.tgz", - "integrity": "sha512-mPFwmEWmRivw2F8x3w3l2m6htAUN97Gy0kwpO++2m9iT1Gt8RCFVUfv9U/sIbHJ6rY4P6/ooqFL/eL7ock+pPg==", + "version": "1.5.88", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.88.tgz", + "integrity": "sha512-K3C2qf1o+bGzbilTDCTBhTQcMS9KW60yTAaTeeXsfvQuTDDwlokLam/AdqlqcSy9u4UainDgsHV23ksXAOgamw==", "dev": true, "license": "ISC" }, diff --git a/src/application/utilities.ts b/src/application/utilities.ts index 5f4f9fc..55e5ed4 100644 --- a/src/application/utilities.ts +++ b/src/application/utilities.ts @@ -1,6 +1,6 @@ -import type { BaseStorage } from '@/storage/baseStorage' import config from '@/application/config' import type { HttpResponse } from '@/application/types' +import type { BaseStorage } from '@/storage/baseStorage' export function uuidv4() { return '10000000-1000-4000-8000-100000000000'.replace(/[018]/g, (c) => (+c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (+c / 4)))).toString(16)) @@ -49,4 +49,4 @@ export async function downloadCache(e await storage.add(item, overwrite) } -} \ No newline at end of file +} diff --git a/src/components/gameMaster/assetManager/partials/tile/TileDetails.vue b/src/components/gameMaster/assetManager/partials/tile/TileDetails.vue index 00c5d9b..14c4799 100644 --- a/src/components/gameMaster/assetManager/partials/tile/TileDetails.vue +++ b/src/components/gameMaster/assetManager/partials/tile/TileDetails.vue @@ -33,7 +33,6 @@ import { computed, onBeforeUnmount, onMounted, ref, toRaw, watch } from 'vue' const gameStore = useGameStore() const assetManagerStore = useAssetManagerStore() -const mapEditorStore = useMapEditorStore() const selectedTile = computed(() => assetManagerStore.selectedTile) @@ -72,10 +71,6 @@ function refreshTileList(unsetSelectedTile = true) { if (unsetSelectedTile) { assetManagerStore.setSelectedTile(null) } - - if (mapEditorStore.active) { - mapEditorStore.setTileList(response) - } }) } diff --git a/src/components/gameMaster/mapEditor/Map.vue b/src/components/gameMaster/mapEditor/Map.vue index d600ccb..7a2af2a 100644 --- a/src/components/gameMaster/mapEditor/Map.vue +++ b/src/components/gameMaster/mapEditor/Map.vue @@ -9,7 +9,7 @@ import MapEventTiles from '@/components/gameMaster/mapEditor/mapPartials/MapEven import MapTiles from '@/components/gameMaster/mapEditor/mapPartials/MapTiles.vue' import PlacedMapObjects from '@/components/gameMaster/mapEditor/mapPartials/PlacedMapObjects.vue' import { useMapEditorStore } from '@/stores/mapEditorStore' -import { onUnmounted, shallowRef } from 'vue' +import { onMounted, onUnmounted, shallowRef } from 'vue' const mapEditorStore = useMapEditorStore() const tileMap = shallowRef() diff --git a/src/components/gameMaster/mapEditor/mapPartials/MapTiles.vue b/src/components/gameMaster/mapEditor/mapPartials/MapTiles.vue index 4b55b04..cbf80e6 100644 --- a/src/components/gameMaster/mapEditor/mapPartials/MapTiles.vue +++ b/src/components/gameMaster/mapEditor/mapPartials/MapTiles.vue @@ -5,17 +5,19 @@ diff --git a/src/components/gameMaster/mapEditor/partials/TileList.vue b/src/components/gameMaster/mapEditor/partials/TileList.vue index 6728bd7..b4e025b 100644 --- a/src/components/gameMaster/mapEditor/partials/TileList.vue +++ b/src/components/gameMaster/mapEditor/partials/TileList.vue @@ -228,9 +228,5 @@ function isActiveTile(tile: Tile): boolean { onMounted(async () => { isModalOpen.value = true - gameStore.connection?.emit('gm:tile:list', {}, (response: Tile[]) => { - mapEditorStore.setTileList(response) - response.forEach((tile) => processTile(tile)) - }) }) diff --git a/src/components/gameMaster/mapEditor/partials/Toolbar.vue b/src/components/gameMaster/mapEditor/partials/Toolbar.vue index b5c2d1e..97cb68c 100644 --- a/src/components/gameMaster/mapEditor/partials/Toolbar.vue +++ b/src/components/gameMaster/mapEditor/partials/Toolbar.vue @@ -1,7 +1,7 @@ diff --git a/src/composables/useMapEditorComposable.ts b/src/composables/useMapEditorComposable.ts index e69de29..af344b4 100644 --- a/src/composables/useMapEditorComposable.ts +++ b/src/composables/useMapEditorComposable.ts @@ -0,0 +1,31 @@ +import type { Map } from '@/application/types' +import { ref } from 'vue' + +const currentMap = ref(null) + +export function useMapEditorComposable() { + const loadMap = (map: Map) => { + currentMap.value = map + } + + const updateProperty = (property: K, value: Map[K]) => { + if (currentMap.value) { + currentMap.value[property] = value + } + } + + const clearMap = () => { + if (!currentMap.value) return + + currentMap.value.placedMapObjects = [] + currentMap.value.mapEventTiles = [] + currentMap.value.tiles = [] + } + + return { + currentMap, + loadMap, + updateProperty, + clearMap + } +} diff --git a/src/storage/baseStorage.ts b/src/storage/baseStorage.ts index 479e264..457c975 100644 --- a/src/storage/baseStorage.ts +++ b/src/storage/baseStorage.ts @@ -23,6 +23,14 @@ export class BaseStorage { } } + async update(id: string, item: Partial) { + try { + await this.dexie.table(this.tableName).update(id, item) + } catch (error) { + console.error(`Failed to update ${this.tableName} ${id}:`, error) + } + } + async delete(id: string) { try { await this.dexie.table(this.tableName).delete(id) diff --git a/src/stores/mapEditorStore.ts b/src/stores/mapEditorStore.ts index fd25d5a..8c7906b 100644 --- a/src/stores/mapEditorStore.ts +++ b/src/stores/mapEditorStore.ts @@ -1,8 +1,8 @@ -import type { Map, MapEffect, MapObject, Tile, UUID } from '@/application/types' +import type { MapObject } from '@/application/types' import { defineStore } from 'pinia' export type TeleportSettings = { - toMap: Map | null + toMapId: string toPositionX: number toPositionY: number toRotation: number @@ -12,12 +12,9 @@ export const useMapEditorStore = defineStore('mapEditor', { state: () => { return { active: false, - mapId: '', tool: 'move', drawMode: 'tile', eraserMode: 'tile', - tileList: [] as Tile[], - mapObjectList: [] as MapObject[], selectedTile: '', selectedMapObject: null as MapObject | null, isTileListModalShown: false, @@ -26,15 +23,8 @@ export const useMapEditorStore = defineStore('mapEditor', { isCreateMapModalShown: false, isSettingsModalShown: false, shouldClearTiles: false, - mapSettings: { - name: '', - width: 0, - height: 0, - pvp: false, - mapEffects: [] as MapEffect[] - }, teleportSettings: { - toMap: null, + toMapId: '', toPositionX: 0, toPositionY: 0, toRotation: 0 @@ -46,24 +36,6 @@ export const useMapEditorStore = defineStore('mapEditor', { if (this.active) this.reset() this.active = !this.active }, - setMapId(mapId: UUID) { - this.mapId = mapId - }, - setMapName(name: string) { - this.mapSettings.name = name - }, - setMapWidth(width: number) { - this.mapSettings.width = width - }, - setMapHeight(height: number) { - this.mapSettings.height = height - }, - setMapPvp(pvp: boolean) { - this.mapSettings.pvp = pvp - }, - setMapEffects(mapEffects: MapEffect[]) { - this.mapSettings.mapEffects = mapEffects - }, setTool(tool: string) { this.tool = tool }, @@ -73,12 +45,6 @@ export const useMapEditorStore = defineStore('mapEditor', { setEraserMode(mode: string) { this.eraserMode = mode }, - setTileList(tiles: Tile[]) { - this.tileList = tiles - }, - setMapObjectList(objects: MapObject[]) { - this.mapObjectList = objects - }, setSelectedTile(tile: string) { this.selectedTile = tile }, @@ -105,9 +71,6 @@ export const useMapEditorStore = defineStore('mapEditor', { this.shouldClearTiles = false }, reset() { - this.mapId = '' - this.tileList = [] - this.mapObjectList = [] this.tool = 'move' this.drawMode = 'tile' this.selectedTile = ''