diff --git a/src/app/components/food-pantry/food-pantry.component.html b/src/app/components/food-pantry/food-pantry.component.html index dd1f932..3a9c836 100644 --- a/src/app/components/food-pantry/food-pantry.component.html +++ b/src/app/components/food-pantry/food-pantry.component.html @@ -1 +1,12 @@ -

food-pantry works!

+
+
+
+

food-pantry works!

+ X +
+ +
+
diff --git a/src/app/components/food-pantry/food-pantry.component.ts b/src/app/components/food-pantry/food-pantry.component.ts index 470ae00..16a611e 100644 --- a/src/app/components/food-pantry/food-pantry.component.ts +++ b/src/app/components/food-pantry/food-pantry.component.ts @@ -1,10 +1,19 @@ -import { Component } from '@angular/core'; +import { Component, inject, output, OutputEmitterRef, Signal } from '@angular/core'; +import { ButtonComponent } from "../ui-elements/button/button.component"; +import { Food } from '../../types/food'; +import { FoodStore } from '../../api/food.store'; +import { GridComponent } from "../grid/grid.component"; @Component({ selector: 'ff-food-pantry', - imports: [], + imports: [ButtonComponent, GridComponent], templateUrl: './food-pantry.component.html', }) export class FoodPantryComponent { + public readonly onClose: OutputEmitterRef = output(); + public readonly onFoodChosen: OutputEmitterRef = output(); + private readonly foodStore: FoodStore = inject(FoodStore); + + protected readonly foods: Signal = this.foodStore.foods; } diff --git a/src/app/components/grid/grid.component.html b/src/app/components/grid/grid.component.html new file mode 100644 index 0000000..7105d86 --- /dev/null +++ b/src/app/components/grid/grid.component.html @@ -0,0 +1,12 @@ +
+ @for (item of gridItems(); track $index) { +
+ } +
diff --git a/src/app/components/grid/grid.component.spec.ts b/src/app/components/grid/grid.component.spec.ts new file mode 100644 index 0000000..fd0f4a1 --- /dev/null +++ b/src/app/components/grid/grid.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { GridComponent } from './grid.component'; + +describe('GridComponent', () => { + let component: GridComponent; + let fixture: ComponentFixture>; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [GridComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(GridComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/grid/grid.component.ts b/src/app/components/grid/grid.component.ts new file mode 100644 index 0000000..68f0f17 --- /dev/null +++ b/src/app/components/grid/grid.component.ts @@ -0,0 +1,14 @@ +import { NgStyle } from '@angular/common'; +import { Component, input, InputSignal, output, OutputEmitterRef } from '@angular/core'; + +@Component({ + selector: 'ff-grid', + imports: [NgStyle], + templateUrl: './grid.component.html', +}) +export class GridComponent { + public readonly gridItems: InputSignal = input.required(); + public readonly size: InputSignal = input(5); + + public readonly onSelect: OutputEmitterRef = output(); +} diff --git a/src/app/components/inventory/inventory.component.html b/src/app/components/inventory/inventory.component.html index c3268ea..6e21612 100644 --- a/src/app/components/inventory/inventory.component.html +++ b/src/app/components/inventory/inventory.component.html @@ -1 +1,8 @@ -

inventory works!

+
+
+
+

inventory works!

+ X +
+
+
diff --git a/src/app/components/inventory/inventory.component.ts b/src/app/components/inventory/inventory.component.ts index f92d304..6a44e1a 100644 --- a/src/app/components/inventory/inventory.component.ts +++ b/src/app/components/inventory/inventory.component.ts @@ -1,10 +1,13 @@ -import { Component } from '@angular/core'; +import { Component, output, OutputEmitterRef } from '@angular/core'; +import { ButtonComponent } from "../ui-elements/button/button.component"; @Component({ selector: 'ff-inventory', - imports: [], + imports: [ButtonComponent], templateUrl: './inventory.component.html', }) export class InventoryComponent { + public readonly onClose: OutputEmitterRef = output(); + public readonly onItemChosen: OutputEmitterRef = output(); } diff --git a/src/app/components/ui-elements/button/button.component.html b/src/app/components/ui-elements/button/button.component.html index be75a5c..ebe3667 100644 --- a/src/app/components/ui-elements/button/button.component.html +++ b/src/app/components/ui-elements/button/button.component.html @@ -1,6 +1,6 @@ diff --git a/src/app/logic/chibi-behaviour/brain.ts b/src/app/logic/chibi-behaviour/brain.ts index 483c9be..41b6bcd 100644 --- a/src/app/logic/chibi-behaviour/brain.ts +++ b/src/app/logic/chibi-behaviour/brain.ts @@ -1,9 +1,11 @@ +import { Chibi } from "../../types/chibi/chibi"; import { EChibiInteraction } from "../../types/chibi/chibi-interaction"; -import { EChibiStateName } from "../../types/chibi/chibi-state-name"; +import { Food } from "../../types/food"; export interface IBrain { //function for time passegs + autonomous state changes + exist(chibi: Chibi): void; - resolveInteraction(state: EChibiStateName, interaction: EChibiInteraction): EChibiStateName + resolveInteraction(chibi: Chibi, interaction: EChibiInteraction, item?: Food): void } \ No newline at end of file diff --git a/src/app/logic/chibi-behaviour/brains/aperio.brain.ts b/src/app/logic/chibi-behaviour/brains/aperio.brain.ts index a540582..51ec016 100644 --- a/src/app/logic/chibi-behaviour/brains/aperio.brain.ts +++ b/src/app/logic/chibi-behaviour/brains/aperio.brain.ts @@ -1,12 +1,29 @@ +import { Chibi } from "../../../types/chibi/chibi"; import { EChibiInteraction } from "../../../types/chibi/chibi-interaction"; import { EChibiStateName } from "../../../types/chibi/chibi-state-name"; +import { Food } from "../../../types/food"; import { IBrain } from "../brain"; export class Aperio implements IBrain { - resolveInteraction(state: EChibiStateName, interaction: EChibiInteraction): EChibiStateName { - switch (state) { - case EChibiStateName.Sleeping: return this.resolveSleepingInteraction(interaction); - default: return EChibiStateName.Sleeping; + + private hasBeenAwakeFor: number = 0; + + exist(chibi: Chibi): void { + console.log('Brain is braining'); + if (!EChibiStateName.Sleeping) { + this.hasBeenAwakeFor++; + if (this.hasBeenAwakeFor > 60) { + chibi.state = EChibiStateName.Sleeping; + } + } + } + + resolveInteraction(chibi: Chibi, interaction: EChibiInteraction, item?: Food): void { + switch (chibi.state) { + case EChibiStateName.Sleeping: chibi.state = this.resolveSleepingInteraction(interaction); break; + case EChibiStateName.Awake: chibi.state = this.resolveAwakeInteraction(interaction, item); break; + default: + chibi.state = EChibiStateName.Sleeping; break; } } @@ -39,4 +56,11 @@ export class Aperio implements IBrain { } return EChibiStateName.Sleeping; } + + private resolveAwakeInteraction(interaction: EChibiInteraction, item?: Food): EChibiStateName { + if (EChibiInteraction.Feed) { + return EChibiStateName.Eating; + } + return EChibiStateName.Idle; + } }; \ No newline at end of file diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index c0d13a5..67d13b6 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -1,5 +1,6 @@ import { Component } from '@angular/core'; import { RouterLink } from "@angular/router"; +import { TranslateableComponent } from '../../components/translateable.component'; @Component({ selector: 'ff-home', diff --git a/src/app/pages/interactions/interactions.component.html b/src/app/pages/interactions/interactions.component.html index effd089..52c6376 100644 --- a/src/app/pages/interactions/interactions.component.html +++ b/src/app/pages/interactions/interactions.component.html @@ -1,3 +1,4 @@ +@let shownMenu = interactionMenuState();
@if (chibi()) { @@ -12,11 +13,26 @@
}
-
- - - {{ - lang.game.actions.wakeUp - }} +
+ @if (shownMenu == EInteractionMenuState.Pantry) { + + } + @if (shownMenu == EInteractionMenuState.Inventory) { + + } +
+ {{ + lang.game.actions.giveItem + }} + {{ + lang.game.actions.feed + }} + {{ + lang.game.actions.wakeUp + }} +
diff --git a/src/app/pages/interactions/interactions.component.ts b/src/app/pages/interactions/interactions.component.ts index 332d113..e4e4621 100644 --- a/src/app/pages/interactions/interactions.component.ts +++ b/src/app/pages/interactions/interactions.component.ts @@ -1,4 +1,4 @@ -import { Component, computed, effect, inject, input, InputSignal, Signal } from '@angular/core'; +import { Component, computed, effect, inject, input, InputSignal, signal, Signal, WritableSignal } from '@angular/core'; import { HeaderComponent } from "../../components/ui-elements/header/header.component"; import { ERouteKey } from '../../types/route-key'; import { Chibi, ChibiId } from '../../types/chibi/chibi'; @@ -11,6 +11,14 @@ import { EChibiInteraction } from '../../types/chibi/chibi-interaction'; import { IBrain } from '../../logic/chibi-behaviour/brain'; import { BRAIN_MAP } from '../../logic/chibi-behaviour/brain-map'; import { TranslateableComponent } from '../../components/translateable.component'; +import { Food } from '../../types/food'; +import { interval } from 'rxjs'; + +enum EInteractionMenuState { + Neutral, + Pantry, + Inventory +} @Component({ selector: 'ff-interactions', @@ -25,23 +33,41 @@ export class InteractionsComponent extends TranslateableComponent { protected readonly chibi: Signal = computed(() => { return this.chibiStore.chibis().find((chibi: Chibi) => chibi.id === this.chibiId()) as Chibi; }); + protected readonly interactionMenuState: WritableSignal = signal(EInteractionMenuState.Neutral); + protected readonly EInteractionMenuState: typeof EInteractionMenuState = EInteractionMenuState; protected readonly ERouteKey: typeof ERouteKey = ERouteKey; protected readonly EChibiInteraction: typeof EChibiInteraction = EChibiInteraction; private brain!: IBrain; constructor() { + super(); effect(() => { if (this.chibi()) { this.brain = BRAIN_MAP[this.chibi().name]!; } }) + interval(1000).subscribe(() => { + this.brain.exist(this.chibi()); + }) } - public interact(interaction: EChibiInteraction): void { - console.log(`${interaction} ${this.chibi().name}`); - this.chibi().state = this.brain.resolveInteraction(this.chibi().state, interaction); + public interact(interaction: EChibiInteraction, item?: Food): void { + console.log(`${interaction} ${this.chibi().name} and item ${item}`); + this.brain.resolveInteraction(this.chibi(), interaction, item); + } + + public openFoodPantry(): void { + this.interactionMenuState.set(EInteractionMenuState.Pantry); + } + + public openInventory(): void { + this.interactionMenuState.set(EInteractionMenuState.Inventory); + } + + public closeMenu(): void { + this.interactionMenuState.set(EInteractionMenuState.Neutral); } } diff --git a/src/app/types/translations/english.ts b/src/app/types/translations/english.ts index ef661a1..d3b263b 100644 --- a/src/app/types/translations/english.ts +++ b/src/app/types/translations/english.ts @@ -15,7 +15,9 @@ export const ENG_TRANSLATIONS: Translation = { foodPantry: {}, inventory: {}, actions: { - wakeUp: 'Wake up!' + wakeUp: 'Wake up!', + feed: 'Feed', + giveItem: 'Give Item' } } } \ No newline at end of file diff --git a/src/app/types/translations/translation.ts b/src/app/types/translations/translation.ts index cac8d97..f0379bc 100644 --- a/src/app/types/translations/translation.ts +++ b/src/app/types/translations/translation.ts @@ -18,6 +18,8 @@ export type Translation = { inventory: {}, actions: { wakeUp: string; + feed: string; + giveItem: string; } } }