From d7d15026d8168ff871c91fa2ff866c5e80dd5d64 Mon Sep 17 00:00:00 2001 From: David Camp Date: Thu, 7 Aug 2025 19:51:40 -0700 Subject: [PATCH] Add GPS mode toggle and partial implementation --- index.js | 13 ++++++++++++- legend.js | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 990f135..80bb024 100644 --- a/index.js +++ b/index.js @@ -497,9 +497,20 @@ function redrawDynamics(){ for(const marker of MapData.dynamicMarkers){ curSprite = null; marker.visible = false; - if(marker.hidden || (marker.minZoom && MapData.view.scale < marker.minZoom) || (marker.maxZoom && MapData.view.scale > marker.maxZoom)) continue; let markerX = MapData.view.convertX(marker.position.x); let markerY = MapData.view.convertY(marker.position.z); + + // Placing this here means the map should always snap to the player if the toggle is on. + // Placing it after culling means that if the user fast travels the map won't snap to them until manually scrolled to near their position. + if(MapData.layers.gps && marker.type === 'player') { + //This works fine + MapData.view.x = -marker.position.x * MapData.view.scale + mapCanvas.width * 0.5; + //This does not + // MapData.view.y = -marker.position.z * MapData.view.scale; + MapData.view.dirty = true; + } + + if(marker.hidden || (marker.minZoom && MapData.view.scale < marker.minZoom) || (marker.maxZoom && MapData.view.scale > marker.maxZoom)) continue; if(markerX > mapCanvas.width + Config.viewCullMargin || markerX < -Config.viewCullMargin || markerY > mapCanvas.height + Config.viewCullMargin || markerY < -Config.viewCullMargin) continue; // View Culling switch(marker.type){ case 'player': diff --git a/legend.js b/legend.js index bd83411..cf1c0dc 100644 --- a/legend.js +++ b/legend.js @@ -256,7 +256,20 @@ let settingEntries = [ func: state =>{ MapData.layers.player = state; MapData.view.dynDirty = true; - } + }, + children: [ + { + label: 'Follow Player', + tooltip: 'Keep View centered on player', + id: 'toggle_gps', + saveState: true, + state: true, + func: state =>{ + MapData.layers.gps = state; + MapData.view.dynDirty = true; + } + } + ] }, { label: 'Train Cars',