Skip to content

Commit

Permalink
Split stats & inventory screen for better mobile experience
Browse files Browse the repository at this point in the history
  • Loading branch information
shezard committed Jul 23, 2023
1 parent 3aadb51 commit 122b07e
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 55 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ You can preview the production build with `npm run preview`.
- [x] Add treasure chest
- [x] Pause game while in the menu
- [x] Container: fix store not updating
- [ ] Mobile
- [ ] Fix icons for left / right rotation
- [ ] Add cross to exit menus
- [ ] Cursor
- [x] Click on AI should attack
- [x] Fix cursor bypassing walls
Expand Down
3 changes: 3 additions & 0 deletions src/components/Game.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import Container from './Menu/Container.svelte';
import Dialog from './Menu/Dialog.svelte';
import Editor from './Editor/Editor.svelte';
import Stats from './Menu/Stats.svelte';
$: shaking = $store.screen.shaking;
Expand All @@ -37,6 +38,8 @@
<Editor />
{:else if $store.game.state == 'inventory'}
<Inventory />
{:else if $store.game.state == 'stats'}
<Stats />
{:else if $store.game.state == 'container'}
<Container />
{:else if $store.game.state == 'dialog'}
Expand Down
10 changes: 10 additions & 0 deletions src/components/Menu/Container.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { noop } from '$lib/helpers';
import { container } from '$stores/container';
import { player } from '$stores/player';
import { store } from '$stores/store';
import type { Item, ItemName } from '../..';
import MenuItem from './Item.svelte';
Expand Down Expand Up @@ -41,6 +42,15 @@
</script>

<div class="menu text-white">

<div
class="text-3xl float-right ml-10 cursor-pointer"
on:click={() => store.back()}
on:keypress={noop}
>
X
</div>

