Skip to content

Commit

Permalink
feat(settings): reset balance button
Browse files Browse the repository at this point in the history
  • Loading branch information
AnsonH committed Nov 19, 2024
1 parent e29d203 commit 8aea4a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/lib/components/SettingsWindow/SettingsWindow.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { DEFAULT_BALANCE } from '$lib/constants/game';
import { balance } from '$lib/stores/game';
import { isGameSettingsOpen } from '$lib/stores/layout';
import { isAnimationOn } from '$lib/stores/settings';
import { hasPreferReducedMotion } from '$lib/utils/settings';
Expand All @@ -24,11 +26,18 @@
<p class="text-sm font-medium text-white">Game Settings</p>
</svelte:fragment>

<div class="flex flex-col gap-4">
<div class="flex flex-col gap-5">
<div class="flex items-center gap-4">
<Switch id="isAnimationOn" bind:checked={$isAnimationOn} />
<Label.Root for="isAnimationOn" class="text-sm text-white">Animations</Label.Root>
</div>

<button
on:click={() => ($balance = DEFAULT_BALANCE)}
class="touch-manipulation self-start rounded-md bg-red-500 px-3 py-2 text-sm text-white transition-colors hover:bg-red-400 active:bg-red-600"
>
Reset Balance
</button>
</div>
</DraggableWindow>
{/if}
2 changes: 2 additions & 0 deletions src/lib/constants/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { RiskLevel } from '$lib/types';
import { getBinColors } from '$lib/utils/colors';
import { computeBinProbabilities } from '$lib/utils/numbers';

export const DEFAULT_BALANCE = 200;

export const LOCAL_STORAGE_KEY = {
BALANCE: 'plinko_balance',
SETTINGS: {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/stores/game.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import PlinkoEngine from '$lib/components/Plinko/PlinkoEngine';
import { binColor } from '$lib/constants/game';
import { binColor, DEFAULT_BALANCE } from '$lib/constants/game';
import {
RiskLevel,
type BetAmountOfExistingBalls,
Expand Down Expand Up @@ -37,7 +37,7 @@ export const totalProfitHistory = writable<number[]>([0]);
* on every balance change. This prevents unnecessary writes to local storage, which can
* be slow on low-end devices.
*/
export const balance = writable<number>(200);
export const balance = writable<number>(DEFAULT_BALANCE);

/**
* RGB colors for every bin. The length of the array is the number of bins.
Expand Down

0 comments on commit 8aea4a9

Please sign in to comment.