Skip to content

Commit

Permalink
chore: add hardcore logging
Browse files Browse the repository at this point in the history
  • Loading branch information
neolectron committed Jul 28, 2023
1 parent 66e6a24 commit f5d5629
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/machines/bar.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export const barMachine = hotspotMachine
.withConfig({
actions: {
updatePersons: (context) => {
console.log(
'bar.updatePersons - updating persons by sending triggerDrink',
);
context.persons.forEach((p) => p.send('triggerDrink'));
return context;
},
Expand Down
3 changes: 3 additions & 0 deletions src/machines/game.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const gameMachine = createMachine(
},
entry: assign((context) => {
const disasterForTheNight = generateRandomDisasters(context.currentNight);
console.log('game is starting');
return {
...context,
disasterForTheNight,
Expand All @@ -75,6 +76,7 @@ export const gameMachine = createMachine(
{
// game tick
actions: assign((context) => {
console.log('game tick');
const clock =
context.clock + METERS_CONFIG.clock.incrementValue;

Expand Down Expand Up @@ -152,6 +154,7 @@ export const gameMachine = createMachine(
},
onRemovePersonFromAllHotspots: {
actions: (context, event) => {
console.log('Game.onRemovePersonFromAllHotspots');
const { bar, toilet } = context.hotspots;
bar.send({
type: 'onUnregisterPerson',
Expand Down
21 changes: 12 additions & 9 deletions src/machines/hotspot.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const hotspotMachine = createMachine(
// },
actions: assign((context, event) => {
console.log(
'hotspot.onRegisterPerson - checking if the person is in the hotspot',
'hotspot.onRegisterPerson - adding the person to the hotspot context',
);
return {
...context,
Expand All @@ -51,16 +51,19 @@ export const hotspotMachine = createMachine(
}),
},
onUnregisterPerson: {
cond: (context, event) => {
// cond: (context, event) => {
// console.log(
// 'hotspot.onUnregisterPerson - checking if the person is in the hotspot',
// );
// const isAlreadyInHotspot = Boolean(
// context.persons.find((p) => p.id === event.person.id),
// );
// return isAlreadyInHotspot;
// },
actions: assign((context, event) => {
console.log(
'hotspot.onUnregisterPerson - checking if the person is in the hotspot',
);
const isAlreadyInHotspot = Boolean(
context.persons.find((p) => p.id === event.person.id),
'hotspot.onUnregisterPerson - removing the person to the hotspot context',
);
return isAlreadyInHotspot;
},
actions: assign((context, event) => {
return {
...context,
persons: context.persons.filter((p) => p.id !== event.person.id),
Expand Down
2 changes: 2 additions & 0 deletions src/machines/person.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const personMachine = createMachine(
on: {
onUnregisterFromAllHotspot: {
actions: assign((context, _, meta) => {
console.log('Person.onUnregisterFromAllHotspot');
sendParent({
type: 'onRemovePersonFromAllHotspots',
personID: meta._event.origin,
Expand Down Expand Up @@ -209,6 +210,7 @@ export const personMachine = createMachine(
{
actions: {
drink: assign((context) => {
console.log('person is drinking');
return {
...context,
meters: {
Expand Down

0 comments on commit f5d5629

Please sign in to comment.