wip: add Alt+1-9 keyboard shortcuts for buying buildings
This commit is contained in:
31
game.js
31
game.js
@@ -1887,6 +1887,7 @@ function renderBuildings() {
|
||||
html += '</div>';
|
||||
|
||||
let visibleCount = 0;
|
||||
let slotIndex = 0;
|
||||
|
||||
for (const def of BDEF) {
|
||||
const isUnlocked = def.unlock();
|
||||
@@ -1907,6 +1908,10 @@ function renderBuildings() {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Slot number for keyboard shortcut (Alt+1-9)
|
||||
const slotLabel = slotIndex < 9 ? `<span style="color:#444;font-size:9px;position:absolute;top:4px;right:6px">${slotIndex + 1}</span>` : '';
|
||||
slotIndex++;
|
||||
|
||||
// Calculate bulk cost display
|
||||
let qty = G.buyAmount;
|
||||
let afford = false;
|
||||
@@ -1940,7 +1945,8 @@ function renderBuildings() {
|
||||
return `+${label}/${r}/s`;
|
||||
}).join(', ') : '';
|
||||
|
||||
html += `<button class="build-btn ${afford ? 'can-buy' : ''}" onclick="buyBuilding('${def.id}')" title="${def.edu}">`;
|
||||
html += `<button class="build-btn ${afford ? 'can-buy' : ''}" onclick="buyBuilding('${def.id}')" title="${def.edu}" style="position:relative">`;
|
||||
html += slotLabel;
|
||||
html += `<span class="b-name">${def.name}</span>`;
|
||||
if (count > 0) html += `<span class="b-count">x${count}</span>`;
|
||||
html += `<span class="b-cost">Cost: ${costStr}</span>`;
|
||||
@@ -2866,6 +2872,20 @@ function toggleHelp() {
|
||||
el.style.display = isOpen ? 'none' : 'flex';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns ordered list of currently visible (unlocked) building IDs.
|
||||
* Used for keyboard shortcut mapping (Alt+1-9).
|
||||
*/
|
||||
function getVisibleBuildingIds() {
|
||||
const ids = [];
|
||||
for (const def of BDEF) {
|
||||
if (def.unlock()) {
|
||||
ids.push(def.id);
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
// Keyboard shortcuts
|
||||
window.addEventListener('keydown', function (e) {
|
||||
// Help toggle (? or /) — works even in input fields
|
||||
@@ -2901,6 +2921,15 @@ window.addEventListener('keydown', function (e) {
|
||||
if (e.code === 'KeyS') activateSprint();
|
||||
if (e.code === 'KeyE') exportSave();
|
||||
if (e.code === 'KeyI') importSave();
|
||||
// Alt+1-9: buy building by slot position
|
||||
if (e.altKey && e.code >= 'Digit1' && e.code <= 'Digit9') {
|
||||
e.preventDefault();
|
||||
const slot = parseInt(e.code.replace('Digit', '')) - 1;
|
||||
const visible = getVisibleBuildingIds();
|
||||
if (slot < visible.length) {
|
||||
buyBuilding(visible[slot]);
|
||||
}
|
||||
}
|
||||
if (e.code === 'Escape') {
|
||||
const el = document.getElementById('help-overlay');
|
||||
if (el && el.style.display === 'flex') toggleHelp();
|
||||
|
||||
@@ -204,6 +204,7 @@ Events Resolved: <span id="st-resolved">0</span>
|
||||
<div style="display:flex;justify-content:space-between"><span style="color:#555">Ops → Knowledge</span><span style="color:#b388ff;font-family:monospace">3</span></div>
|
||||
<div style="display:flex;justify-content:space-between"><span style="color:#555">Ops → Trust</span><span style="color:#b388ff;font-family:monospace">4</span></div>
|
||||
<div style="display:flex;justify-content:space-between"><span style="color:#555">Cycle Buy Amount (x1/x10/MAX)</span><span style="color:#4a9eff;font-family:monospace">B</span></div>
|
||||
<div style="display:flex;justify-content:space-between"><span style="color:#555">Buy Building (by slot)</span><span style="color:#4a9eff;font-family:monospace">Alt+1..9</span></div>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user