Skip to content

Commit

Permalink
chore: add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
neolectron committed Jul 28, 2023
1 parent ddf9c86 commit c7f128b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/gl/House/HotSpots/AppartmentHotspot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const AppartmentHotspot = ({
const gameService = useGameMachineProvider();
const hotspotService = useSelector(
gameService,
(state) => state.context.hotspots.bar,
(state) => state.context.hotspots[type],
);

useCursor(isHovered);
Expand Down Expand Up @@ -65,7 +65,7 @@ export const AppartmentHotspot = ({
setDraggingId(null);

if (draggingActorRef) {
console.log(draggingActorRef);
console.log('person has been dropped on a hotspot', hotspotService);
hotspotService.send({
type: 'onRegisterPerson',
person: draggingActorRef,
Expand Down
1 change: 1 addition & 0 deletions src/machines/bar.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const barMachine = hotspotMachine
.withContext({
...hotspotMachine.context,
maxPersons: 6,
name: 'Bar',
})
.withConfig({
actions: {
Expand Down
18 changes: 14 additions & 4 deletions src/machines/game.machine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { type ActorRefFrom, assign, createMachine, spawn } from 'xstate';
import {
type ActorRefFrom,
assign,
createMachine,
spawn,
interpret,
} from 'xstate';
import { MathUtils } from 'three';

import { personMachine } from './person.machine';
Expand Down Expand Up @@ -41,10 +47,14 @@ export const gameMachine = createMachine(
description:
'The game machine is the root machine of the game, it handles the game state.',
context: {
persons: [spawn(personMachine, MathUtils.generateUUID())],
persons: [
interpret(personMachine, { id: MathUtils.generateUUID() }).start(),
],
hotspots: {
bar: spawn(barMachine, MathUtils.generateUUID()),
toilet: spawn(toiletMachine, MathUtils.generateUUID()),
bar: interpret(barMachine, { id: MathUtils.generateUUID() }).start(),
toilet: interpret(toiletMachine, {
id: MathUtils.generateUUID(),
}).start(),
},
clock: METERS_CONFIG.clock.initialValue,
currentNight: 0,
Expand Down
12 changes: 12 additions & 0 deletions src/machines/hotspot.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const hotspotMachine = createMachine(
context: {
maxPersons: 3,
persons: [],
name: 'GenericHotspot',
},
initial: 'Ticking',
states: {
Expand Down Expand Up @@ -49,6 +50,7 @@ export const hotspotMachine = createMachine(
persons: [...context.persons, event.person],
};
}),
// actions: 'test',
},
onUnregisterPerson: {
// cond: (context, event) => {
Expand All @@ -75,6 +77,7 @@ export const hotspotMachine = createMachine(
context: {} as {
persons: ActorRefFrom<typeof personMachine>[];
maxPersons: number;
name: string;
},
events: {} as
| { type: 'onUpdatePerson' }
Expand All @@ -94,6 +97,15 @@ export const hotspotMachine = createMachine(
},
{
actions: {
// test: assign((context, event) => {
// console.log(
// 'hotspot.onRegisterPerson - adding the person to the hotspot context',
// );
// return {
// ...context,
// persons: [...context.persons, event.person],
// };
// }),
updateHype: (context) => {
if (context.persons.length < 1) return context;
sendParent({
Expand Down

0 comments on commit c7f128b

Please sign in to comment.