<div class="grid grid-cols-3">
<div class="flex flex-col items-center">
<div class="text-3xl">Bag</div>
Expand Down
46 changes: 3 additions & 43 deletions src/components/Menu/Inventory.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts">
import { noop } from '$lib/helpers';
import { player } from '$stores/player';
import type { BaseStatsName, Item } from '../..';
import type { Item } from '../..';
import MenuItem from './Item.svelte';
const toBag = (item: Item) => () => {
Expand All @@ -22,52 +21,13 @@
$: offHand = $player.inventory.offHand;
$: armor = $player.inventory.armor;
$: baseStats = $player.getBaseStats();
$: stats = $player.getStats();
const addBaseStats = (baseStatsName : BaseStatsName) => () => {
player.update((player) => {
player.baseStats[baseStatsName]++;
player.freeBaseStatsPoint--;
return player;
});
}
</script>

<div class="menu text-white">
<div class="text-3xl">Stats</div>

<div class="grid grid-cols-4 text-2xl">
<div class="pl-10">
Level : {$player.level} <br />
XP : {$player.xp} / {$player.getNeededXp()} <br />
</div>
<div>
Strength : {baseStats.strength} {#if $player.freeBaseStatsPoint > 0}
<span on:click={addBaseStats('strength')} on:keypress={noop}>+</span>
{/if}<br />
Dexterity : {baseStats.dexterity} {#if $player.freeBaseStatsPoint > 0}
<span on:click={addBaseStats('dexterity')} on:keypress={noop}>+</span>
{/if}<br />
wisdom : {baseStats.wisdom} {#if $player.freeBaseStatsPoint > 0}
<span on:click={addBaseStats('wisdom')} on:keypress={noop}>+</span>
{/if}<br />
</div>
<div>
AC : {stats.ac} <br />
Hit : {stats.hit} <br />
HP : {stats.hp} <br />
</div>
<div>
Attack : {stats.pAttack} <br />
Defense : {stats.pDefense} <br />
</div>
</div>

<div class="grid grid-cols-2 mt-5">
<div>
<div class="text-3xl">Inventory</div>
<div class="grid grid-inventory text-2xl pl-10">
<div class="grid grid-inventory text-2xl pl-5">
<div>
Main Hand
</div>
Expand Down Expand Up @@ -103,7 +63,7 @@
</div>
</div>

<div class="flex flex-col">
<div class="flex flex-col pl-5">
<div class="text-3xl">Bag</div>

<div class="grid grid-bag">
Expand Down
47 changes: 47 additions & 0 deletions src/components/Menu/Stats.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script lang="ts">
import { noop } from '$lib/helpers';
import { player } from '$stores/player';
import type { BaseStatsName } from '../..';
$: baseStats = $player.getBaseStats();
$: stats = $player.getStats();
const addBaseStats = (baseStatsName : BaseStatsName) => () => {
player.update((player) => {
player.baseStats[baseStatsName]++;
player.freeBaseStatsPoint--;
return player;
});
}
</script>

<div class="menu text-white">
<div class="text-3xl">Stats</div>

<div class="grid grid-cols-2 text-2xl">
<div class="pl-5">
Level : {$player.level} <br />
XP : {$player.xp} / {$player.getNeededXp()} <br />
</div>
<div class="pl-5">
Strength : {baseStats.strength} {#if $player.freeBaseStatsPoint > 0}
<span on:click={addBaseStats('strength')} on:keypress={noop}>+</span>
{/if}<br />
Dexterity : {baseStats.dexterity} {#if $player.freeBaseStatsPoint > 0}
<span on:click={addBaseStats('dexterity')} on:keypress={noop}>+</span>
{/if}<br />
Wisdom : {baseStats.wisdom} {#if $player.freeBaseStatsPoint > 0}
<span on:click={addBaseStats('wisdom')} on:keypress={noop}>+</span>
{/if}<br />
</div>
<div class="pl-5 mt-5">
AC : {stats.ac} <br />
Hit : {stats.hit} <br />
HP : {stats.hp} <br />
</div>
<div class="pl-5 mt-5">
Attack : {stats.pAttack} <br />
Defense : {stats.pDefense} <br />
</div>
</div>
</div>
6 changes: 5 additions & 1 deletion src/components/Scene.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
const keyPress = (e: KeyboardEvent) => {
if (
($store.game.state !== 'inventory' && $store.game.state !== 'running') ||
($store.game.state !== 'stats' && $store.game.state !== 'inventory' && $store.game.state !== 'running') ||
$store.game.running === 'gameOver'
) {
return;
Expand Down Expand Up @@ -69,6 +69,10 @@
store.navigateTo('inventory');
}
if (e.code === $keyboard.stats) {
store.navigateTo('stats');
}
updateCursor();
};
Expand Down
13 changes: 7 additions & 6 deletions src/components/UI.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { player } from '$stores/player';
import { ui } from '$stores/ui';
import { Canvas } from '@threlte/core';
import { noop } from 'svelte/internal';
export let canvas : Canvas;
Expand Down Expand Up @@ -55,12 +56,12 @@
{/each}
</div>
<div class="m-[10px] grid grid-cols-3 text-center">
<div class="w-10 cursor-pointer" on:click={() => player.rotateLeft(canvas.ctx.camera)}>&#11170;</div>
<diV class="w-10 cursor-pointer" on:click={() => player.moveForward(canvas.ctx.camera)}>&uparrow;</diV>
<div class="w-10 cursor-pointer" on:click={() => player.rotateRight(canvas.ctx.camera)}>&#11171;</div>
<div class="w-10 cursor-pointer" on:click={() => player.moveLeft(canvas.ctx.camera)}>&leftarrow;</div>
<div class="w-10 cursor-pointer" on:click={() => player.moveBackward(canvas.ctx.camera)}>&downarrow;</div>
<div class="w-10 cursor-pointer" on:click={() => player.moveRight(canvas.ctx.camera)}>&rightarrow;</div>
<div class="w-10 cursor-pointer" on:click={() => player.rotateLeft(canvas.ctx.camera)} on:keypress={noop}>&#11170;</div>
<diV class="w-10 cursor-pointer" on:click={() => player.moveForward(canvas.ctx.camera)} on:keypress={noop}>&uparrow;</diV>
<div class="w-10 cursor-pointer" on:click={() => player.rotateRight(canvas.ctx.camera)} on:keypress={noop}>&#11171;</div>
<div class="w-10 cursor-pointer" on:click={() => player.moveLeft(canvas.ctx.camera)} on:keypress={noop}>&leftarrow;</div>
<div class="w-10 cursor-pointer" on:click={() => player.moveBackward(canvas.ctx.camera)} on:keypress={noop}>&downarrow;</div>
<div class="w-10 cursor-pointer" on:click={() => player.moveRight(canvas.ctx.camera)} on:keypress={noop}>&rightarrow;</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type GameState = (
running: 'newGame' | 'continue';
}
| {
state: 'running' | 'inventory' | 'container';
state: 'running' | 'stats' | 'inventory' | 'container';
running: 'continue' | 'gameOver';
}
) & {
Expand Down
7 changes: 5 additions & 2 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
:global(.menu) {
position: relative;
width: 60vw;
height: 60vh;
@media(max-width: 1279) {
width: 60vw;
height: 60vh;
}
}
:global(.action::before) {
Expand Down
4 changes: 3 additions & 1 deletion src/stores/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Keyboard {
rotateLeft: string;
rotateRight: string;
inventory: string;
stats: string;
}

export type Action = keyof Keyboard;
Expand All @@ -19,5 +20,6 @@ export const keyboard = writable<Keyboard>({
right: 'KeyD',
rotateLeft: 'KeyQ',
rotateRight: 'KeyE',
inventory: 'KeyI'
inventory: 'KeyI',
stats: 'KeyC'
});
10 changes: 9 additions & 1 deletion src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import level2 from '$maps/level-2.json';
import { Level } from '../lib/Level';
import type { LevelProp, Store } from '..';

type Route = 'main' | 'control' | 'editor' | 'running' | 'inventory' | 'container' | 'dialog';
type Route =
| 'main'
| 'control'
| 'editor'
| 'running'
| 'stats'
| 'inventory'
| 'container'
| 'dialog';

const initialStoreState: Store = {
game: {
Expand Down

0 comments on commit 122b07e

Please sign in to comment.