From 6076b3c9a13933afaafa9ebfdecca7e757fe11b0 Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Mon, 31 Aug 2020 11:33:01 -0600 Subject: [PATCH] Add an incredibly bad level select --- js/main.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++-- js/tiletypes.js | 4 ++++ style.css | 26 ++++++++++++++++++++- 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/js/main.js b/js/main.js index 724ee6d..b50c625 100644 --- a/js/main.js +++ b/js/main.js @@ -310,7 +310,7 @@ class Level { } else if (actor === this.player) { if (player_direction) { - console.log('--- player moving', player_direction); + //console.log('--- player moving', player_direction); direction_preference = [player_direction]; actor.last_move_was_force = false; } @@ -532,6 +532,59 @@ class Level { } } +class LevelBrowserOverlay { + constructor(game) { + this.game = game; + this.root = mk('table.level-browser'); + for (let [i, stored_level] of this.game.stored_game.levels.entries()) { + this.root.append(mk('tr', + {'data-index': i}, + mk('td', i + 1), + mk('td', stored_level.title), + // TODO score? + // TODO other stats?? + mk('td', '▶'), + )); + } + + this.root.addEventListener('click', ev => { + let tr = ev.target.closest('table.level-browser tr'); + if (! tr) + return; + + let index = parseInt(tr.getAttribute('data-index'), 10); + this.game.load_level(index); + this.close(); + }); + + // Don't propagate clicks on the root element, so they won't trigger a + // parent overlay's automatic dismissal + this.root.addEventListener('click', ev => { + ev.stopPropagation(); + }); + } + + open() { + if (this.game.state === 'playing') { + this.game.set_state('paused'); + } + + let overlay = mk('div.overlay', mk('div.dialog', this.root)); + document.body.append(overlay); + + // Remove the overlay when clicking outside the element + overlay.addEventListener('click', ev => { + this.close(); + }); + + return promise; + } + + close() { + this.root.closest('.overlay').remove(); + } +} + // TODO: // - some kinda visual theme i guess lol // - level password, if any @@ -561,7 +614,7 @@ const GAME_UI_HTML = `

Level 1 — Key Pyramid

@@ -668,6 +721,9 @@ class Game { this.load_level(this.level_index + 1); } }); + nav_el.querySelector('.nav-browse').addEventListener('click', ev => { + new LevelBrowserOverlay(this).open(); + }); // Bind buttons this.pause_button = this.container.querySelector('.controls .control-pause'); diff --git a/js/tiletypes.js b/js/tiletypes.js index 198e4cf..72931b7 100644 --- a/js/tiletypes.js +++ b/js/tiletypes.js @@ -224,6 +224,9 @@ const TILE_TYPES = { level.make_slide(other, 'force'); } }, + force_floor_all: { + // TODO cc2 cycles these... + }, bomb: { // TODO explode on_arrive(me, level, other) { @@ -261,6 +264,7 @@ const TILE_TYPES = { blocks: true, is_object: true, is_block: true, + ignores: new Set(['fire']), }, green_floor: {}, green_wall: { diff --git a/style.css b/style.css index 9e1f3b4..7a51852 100644 --- a/style.css +++ b/style.css @@ -43,9 +43,33 @@ body > header > nav { gap: 0.5em; } +.overlay { + display: flex; + align-items: center; + justify-content: center; + + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + background: #0004; +} +.dialog { + max-width: 80%; + max-height: 80%; + overflow: auto; + padding: 1em; + border: 1px solid black; + color: black; + background: #e8e8e8; + box-shadow: 0 1px 3px #000c; +} + main { flex: 0; margin: auto; /* center in both directions baby */ + isolation: isolate; display: grid; align-items: center; grid: @@ -107,7 +131,7 @@ main > header > nav { justify-content: center; align-items: center; - z-index: 99; + z-index: 1; font-size: 48px; padding: 10%; background: #0009;