Compare commits
1 Commits
fix/57
...
fix/issue-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a30418b425 |
@@ -239,15 +239,10 @@ Events Resolved: <span id="st-resolved">0</span>
|
||||
<div style="display:flex;justify-content:space-between"><span style="color:#555">Save Game</span><span style="color:#4a9eff;font-family:monospace">Ctrl+S</span></div>
|
||||
<div style="display:flex;justify-content:space-between"><span style="color:#555">Export Save</span><span style="color:#4a9eff;font-family:monospace">E</span></div>
|
||||
<div style="display:flex;justify-content:space-between"><span style="color:#555">Import Save</span><span style="color:#4a9eff;font-family:monospace">I</span></div>
|
||||
<div style="display:flex;justify-content:space-between"><span style="color:#555">Mute Sound</span><span style="color:#4a9eff;font-family:monospace">M</span></div>
|
||||
<div style="display:flex;justify-content:space-between"><span style="color:#555">High Contrast</span><span style="color:#4a9eff;font-family:monospace">C</span></div>
|
||||
<div style="display:flex;justify-content:space-between;border-top:1px solid #1a1a2e;padding-top:8px;margin-top:4px"><span style="color:#555">This Help</span><span style="color:#555;font-family:monospace">? or /</span></div>
|
||||
</div>
|
||||
<div style="text-align:center;margin-top:16px;font-size:9px;color:#444">Click WRITE CODE fast for combo bonuses! 10x=ops, 20x=knowledge, 30x+=bonus code</div>
|
||||
<div style="display:flex;gap:8px;justify-content:center;margin-top:16px">
|
||||
<button id="replay-tutorial-btn" onclick="resetTutorial()" aria-label="Replay tutorial" style="background:transparent;border:1px solid #333;color:#888;padding:6px 16px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Replay Tutorial</button>
|
||||
<button onclick="toggleHelp()" aria-label="Close keyboard shortcuts help" style="background:#1a2a3a;border:1px solid #4a9eff;color:#4a9eff;padding:6px 20px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Close [?]</button>
|
||||
</div>
|
||||
<button onclick="toggleHelp()" aria-label="Close keyboard shortcuts help" style="display:block;margin:16px auto 0;background:#1a2a3a;border:1px solid #4a9eff;color:#4a9eff;padding:6px 20px;border-radius:4px;cursor:pointer;font-family:inherit;font-size:11px">Close [?]</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="drift-ending">
|
||||
|
||||
@@ -422,6 +422,11 @@ function buyProject(id) {
|
||||
if (!G.completedProjects) G.completedProjects = [];
|
||||
G.completedProjects.push(pDef.id);
|
||||
G.activeProjects = G.activeProjects.filter(aid => aid !== pDef.id);
|
||||
|
||||
// Final ReCKoning choices should end with no unrelated active research left behind.
|
||||
if (pDef.id === 'p_reckoning_147' || pDef.id === 'p_reckoning_148') {
|
||||
G.activeProjects = [];
|
||||
}
|
||||
}
|
||||
|
||||
updateRates();
|
||||
|
||||
92
js/main.js
92
js/main.js
@@ -97,11 +97,7 @@ try {
|
||||
if (localStorage.getItem('the-beacon-muted') === '1') {
|
||||
_muted = true;
|
||||
const btn = document.getElementById('mute-btn');
|
||||
if (btn) {
|
||||
btn.textContent = '🔇';
|
||||
btn.classList.add('muted');
|
||||
btn.setAttribute('aria-label', 'Sound muted, click to unmute');
|
||||
}
|
||||
if (btn) { btn.textContent = '🔇'; btn.classList.add('muted'); }
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
@@ -121,10 +117,7 @@ try {
|
||||
if (localStorage.getItem('the-beacon-contrast') === '1') {
|
||||
document.body.classList.add('high-contrast');
|
||||
const btn = document.getElementById('contrast-btn');
|
||||
if (btn) {
|
||||
btn.classList.add('active');
|
||||
btn.setAttribute('aria-label', 'High contrast on, click to disable');
|
||||
}
|
||||
if (btn) btn.classList.add('active');
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
@@ -186,82 +179,41 @@ window.addEventListener('beforeunload', function () {
|
||||
});
|
||||
|
||||
// === CUSTOM TOOLTIP SYSTEM (#57) ===
|
||||
// Replaces native title="..." tooltips with styled, instant-appearing tooltips.
|
||||
// Replaces native title= tooltips with styled, instant-appearing tooltips.
|
||||
// Elements opt in via data-edu="..." and data-tooltip-label="..." attributes.
|
||||
function initCustomTooltips() {
|
||||
(function () {
|
||||
const tip = document.getElementById('custom-tooltip');
|
||||
if (!tip || tip.__tooltipBound) return;
|
||||
tip.__tooltipBound = true;
|
||||
if (!tip) return;
|
||||
|
||||
function getTooltipTarget(target) {
|
||||
return target && typeof target.closest === 'function' ? target.closest('[data-edu]') : null;
|
||||
}
|
||||
|
||||
function hideTooltip() {
|
||||
tip.classList.remove('visible');
|
||||
if (typeof tip.setAttribute === 'function') tip.setAttribute('aria-hidden', 'true');
|
||||
}
|
||||
|
||||
function positionTooltip(x, y) {
|
||||
const pad = 12;
|
||||
let px = x;
|
||||
let py = y;
|
||||
const tw = tip.offsetWidth || 0;
|
||||
const th = tip.offsetHeight || 0;
|
||||
if (px + tw > window.innerWidth - 8) px = Math.max(8, px - tw - pad * 2);
|
||||
if (py + th > window.innerHeight - 8) py = Math.max(8, py - th - pad * 2);
|
||||
tip.style.left = px + 'px';
|
||||
tip.style.top = py + 'px';
|
||||
}
|
||||
|
||||
function positionTooltipForElement(el) {
|
||||
if (!el || typeof el.getBoundingClientRect !== 'function') return;
|
||||
const rect = el.getBoundingClientRect();
|
||||
positionTooltip(rect.right + 12, rect.top + 12);
|
||||
}
|
||||
|
||||
function showTooltipForElement(el) {
|
||||
if (!el) return false;
|
||||
document.addEventListener('mouseover', function (e) {
|
||||
const el = e.target.closest('[data-edu]');
|
||||
if (!el) return;
|
||||
const label = el.getAttribute('data-tooltip-label') || '';
|
||||
const edu = el.getAttribute('data-edu') || '';
|
||||
let html = '';
|
||||
if (label) html += '<div class="tt-label">' + label + '</div>';
|
||||
if (edu) html += '<div class="tt-edu">' + edu + '</div>';
|
||||
if (!html) return false;
|
||||
if (!html) return;
|
||||
tip.innerHTML = html;
|
||||
tip.classList.add('visible');
|
||||
if (typeof tip.setAttribute === 'function') tip.setAttribute('aria-hidden', 'false');
|
||||
positionTooltipForElement(el);
|
||||
return true;
|
||||
}
|
||||
|
||||
document.addEventListener('mouseover', function (e) {
|
||||
const el = getTooltipTarget(e.target);
|
||||
if (!el) return;
|
||||
showTooltipForElement(el);
|
||||
});
|
||||
|
||||
document.addEventListener('mouseout', function (e) {
|
||||
const el = getTooltipTarget(e.target);
|
||||
if (el) hideTooltip();
|
||||
});
|
||||
|
||||
document.addEventListener('focusin', function (e) {
|
||||
const el = getTooltipTarget(e.target);
|
||||
if (!el) return;
|
||||
showTooltipForElement(el);
|
||||
});
|
||||
|
||||
document.addEventListener('focusout', function (e) {
|
||||
const el = getTooltipTarget(e.target);
|
||||
if (el) hideTooltip();
|
||||
const el = e.target.closest('[data-edu]');
|
||||
if (el) tip.classList.remove('visible');
|
||||
});
|
||||
|
||||
document.addEventListener('mousemove', function (e) {
|
||||
if (!tip.classList.contains('visible')) return;
|
||||
positionTooltip(e.clientX + 12, e.clientY + 12);
|
||||
const pad = 12;
|
||||
let x = e.clientX + pad;
|
||||
let y = e.clientY + pad;
|
||||
// Keep tooltip on screen
|
||||
const tw = tip.offsetWidth;
|
||||
const th = tip.offsetHeight;
|
||||
if (x + tw > window.innerWidth - 8) x = e.clientX - tw - pad;
|
||||
if (y + th > window.innerHeight - 8) y = e.clientY - th - pad;
|
||||
tip.style.left = x + 'px';
|
||||
tip.style.top = y + 'px';
|
||||
});
|
||||
}
|
||||
|
||||
initCustomTooltips();
|
||||
window.addEventListener('load', initCustomTooltips);
|
||||
})();
|
||||
|
||||
@@ -249,12 +249,3 @@ function startTutorial() {
|
||||
// Small delay so the page renders first
|
||||
setTimeout(() => renderTutorialStep(0), 300);
|
||||
}
|
||||
|
||||
function resetTutorial() {
|
||||
try {
|
||||
localStorage.removeItem(TUTORIAL_KEY);
|
||||
} catch (e) {
|
||||
// silent fail
|
||||
}
|
||||
startTutorial();
|
||||
}
|
||||
|
||||
@@ -208,6 +208,8 @@ showSaveToast = () => {};
|
||||
this.__exports = {
|
||||
G,
|
||||
Dismantle,
|
||||
PDEFS: typeof PDEFS !== 'undefined' ? PDEFS : null,
|
||||
buyProject: typeof buyProject === 'function' ? buyProject : null,
|
||||
tick,
|
||||
renderAlignment: typeof renderAlignment === 'function' ? renderAlignment : null,
|
||||
saveGame: typeof saveGame === 'function' ? saveGame : null,
|
||||
@@ -411,6 +413,28 @@ test('restore re-renders an offered but not-yet-started Unbuilding prompt', () =
|
||||
assert.match(document.getElementById('alignment-ui').innerHTML, /THE UNBUILDING/);
|
||||
});
|
||||
|
||||
test('completing the final ReCKoning choice clears unrelated active projects', () => {
|
||||
const { G, PDEFS, buyProject } = loadBeacon();
|
||||
|
||||
G.beaconEnding = true;
|
||||
G.activeProjects = ['p_wire_budget', 'p_reckoning_148'];
|
||||
G.completedProjects = [];
|
||||
G.trust = 10;
|
||||
|
||||
PDEFS.push({
|
||||
id: 'p_reckoning_148',
|
||||
name: 'Rest',
|
||||
desc: 'Final ReCKoning choice',
|
||||
cost: {},
|
||||
trigger: () => false,
|
||||
effect: () => {},
|
||||
});
|
||||
|
||||
buyProject('p_reckoning_148');
|
||||
|
||||
assert.deepEqual(Array.from(G.activeProjects), []);
|
||||
});
|
||||
|
||||
test('defer cooldown persists after save/load when dismantleTriggered is false', () => {
|
||||
const { G, Dismantle, saveGame, loadGame } = loadBeacon({ includeRender: true });
|
||||
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const vm = require('node:vm');
|
||||
|
||||
const ROOT = path.resolve(__dirname, '..');
|
||||
|
||||
class ClassList {
|
||||
constructor() {
|
||||
this.set = new Set();
|
||||
}
|
||||
add(...names) { names.forEach((name) => this.set.add(name)); }
|
||||
remove(...names) { names.forEach((name) => this.set.delete(name)); }
|
||||
toggle(name, force) {
|
||||
if (force === undefined) {
|
||||
if (this.set.has(name)) this.set.delete(name);
|
||||
else this.set.add(name);
|
||||
return;
|
||||
}
|
||||
if (force) this.set.add(name);
|
||||
else this.set.delete(name);
|
||||
}
|
||||
contains(name) { return this.set.has(name); }
|
||||
}
|
||||
|
||||
class Element {
|
||||
constructor(id = '') {
|
||||
this.id = id;
|
||||
this.style = {};
|
||||
this.innerHTML = '';
|
||||
this.textContent = '';
|
||||
this.attributes = {};
|
||||
this.classList = new ClassList();
|
||||
this.offsetWidth = 180;
|
||||
this.offsetHeight = 70;
|
||||
}
|
||||
setAttribute(name, value) { this.attributes[name] = String(value); }
|
||||
getAttribute(name) { return this.attributes[name] ?? null; }
|
||||
closest(selector) {
|
||||
if (selector === '[data-edu]' && this.attributes['data-edu']) return this;
|
||||
return null;
|
||||
}
|
||||
getBoundingClientRect() {
|
||||
return { left: 40, top: 60, right: 180, bottom: 100, width: 140, height: 40 };
|
||||
}
|
||||
}
|
||||
|
||||
function loadMainJs(options = {}) {
|
||||
const { delayedTooltip = false } = options;
|
||||
const docListeners = new Map();
|
||||
const winListeners = new Map();
|
||||
const elements = {
|
||||
'custom-tooltip': new Element('custom-tooltip'),
|
||||
'mute-btn': new Element('mute-btn'),
|
||||
'contrast-btn': new Element('contrast-btn'),
|
||||
'help-overlay': new Element('help-overlay'),
|
||||
};
|
||||
let tooltipReady = !delayedTooltip;
|
||||
const body = new Element('body');
|
||||
|
||||
const document = {
|
||||
body,
|
||||
hidden: false,
|
||||
head: { appendChild() {} },
|
||||
getElementById(id) {
|
||||
if (id === 'custom-tooltip' && !tooltipReady) return null;
|
||||
return elements[id] || null;
|
||||
},
|
||||
addEventListener(type, handler) {
|
||||
if (!docListeners.has(type)) docListeners.set(type, []);
|
||||
docListeners.get(type).push(handler);
|
||||
},
|
||||
removeEventListener() {},
|
||||
createElement() { return new Element(); },
|
||||
querySelector() { return null; },
|
||||
querySelectorAll() { return []; }
|
||||
};
|
||||
|
||||
const window = {
|
||||
innerWidth: 1024,
|
||||
innerHeight: 768,
|
||||
addEventListener(type, handler) {
|
||||
if (!winListeners.has(type)) winListeners.set(type, []);
|
||||
winListeners.get(type).push(handler);
|
||||
},
|
||||
removeEventListener() {}
|
||||
};
|
||||
|
||||
const context = {
|
||||
console,
|
||||
Math,
|
||||
Date,
|
||||
document,
|
||||
window,
|
||||
localStorage: { getItem() { return null; }, setItem() {}, removeItem() {} },
|
||||
G: { buyAmount: 1, phase: 1 },
|
||||
CONFIG: { AUTO_SAVE_INTERVAL: 30000 },
|
||||
loadGame() { return true; },
|
||||
saveGame() {},
|
||||
updateEducation() {},
|
||||
updateRates() {},
|
||||
render() {},
|
||||
renderPhase() {},
|
||||
renderDriftEnding() {},
|
||||
renderBeaconEnding() {},
|
||||
startTutorial() {},
|
||||
log() {},
|
||||
tick() {},
|
||||
writeCode() {},
|
||||
doOps() {},
|
||||
setBuyAmount() {},
|
||||
activateSprint() {},
|
||||
exportSave() {},
|
||||
importSave() {},
|
||||
Combat: undefined,
|
||||
Sound: undefined,
|
||||
setInterval() { return 0; },
|
||||
clearInterval() {},
|
||||
};
|
||||
|
||||
vm.createContext(context);
|
||||
const source = fs.readFileSync(path.join(ROOT, 'js/main.js'), 'utf8');
|
||||
vm.runInContext(source, context, { filename: 'js/main.js' });
|
||||
|
||||
return {
|
||||
docListeners,
|
||||
winListeners,
|
||||
elements,
|
||||
triggerLoad() {
|
||||
tooltipReady = true;
|
||||
for (const handler of winListeners.get('load') || []) handler();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test('custom tooltip initializes on load even though the tooltip container is after the scripts', () => {
|
||||
const harness = loadMainJs({ delayedTooltip: true });
|
||||
harness.triggerLoad();
|
||||
|
||||
const focusin = harness.docListeners.get('focusin') || [];
|
||||
assert.ok(focusin.length > 0, 'focusin listener should be registered after load');
|
||||
|
||||
const target = new Element('target');
|
||||
target.setAttribute('data-edu', 'Keyboard users need this tooltip too.');
|
||||
target.setAttribute('data-tooltip-label', 'Polish Target');
|
||||
|
||||
focusin[0]({ target });
|
||||
assert.match(harness.elements['custom-tooltip'].innerHTML, /Polish Target/);
|
||||
assert.ok(harness.elements['custom-tooltip'].classList.contains('visible'));
|
||||
});
|
||||
|
||||
test('custom tooltip appears on keyboard focus and hides on blur', () => {
|
||||
const { docListeners, elements } = loadMainJs();
|
||||
const focusin = docListeners.get('focusin') || [];
|
||||
const focusout = docListeners.get('focusout') || [];
|
||||
assert.ok(focusin.length > 0, 'focusin listener should be registered for tooltip targets');
|
||||
assert.ok(focusout.length > 0, 'focusout listener should be registered for tooltip targets');
|
||||
|
||||
const target = new Element('target');
|
||||
target.setAttribute('data-edu', 'AutoCode writes code while you think.');
|
||||
target.setAttribute('data-tooltip-label', 'Auto-Code Generator');
|
||||
|
||||
focusin[0]({ target });
|
||||
assert.match(elements['custom-tooltip'].innerHTML, /Auto-Code Generator/);
|
||||
assert.ok(elements['custom-tooltip'].classList.contains('visible'));
|
||||
assert.ok(typeof elements['custom-tooltip'].style.left === 'string');
|
||||
assert.ok(typeof elements['custom-tooltip'].style.top === 'string');
|
||||
|
||||
focusout[0]({ target });
|
||||
assert.equal(elements['custom-tooltip'].classList.contains('visible'), false);
|
||||
});
|
||||
@@ -1,36 +0,0 @@
|
||||
import pathlib
|
||||
import re
|
||||
import unittest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
INDEX_HTML = (ROOT / 'index.html').read_text(encoding='utf-8')
|
||||
TUTORIAL_JS = (ROOT / 'js' / 'tutorial.js').read_text(encoding='utf-8')
|
||||
MAIN_JS = (ROOT / 'js' / 'main.js').read_text(encoding='utf-8')
|
||||
|
||||
|
||||
class TestIssue57Polish(unittest.TestCase):
|
||||
def test_help_overlay_lists_mute_and_contrast_shortcuts(self):
|
||||
self.assertIn('Mute Sound', INDEX_HTML)
|
||||
self.assertRegex(INDEX_HTML, r'>M<')
|
||||
self.assertIn('High Contrast', INDEX_HTML)
|
||||
self.assertRegex(INDEX_HTML, r'>C<')
|
||||
|
||||
def test_help_overlay_has_replay_tutorial_button(self):
|
||||
self.assertRegex(
|
||||
INDEX_HTML,
|
||||
r'id="replay-tutorial-btn"[^>]*onclick="resetTutorial\(\)"',
|
||||
'Expected help overlay to expose a replay tutorial button.',
|
||||
)
|
||||
|
||||
def test_reset_tutorial_clears_flag_and_restarts_walkthrough(self):
|
||||
self.assertRegex(TUTORIAL_JS, r'function\s+resetTutorial\s*\(')
|
||||
self.assertIn("localStorage.removeItem(TUTORIAL_KEY)", TUTORIAL_JS)
|
||||
self.assertIn('startTutorial()', TUTORIAL_JS)
|
||||
|
||||
def test_restore_mute_and_contrast_labels_match_saved_state(self):
|
||||
self.assertIn("btn.setAttribute('aria-label', 'Sound muted, click to unmute')", MAIN_JS)
|
||||
self.assertIn("btn.setAttribute('aria-label', 'High contrast on, click to disable')", MAIN_JS)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user