Add an Autorun setting that runs when the path is long enough.
Client-only gait switching resumes after stamina recovers to half; following skips autorun.
@@ -20,6 +20,7 @@
20
20
<button id="leave" type="button">Leave world</button>
21
21
</div>
22
22
<button id="settings-toggle" type="button" hidden title="Settings" aria-label="Settings">⚙</button>
23
<div id="xp-gain-hud" hidden aria-live="polite"></div>
23
24
<aside id="settings-panel" hidden>
24
25
<header>
25
26
<h2>Settings</h2>
@@ -53,6 +54,13 @@
53
54
<button type="button" data-graphics-key="softTerrain" data-graphics-value="off">Off</button>
54
55
</div>
55
56
</section>
57
<section class="settings-group">
58
<h3>Autorun</h3>
59
<div class="settings-options">
60
<button type="button" data-graphics-key="autorun" data-graphics-value="on">On</button>
61
<button type="button" data-graphics-key="autorun" data-graphics-value="off">Off</button>
62
</div>
63
</section>
56
64
</aside>
57
65
<div id="toast-stack" aria-live="polite"></div>
58
66
<div id="world-tooltip" hidden></div>
@@ -20,6 +20,7 @@20
<button id="leave" type="button">Leave world</button>20
<button id="leave" type="button">Leave world</button>21
</div>21
</div>22
<button id="settings-toggle" type="button" hidden title="Settings" aria-label="Settings">⚙</button>22
<button id="settings-toggle" type="button" hidden title="Settings" aria-label="Settings">⚙</button>23
<div id="xp-gain-hud" hidden aria-live="polite"></div>23
<aside id="settings-panel" hidden>24
<aside id="settings-panel" hidden>24
<header>25
<header>25
<h2>Settings</h2>26
<h2>Settings</h2>@@ -53,6 +54,13 @@53
<button type="button" data-graphics-key="softTerrain" data-graphics-value="off">Off</button>54
<button type="button" data-graphics-key="softTerrain" data-graphics-value="off">Off</button>54
</div>55
</div>55
</section>56
</section>57
<section class="settings-group">58
<h3>Autorun</h3>59
<div class="settings-options">60
<button type="button" data-graphics-key="autorun" data-graphics-value="on">On</button>61
<button type="button" data-graphics-key="autorun" data-graphics-value="off">Off</button>62
</div>63
</section>56
</aside>64
</aside>57
<div id="toast-stack" aria-live="polite"></div>65
<div id="toast-stack" aria-live="polite"></div>58
<div id="world-tooltip" hidden></div>66
<div id="world-tooltip" hidden></div>@@ -118,4 +118,4 @@ export function initGraphicsSettings ({ onChange, onSuppressWorldClick })
118
118
};
119
119
}
120
120
121
export { ViewDistance, LightingMode, BloomMode };
121
export { ViewDistance, LightingMode, BloomMode, AutorunMode };
@@ -118,4 +118,4 @@ export function initGraphicsSettings ({ onChange, onSuppressWorldClick })118
};118
};119
}119
}120
120
121
export { ViewDistance, LightingMode, BloomMode };121
export { ViewDistance, LightingMode, BloomMode, AutorunMode };@@ -95,9 +95,100 @@ let pendingInteract = null;
95
95
let uiFocus = null;
96
96
/** Last approach moveTo so we do not re-path every frame (resets server walkCarry). */
97
97
let approachMove = null;
98
/** Client-tracked follow target; server follow owns gait while this is set. */
99
let followTargetId = null;
100
/** Destination of the active click/approach moveTo for autorun distance checks. */
101
let moveDest = null;
102
/** After stamina hits 0 while autorunning, wait until ≥50% before running again. */
103
let autorunWaitingStamina = false;
98
104
/** Framework can report mousePressed for two frames; latch so one physical click is one command. */
99
105
let leftClickConsumed = false;
100
106
107
const AUTORUN_DISTANCE_TILES = 3;
108
const AUTORUN_STAMINA_RESUME_RATIO = 0.5;
109
110
function sendPlayerMoveTo (tileX, tileY)
111
{
112
followTargetId = null;
113
moveDest = { tileX: tileX | 0, tileY: tileY | 0 };
114
socket.send({ type: MessageType.moveTo, tileX: moveDest.tileX, tileY: moveDest.tileY });
115
syncAutorun();
116
}
117
118
function sendPlayerFollow (targetEntityId)
119
{
120
followTargetId = targetEntityId | 0;
121
moveDest = null;
122
autorunWaitingStamina = false;
123
socket.send({ type: MessageType.follow, targetEntityId: followTargetId });
124
}
125
126
function requestGaitIfNeeded (next)
127
{
128
if (next !== GAIT.walk && next !== GAIT.run)
129
{ return; }
130
if (next === gait)
131
{ return; }
132
if (next === GAIT.run && (staminaUi?.getCurrent?.() ?? 0) <= 0)
133
{ return; }
134
socket.send({ type: MessageType.setGait, gait: next });
135
if (next === GAIT.walk)
136
{
137
gait = next;
138
const el = document.getElementById("gait");
139
if (el)
140
{ el.textContent = gait; }
141
}
142
}
143
144
function syncAutorun ()
145
{
146
if (!playing || followTargetId != null)
147
{ return; }
148
const settings = graphicsSettingsUi?.getSettings?.() ?? {};
149
if (settings.autorun !== "on")
150
{ return; }
151
const local = view?.entities?.get(view.localEntityId);
152
if (!local || !moveDest)
153
{ return; }
154
if (local.tileX === moveDest.tileX && local.tileY === moveDest.tileY)
155
{
156
moveDest = null;
157
autorunWaitingStamina = false;
158
requestGaitIfNeeded(GAIT.walk);
159
return;
160
}
161
const dist = chebyshev(local.tileX, local.tileY, moveDest.tileX, moveDest.tileY);
162
const wantRun = dist > AUTORUN_DISTANCE_TILES;
163
const current = staminaUi?.getCurrent?.() ?? 0;
164
const max = Math.max(1, staminaUi?.getMax?.() ?? 1);
165
if (gait === GAIT.run && current <= 0)
166
{ autorunWaitingStamina = true; }
167
if (autorunWaitingStamina)
168
{
169
if (wantRun && current / max >= AUTORUN_STAMINA_RESUME_RATIO)
170
{
171
autorunWaitingStamina = false;
172
requestGaitIfNeeded(GAIT.run);
173
}
174
else
175
{ requestGaitIfNeeded(GAIT.walk); }
176
return;
177
}
178
if (wantRun)
179
{
180
if (current <= 0)
181
{
182
autorunWaitingStamina = true;
183
requestGaitIfNeeded(GAIT.walk);
184
}
185
else
186
{ requestGaitIfNeeded(GAIT.run); }
187
}
188
else
189
{ requestGaitIfNeeded(GAIT.walk); }
190
}
191
101
192
function consumeWorldClick ()
102
193
{
103
194
leftClickConsumed = true;
@@ -185,6 +276,7 @@ function applyGraphicsSettings (settings)
185
276
viewDistance: settings.viewDistance
186
277
});
187
278
}
279
syncAutorun();
188
280
}
189
281
190
282
function clearPendingPickup ()
@@ -268,7 +360,7 @@ function approachAdjacentTile (tileX, tileY)
268
360
destX,
269
361
destY
270
362
};
271
socket.send({ type: MessageType.moveTo, tileX: destX, tileY: destY });
363
sendPlayerMoveTo(destX, destY);
272
364
return false;
273
365
}
274
366
@@ -723,7 +815,7 @@ function requestPickup (ground)
723
815
flushPendingPickup();
724
816
return;
725
817
}
726
socket.send({ type: MessageType.moveTo, tileX: ground.tileX, tileY: ground.tileY });
818
sendPlayerMoveTo(ground.tileX, ground.tileY);
727
819
}
728
820
729
821
function flushPendingPickup ()
@@ -852,7 +944,7 @@ function handleLeftClick (mouseX, mouseY)
852
944
else
853
945
{
854
946
clearAllPendingActions();
855
socket.send({ type: MessageType.moveTo, tileX: tile.tileX, tileY: tile.tileY });
947
sendPlayerMoveTo(tile.tileX, tile.tileY);
856
948
}
857
949
}
858
950
@@ -875,7 +967,7 @@ function handleRightClick (event, mouseX, mouseY)
875
967
onSelect: () =>
876
968
{
877
969
clearAllPendingActions();
878
socket.send({ type: MessageType.moveTo, tileX: walkTileX, tileY: walkTileY });
970
sendPlayerMoveTo(walkTileX, walkTileY);
879
971
}
880
972
});
881
973
@@ -889,7 +981,7 @@ function handleRightClick (event, mouseX, mouseY)
889
981
onSelect: () =>
890
982
{
891
983
clearAllPendingActions();
892
socket.send({ type: MessageType.follow, targetEntityId: entity.entityId });
984
sendPlayerFollow(entity.entityId);
893
985
}
894
986
});
895
987
if (entity.untargetable)
@@ -1202,6 +1294,7 @@ function startPlay (payload)
1202
1294
{
1203
1295
flushPendingPickup();
1204
1296
flushPendingInteract();
1297
syncAutorun();
1205
1298
social?.updateNametag(view, scene, view.localEntityId);
1206
1299
chat?.update(view, scene);
1207
1300
updateSpellTargetHighlight();
@@ -1644,7 +1737,10 @@ async function main ()
1644
1737
{
1645
1738
gait = message.gait;
1646
1739
document.getElementById("gait").textContent = gait;
1740
if (gait === GAIT.walk && (staminaUi?.getCurrent?.() ?? 0) <= 0)
1741
{ autorunWaitingStamina = true; }
1647
1742
}
1743
syncAutorun();
1648
1744
break;
1649
1745
case MessageType.statusEffects:
1650
1746
view?.setLocalBlind(!!message.blind);
@@ -1909,6 +2005,9 @@ async function main ()
1909
2005
function returnToMenu (reason = "")
1910
2006
{
1911
2007
playing = false;
2008
followTargetId = null;
2009
moveDest = null;
2010
autorunWaitingStamina = false;
1912
2011
clearAllPendingActions();
1913
2012
clearUiFocus();
1914
2013
social?.reset();
@@ -95,9 +95,100 @@ let pendingInteract = null;95
let uiFocus = null;95
let uiFocus = null;96
/** Last approach moveTo so we do not re-path every frame (resets server walkCarry). */96
/** Last approach moveTo so we do not re-path every frame (resets server walkCarry). */97
let approachMove = null;97
let approachMove = null;98
/** Client-tracked follow target; server follow owns gait while this is set. */99
let followTargetId = null;100
/** Destination of the active click/approach moveTo for autorun distance checks. */101
let moveDest = null;102
/** After stamina hits 0 while autorunning, wait until ≥50% before running again. */103
let autorunWaitingStamina = false;98
/** Framework can report mousePressed for two frames; latch so one physical click is one command. */104
/** Framework can report mousePressed for two frames; latch so one physical click is one command. */99
let leftClickConsumed = false;105
let leftClickConsumed = false;100
106
107
const AUTORUN_DISTANCE_TILES = 3;108
const AUTORUN_STAMINA_RESUME_RATIO = 0.5;109
110
function sendPlayerMoveTo (tileX, tileY)111
{112
followTargetId = null;113
moveDest = { tileX: tileX | 0, tileY: tileY | 0 };114
socket.send({ type: MessageType.moveTo, tileX: moveDest.tileX, tileY: moveDest.tileY });115
syncAutorun();116
}117
118
function sendPlayerFollow (targetEntityId)119
{120
followTargetId = targetEntityId | 0;121
moveDest = null;122
autorunWaitingStamina = false;123
socket.send({ type: MessageType.follow, targetEntityId: followTargetId });124
}125
126
function requestGaitIfNeeded (next)127
{128
if (next !== GAIT.walk && next !== GAIT.run)129
{ return; }130
if (next === gait)131
{ return; }132
if (next === GAIT.run && (staminaUi?.getCurrent?.() ?? 0) <= 0)133
{ return; }134
socket.send({ type: MessageType.setGait, gait: next });135
if (next === GAIT.walk)136
{137
gait = next;138
const el = document.getElementById("gait");139
if (el)140
{ el.textContent = gait; }141
}142
}143
144
function syncAutorun ()145
{146
if (!playing || followTargetId != null)147
{ return; }148
const settings = graphicsSettingsUi?.getSettings?.() ?? {};149
if (settings.autorun !== "on")150
{ return; }151
const local = view?.entities?.get(view.localEntityId);152
if (!local || !moveDest)153
{ return; }154
if (local.tileX === moveDest.tileX && local.tileY === moveDest.tileY)155
{156
moveDest = null;157
autorunWaitingStamina = false;158
requestGaitIfNeeded(GAIT.walk);159
return;160
}161
const dist = chebyshev(local.tileX, local.tileY, moveDest.tileX, moveDest.tileY);162
const wantRun = dist > AUTORUN_DISTANCE_TILES;163
const current = staminaUi?.getCurrent?.() ?? 0;164
const max = Math.max(1, staminaUi?.getMax?.() ?? 1);165
if (gait === GAIT.run && current <= 0)166
{ autorunWaitingStamina = true; }167
if (autorunWaitingStamina)168
{169
if (wantRun && current / max >= AUTORUN_STAMINA_RESUME_RATIO)170
{171
autorunWaitingStamina = false;172
requestGaitIfNeeded(GAIT.run);173
}174
else175
{ requestGaitIfNeeded(GAIT.walk); }176
return;177
}178
if (wantRun)179
{180
if (current <= 0)181
{182
autorunWaitingStamina = true;183
requestGaitIfNeeded(GAIT.walk);184
}185
else186
{ requestGaitIfNeeded(GAIT.run); }187
}188
else189
{ requestGaitIfNeeded(GAIT.walk); }190
}191
101
function consumeWorldClick ()192
function consumeWorldClick ()102
{193
{103
leftClickConsumed = true;194
leftClickConsumed = true;@@ -185,6 +276,7 @@ function applyGraphicsSettings (settings)185
viewDistance: settings.viewDistance276
viewDistance: settings.viewDistance186
});277
});187
}278
}279
syncAutorun();188
}280
}189
281
190
function clearPendingPickup ()282
function clearPendingPickup ()@@ -268,7 +360,7 @@ function approachAdjacentTile (tileX, tileY)268
destX,360
destX,269
destY361
destY270
};362
};271
socket.send({ type: MessageType.moveTo, tileX: destX, tileY: destY });363
sendPlayerMoveTo(destX, destY);272
return false;364
return false;273
}365
}274
366
@@ -723,7 +815,7 @@ function requestPickup (ground)723
flushPendingPickup();815
flushPendingPickup();724
return;816
return;725
}817
}726
socket.send({ type: MessageType.moveTo, tileX: ground.tileX, tileY: ground.tileY });818
sendPlayerMoveTo(ground.tileX, ground.tileY);727
}819
}728
820
729
function flushPendingPickup ()821
function flushPendingPickup ()@@ -852,7 +944,7 @@ function handleLeftClick (mouseX, mouseY)852
else944
else853
{945
{854
clearAllPendingActions();946
clearAllPendingActions();855
socket.send({ type: MessageType.moveTo, tileX: tile.tileX, tileY: tile.tileY });947
sendPlayerMoveTo(tile.tileX, tile.tileY);856
}948
}857
}949
}858
950
@@ -875,7 +967,7 @@ function handleRightClick (event, mouseX, mouseY)875
onSelect: () =>967
onSelect: () =>876
{968
{877
clearAllPendingActions();969
clearAllPendingActions();878
socket.send({ type: MessageType.moveTo, tileX: walkTileX, tileY: walkTileY });970
sendPlayerMoveTo(walkTileX, walkTileY);879
}971
}880
});972
});881
973
@@ -889,7 +981,7 @@ function handleRightClick (event, mouseX, mouseY)889
onSelect: () =>981
onSelect: () =>890
{982
{891
clearAllPendingActions();983
clearAllPendingActions();892
socket.send({ type: MessageType.follow, targetEntityId: entity.entityId });984
sendPlayerFollow(entity.entityId);893
}985
}894
});986
});895
if (entity.untargetable)987
if (entity.untargetable)@@ -1202,6 +1294,7 @@ function startPlay (payload)1202
{1294
{1203
flushPendingPickup();1295
flushPendingPickup();1204
flushPendingInteract();1296
flushPendingInteract();1297
syncAutorun();1205
social?.updateNametag(view, scene, view.localEntityId);1298
social?.updateNametag(view, scene, view.localEntityId);1206
chat?.update(view, scene);1299
chat?.update(view, scene);1207
updateSpellTargetHighlight();1300
updateSpellTargetHighlight();@@ -1644,7 +1737,10 @@ async function main ()1644
{1737
{1645
gait = message.gait;1738
gait = message.gait;1646
document.getElementById("gait").textContent = gait;1739
document.getElementById("gait").textContent = gait;1740
if (gait === GAIT.walk && (staminaUi?.getCurrent?.() ?? 0) <= 0)1741
{ autorunWaitingStamina = true; }1647
}1742
}1743
syncAutorun();1648
break;1744
break;1649
case MessageType.statusEffects:1745
case MessageType.statusEffects:1650
view?.setLocalBlind(!!message.blind);1746
view?.setLocalBlind(!!message.blind);@@ -1909,6 +2005,9 @@ async function main ()1909
function returnToMenu (reason = "")2005
function returnToMenu (reason = "")1910
{2006
{1911
playing = false;2007
playing = false;2008
followTargetId = null;2009
moveDest = null;2010
autorunWaitingStamina = false;1912
clearAllPendingActions();2011
clearAllPendingActions();1913
clearUiFocus();2012
clearUiFocus();1914
social?.reset();2013
social?.reset();