Skip to content

Commit

Permalink
start: change new game and load game button look for unavailable
Browse files Browse the repository at this point in the history
Dim the cards for new game and load game when the actions aren't
possible. Always display the button text though.
  • Loading branch information
jnikula committed Mar 18, 2024
1 parent 8059a5e commit d8db6c5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
18 changes: 6 additions & 12 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}
function ui_new_game(): void {
if (!ui_can_new_game())
if (!$names.can_new_game())
return;
// Note: Fullscreen can only be entered via user interaction
Expand Down Expand Up @@ -247,36 +247,30 @@
</div>
{/each}

<div class='info-card' on:click={ui_new_game}>
<div class='info-card {$names.can_new_game() ? "" : "unavailable"}' on:click={ui_new_game}>
<div class='info-card-copyright' on:click|stopPropagation={() => false}><a href="https://jnikula.github.io/piste-on-piste/">&copy; 2022-2024 Jani Nikula<br>License: GPL 3.0 or later &#x1f517;</a></div>
<div></div>
<div>Piste</div>
<div>on</div>
<div>Piste</div>
<div></div>
{#if ui_can_new_game }
<div class='card-button'>New game</div>
{:else}
<div></div>
{/if}
<div class='card-button'>New game</div>
</div>
{#each $game.saved_games as save_game, index (save_game.slot) }
<div class='info-card' on:click={() => ui_load_game(save_game)}>
<div class='info-card {save_game.timestamp ? "" : "unavailable"}' on:click={() => ui_load_game(save_game)}>
<div>Game save {index}</div>
<div></div>
{#if save_game.timestamp }
<div>Started</div>
<div>{timeutil.format_date(save_game.timestamp)}</div>
<div>{timeutil.format_time(save_game.timestamp)}</div>
<div></div>
<div class='card-button'>Load game</div>
{:else}
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
{/if}
<div></div>
<div class='card-button'>Load game</div>
</div>
{/each}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/Names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ class Names {
return dupes.length === 1;
}

all_valid(): boolean {
_all_valid(): boolean {
return this.names.filter((x) => !this.valid_name(x.name)).length === 0;
}

can_new_game(): boolean {
return this._all_valid();
}
}

function create_names(_names: Names) {
Expand Down

0 comments on commit d8db6c5

Please sign in to comment.