Integrate Vantage live map for guild claims [skip ci]
This commit is contained in:
1 parent
52de8c3031
commit
602e7fd0f0
17 files changed
+470
-21
No files matched your search
@@ -7,6 +7,7 @@
|
||||
import { invoke } from '../lib/tauri';
|
||||
import { toast } from '../lib/store.svelte';
|
||||
import type { GuildClaim } from '../lib/types';
|
||||
import VantageMap from './VantageMap.svelte';
|
||||
|
||||
let {
|
||||
instanceId,
|
||||
@@ -22,7 +23,7 @@
|
||||
onunclaim?: (claimId: number) => void;
|
||||
} = $props();
|
||||
|
||||
let servers = $state<Array<{ id: number; name: string; instance_id: string }>>([]);
|
||||
let servers = $state<Array<{ id: number; name: string; instance_id: string; map_url: string }>>([]);
|
||||
let serverId = $state<number | null>(null);
|
||||
let dimension = $state<'minecraft:overworld' | 'minecraft:the_nether' | 'minecraft:the_end'>('minecraft:overworld');
|
||||
let centerX = $state(0);
|
||||
@@ -31,8 +32,13 @@
|
||||
let claims = $state<GuildClaim[]>([]);
|
||||
let loading = $state(false);
|
||||
let claiming = $state(false);
|
||||
let claimLoad = 0;
|
||||
let hoveredChunk = $state<{ x: number; z: number } | null>(null);
|
||||
let selectedChunk = $state<{ x: number; z: number } | null>(null);
|
||||
let mapDimensions = $state<string[]>([]);
|
||||
let mapFailed = $state(false);
|
||||
const mapUrl = $derived(servers.find((s) => s.id === serverId)?.map_url || '');
|
||||
$effect(() => { mapUrl; mapFailed = false; mapDimensions = []; });
|
||||
|
||||
const dimensions = [
|
||||
{ id: 'minecraft:overworld', label: 'Overworld', icon: Globe },
|
||||
@@ -41,20 +47,23 @@
|
||||
] as const;
|
||||
|
||||
async function loadClaims() {
|
||||
const request = ++claimLoad;
|
||||
if (!instanceId || !serverId) { claims = []; return; }
|
||||
loading = true;
|
||||
claims = [];
|
||||
try {
|
||||
claims = await invoke<GuildClaim[]>('get_guild_claims', {
|
||||
const next = await invoke<GuildClaim[]>('get_guild_claims', {
|
||||
instanceId,
|
||||
serverId,
|
||||
centerX,
|
||||
centerZ,
|
||||
dimension
|
||||
});
|
||||
if (request === claimLoad) claims = next;
|
||||
} catch (e: any) {
|
||||
toast(e?.message ?? 'Failed to load territory claims', 'error');
|
||||
if (request === claimLoad) toast(e?.message ?? 'Failed to load territory claims', 'error');
|
||||
} finally {
|
||||
loading = false;
|
||||
if (request === claimLoad) loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +158,8 @@
|
||||
<button
|
||||
class="dim-btn"
|
||||
class:active={dimension === dim.id}
|
||||
onclick={() => { dimension = dim.id; selectedChunk = null; }}
|
||||
disabled={!!mapUrl && !mapFailed && mapDimensions.length > 0 && !mapDimensions.includes(dim.id)}
|
||||
onclick={() => { dimension = dim.id; claims = []; selectedChunk = null; }}
|
||||
>
|
||||
<DimIcon size={14} />
|
||||
<span>{dim.label}</span>
|
||||
@@ -175,6 +185,22 @@
|
||||
</div>
|
||||
|
||||
<!-- Main Chunk Map Canvas / Grid -->
|
||||
{#if mapUrl && !mapFailed}
|
||||
{#key `${serverId}:${mapUrl}`}
|
||||
<VantageMap
|
||||
world={mapUrl}
|
||||
serverId={serverId!}
|
||||
{claims}
|
||||
{dimension}
|
||||
{myGuildId}
|
||||
onselect={(x, z) => { selectedChunk = { x, z }; }}
|
||||
ondimension={(value) => { if (dimension !== value) { dimension = value; claims = []; selectedChunk = null; } }}
|
||||
ondimensions={(value) => { mapDimensions = value; }}
|
||||
oncenterchange={(x, z) => { centerX = x; centerZ = z; }}
|
||||
onerror={(message) => { toast(`Live map unavailable: ${message}. Showing chunk grid.`, 'error'); mapFailed = true; }}
|
||||
/>
|
||||
{/key}
|
||||
{:else}
|
||||
<div class="grid-wrapper">
|
||||
<div
|
||||
class="chunk-grid"
|
||||
@@ -214,6 +240,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Legend & Action Bar -->
|
||||
<div class="map-footer">
|
||||
|
||||
Reference in new issue
Block a user