From 2dc9c013e327e48ca984df568f12bd6166d162eb Mon Sep 17 00:00:00 2001 From: Isha Dijcks Date: Mon, 18 Aug 2025 00:35:48 +0200 Subject: [PATCH 1/3] Add demo farming game # Conflicts: # apps/website/src/routes/demo/+page.svelte # Conflicts: # apps/website/src/lib/demo/content.ts # apps/website/src/lib/demo/demo.svelte.ts # apps/website/src/lib/demo/features/Farming.ts --- .../lib/components/farming/FarmDisplay.svelte | 58 +++++++++ .../lib/components/farming/FarmPlot.svelte | 28 +++++ apps/website/src/lib/demo/content.ts | 40 ++++++- apps/website/src/lib/demo/demo.svelte.ts | 3 +- .../src/lib/demo/features/Farming.svelte.ts | 112 ++++++++++++++++++ apps/website/src/lib/demo/features/Farming.ts | 31 ----- .../src/lib/demo/features/FarmingState.ts | 17 +++ .../website/src/lib/demo/model/PlantDetail.ts | 1 + apps/website/src/routes/+layout.svelte | 2 +- apps/website/src/routes/demo/+page.svelte | 2 + .../plants/cauliflower/cauliflower_00.png | Bin 0 -> 120 bytes .../plants/cauliflower/cauliflower_01.png | Bin 0 -> 151 bytes .../plants/cauliflower/cauliflower_02.png | Bin 0 -> 199 bytes .../plants/cauliflower/cauliflower_03.png | Bin 0 -> 244 bytes .../plants/cauliflower/cauliflower_04.png | Bin 0 -> 263 bytes .../plants/cauliflower/cauliflower_05.png | Bin 0 -> 249 bytes .../static/plants/sunflower/sunflower_00.png | Bin 0 -> 165 bytes .../static/plants/sunflower/sunflower_01.png | Bin 0 -> 195 bytes .../static/plants/sunflower/sunflower_02.png | Bin 0 -> 219 bytes .../static/plants/sunflower/sunflower_03.png | Bin 0 -> 284 bytes .../static/plants/sunflower/sunflower_04.png | Bin 0 -> 442 bytes .../static/plants/sunflower/sunflower_05.png | Bin 0 -> 402 bytes 22 files changed, 259 insertions(+), 35 deletions(-) create mode 100644 apps/website/src/lib/components/farming/FarmDisplay.svelte create mode 100644 apps/website/src/lib/components/farming/FarmPlot.svelte create mode 100644 apps/website/src/lib/demo/features/Farming.svelte.ts create mode 100644 apps/website/src/lib/demo/features/FarmingState.ts create mode 100644 apps/website/static/plants/cauliflower/cauliflower_00.png create mode 100644 apps/website/static/plants/cauliflower/cauliflower_01.png create mode 100644 apps/website/static/plants/cauliflower/cauliflower_02.png create mode 100644 apps/website/static/plants/cauliflower/cauliflower_03.png create mode 100644 apps/website/static/plants/cauliflower/cauliflower_04.png create mode 100644 apps/website/static/plants/cauliflower/cauliflower_05.png create mode 100644 apps/website/static/plants/sunflower/sunflower_00.png create mode 100644 apps/website/static/plants/sunflower/sunflower_01.png create mode 100644 apps/website/static/plants/sunflower/sunflower_02.png create mode 100644 apps/website/static/plants/sunflower/sunflower_03.png create mode 100644 apps/website/static/plants/sunflower/sunflower_04.png create mode 100644 apps/website/static/plants/sunflower/sunflower_05.png diff --git a/apps/website/src/lib/components/farming/FarmDisplay.svelte b/apps/website/src/lib/components/farming/FarmDisplay.svelte new file mode 100644 index 0000000..b5082d7 --- /dev/null +++ b/apps/website/src/lib/components/farming/FarmDisplay.svelte @@ -0,0 +1,58 @@ + + +
+
+
+ + +
+ {#each farming.plots as plot, i (i)} + + {/each} +
+
+
+
diff --git a/apps/website/src/lib/components/farming/FarmPlot.svelte b/apps/website/src/lib/components/farming/FarmPlot.svelte new file mode 100644 index 0000000..74cd5f2 --- /dev/null +++ b/apps/website/src/lib/components/farming/FarmPlot.svelte @@ -0,0 +1,28 @@ + + +
+ {#if plant} +
+ {plant.name} + {#if !farming.isReady(index)} + + {/if} +
+ {/if} +
diff --git a/apps/website/src/lib/demo/content.ts b/apps/website/src/lib/demo/content.ts index 8e56ed6..58590ca 100644 --- a/apps/website/src/lib/demo/content.ts +++ b/apps/website/src/lib/demo/content.ts @@ -2,15 +2,51 @@ import type { CurrencyDetail } from '$lib/demo/model/CurrencyDetail'; import type { AchievementDetail } from '$lib/demo/model/AchievementDetail'; import type { StatisticDetail } from '$lib/demo/model/StatisticDetail'; import type { PlantDetail } from '$lib/demo/model/PlantDetail'; +import type { PlantId } from '$lib/demo/demo.svelte'; // TODO(@Isha): Replace with Zod parsing // First we declare our fully static content export const plants = [ - { id: '/plant/sunflower', name: 'Sunflower', growthTime: 1, moneyReward: 10 }, - { id: '/plant/cauliflower', name: 'Cauliflower', growthTime: 1.5, moneyReward: 20 }, + { + id: '/plant/sunflower', + name: 'Sunflower', + growthTime: 10, + moneyReward: 10, + stages: [ + '/plants/sunflower/sunflower_00.png', + '/plants/sunflower/sunflower_01.png', + '/plants/sunflower/sunflower_02.png', + '/plants/sunflower/sunflower_03.png', + '/plants/sunflower/sunflower_04.png', + '/plants/sunflower/sunflower_05.png', + ], + }, + { + id: '/plant/cauliflower', + name: 'Cauliflower', + growthTime: 30, + moneyReward: 20, + stages: [ + '/plants/cauliflower/cauliflower_00.png', + '/plants/cauliflower/cauliflower_01.png', + '/plants/cauliflower/cauliflower_02.png', + '/plants/cauliflower/cauliflower_03.png', + '/plants/cauliflower/cauliflower_04.png', + '/plants/cauliflower/cauliflower_05.png', + ], + }, ] as const satisfies PlantDetail[]; +export const getPlant = (id: PlantId): PlantDetail => { + // TODO(@Isha): Make into dictionary lookup + const plant = plants.find((p) => p.id === id); + if (!plant) { + throw new Error(`Plant with id '${id}' not found.`); + } + return plant; +}; + export const currencies: CurrencyDetail[] = [ { id: '/currency/money', name: 'Money', icon: '/icon/coin' }, { id: '/currency/gems', name: 'Gems', icon: '/icon/gem-blue' }, diff --git a/apps/website/src/lib/demo/demo.svelte.ts b/apps/website/src/lib/demo/demo.svelte.ts index 91d60e8..69e6100 100644 --- a/apps/website/src/lib/demo/demo.svelte.ts +++ b/apps/website/src/lib/demo/demo.svelte.ts @@ -14,7 +14,7 @@ import { type ExtractCondition, StatisticPlugin, } from '@123ishatest/ludiek'; -import { Farming } from '$lib/demo/features/Farming'; +import { Farming } from '$lib/demo/features/Farming.svelte'; import { achievements, currencies, plants, statistics } from '$lib/demo/content'; // Define plugins with reactive state @@ -53,6 +53,7 @@ export const game = new LudiekGame(engine, { }); engine.plugins.currency.loadContent(currencies); +engine.plugins.currency.loadContent(plants); engine.plugins.statistic.loadContent(statistics); engine.plugins.achievement.loadContent(achievements); diff --git a/apps/website/src/lib/demo/features/Farming.svelte.ts b/apps/website/src/lib/demo/features/Farming.svelte.ts new file mode 100644 index 0000000..8dca8ab --- /dev/null +++ b/apps/website/src/lib/demo/features/Farming.svelte.ts @@ -0,0 +1,112 @@ +import { LudiekFeature } from '@123ishatest/ludiek'; +import type { EnginePlugins, PlantId } from '$lib/demo/demo.svelte'; + +import type { PlantDetail } from '$lib/demo/model/PlantDetail'; +import { emptyPlot, type FarmingState, type FarmPlotState } from '$lib/demo/features/FarmingState'; +import { getPlant } from '$lib/demo/content'; + +export class Farming extends LudiekFeature { + public readonly name: string = 'farming'; + private readonly FARM_PLOTS = 25; + protected _state: FarmingState = $state({ + plots: [], + }); + + public readonly plants: PlantDetail[]; + + constructor(plants: PlantDetail[]) { + super(); + this.plants = plants; + + for (let i = 0; i < this.FARM_PLOTS; i++) { + this._state.plots.push(emptyPlot()); + } + } + + update(delta: number) { + this.growAllPlants(delta); + } + + public growAllPlants(amount: number): void { + this._state.plots.forEach((plot) => { + if (!plot.plant) { + return; + } + plot.progress += amount; + }); + } + + public sow(index: number, id: PlantId): void { + if (!this.isEmpty(index)) { + return; + } + + this._plugins.statistic.incrementMapStatistic('/statistic/plants-planted', id); + this._state.plots[index] = { + plant: id, + progress: 0, + }; + } + + public reap(index: number): void { + if (!this.isReady(index)) { + return; + } + const plot = this.getPlot(index); + const plant = getPlant(plot.plant as PlantId); + + this._plugins.currency.gainCurrency({ id: '/currency/money', amount: plant.moneyReward }); + this.clear(index); + } + + public getGrowthStage(index: number): string { + if (this.isEmpty(index)) { + return ''; + } + const progress = this.getProgress(index); + const plot = this.getPlot(index); + const plant = getPlant(plot.plant as PlantId); + + const stage = Math.floor(progress * (plant.stages.length - 1)); + return plant.stages[stage]; + } + + public getProgress(index: number): number { + if (this.isEmpty(index)) { + return 0; + } + const plot = this.getPlot(index); + const plant = getPlant(plot.plant as PlantId); + return Math.min(1, plot.progress / plant.growthTime); + } + + public clear(index: number): void { + this._state.plots[index] = emptyPlot(); + } + + public getPlant(id: PlantId): PlantDetail { + return this.plants.find((plant) => plant.id === id) as PlantDetail; + } + + public isEmpty(index: number): boolean { + return this.getPlot(index).plant == null; + } + + public isReady(index: number): boolean { + const plot = this.getPlot(index); + if (!plot.plant) { + return false; + } + + const plant = getPlant(plot.plant); + return plot.progress >= plant.growthTime; + } + + public getPlot(index: number): FarmPlotState { + return this._state.plots[index]; + } + + public get plots(): FarmPlotState[] { + return this._state.plots; + } +} diff --git a/apps/website/src/lib/demo/features/Farming.ts b/apps/website/src/lib/demo/features/Farming.ts index 4a4e302..e69de29 100644 --- a/apps/website/src/lib/demo/features/Farming.ts +++ b/apps/website/src/lib/demo/features/Farming.ts @@ -1,31 +0,0 @@ -import { LudiekFeature } from '@123ishatest/ludiek'; -import type { EnginePlugins, PlantId } from '$lib/demo/demo.svelte'; - -import type { PlantDetail } from '$lib/demo/model/PlantDetail'; -import { SowSeedController } from '$lib/demo/features/SowPlantController'; - -export class Farming extends LudiekFeature { - readonly name = 'farming'; - protected _state = {}; - - public readonly config = { - controllers: [new SowSeedController(this)], - }; - - public readonly plants: PlantDetail[]; - - constructor(plants: PlantDetail[]) { - super(); - this.plants = plants; - } - - public sow(id: PlantId): void { - const plant = this.getPlant(id); - this._plugins.currency.gainCurrency({ id: '/currency/money', amount: plant.moneyReward }); - this._plugins.statistic.incrementMapStatistic('/statistic/plants-planted', plant.id); - } - - public getPlant(id: PlantId): PlantDetail { - return this.plants.find((plant) => plant.id === id) as PlantDetail; - } -} diff --git a/apps/website/src/lib/demo/features/FarmingState.ts b/apps/website/src/lib/demo/features/FarmingState.ts new file mode 100644 index 0000000..695deb6 --- /dev/null +++ b/apps/website/src/lib/demo/features/FarmingState.ts @@ -0,0 +1,17 @@ +import type { PlantId } from '$lib/demo/demo.svelte'; + +export interface FarmPlotState { + plant: PlantId | null; + progress: number; +} + +export const emptyPlot = (): FarmPlotState => { + return { + plant: null, + progress: 0, + }; +}; + +export interface FarmingState { + plots: FarmPlotState[]; +} diff --git a/apps/website/src/lib/demo/model/PlantDetail.ts b/apps/website/src/lib/demo/model/PlantDetail.ts index 84f7d5c..6b89458 100644 --- a/apps/website/src/lib/demo/model/PlantDetail.ts +++ b/apps/website/src/lib/demo/model/PlantDetail.ts @@ -3,4 +3,5 @@ export interface PlantDetail { name: string; growthTime: number; moneyReward: number; + stages: string[]; } diff --git a/apps/website/src/routes/+layout.svelte b/apps/website/src/routes/+layout.svelte index 22b272c..97cffb2 100644 --- a/apps/website/src/routes/+layout.svelte +++ b/apps/website/src/routes/+layout.svelte @@ -7,7 +7,7 @@
-
+
{@render children()}
diff --git a/apps/website/src/routes/demo/+page.svelte b/apps/website/src/routes/demo/+page.svelte index 6406619..279f35b 100644 --- a/apps/website/src/routes/demo/+page.svelte +++ b/apps/website/src/routes/demo/+page.svelte @@ -1,5 +1,6 @@ + +
+ {amount} + {currency.name} +
diff --git a/apps/website/src/lib/components/farming/FarmDisplay.svelte b/apps/website/src/lib/components/farming/FarmDisplay.svelte index b5082d7..b315e29 100644 --- a/apps/website/src/lib/components/farming/FarmDisplay.svelte +++ b/apps/website/src/lib/components/farming/FarmDisplay.svelte @@ -1,9 +1,10 @@ + +
+
+
-
- - -
- {#each farming.plots as plot, i (i)} - + +
+ + + + {#each plants as plant (plant.id)} + + + + + + + {/each} + +
+
+ {plant.name} + {plant.name} +
+
{currency.getBalance(plant.id)} + + +
+ +
+
+ +
+ + + +
+ +
+ {#each farming.plots as plot, i (i)} + - {/each} + > + + + {/each} +
+
diff --git a/apps/website/src/lib/components/farming/FarmPlot.svelte b/apps/website/src/lib/components/farming/FarmPlot.svelte index 74cd5f2..659144b 100644 --- a/apps/website/src/lib/components/farming/FarmPlot.svelte +++ b/apps/website/src/lib/components/farming/FarmPlot.svelte @@ -17,12 +17,20 @@
+ {#if plant}
+ {plant.name} + {#if !farming.isReady(index)} {/if}
{/if} +
+ + \ No newline at end of file diff --git a/apps/website/src/lib/demo/content.ts b/apps/website/src/lib/demo/content.ts index 58590ca..0e2af29 100644 --- a/apps/website/src/lib/demo/content.ts +++ b/apps/website/src/lib/demo/content.ts @@ -2,24 +2,84 @@ import type { CurrencyDetail } from '$lib/demo/model/CurrencyDetail'; import type { AchievementDetail } from '$lib/demo/model/AchievementDetail'; import type { StatisticDetail } from '$lib/demo/model/StatisticDetail'; import type { PlantDetail } from '$lib/demo/model/PlantDetail'; -import type { PlantId } from '$lib/demo/demo.svelte'; // TODO(@Isha): Replace with Zod parsing // First we declare our fully static content export const plants = [ { - id: '/plant/sunflower', - name: 'Sunflower', + id: '/plant/cabbage', + name: 'Cabbage', growthTime: 10, moneyReward: 10, + seedCost: 6, stages: [ - '/plants/sunflower/sunflower_00.png', - '/plants/sunflower/sunflower_01.png', - '/plants/sunflower/sunflower_02.png', - '/plants/sunflower/sunflower_03.png', - '/plants/sunflower/sunflower_04.png', - '/plants/sunflower/sunflower_05.png', + '/plants/cabbage/cabbage_00.png', + '/plants/cabbage/cabbage_01.png', + '/plants/cabbage/cabbage_02.png', + '/plants/cabbage/cabbage_03.png', + '/plants/cabbage/cabbage_04.png', + '/plants/cabbage/cabbage_05.png', + ], + }, + { + id: '/plant/potato', + name: 'Potato', + growthTime: 20, + moneyReward: 20, + seedCost: 12, + stages: [ + '/plants/potato/potato_00.png', + '/plants/potato/potato_01.png', + '/plants/potato/potato_02.png', + '/plants/potato/potato_03.png', + '/plants/potato/potato_04.png', + '/plants/potato/potato_05.png', + ], + }, + { + id: '/plant/carrot', + name: 'Carrot', + growthTime: 30, + moneyReward: 40, + seedCost: 20, + stages: [ + '/plants/carrot/carrot_00.png', + '/plants/carrot/carrot_01.png', + '/plants/carrot/carrot_02.png', + '/plants/carrot/carrot_03.png', + '/plants/carrot/carrot_04.png', + '/plants/carrot/carrot_05.png', + ], + }, + { + id: '/plant/beetroot', + name: 'Beetroot', + growthTime: 40, + moneyReward: 50, + seedCost: 40, + stages: [ + '/plants/beetroot/beetroot_00.png', + '/plants/beetroot/beetroot_01.png', + '/plants/beetroot/beetroot_02.png', + '/plants/beetroot/beetroot_03.png', + '/plants/beetroot/beetroot_04.png', + '/plants/beetroot/beetroot_05.png', + ], + }, + { + id: '/plant/radish', + name: 'Radish', + growthTime: 50, + moneyReward: 20, + seedCost: 75, + stages: [ + '/plants/radish/radish_00.png', + '/plants/radish/radish_01.png', + '/plants/radish/radish_02.png', + '/plants/radish/radish_03.png', + '/plants/radish/radish_04.png', + '/plants/radish/radish_05.png', ], }, { @@ -27,6 +87,7 @@ export const plants = [ name: 'Cauliflower', growthTime: 30, moneyReward: 20, + seedCost: 120, stages: [ '/plants/cauliflower/cauliflower_00.png', '/plants/cauliflower/cauliflower_01.png', @@ -36,7 +97,38 @@ export const plants = [ '/plants/cauliflower/cauliflower_05.png', ], }, + { + id: '/plant/pumpkin', + name: 'Pumpkin', + growthTime: 30, + seedCost: 200, + moneyReward: 20, + stages: [ + '/plants/pumpkin/pumpkin_00.png', + '/plants/pumpkin/pumpkin_01.png', + '/plants/pumpkin/pumpkin_02.png', + '/plants/pumpkin/pumpkin_03.png', + '/plants/pumpkin/pumpkin_04.png', + '/plants/pumpkin/pumpkin_05.png', + ], + }, + { + id: '/plant/sunflower', + name: 'Sunflower', + growthTime: 10, + moneyReward: 10, + seedCost: 1000, + stages: [ + '/plants/sunflower/sunflower_00.png', + '/plants/sunflower/sunflower_01.png', + '/plants/sunflower/sunflower_02.png', + '/plants/sunflower/sunflower_03.png', + '/plants/sunflower/sunflower_04.png', + '/plants/sunflower/sunflower_05.png', + ], + }, ] as const satisfies PlantDetail[]; +export type PlantId = (typeof plants)[number]['id']; export const getPlant = (id: PlantId): PlantDetail => { // TODO(@Isha): Make into dictionary lookup @@ -48,10 +140,21 @@ export const getPlant = (id: PlantId): PlantDetail => { }; export const currencies: CurrencyDetail[] = [ - { id: '/currency/money', name: 'Money', icon: '/icon/coin' }, - { id: '/currency/gems', name: 'Gems', icon: '/icon/gem-blue' }, + { id: '/currency/money', name: 'Money', icon: '/icons/egg.png' }, + { id: '/currency/compost', name: 'Compost', icon: '/icon/compost' }, ]; +export type CurrencyId = (typeof currencies)[number]['id']; + +export const getCurrency = (id: CurrencyId): CurrencyDetail => { + // TODO(@Isha): Make into dictionary lookup + const currency = currencies.find((c) => c.id === id); + if (!currency) { + throw new Error(`Currency with id '${id}' not found.`); + } + return currency; +}; + export const statistics: StatisticDetail[] = [ { id: '/statistic/total-money', type: 'scalar' }, { id: '/statistic/plants-planted', type: 'map' }, diff --git a/apps/website/src/lib/demo/features/Farming.svelte.ts b/apps/website/src/lib/demo/features/Farming.svelte.ts index 8dca8ab..7736571 100644 --- a/apps/website/src/lib/demo/features/Farming.svelte.ts +++ b/apps/website/src/lib/demo/features/Farming.svelte.ts @@ -1,13 +1,13 @@ import { LudiekFeature } from '@123ishatest/ludiek'; -import type { EnginePlugins, PlantId } from '$lib/demo/demo.svelte'; +import type { EnginePlugins } from '$lib/demo/demo.svelte'; import type { PlantDetail } from '$lib/demo/model/PlantDetail'; import { emptyPlot, type FarmingState, type FarmPlotState } from '$lib/demo/features/FarmingState'; -import { getPlant } from '$lib/demo/content'; +import { getPlant, type PlantId } from '$lib/demo/content'; export class Farming extends LudiekFeature { public readonly name: string = 'farming'; - private readonly FARM_PLOTS = 25; + public readonly FARM_PLOTS = 25; protected _state: FarmingState = $state({ plots: [], }); @@ -40,6 +40,15 @@ export class Farming extends LudiekFeature { if (!this.isEmpty(index)) { return; } + const plant = getPlant(id); + if ( + !this._plugins.currency.payCurrency({ + id: plant.id, + amount: 1, + }) + ) { + return; + } this._plugins.statistic.incrementMapStatistic('/statistic/plants-planted', id); this._state.plots[index] = { diff --git a/apps/website/src/lib/demo/features/FarmingState.ts b/apps/website/src/lib/demo/features/FarmingState.ts index 695deb6..f7d3ce6 100644 --- a/apps/website/src/lib/demo/features/FarmingState.ts +++ b/apps/website/src/lib/demo/features/FarmingState.ts @@ -1,4 +1,4 @@ -import type { PlantId } from '$lib/demo/demo.svelte'; +import type { PlantId } from '$lib/demo/content'; export interface FarmPlotState { plant: PlantId | null; diff --git a/apps/website/src/lib/demo/model/PlantDetail.ts b/apps/website/src/lib/demo/model/PlantDetail.ts index 6b89458..0931e77 100644 --- a/apps/website/src/lib/demo/model/PlantDetail.ts +++ b/apps/website/src/lib/demo/model/PlantDetail.ts @@ -2,6 +2,7 @@ export interface PlantDetail { id: string; name: string; growthTime: number; + seedCost: number moneyReward: number; stages: string[]; } diff --git a/apps/website/src/routes/demo/+page.svelte b/apps/website/src/routes/demo/+page.svelte index 279f35b..0dd68ed 100644 --- a/apps/website/src/routes/demo/+page.svelte +++ b/apps/website/src/routes/demo/+page.svelte @@ -4,7 +4,7 @@ import { onMount } from 'svelte'; let money = $derived(currency.getBalance('/currency/money')); - let gems = $derived(currency.getBalance('/currency/gems')); + let compost = $derived(currency.getBalance('/currency/compost')); let planted = $derived(statistic.getMapStatistic('/statistic/plants-planted', '/plant/sunflower')); currency.onCurrencyGain.sub((c) => { @@ -35,7 +35,7 @@ }, output: { type: 'currency', - id: '/currency/gems', + id: '/currency/compost', amount: 1, }, }); @@ -49,10 +49,9 @@

You have {money} money

-

You have {gems} gems

+

You have {compost} compost

You have planted {planted} sunflowers

+ - -
diff --git a/apps/website/static/icons/egg.png b/apps/website/static/icons/egg.png new file mode 100644 index 0000000000000000000000000000000000000000..b9efbace5a3787cd08653abd63f963596094dd53 GIT binary patch literal 229 zcmeAS@N?(olHy`uVBq!ia0vp^AT~D#8<2F%laT;YYdl>XLnNjq|M~yl{_ttp%aTWI zjU@TDr~XZMVA>XXSt8M9gOdP*W{~kE*RbOSukWPpNKz|t_1UD9aM_VTg>7?dDOXA{pFV#1;t)?ydz5kDnwFVtMdq7?4}=|NI1!bTv*GIfINS7u1cw{{Xt1!PC{xWt~$(698_$SX}@B literal 0 HcmV?d00001 diff --git a/apps/website/static/icons/img.png b/apps/website/static/icons/img.png new file mode 100644 index 0000000000000000000000000000000000000000..c5e9c90cd76101d9d2647b8a7c6fdb8f29e8a651 GIT binary patch literal 178 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`m7Xq+Ar*1S6`R()u(!H5QNBTR z@oMHowi3n(hn&~Wl;Cnqy1~;Z%@Ew+Yiwtlz`VipL6P0AD7F;F844ZoIq98Eg_2E4 z44dAHNH(13mS9`Jt)P9R?c&uSb+HYa2ih*0CQCHraG3S1lU&Vc;JhKRq||~}ft8<` ZnL)Pf+{qIW{vby%c)I$ztaD0e0sv!>IBx&| literal 0 HcmV?d00001 diff --git a/apps/website/static/icons/plot_background.png b/apps/website/static/icons/plot_background.png new file mode 100644 index 0000000000000000000000000000000000000000..3caf094bd8ee3e7ba626c0cac79725e3e6d7fe76 GIT binary patch literal 86 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`vYsxEAr*1S6`R()uveYI7~2qH jlXYMP<6<@*F=hshq~G#|F|W#j3K=|I{an^LB{Ts5JA@X4 literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/beetroot/beetroot_00.png b/apps/website/static/plants/beetroot/beetroot_00.png new file mode 100644 index 0000000000000000000000000000000000000000..26fac3540be8e79b100b555fd117a6adb1fdc382 GIT binary patch literal 123 zcmeAS@N?(olHy`uVBq!ia0vp^tRT$61|)m))t&+=Cr=m05RRG2fByfsKU|mJ{GW&8 zz=@Egd{(i5?n1U?Hnz6^J_bF`h1tAsjQ4fBgS%-yFOAc)dXH znY57Z!e9Bb&z>##eIcJsAYf~9s)fy0Z5JjLg@vctrd1UF6rYhcbMeY^0{i}I9e&PU xe}GA0!=>QajjfH1jfG2>n?;Dr7#J8ZF(}!qR`n=7cnh?L!PC{xWt~$(69A0sHd6oq literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/beetroot/beetroot_02.png b/apps/website/static/plants/beetroot/beetroot_02.png new file mode 100644 index 0000000000000000000000000000000000000000..276e7dcfa7ccc8383b0c7c7973c5afc216397d1e GIT binary patch literal 197 zcmeAS@N?(olHy`uVBq!ia0vp^96-#*!3HG%vEKg;q0l4Dehabo!V;Lm@Mg#RBsu!4;&m%#L0OB+T;kVCcw zc7hdbe(?k>;VU5nroGmeGqS*pbyWSt;Hb(6<$YqJP0003mNkly&g1{jdCwFh(j|LB25HnLm-)Bb<-7^fef3}%BhYzyoJvHv@&eqz{v zn~!1hizi@7UkMoom>5W{*ZOh>7O3H1#UKEp9aZ_D!U(bbxA{P}Gr~O$H3cg`mIG^m zIRTp{m>5hA*bnv^M*p=0t-)@_20)6hy*~<85Ay@#wf9H=GcZ`gJ&SBANU@fnHAoF2 z;#%S?V5Wc-A}a>TMfv_kI0>9i+Ooi*g~Q+A#AsVJjR63E8ID0^?Gyz70000P)(@V8W$Y)sB?`ge7#@7}R5(vD<>p0GMVFxP9n1 zE`9i200ZU69S9o0f^0Jb)Xy*%Fc1+2Ea=V#(IBUTG_t;U!oZ+HzzfKlk!^(miPP_i z^8(0Lke@fdc*5X>rf6GWCp;EF^3#t`hI@%oEyn3TD5}tHhuN$pXwA@P%LkX=f13}* z5O6|5j%VZmv)3^Czr)WH!`aA&u%K%~2IZRJ3=9mP@P+~2bO5piWE;Be$N(OQ_yD>l z5V-dKD452XnP4E(GWWl)gbaquV1^Jh0A>iX&7hbe$pCZ!iX9Mr@Wwet06Kbx|Jc!T Q>Hq)$07*qoM6N<$g6Fu3egFUf literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/cabbage/cabbage_00.png b/apps/website/static/plants/cabbage/cabbage_00.png new file mode 100644 index 0000000000000000000000000000000000000000..f8a5d36cb0d0c811268ae1fc070d8a7c16cd6fcf GIT binary patch literal 131 zcmeAS@N?(olHy`uVBq!ia0vp^tRT$61|)m))t&+=FHaZ85RRG2fByfsKfLY0x&J%? z54P@`GqEt+;ds6KRezrOb5af*N>8s#O1Sms5vPx!%!UIIHNO)k)$r&rKJ%C8<~x1h fERVtdV;l@0ri;Jj6ztdpG?l^A)z4*}Q$iB}Cg3oL literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/cabbage/cabbage_01.png b/apps/website/static/plants/cabbage/cabbage_01.png new file mode 100644 index 0000000000000000000000000000000000000000..ea5d7dd5110b5a37245d9ad418ba6b3d611e12ea GIT binary patch literal 211 zcmV;^04)EBP)p@&Et-4C=AY z40ANq!HQF^-vrCd(NqW1Dc5f@f>nYPf{ky>LNOU;lIh2t3>=+z8303j?z%)r3#e_LQDM5SG)2ZPpnmH&OVd<^?Aw1t3WV1_nj|Tgx^Q6jDE?00000 LNkvXXu0mjfYkgG2 literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/cabbage/cabbage_03.png b/apps/website/static/plants/cabbage/cabbage_03.png new file mode 100644 index 0000000000000000000000000000000000000000..05a1e8f838e96d8d10ff08b29e3d6fbcdd7628d6 GIT binary patch literal 303 zcmV+~0nq-5P)|`yVpgKJ=S`>BZ$= za1%j_K?-01#0H7M07xwhhyl{c5O{}yVLgZ^!{EpOaTZAN<`+*Gu7TtZL9~H1Fuu6_ z>%W998$<%C2?XGZp{9e>GOEQmG0f3a|DSUGCId(lk|YX$j;1=pw^z>@!A=6{1Z%o{ z6D3Yy8bOLdYQO|2;tscE!PKC}A_9OFe|zK-szN}+>)K(<1mTc-X80jJJ^ZutWo0@-39ojV0m#4ZH~ zXU8~vhVscwLCT(bg- z_up~{+4;(cNhKsA^e@CFS&*Cx5LY|kxx!MQc2YygogMHs8sdTyLTq;HBUc<=A|JBz zRoPP$k#hm+2Aarm2e4skGVef&;_bn3mkYkmP8X1{5b0-6P3@XLWp}wC0S k+TSbTwj@6JS6Nxdg!}fCMyWKqJUbfmnjvB#IMYE2evalGpH-Zom^=^Zu{@ z``eii0;K!q9EzETU**xUjYIpgC~qetrawSGMV literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/carrot/carrot_00.png b/apps/website/static/plants/carrot/carrot_00.png new file mode 100644 index 0000000000000000000000000000000000000000..0ca2b5fa40f17dea5e98d8f9b34feff3ee0902f4 GIT binary patch literal 171 zcmeAS@N?(olHy`uVBq!ia0vp^>>$j+1|*LJgB>AsjQ4|NQ@NfB0O}f&V-l z2VU4E+Rix6GTGomLGlBk$t;Hd*Rq091MAX^tpMWLN@~~ OX7F_Nb6Mw<&;$T2Jw0du literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/carrot/carrot_02.png b/apps/website/static/plants/carrot/carrot_02.png new file mode 100644 index 0000000000000000000000000000000000000000..73edb91b9e07371083ecc1100c5e92ce6b86b4a3 GIT binary patch literal 187 zcmeAS@N?(olHy`uVBq!ia0vp^Y(UJ;0V1_0*t`W&O`a}}AsjQ4|NQ@N&&=^-tpnd2x#OuXTY#=%@O1TaS?83{1ON=AM%VxV literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/carrot/carrot_03.png b/apps/website/static/plants/carrot/carrot_03.png new file mode 100644 index 0000000000000000000000000000000000000000..4712a82fa624353b3ef10849940d84aa22d26f73 GIT binary patch literal 259 zcmV+e0sQ`nP)7ii`2X?IO)#5ZP8~!sf(c0*I|h?%!~bFm_ZX1Ds|QM8c_x_H?L)ue(#UM4 zXNM1hRld0V3oZy^iz(a#TfqV%HnJc6f8gD3hK#8Y1vB2gWpH@@=|2Peb4I2g<;wpV zEOi+iQdq$fV969#29Vg#6Yu^r?(@?BZ>jT{f!#s~EC>e2FM}i*j$h$rU}CYh0*iqJ zU;xGj$$@;qc$(iGt`m$I7#N^pj9^DX75!(p4(0Jf#26SD7yy<9PTQ1`24w&M002ov JPDHLkV1kXgXs-YO literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/carrot/carrot_04.png b/apps/website/static/plants/carrot/carrot_04.png new file mode 100644 index 0000000000000000000000000000000000000000..745b3106bac3ba5d374635fe17c92696654db881 GIT binary patch literal 310 zcmV-60m=S}P)7iifG`*s7&k>sz~F-wf&|4B?tw*bANmcZRqa^8^s5I-V8u*Qw)PkbV2WU3 zAixAO{>9~AC=wtxNK8!O9wS)cv%?3$5;uZAF~AhV6oJHMKYxxeaU=WD{|uJ83^U%n z1uFny5E~@Mz`*c-Bl}SX#_wfH|Je)e85oXV2J1X92V%WL3dEft#XtKGGBED*(*JL% z^O=F&LI^Ga22hPZPrPF|euWqA8L$94Ko$ds<9=@gu&E#bGa04`WSZmF3ye%V3j#4r zLI?Z34IoytSX+U0q63f^NbZ-aBE;&$ZCT)8z+oWcw^z>@01S|XKx3X!4*&oF07*qo IM6N<$f?_s!TmS$7 literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/carrot/carrot_05.png b/apps/website/static/plants/carrot/carrot_05.png new file mode 100644 index 0000000000000000000000000000000000000000..3d54fd13a3b15bff6206c776a55760b1199515b0 GIT binary patch literal 248 zcmV7iifG`*s7&b*rU}V4nm_WkzU7r8N6z(yA@Xf84aj69Z7LduRcB~Ay5B+8U z(IBwj+W>Bxe2}2Y^!Os)#;Oyg9c)`wNLUtc6#mE3f13twtr@@^Ba~4Pf7XUd6 y#RiZYL4x=IhLd2LaA`zw5;{N*PB36#U;qF|-duAAsgs8Q0000G{3q%m39!Ee;=%%+tNeJuRh?vu0m`pii@??#wICN(DNM+7WiJxh>5icK+f-}bkAfYva0y85}Sb4q9e0FfUx^Z)<= literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/potato/potato_01.png b/apps/website/static/plants/potato/potato_01.png new file mode 100644 index 0000000000000000000000000000000000000000..0a72ca3626e87dd6d0a09b83685c9d952792f961 GIT binary patch literal 166 zcmeAS@N?(olHy`uVBq!ia0vp^Y#_`5A|IT2?*XK8JzX3_IA$jQ`TyUZnd8S=4F+Q~ zSD%D0(SZjJyx46s|Ka1sv;T*_jX21aC;#j00sZCYPHfRkVv1mptf?uP+{k$(crPOZ5@1w|ar!Tz%f_H;#|jobJoPJzA{H3q_MzW!Z7>r-3gK3K ze((n@sp`uGHVvfV#pPdc6Bv0Fz)Y}CWYd_SMlsBI_ZIHZ+nc|Eb%U$`Yb&w0`k!JU z!m!UkAFSZB)kTImC%&ON5(J*_Iu53J#JEtc083tZgHVXX2K(Z0Th{+SM~@*J#=v52 v#qjObb4JEuJ4*(CcLTT&kOT4CtLF>=avD@O@U{F<00000NkvXXu0mjfF4AV? literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/potato/potato_04.png b/apps/website/static/plants/potato/potato_04.png new file mode 100644 index 0000000000000000000000000000000000000000..a3f8d18a30417b3d64965cbfeb1de03a3a66cd1c GIT binary patch literal 309 zcmV-50m}Y~P)f4P4;wg43U_c{OA9FduEO|-_05f z791#i&FYq7$K9c^ar>|NNs3Hj4@@t#XS;-*VF`M2_H*yUpHs~f8lUg(YtGy%kuDNF zLt;b2d2ziY4YufBo{A$o9;h|nm}I4ta8yI>(3<0HGphLHlJERtP2$>=G~=WJ1Hasi z>$j+1|*LJg3;LLgzh~tAH_66NOoV*HfbL=NboFyt=akR{0B8F}`2YX_ literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/pumpkin/pumpkin_02.png b/apps/website/static/plants/pumpkin/pumpkin_02.png new file mode 100644 index 0000000000000000000000000000000000000000..c11be21fc7863a4ab905f2bab33be386d4c757d3 GIT binary patch literal 263 zcmV+i0r>ujP)B3L580n-!lCDugcKL zA_y@F3DVH==NH)FU_~GS5SXK>&cN^os$3J|djA22KT-{I^^E z{{NHnzZhSgco^KdzA)_k%EMsqpas!@tQZDB z3SeFXX#yz*@fg)&oUlbTJP0003GNkl*Ax(gs056t-u*2K8aOCPKl1V9=PrQR`04WA3gnJsR@2~)vAx!9Qh5=+-U;v~R97=G{USWVc3#JKK4g|oV1PeNl z1c*jA6(-kn@E9Xl!{N59{~LE+fGdJ&LUyjdy8*+uSI-$4i|s7I90mpk)KrKG7{9%G a&Hw;|gprYVD*0ys0000JP0002}Nkl*Ax(gs056t-u*2K8aOCPKl1V9=PrQR`04WA3gnJsR@9+Se8jx*4<}<-O38F#HLRSQG4ze0>u!0nVf(|Tk1=S{y z7)TCg7&ur#VU4T^qyVNE8T1@H#>iA+Zv|$cn~F{Ges2Q?0OucxEuCW_1poj507*qo IM6N<$f`^HD00000 literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/radish/radish_00.png b/apps/website/static/plants/radish/radish_00.png new file mode 100644 index 0000000000000000000000000000000000000000..7893e11ad9ebd2a8925f5e8a29e5fee991a4eafa GIT binary patch literal 153 zcmeAS@N?(olHy`uVBq!ia0vp^Y#_`5A|IT2?*XI|JY5_^IA$jQ`TyVkaBtD{|HXba z$qh`$<~1LekoaEt@_%@DVcL(Hhe{DLs~RR|z82SOi}wC@D8zV4L_y<<|2_td&%^H> zP<3QbImmITRqrIz=7QJa>;5NP>&)lT6pQI$n07#U;fJG@89=)jJYD@<);T3K0RVFi BJdywa literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/radish/radish_01.png b/apps/website/static/plants/radish/radish_01.png new file mode 100644 index 0000000000000000000000000000000000000000..51e22e5a0f8462f2ef17d01888be09ee14967f63 GIT binary patch literal 141 zcmeAS@N?(olHy`uVBq!ia0vp^Y#_`5A|IT2?*XJjJY5_^IA$jQ`TyU(xoXYldN!4U z;*W7|Zd)am|KE1=&WT4n?aS*@6POJ1zopr051|W*Z=?k literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/radish/radish_02.png b/apps/website/static/plants/radish/radish_02.png new file mode 100644 index 0000000000000000000000000000000000000000..318e384d5e26828d9d755d64166c9d10fe53021b GIT binary patch literal 180 zcmeAS@N?(olHy`uVBq!ia0vp^96-#@!3HEvBYEP0RJEszV+hC0j z+j#M3k3w6nnK?6u%)DQsKFXhGI`rIbuWM#iDY44$rjF6*2UngGk-KU@F+ literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/radish/radish_03.png b/apps/website/static/plants/radish/radish_03.png new file mode 100644 index 0000000000000000000000000000000000000000..d830d96353485b770301a5c7f71aa3fc4c617fa1 GIT binary patch literal 226 zcmeAS@N?(olHy`uVBq!ia0vp^96-#)!3HEdkIOdzsg<5Cjv*3LlYjjGZ{Hl%bGcrC zZR5qCJqm5PX6DQsGV^|k`Y3;%>Ckh#y{?&6rR3%TiO3$ol%A?JpZ}ld|7Y+)YeNI; z#2Y;c!g+f4PT%;+m1M)=aI>dCSZwv|KjlKAE!qr?wd?O2AGv44Y{)3f5jpc<>jAN| ziGPkC`0&ft>F%+)2^%A3h_>I}^v^z`g6pV4YlU%J{`z^wPIJy4IIuz>|C{_-EjKnG ZV3;Tz@Xqalr4`W844$rjF6*2UngB1UT1Wr@ literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/radish/radish_04.png b/apps/website/static/plants/radish/radish_04.png new file mode 100644 index 0000000000000000000000000000000000000000..33ac59cb51c461ba587e38342ade9a24cdbf814d GIT binary patch literal 313 zcmV-90mlA`P)soivB>9|Obd_n5ji?gY!lV)HaH0Is1W z&H`c!8UTrbIrng`&g*0|Ns9{DotRzG-~<00000 LNkvXXu0mjf&RKbK literal 0 HcmV?d00001 diff --git a/apps/website/static/plants/radish/radish_05.png b/apps/website/static/plants/radish/radish_05.png new file mode 100644 index 0000000000000000000000000000000000000000..1eb4e3b8a72ce74cee33f83df21daf0a73a76eb2 GIT binary patch literal 314 zcmV-A0mc4_P)e2@{tNsHA@{-6HO#sI=F0ONz?P@Du3a1s^7>Kq{}GlqA^PBH9z{hlHA z<{3sNtg4UzNHItg46uOcIgI}p7+${z3!&QtGMQoHPOzF-m<9|5cmUW*2XCBX1lxiG zfaE}G;GTv7dkrHnC*?oHYcNA#iZL{xYeZIv;%RhXD$ar3aSRL$0L&G6n5+OY0RR91 M07*qoM6N<$f)B}e%>V!Z literal 0 HcmV?d00001 From a2a0b6f67f260126828aecaabe1734540ed2d3ef Mon Sep 17 00:00:00 2001 From: Isha Dijcks Date: Sun, 7 Sep 2025 15:49:33 +0200 Subject: [PATCH 3/3] Update game --- .../src/lib/components/CurrencyDisplay.svelte | 4 +- .../lib/components/farming/FarmDisplay.svelte | 93 ++++++++----------- .../lib/components/farming/FarmPlot.svelte | 6 +- apps/website/src/lib/demo/demo.svelte.ts | 9 +- .../src/lib/demo/features/Farming.svelte.ts | 11 ++- apps/website/src/lib/demo/features/Farming.ts | 0 .../lib/demo/features/ReapAllController.ts | 23 +++++ .../src/lib/demo/features/SowAllController.ts | 24 +++++ ...lantController.ts => SowSeedController.ts} | 5 +- .../website/src/lib/demo/model/PlantDetail.ts | 2 +- apps/website/src/routes/demo/+page.svelte | 29 +----- 11 files changed, 110 insertions(+), 96 deletions(-) delete mode 100644 apps/website/src/lib/demo/features/Farming.ts create mode 100644 apps/website/src/lib/demo/features/ReapAllController.ts create mode 100644 apps/website/src/lib/demo/features/SowAllController.ts rename apps/website/src/lib/demo/features/{SowPlantController.ts => SowSeedController.ts} (79%) diff --git a/apps/website/src/lib/components/CurrencyDisplay.svelte b/apps/website/src/lib/components/CurrencyDisplay.svelte index 2a746ee..b42b2ef 100644 --- a/apps/website/src/lib/components/CurrencyDisplay.svelte +++ b/apps/website/src/lib/components/CurrencyDisplay.svelte @@ -4,7 +4,7 @@ import { asset } from '$app/paths'; interface Props { - amount: number + amount: number; currency: CurrencyDetail; } @@ -14,6 +14,6 @@
+ {currency.name} {amount} - {currency.name}
diff --git a/apps/website/src/lib/components/farming/FarmDisplay.svelte b/apps/website/src/lib/components/farming/FarmDisplay.svelte index b315e29..d5c9715 100644 --- a/apps/website/src/lib/components/farming/FarmDisplay.svelte +++ b/apps/website/src/lib/components/farming/FarmDisplay.svelte @@ -43,78 +43,66 @@ }; const harvestAll = (): void => { - for (let i = 0; i < farming.FARM_PLOTS; i++) { - farming.reap(i); - } + game.request({ + type: '/farming/reap-all', + }); }; const plantAll = (): void => { - for (let i = 0; i < farming.FARM_PLOTS; i++) { - farming.sow(i, selectedSeed); - } + game.request({ + type: '/farming/sow-all', + plant: selectedSeed, + }); }; - -
-
-
+
+
+
+ + +
- - -
- -
-
- - - -
- - +
- {#each plants as plant (plant.id)} - - selectSeed(plant.id)} class="cursor-pointer {selectedSeed === plant.id ? 'bg-base-200' : ''}" - > - - - - - {/each} + > + + + + + {/each}
-
- {plant.name} - {plant.name} -
-
{currency.getBalance(plant.id)} - - -
+
+ {plant.name} + {plant.name} +
+
{currency.getBalance(plant.id)} + +
- +
+
+
+ +
-
- -
- - - -
{#each farming.plots as plot, i (i)} @@ -122,6 +110,5 @@
-
diff --git a/apps/website/src/lib/components/farming/FarmPlot.svelte b/apps/website/src/lib/components/farming/FarmPlot.svelte index 659144b..46bf2db 100644 --- a/apps/website/src/lib/components/farming/FarmPlot.svelte +++ b/apps/website/src/lib/components/farming/FarmPlot.svelte @@ -17,10 +17,8 @@
- {#if plant}
- {plant.name} {#if !farming.isReady(index)} @@ -28,9 +26,7 @@ {/if}
{/if} -
\ No newline at end of file + diff --git a/apps/website/src/lib/demo/demo.svelte.ts b/apps/website/src/lib/demo/demo.svelte.ts index 69e6100..30d5cf3 100644 --- a/apps/website/src/lib/demo/demo.svelte.ts +++ b/apps/website/src/lib/demo/demo.svelte.ts @@ -1,17 +1,17 @@ import { AchievementPlugin, AlwaysTrueCondition, - type ExtractOutput, CouponPlugin, createAchievementState, createCouponState, createCurrencyState, createStatisticState, CurrencyPlugin, + type ExtractCondition, type ExtractInput, + type ExtractOutput, LudiekEngine, LudiekGame, - type ExtractCondition, StatisticPlugin, } from '@123ishatest/ludiek'; import { Farming } from '$lib/demo/features/Farming.svelte'; @@ -43,10 +43,10 @@ export type Condition = ExtractCondition; export type PlantId = (typeof plants)[number]['id']; // Create your game -const farming = new Farming(plants); +const farmingFeature = new Farming(plants); export const game = new LudiekGame(engine, { - features: [farming], + features: [farmingFeature], saveKey: '@123ishatest/ludiek-demo', tickDuration: 0.1, saveInterval: 30, @@ -58,3 +58,4 @@ engine.plugins.statistic.loadContent(statistics); engine.plugins.achievement.loadContent(achievements); export const { currency, statistic, achievement } = engine.plugins; +export const { farming } = game.features; diff --git a/apps/website/src/lib/demo/features/Farming.svelte.ts b/apps/website/src/lib/demo/features/Farming.svelte.ts index 7736571..ceab068 100644 --- a/apps/website/src/lib/demo/features/Farming.svelte.ts +++ b/apps/website/src/lib/demo/features/Farming.svelte.ts @@ -1,13 +1,20 @@ import { LudiekFeature } from '@123ishatest/ludiek'; import type { EnginePlugins } from '$lib/demo/demo.svelte'; - import type { PlantDetail } from '$lib/demo/model/PlantDetail'; import { emptyPlot, type FarmingState, type FarmPlotState } from '$lib/demo/features/FarmingState'; import { getPlant, type PlantId } from '$lib/demo/content'; +import { SowSeedController } from '$lib/demo/features/SowSeedController'; +import { SowAllController } from '$lib/demo/features/SowAllController'; +import { ReapAllController } from '$lib/demo/features/ReapAllController'; export class Farming extends LudiekFeature { public readonly name: string = 'farming'; + public readonly config = { + controllers: [new SowSeedController(this), new SowAllController(this), new ReapAllController(this)], + }; + public readonly FARM_PLOTS = 25; + protected _state: FarmingState = $state({ plots: [], }); @@ -27,7 +34,7 @@ export class Farming extends LudiekFeature { this.growAllPlants(delta); } - public growAllPlants(amount: number): void { + private growAllPlants(amount: number): void { this._state.plots.forEach((plot) => { if (!plot.plant) { return; diff --git a/apps/website/src/lib/demo/features/Farming.ts b/apps/website/src/lib/demo/features/Farming.ts deleted file mode 100644 index e69de29..0000000 diff --git a/apps/website/src/lib/demo/features/ReapAllController.ts b/apps/website/src/lib/demo/features/ReapAllController.ts new file mode 100644 index 0000000..1755327 --- /dev/null +++ b/apps/website/src/lib/demo/features/ReapAllController.ts @@ -0,0 +1,23 @@ +import type { BaseRequestShape, LudiekController } from '@123ishatest/ludiek'; +import type { Farming } from '$lib/demo/features/Farming.svelte'; + +export interface ReapAllRequest extends BaseRequestShape { + type: '/farming/reap-all'; +} + +export class ReapAllController implements LudiekController { + readonly type: string = '/farming/reap-all'; + + private readonly _farming: Farming; + + constructor(farming: Farming) { + this._farming = farming; + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + resolve(request: ReapAllRequest): void { + for (let i = 0; i < this._farming.FARM_PLOTS; i++) { + this._farming.reap(i); + } + } +} diff --git a/apps/website/src/lib/demo/features/SowAllController.ts b/apps/website/src/lib/demo/features/SowAllController.ts new file mode 100644 index 0000000..2fe0c91 --- /dev/null +++ b/apps/website/src/lib/demo/features/SowAllController.ts @@ -0,0 +1,24 @@ +import type { BaseRequestShape, LudiekController } from '@123ishatest/ludiek'; +import type { PlantId } from '$lib/demo/demo.svelte'; +import type { Farming } from '$lib/demo/features/Farming.svelte'; + +export interface SowAllRequest extends BaseRequestShape { + type: '/farming/sow-all'; + plant: PlantId; +} + +export class SowAllController implements LudiekController { + readonly type: string = '/farming/sow-all'; + + private readonly _farming: Farming; + + constructor(farming: Farming) { + this._farming = farming; + } + + resolve(request: SowAllRequest): void { + for (let i = 0; i < this._farming.FARM_PLOTS; i++) { + this._farming.sow(i, request.plant); + } + } +} diff --git a/apps/website/src/lib/demo/features/SowPlantController.ts b/apps/website/src/lib/demo/features/SowSeedController.ts similarity index 79% rename from apps/website/src/lib/demo/features/SowPlantController.ts rename to apps/website/src/lib/demo/features/SowSeedController.ts index 5f8e626..2569576 100644 --- a/apps/website/src/lib/demo/features/SowPlantController.ts +++ b/apps/website/src/lib/demo/features/SowSeedController.ts @@ -1,9 +1,10 @@ import type { BaseRequestShape, LudiekController } from '@123ishatest/ludiek'; -import type { Farming } from '$lib/demo/features/Farming'; import type { PlantId } from '$lib/demo/demo.svelte'; +import type { Farming } from '$lib/demo/features/Farming.svelte'; export interface SowSeedRequest extends BaseRequestShape { type: '/farming/sow-seed'; + plot: number; plant: PlantId; } @@ -17,6 +18,6 @@ export class SowSeedController implements LudiekController { } resolve(request: SowSeedRequest): void { - this._farming.sow(request.plant); + this._farming.sow(request.plot, request.plant); } } diff --git a/apps/website/src/lib/demo/model/PlantDetail.ts b/apps/website/src/lib/demo/model/PlantDetail.ts index 0931e77..c1e3e83 100644 --- a/apps/website/src/lib/demo/model/PlantDetail.ts +++ b/apps/website/src/lib/demo/model/PlantDetail.ts @@ -2,7 +2,7 @@ export interface PlantDetail { id: string; name: string; growthTime: number; - seedCost: number + seedCost: number; moneyReward: number; stages: string[]; } diff --git a/apps/website/src/routes/demo/+page.svelte b/apps/website/src/routes/demo/+page.svelte index 0dd68ed..c40fef1 100644 --- a/apps/website/src/routes/demo/+page.svelte +++ b/apps/website/src/routes/demo/+page.svelte @@ -1,5 +1,5 @@