Enhance API and frontend components for character management and map visibility

- Updated API documentation to include `ownedByMe` field in character responses, indicating if a character was last updated by the current user's tokens.
- Modified MapView component to track and display the live status based on user-owned characters.
- Enhanced map data handling to exclude hidden maps for non-admin users and improved character icon representation on the map.
- Refactored character data structures to support new properties and ensure accurate rendering in the frontend.
This commit is contained in:
2026-03-01 17:21:15 +03:00
parent 6a6977ddff
commit 7bdaa6bfcc
9 changed files with 82 additions and 16 deletions

View File

@@ -73,7 +73,7 @@
<span class="text-base-content/80">{{ measurePointA == null ? 'Click first point on map' : 'Click second point' }}</span>
</template>
<template v-else>
<span class="font-mono">Distance: {{ measureDistance.toFixed(2) }} units</span>
<span class="font-mono">Distance: {{ measureDistance.toFixed(3) }} units</span>
<button type="button" class="btn btn-ghost btn-xs ml-2" @click="clearMeasure">Clear</button>
</template>
</div>
@@ -146,6 +146,8 @@ const props = withDefaults(
const mapContainerRef = ref<HTMLElement | null>(null)
const mapRef = ref<HTMLElement | null>(null)
const api = useMapApi()
/** Global state for navbar Live/Offline: true when at least one character is owned by current user's tokens. */
const mapLive = useState<boolean>('mapLive', () => false)
const mapLogic = useMapLogic()
const { resolvePath } = useAppPaths()
const mapNavigate = useMapNavigate()
@@ -275,13 +277,18 @@ onMounted(async () => {
])
const mapsList: MapInfo[] = []
const raw = mapsData as Record<string, { ID?: number; Name?: string; id?: number; name?: string; size?: number }>
const raw = mapsData as Record<
string,
{ ID?: number; Name?: string; id?: number; name?: string; size?: number; Hidden?: boolean; hidden?: boolean }
>
for (const id in raw) {
const m = raw[id]
if (!m || typeof m !== 'object') continue
const idVal = m.ID ?? m.id
const nameVal = m.Name ?? m.name
if (idVal == null || nameVal == null) continue
const hidden = !!(m.Hidden ?? m.hidden)
if (hidden) continue
mapsList.push({ ID: Number(idVal), Name: String(nameVal), size: m.size })
}
mapsList.sort((a, b) => (b.size ?? 0) - (a.size ?? 0))
@@ -354,8 +361,10 @@ onMounted(async () => {
},
})
layersManager.updateCharacters(Array.isArray(charactersData) ? charactersData : [])
const charsList = Array.isArray(charactersData) ? charactersData : []
layersManager.updateCharacters(charsList)
players.value = layersManager.getPlayers()
mapLive.value = charsList.some((c) => c.ownedByMe)
if (props.characterId !== undefined && props.characterId >= 0) {
mapLogic.state.trackingCharacterId.value = props.characterId
@@ -386,8 +395,10 @@ onMounted(async () => {
api
.getCharacters()
.then((body) => {
layersManager!.updateCharacters(Array.isArray(body) ? body : [])
const list = Array.isArray(body) ? body : []
layersManager!.updateCharacters(list)
players.value = layersManager!.getPlayers()
mapLive.value = list.some((c) => c.ownedByMe)
})
.catch(() => clearInterval(intervalId!))
}, 2000)
@@ -482,8 +493,8 @@ onMounted(async () => {
if (!measureMode.value) return
e.originalEvent.stopPropagation()
const point = leafletMap!.project(e.latlng, HnHMaxZoom)
const x = Math.floor(point.x / TileSize)
const y = Math.floor(point.y / TileSize)
const x = point.x / TileSize
const y = point.y / TileSize
if (measurePointA.value == null) {
measurePointA.value = { x, y }
} else if (measurePointB.value == null) {