Loading...
diff --git a/src/components/MainMap.vue b/src/components/MainMap.vue index de8c5ab..ee3db6b 100644 --- a/src/components/MainMap.vue +++ b/src/components/MainMap.vue @@ -9,7 +9,8 @@ import { BlockPos, Chunk, ChunkPos, DensityFunction, Identifier, RandomState, St import YSlider from './YSlider.vue'; import { useSearchStore } from '../stores/useBiomeSearchStore'; import { useSettingsStore } from '../stores/useSettingsStore'; -import { useLoadedDimensionStore } from '../stores/useLoadedDimensionStore' +import { useLoadedDimensionStore } from '../stores/useLoadedDimensionStore'; +import { useCoordinateStore } from '../stores/useCoordinateStore' import { CachedBiomeSource } from '../util/CachedBiomeSource'; import MapButton from './MapButton.vue'; import { SpawnTarget } from '../util/SpawnTarget'; @@ -19,6 +20,7 @@ import { versionMetadata } from "../util"; const searchStore = useSearchStore() const settingsStore = useSettingsStore() const loadedDimensionStore = useLoadedDimensionStore() +const coordinateStore = useCoordinateStore() const i18n = useI18n() let biomeLayer: BiomeLayer @@ -307,6 +309,43 @@ watch(searchStore.structures, () => { updateMarkers() }) +// Coordinate navigation function +function navigateToCoordinates(x: number, z: number) { + if (!map) return + + const crs = map.options.crs! + const point = new L.Point(x, -z) + const latlng = crs.unproject(point) + + // Center the map on the coordinates with a smooth animation + map.setView(latlng, map.getZoom(), { + animate: true, + duration: 0.5 + }) +} + +// Get current map center coordinates +function getCurrentMapCenter() { + if (!map) return + + const center = map.getCenter() + const crs = map.options.crs! + const point = crs.project(center) + + // Convert to Minecraft coordinates + const x = Math.round(point.x) + const z = Math.round(-point.y) + + // Update the coordinate store with current location + coordinateStore.setCoordinates(x, z) +} + +// Expose the navigation functions +defineExpose({ + navigateToCoordinates, + getCurrentMapCenter +}) + diff --git a/src/components/MenuButtons.vue b/src/components/MenuButtons.vue index fb7befa..041b12f 100644 --- a/src/components/MenuButtons.vue +++ b/src/components/MenuButtons.vue @@ -3,19 +3,23 @@ import { ref } from 'vue'; import { useDatapackStore } from '../stores/useDatapackStore'; import FindBiomeDropdown from './dropdown/FindBiomeDropdown.vue'; import OpenDropdown from './dropdown/OpenDropdown.vue'; +import CoordinateDropdown from './dropdown/CoordinateDropdown.vue'; import { vOnClickOutside }from '@vueuse/components'; import { useSearchStore } from '../stores/useBiomeSearchStore'; +import { useCoordinateStore } from '../stores/useCoordinateStore'; import StructureDropdown from './dropdown/StructureDropdown.vue'; import { useSettingsStore } from '../stores/useSettingsStore'; import { EventTracker } from '../util/EventTracker'; const datapackStore = useDatapackStore() const searchStore = useSearchStore() +const coordinateStore = useCoordinateStore() const settingsStore = useSettingsStore() const openDropdownOpen = ref(false) const searchBiomeDropdownOpen = ref(false) const structureDropdownOpen = ref(false) +const coordinateDropdownOpen = ref(false) function reload(event: MouseEvent){ EventTracker.track("reload") @@ -39,6 +43,24 @@ function clearStructureSearch() { structureDropdownOpen.value = false } +function clearCoordinateSearch() { + coordinateStore.clear() + coordinateDropdownOpen.value = false +} + +const emit = defineEmits<{ + navigateToCoordinates: [x: number, z: number] + getCurrentMapCenter: [] +}>() + +function handleCoordinateNavigation(x: number, z: number) { + emit('navigateToCoordinates', x, z) +} + +function handleGetCurrentLocation() { + emit('getCurrentMapCenter') +} + @@ -93,6 +115,20 @@ function clearStructureSearch() { @dblclick.prevent="clearStructureSearch" /> +