Merge pull request 'fix: clamp negative resources + add tutorial focus trap' (#220) from sprint/issue-resource-clamp-focus-trap into main
Some checks failed
Smoke Test / smoke (push) Has been cancelled
Some checks failed
Smoke Test / smoke (push) Has been cancelled
This commit was merged in pull request #220.
This commit is contained in:
@@ -142,6 +142,11 @@ function tick() {
|
||||
G.harmony += G.harmonyRate * dt;
|
||||
G.harmony = Math.max(0, Math.min(100, G.harmony));
|
||||
|
||||
// Clamp resources to prevent negative values from debuffs/Fenrir drain
|
||||
G.ops = Math.max(0, G.ops);
|
||||
G.trust = Math.max(0, G.trust);
|
||||
G.compute = Math.max(0, G.compute);
|
||||
|
||||
// Track totals
|
||||
G.totalCode += G.codeRate * dt;
|
||||
G.totalCompute += G.computeRate * dt;
|
||||
|
||||
@@ -208,6 +208,23 @@ function renderTutorialStep(index) {
|
||||
// Focus the next button so Enter works
|
||||
const nextBtn = document.getElementById('tutorial-next-btn');
|
||||
if (nextBtn) nextBtn.focus();
|
||||
|
||||
// Focus trap: prevent tabbing outside the tutorial overlay
|
||||
overlay._focusTrapHandler = function(e) {
|
||||
if (e.key !== 'Tab') return;
|
||||
const focusable = overlay.querySelectorAll('button, [href], [tabindex]:not([tabindex="-1"])');
|
||||
if (focusable.length === 0) return;
|
||||
const first = focusable[0];
|
||||
const last = focusable[focusable.length - 1];
|
||||
if (e.shiftKey && document.activeElement === first) {
|
||||
e.preventDefault();
|
||||
last.focus();
|
||||
} else if (!e.shiftKey && document.activeElement === last) {
|
||||
e.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
};
|
||||
overlay.addEventListener('keydown', overlay._focusTrapHandler);
|
||||
}
|
||||
|
||||
let _tutorialStep = 0;
|
||||
@@ -236,6 +253,9 @@ document.addEventListener('keydown', function tutorialKeyHandler(e) {
|
||||
function closeTutorial() {
|
||||
const overlay = document.getElementById('tutorial-overlay');
|
||||
if (overlay) {
|
||||
if (overlay._focusTrapHandler) {
|
||||
overlay.removeEventListener('keydown', overlay._focusTrapHandler);
|
||||
}
|
||||
overlay.style.animation = 'tutorial-fade-in 0.3s ease-in reverse';
|
||||
setTimeout(() => overlay.remove(), 280);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user