|
@@ -1,19 +1,26 @@
|
|
|
<script>
|
|
|
import { Name } from '$lib/components';
|
|
|
- import { addComponent } from '$lib/ecs';
|
|
|
+ import { addComponent, removeEntity } from '$lib/ecs';
|
|
|
import { onMount } from 'svelte';
|
|
|
import Select from '../Select.svelte';
|
|
|
import { newGame } from './game';
|
|
|
import { applyProfession, enumProfessions } from './profession';
|
|
|
- import { enumSkills } from './skill';
|
|
|
+ import { enumSkills, purgeSkills } from './skill';
|
|
|
import Stats from './Stats.svelte';
|
|
|
import Skills from './Skills.svelte';
|
|
|
+ import { getInventory, purgeInventory } from '$lib/inventory';
|
|
|
+ import Equipment from './Equipment.svelte';
|
|
|
+ import Inventory from './Inventory.svelte';
|
|
|
+ import { fromTemplate } from '$lib/builder';
|
|
|
+ import { getEquipped, purgeEquipment } from './equipment';
|
|
|
+ import { playerTemplate } from './player';
|
|
|
+ import { notNullish } from '$lib/util';
|
|
|
|
|
|
let { game } = $props();
|
|
|
|
|
|
const game0 = newGame();
|
|
|
|
|
|
- let charNameWidget
|
|
|
+ let charNameWidget;
|
|
|
let tick = $state(false);
|
|
|
|
|
|
let error = $state('');
|
|
@@ -26,22 +33,44 @@
|
|
|
let professionIx = $state(0);
|
|
|
let selectedProfession = $state(professions[0]);
|
|
|
|
|
|
+ let tmpChar = $state();
|
|
|
+
|
|
|
// skip char-creation (for debug purposes)
|
|
|
const autostart = false;
|
|
|
|
|
|
onMount(() => {
|
|
|
charNameWidget.focus();
|
|
|
+ tmpChar = fromTemplate(game0.world, playerTemplate);
|
|
|
if (autostart) {
|
|
|
start();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ let inventory = $state([]);
|
|
|
+ let equipment = $state([]);
|
|
|
+
|
|
|
+ $effect(() => {
|
|
|
+ if (notNullish(tmpChar)) {
|
|
|
+ purgeInventory(game0.world, tmpChar);
|
|
|
+ purgeEquipment(game0.world, tmpChar);
|
|
|
+ purgeSkills(game0.world, tmpChar);
|
|
|
+ applyProfession(game0.world, tmpChar, professions[professionIx]);
|
|
|
+ inventory = getInventory(game0.world, tmpChar);
|
|
|
+ equipment = getEquipped(game0.world, tmpChar);
|
|
|
+ selectedProfession = professions[professionIx];
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
$effect(() => {
|
|
|
tick;
|
|
|
error = '';
|
|
|
});
|
|
|
|
|
|
const start = () => {
|
|
|
+ purgeEquipment(game0.world, tmpChar);
|
|
|
+ purgeInventory(game0.world, tmpChar);
|
|
|
+ removeEntity(game0.world, tmpChar);
|
|
|
+ tmpChar = undefined;
|
|
|
addComponent(game0.world, Name, game0.pc, {
|
|
|
name: playerName,
|
|
|
});
|
|
@@ -62,21 +91,40 @@
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
-<section>
|
|
|
- <h2>New character</h2>
|
|
|
- <input bind:this={charNameWidget} bind:value={playerName} /> the {selectedProfession.name}
|
|
|
- <div>
|
|
|
- <h3>Profession</h3>
|
|
|
- <Select options={professions} bind:value={selectedProfession} bind:index={professionIx} />
|
|
|
+<section class="cc-grid">
|
|
|
+ <div class="cc-leftside">
|
|
|
+ <h2>New character</h2>
|
|
|
+ <input bind:this={charNameWidget} bind:value={playerName} /> the {selectedProfession.name}
|
|
|
+ <div>
|
|
|
+ <h3>Profession</h3>
|
|
|
+ <Select options={professions} bind:index={professionIx} />
|
|
|
+ </div>
|
|
|
+ <div>
|
|
|
+ <h3>Hobby</h3>
|
|
|
+ </div>
|
|
|
+ <Stats game={game0} bind:tick />
|
|
|
+ <Skills world={game0.world} char={tmpChar} tick={selectedProfession} />
|
|
|
+ <div>{error}</div>
|
|
|
+ <button onclick={finishCharacter}>Ok</button>
|
|
|
</div>
|
|
|
- <div>
|
|
|
- <h3>Hobby</h3>
|
|
|
+ <div class="cc-rightside">
|
|
|
+ Starting equipment
|
|
|
+ <Inventory world={game0.world} {inventory} />
|
|
|
+ <Equipment world={game0.world} {equipment} />
|
|
|
</div>
|
|
|
- <Stats game={game0} bind:tick />
|
|
|
- <Skills game={game0} bind:tick />
|
|
|
- <div>{error}</div>
|
|
|
- <button onclick={finishCharacter}>Ok</button>
|
|
|
</section>
|
|
|
|
|
|
<style>
|
|
|
+ .cc-grid {
|
|
|
+ display: grid;
|
|
|
+ grid-template-columns: 1fr 1fr;
|
|
|
+ grid-template-areas:
|
|
|
+ "leftside rightside";
|
|
|
+ }
|
|
|
+ .cc-leftside {
|
|
|
+ grid-area: leftside;
|
|
|
+ }
|
|
|
+ .cc-rightside {
|
|
|
+ grid-area: rightside;
|
|
|
+ }
|
|
|
</style>
|