refactor web

This commit is contained in:
bridge
2025-11-21 01:38:41 +08:00
parent 5a51b6638d
commit 41d2103ffc
14 changed files with 863 additions and 559 deletions

View File

@@ -0,0 +1,35 @@
import { ref } from 'vue'
import type { MapMatrix, Region } from '../types/game'
import { gameApi } from '../services/gameApi'
const mapTiles = ref<MapMatrix>([])
const regions = ref<Region[]>([])
const isMapLoaded = ref(false)
let inFlight: Promise<void> | null = null
async function loadMapData() {
if (isMapLoaded.value) return
if (inFlight) return inFlight
inFlight = gameApi.getMap()
.then((data) => {
mapTiles.value = data.data ?? []
regions.value = data.regions ?? []
isMapLoaded.value = mapTiles.value.length > 0
})
.finally(() => {
inFlight = null
})
return inFlight
}
export function useMapData() {
return {
mapTiles,
regions,
isMapLoaded,
loadMapData
}
}