fix: a village that no longer exists is forgotten and the player picks a world again
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
87f2dc8bd3
commit
72c79240f9
|
|
@ -32,5 +32,16 @@ export function useCurrentWorld() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { current, enter }
|
/** Drop a remembered village that no longer exists (a world reset, a conquest). */
|
||||||
|
function forget(villageId: number) {
|
||||||
|
if (current.value?.villageId !== villageId) return
|
||||||
|
current.value = { ...current.value, villageId: null }
|
||||||
|
try {
|
||||||
|
localStorage.setItem(KEY, JSON.stringify(current.value))
|
||||||
|
} catch {
|
||||||
|
// nothing remembered, nothing to drop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { current, enter, forget }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type { BuildingType, Cost, MarchPlan, MovementType, Resource, Resources, TravelMode, Units, UnitType, VillageState, VillageUpdated } from '~/types/game'
|
import type { BuildingType, Cost, GameError, MarchPlan, MovementType, Resource, Resources, TravelMode, Units, UnitType, VillageState, VillageUpdated } from '~/types/game'
|
||||||
import type { InjectionKey } from 'vue'
|
import type { InjectionKey } from 'vue'
|
||||||
|
|
||||||
const RESOURCES: Resource[] = ['wood', 'clay', 'iron', 'food']
|
const RESOURCES: Resource[] = ['wood', 'clay', 'iron', 'food']
|
||||||
|
|
@ -15,6 +15,7 @@ export function useVillage(villageId: number) {
|
||||||
const unreadReports = useUnreadReports()
|
const unreadReports = useUnreadReports()
|
||||||
// Projections and countdowns run on the server's clock.
|
// Projections and countdowns run on the server's clock.
|
||||||
const { now, sync } = useServerClock()
|
const { now, sync } = useServerClock()
|
||||||
|
const { forget } = useCurrentWorld()
|
||||||
|
|
||||||
async function run(event: string, data: object = {}) {
|
async function run(event: string, data: object = {}) {
|
||||||
busy.value = true
|
busy.value = true
|
||||||
|
|
@ -26,6 +27,12 @@ export function useVillage(villageId: number) {
|
||||||
unreadReports.value = state.unread_reports
|
unreadReports.value = state.unread_reports
|
||||||
return true
|
return true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
// The village is gone (the world was reset): forget it and pick a world again.
|
||||||
|
if (event === 'village.show' && (e as Partial<GameError>)?.code === 'not_found') {
|
||||||
|
forget(villageId)
|
||||||
|
await navigateTo('/worlds')
|
||||||
|
return false
|
||||||
|
}
|
||||||
error.value = errorText(e)
|
error.value = errorText(e)
|
||||||
return false
|
return false
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue