Hot reload for objects when updated inside asset manager so no page reload is required

This commit is contained in:
2024-07-06 22:24:29 +02:00
parent e96b9c9ee9
commit 067478055e
6 changed files with 53 additions and 15 deletions

View File

@ -1,10 +1,12 @@
import { defineStore } from 'pinia'
import { type Asset } from '@/types'
import { type Asset, type Object } from '@/types'
import config from '@/config'
export const useAssetStore = defineStore('assets', {
state: () => ({
assets: [] as Asset[]
assets: [] as Asset[],
tiles: [] as string[],
objects: [] as Object[],
}),
actions: {
setAssets(assets: Asset[]) {
@ -13,6 +15,12 @@ export const useAssetStore = defineStore('assets', {
addAsset(asset: Asset) {
this.assets.push(asset)
},
setTiles(tiles: string[]) {
this.tiles = tiles
},
setObjects(objects: Object[]) {
this.objects = objects
},
fetchAssets() {
fetch(config.server_endpoint + '/assets')
.then((response) => response.json())

View File

@ -1,5 +1,5 @@
import { defineStore } from 'pinia'
import type { Object } from '@/types'
import type { Object, ZoneObject } from '@/types'
export const useZoneEditorStore = defineStore('zoneEditor', {
state: () => ({
@ -7,8 +7,10 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
name: '',
width: 10,
height: 10,
tileList: [] as string[],
tiles: [] as string[][],
objects: [] as Object[],
objectList: [] as Object[],
objects: [] as ZoneObject[],
tool: 'move',
drawMode: 'tile',
selectedTile: '',
@ -28,16 +30,22 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
setHeight(height: number) {
this.height = height
},
setTileList(tiles: string[]) {
this.tileList = tiles
},
setTiles(tiles: string[][]) {
this.tiles = tiles
},
updateTile(x: number, y: number, tile: string) {
this.tiles[y][x] = tile
},
setObjects(objects: Object[]) {
setObjectList(objects: Object[]) {
this.objectList = objects
},
setObjects(objects: ZoneObject[]) {
this.objects = objects
},
updateObject(index: number, object: Object) {
updateObject(index: number, object: ZoneObject) {
this.objects[index] = object
},
setTool(tool: string) {
@ -59,7 +67,9 @@ export const useZoneEditorStore = defineStore('zoneEditor', {
this.name = ''
this.width = 10
this.height = 10
this.tileList = []
this.tiles = []
this.objectList = []
this.objects = []
this.tool = 'move'
this.drawMode = 'tile'