1
0
forked from noxious/client

Minor improvements

This commit is contained in:
2025-02-06 13:22:52 +01:00
parent 7730fd81bd
commit 90f3056e08
4 changed files with 48 additions and 9 deletions

View File

@ -33,7 +33,7 @@
<input class="input-field" v-model="mapObjectOriginY" name="originY" id="originY" type="number" />
</div>
</div>
<button class="btn-cyan px-4 py-1.5 min-w-24" type="submit">Save</button>
<button class="btn-cyan px-4 py-1.5 min-w-24" @click="handleUpdate">Save</button>
</form>
</div>
</template>
@ -41,9 +41,12 @@
</template>
<script setup lang="ts">
import type { Map as MapT, PlacedMapObject } from '@/application/types'
import type { Map as MapT, MapObject, PlacedMapObject } from '@/application/types'
import Modal from '@/components/utilities/Modal.vue'
import { ref } from 'vue'
import { onMounted, ref } from 'vue'
import { MapObjectStorage } from '@/storage/storages'
import { useGameStore } from '@/stores/gameStore'
import { useMapEditorComposable } from '@/composables/useMapEditorComposable'
const props = defineProps<{
placedMapObject: PlacedMapObject
@ -52,6 +55,11 @@ const props = defineProps<{
const emit = defineEmits(['move', 'rotate', 'delete'])
const gameStore = useGameStore()
const mapEditor = useMapEditorComposable()
const mapObjectStorage = new MapObjectStorage()
const mapObject = ref<MapObject | null>(null)
const showMapObjectSettings = ref(false)
const mapObjectName = ref('')
const mapObjectOriginX = ref(0)
@ -68,4 +76,37 @@ const handleRotate = () => {
const handleDelete = () => {
emit('delete', props.placedMapObject.id, props.map)
}
async function handleUpdate () {
if (!mapObject.value) return
gameStore.connection?.emit(
'gm:mapObject:update',
{
id: props.placedMapObject.mapObject as string,
name: mapObjectName.value,
originX: mapObjectOriginX.value,
originY: mapObjectOriginY.value,
}, async (response: boolean) => {
if (!response) return
// Update mapObject in storage
await mapObjectStorage.update(mapObject.value!.id, {
name: mapObjectName.value,
originX: mapObjectOriginX.value,
originY: mapObjectOriginY.value
})
}
)
}
onMounted(async () => {
if (!props.placedMapObject.mapObject) return
mapObject.value = await mapObjectStorage.get(props.placedMapObject.mapObject as string)
if (!mapObject.value) return
mapObjectName.value = mapObject.value.name
mapObjectOriginX.value = mapObject.value.originX
mapObjectOriginY.value = mapObject.value.originY
})
</script>