Skip to content

Commit 24cdd39

Browse files
committed
configurable game height
1 parent c830152 commit 24cdd39

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

game-menu.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
this._currentRomSource = null;
1919
this._currentParentRomSource = null;
2020
this._currentBiosSource = null;
21+
this._currentGameHeight = ''; // empty = 100% (default)
2122

2223
this.shadowRoot.innerHTML = this.getTemplate();
2324

@@ -33,6 +34,7 @@
3334
this.biosFileInput = this.shadowRoot.getElementById('biosFileInput');
3435
this.loadingOverlay = this.shadowRoot.getElementById('loadingOverlay');
3536
this.cancelButton = this.shadowRoot.getElementById('cancelButton');
37+
this.gameHeightSelect = this.shadowRoot.getElementById('gameHeightSelect');
3638
}
3739

3840
connectedCallback() { this.init(); }
@@ -159,6 +161,12 @@
159161
<input type="text" id="biosUrlInput" placeholder="BIOS URL (optional)">
160162
<button class="upload-btn" id="biosUploadButton">+</button>
161163
<select id="consoleSelect" class="full-width"><option value="">Select Console</option></select>
164+
<select id="gameHeightSelect" class="full-width">
165+
<option value="">Game Height: 100%</option>
166+
<option value="90">90%</option>
167+
<option value="75">75%</option>
168+
<option value="60">60%</option>
169+
</select>
162170
<button class="start-button full-width" id="startButton" disabled>Start Game</button>
163171
<div class="loading-overlay" id="loadingOverlay">
164172
<div class="loading-spinner"></div>
@@ -283,6 +291,10 @@
283291

284292
this.consoleSelect.onchange = () => this.updateStartButtonState();
285293

294+
this.gameHeightSelect.onchange = (e) => {
295+
this._currentGameHeight = e.target.value;
296+
};
297+
286298
this.presetSelect.onchange = (e) => {
287299
if (e.target.value) {
288300
this.applyPreset(e.target.value);
@@ -305,7 +317,8 @@
305317
parentRomSource: this._currentParentRomSource,
306318
biosSource: this._currentBiosSource,
307319
core: this.consoleSelect.value,
308-
romName
320+
romName,
321+
gameHeight: this._currentGameHeight || null
309322
};
310323

311324
this.showLoading();
@@ -402,6 +415,7 @@
402415
this.romUrlInput.disabled = !connected;
403416
this.biosUrlInput.disabled = !connected;
404417
this.consoleSelect.disabled = !connected;
418+
this.gameHeightSelect.disabled = !connected;
405419
this.updateStartButtonState();
406420

407421
if (!connected) {

screen.html

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<style>
2222
html, body { margin: 0; padding: 0; width: 100%; height: 100%; background: #1a1a1a; font-family: Arial, sans-serif; }
2323
body { display: flex; justify-content: center; align-items: center; }
24-
.game-container { width: 100%; height: 100%; border-radius: 8px; overflow: hidden; position: relative; }
24+
.game-container { width: 100%; height: 100%; border-radius: 8px; overflow: hidden; position: relative; display: flex; align-items: center; justify-content: center; }
2525
#game { width: 100%; height: 100%; }
2626

2727
#loadingOverlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.8); z-index: 2000; display: none; align-items: center; justify-content: center; }
@@ -438,7 +438,8 @@
438438
source: gameData.romSource,
439439
name: gameData.romName.split('.').slice(0, -1).join('.'),
440440
core: gameData.core,
441-
biosSource: gameData.biosSource
441+
biosSource: gameData.biosSource,
442+
gameHeight: gameData.gameHeight || null
442443
};
443444
setState(State.LOADING);
444445
initializeEmulator();
@@ -465,8 +466,14 @@
465466
console.warn('Emulator cleanup error:', e);
466467
}
467468

468-
// Clear game container
469-
document.getElementById('game').innerHTML = '';
469+
// Clear game container and reset height
470+
const container = document.querySelector('.game-container');
471+
const gameEl = document.getElementById('game');
472+
gameEl.innerHTML = '';
473+
gameEl.style.height = '';
474+
gameEl.style.width = '';
475+
container.style.height = '';
476+
container.style.width = '';
470477

471478
// Reset state
472479
pendingROM = null;
@@ -519,6 +526,20 @@
519526
}, { passive: true });
520527
});
521528

529+
function applyGameHeight(heightPercent) {
530+
const container = document.querySelector('.game-container');
531+
const gameEl = document.getElementById('game');
532+
if (heightPercent) {
533+
container.style.height = heightPercent + 'vh';
534+
container.style.width = '100%';
535+
gameEl.style.height = '100%';
536+
gameEl.style.width = '100%';
537+
} else {
538+
container.style.height = '100%';
539+
container.style.width = '100%';
540+
}
541+
}
542+
522543
function initializeEmulator() {
523544
window.EJS_player = '#game';
524545
window.EJS_pathtodata = 'EmulatorJS/data/';
@@ -530,6 +551,11 @@
530551
window.EJS_backgroundBlur = false;
531552
window.EJS_backgroundColor = '#1a1a1a';
532553
window.EJS_defaultOptions = { "save-state-location": "browser" };
554+
555+
// Apply game height if specified
556+
if (pendingROM?.gameHeight) {
557+
applyGameHeight(pendingROM.gameHeight);
558+
}
533559
// Disable network-dependent features
534560
window.EJS_disableAutoLang = true; // Don't auto-fetch language files
535561
window.EJS_language = "en"; // Use English (built-in, no fetch needed)
@@ -562,6 +588,10 @@
562588
window.EJS_onGameStart = function() {
563589
console.log('Game started');
564590
setState(State.PLAYING);
591+
// Reapply game height after EmulatorJS has initialized
592+
if (pendingROM?.gameHeight) {
593+
applyGameHeight(pendingROM.gameHeight);
594+
}
565595
setTimeout(() => {
566596
const ctx = EJS_emulator?.Module?.AL?.currentCtx?.audioCtx;
567597
if (ctx?.state === 'suspended') {

0 commit comments

Comments
 (0)