102 lines
4.0 KiB
Vue
102 lines
4.0 KiB
Vue
<template>
|
|
<div class="relative mb-5 flex items-center gap-x-2.5">
|
|
<input v-model="searchQuery" class="input-field flex-grow" placeholder="Search..." @input="handleSearch" />
|
|
<label for="upload-asset" class="bg-cyan text-white border border-solid border-white/25 rounded drop-shadow-20 p-2.5 inline-flex items-center justify-center hover:bg-cyan-800 hover:cursor-pointer">
|
|
<input class="hidden" id="upload-asset" ref="objectUploadField" type="file" accept="image/png" multiple @change="handleFileUpload" />
|
|
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
|
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4" />
|
|
</svg>
|
|
</label>
|
|
</div>
|
|
<div v-bind="containerProps" class="overflow-y-auto relative p-2.5 rounded-md default-border bg-gray" @scroll="onScroll">
|
|
<div v-bind="wrapperProps" ref="elementToScroll" class="flex flex-col gap-2.5">
|
|
<a v-for="{ data: mapObject } in list" :key="mapObject.id" class="relative p-2.5 cursor-pointer block rounded hover:bg-cyan group" :class="{ 'bg-cyan': assetManagerStore.selectedMapObject?.id === mapObject.id }" @click="assetManagerStore.setSelectedMapObject(mapObject as MapObject)">
|
|
<div class="flex items-center gap-2.5">
|
|
<div class="h-7 w-16 max-w-16 flex justify-center">
|
|
<img class="h-7" :src="`${config.server_endpoint}/assets/map_objects/${mapObject.id}.png`" alt="Object" />
|
|
</div>
|
|
<span :class="{ 'text-white': assetManagerStore.selectedMapObject?.id === mapObject.id }">{{ mapObject.name }}</span>
|
|
</div>
|
|
</a>
|
|
</div>
|
|
<div class="absolute w-12 h-12 bottom-2.5 right-2.5">
|
|
<button class="fixed min-w-[unset] w-12 h-12 rounded-md bg-cyan p-0 hover:bg-cyan-800" v-show="hasScrolled" @click="toTop">
|
|
<img class="invert w-8 h-8 center-element rotate-180" src="/assets/icons/mapEditor/chevron.svg" alt="" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import config from '@/application/config'
|
|
import type { MapObject } from '@/application/types'
|
|
import { useAssetManagerStore } from '@/stores/assetManagerStore'
|
|
import { useGameStore } from '@/stores/gameStore'
|
|
import { useVirtualList } from '@vueuse/core'
|
|
import { computed, onMounted, ref } from 'vue'
|
|
|
|
const gameStore = useGameStore()
|
|
const objectUploadField = ref(null)
|
|
const assetManagerStore = useAssetManagerStore()
|
|
|
|
const searchQuery = ref('')
|
|
|
|
const hasScrolled = ref(false)
|
|
const elementToScroll = ref()
|
|
|
|
const handleFileUpload = (e: Event) => {
|
|
const files = (e.target as HTMLInputElement).files
|
|
if (!files) return
|
|
gameStore.connection?.emit('gm:mapObject:upload', files, (response: boolean) => {
|
|
console.log(response)
|
|
if (!response) {
|
|
if (config.development) console.error('Failed to upload object')
|
|
return
|
|
}
|
|
|
|
gameStore.connection?.emit('gm:mapObject:list', {}, (response: MapObject[]) => {
|
|
assetManagerStore.setMapObjectList(response)
|
|
})
|
|
})
|
|
}
|
|
|
|
const handleSearch = () => {
|
|
// Trigger a re-render of the virtual list
|
|
virtualList.value?.scrollTo(0)
|
|
}
|
|
|
|
const filteredObjects = computed(() => {
|
|
if (!searchQuery.value) {
|
|
return assetManagerStore.mapObjectList
|
|
}
|
|
return assetManagerStore.mapObjectList.filter((object) => object.name.toLowerCase().includes(searchQuery.value.toLowerCase()))
|
|
})
|
|
|
|
const { list, containerProps, wrapperProps, scrollTo } = useVirtualList(filteredObjects, {
|
|
itemHeight: 48
|
|
})
|
|
|
|
const virtualList = ref({ scrollTo })
|
|
|
|
const onScroll = () => {
|
|
let scrollTop = elementToScroll.value.style.marginTop.replace('px', '')
|
|
|
|
if (scrollTop > 80) {
|
|
hasScrolled.value = true
|
|
} else if (scrollTop <= 80) {
|
|
hasScrolled.value = false
|
|
}
|
|
}
|
|
|
|
function toTop() {
|
|
virtualList.value?.scrollTo(0)
|
|
}
|
|
|
|
onMounted(() => {
|
|
gameStore.connection?.emit('gm:mapObject:list', {}, (response: MapObject[]) => {
|
|
console.log(response)
|
|
assetManagerStore.setMapObjectList(response)
|
|
})
|
|
})
|
|
</script>
|