Skip to content

Commit

Permalink
fix - prevent addPerson duplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
sdubourg committed Jul 26, 2023
1 parent cd226f9 commit 8c368c1
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 56 deletions.
12 changes: 9 additions & 3 deletions src/components/gl/House/HotSpots/AppartmentHotspot.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { a, easings, useSpring } from '@react-spring/three';
import { useCursor } from '@react-three/drei';
import { Text, useCursor } from '@react-three/drei';
import { type MeshProps } from '@react-three/fiber';
import { useInterpret } from '@xstate/react';
import { useInterpret, useSelector } from '@xstate/react';
import { useRef, useState } from 'react';
import type { Mesh } from 'three';
import { shallow } from 'zustand/shallow';
Expand All @@ -19,6 +19,8 @@ export const AppartmentHotspot = ({
const service = useInterpret(hotSpotMachine);
useCursor(isHovered);

const { persons } = useSelector(service, (s) => s.context);

const {
setIsDragging,
isDragging,
Expand Down Expand Up @@ -89,7 +91,11 @@ export const AppartmentHotspot = ({
material-map={materials.map}
material-emissiveMap={materials.map}
name="hotspot"
/>
>
<Text color="blue" position-y={6} fontSize={5}>
{persons.length}
</Text>
</a.mesh>
</a.group>
);
};
2 changes: 1 addition & 1 deletion src/machines/hotspot.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const hotspotMachine = createMachine(
});
return {
...context,
persons: [...context.persons, event.person],
persons: Array.from(new Set([...context.persons, event.person])),
};
}),
removePerson: assign((context, event) => {
Expand Down
127 changes: 75 additions & 52 deletions src/machines/person.machine.typegen.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,76 @@
// This file was automatically generated. Edits will be overwritten

// This file was automatically generated. Edits will be overwritten

export interface Typegen0 {
'@@xstate/typegen': true;
internalEvents: {
"": { type: "" };
"xstate.after(1000)#Person.actionFlow.Doing.Drinking": { type: "xstate.after(1000)#Person.actionFlow.Doing.Drinking" };
"xstate.after(1000)#Person.actionFlow.Doing.Pissing": { type: "xstate.after(1000)#Person.actionFlow.Doing.Pissing" };
"xstate.after(1000)#Person.actionFlow.Resting.Idle": { type: "xstate.after(1000)#Person.actionFlow.Resting.Idle" };
"xstate.after(500)#Person.meterFlow.Active": { type: "xstate.after(500)#Person.meterFlow.Active" };
"xstate.init": { type: "xstate.init" };
};
invokeSrcNameMap: {

};
missingImplementations: {
actions: never;
delays: never;
guards: never;
services: never;
};
eventsCausingActions: {
"decreaseHype": "xstate.after(1000)#Person.actionFlow.Doing.Drinking" | "xstate.after(1000)#Person.actionFlow.Resting.Idle";
"drink": "xstate.after(1000)#Person.actionFlow.Doing.Drinking";
"emptyPee": "xstate.after(1000)#Person.actionFlow.Doing.Drinking";
"increaseHype": "xstate.after(1000)#Person.actionFlow.Doing.Drinking";
"pee": "xstate.after(1000)#Person.actionFlow.Doing.Pissing";
"registerHotspot": "onRegisterHotspot";
"unregisterHotspot": "onUnregisterHotspot";
"updateNeeds": "xstate.after(500)#Person.meterFlow.Active";
};
eventsCausingDelays: {

};
eventsCausingGuards: {
"canPee": "xstate.after(1000)#Person.actionFlow.Doing.Pissing";
"isActionDrink": "onDrop";
"isActionPiss": "onDrop";
"isPeeEmpty": "xstate.after(1000)#Person.actionFlow.Doing.Pissing";
"isPeeFull": "xstate.after(1000)#Person.actionFlow.Doing.Drinking";
"isThirsty": "xstate.after(1000)#Person.actionFlow.Doing.Drinking";
};
eventsCausingServices: {

};
matchesStates: "actionFlow" | "actionFlow.Blocking" | "actionFlow.Blocking.PissingHimself" | "actionFlow.Doing" | "actionFlow.Doing.Drinking" | "actionFlow.Doing.Pissing" | "actionFlow.Resting" | "actionFlow.Resting.Dragging" | "actionFlow.Resting.Idle" | "meterFlow" | "meterFlow.Active" | "meterFlow.Inactive" | { "actionFlow"?: "Blocking" | "Doing" | "Resting" | { "Blocking"?: "PissingHimself";
"Doing"?: "Drinking" | "Pissing";
"Resting"?: "Dragging" | "Idle"; };
"meterFlow"?: "Active" | "Inactive"; };
tags: never;
}

export interface Typegen0 {
'@@xstate/typegen': true;
internalEvents: {
'': { type: '' };
'xstate.after(1000)#Person.actionFlow.Doing.Drinking': {
type: 'xstate.after(1000)#Person.actionFlow.Doing.Drinking';
};
'xstate.after(1000)#Person.actionFlow.Doing.Pissing': {
type: 'xstate.after(1000)#Person.actionFlow.Doing.Pissing';
};
'xstate.after(1000)#Person.actionFlow.Resting.Idle': {
type: 'xstate.after(1000)#Person.actionFlow.Resting.Idle';
};
'xstate.after(500)#Person.meterFlow.Active': {
type: 'xstate.after(500)#Person.meterFlow.Active';
};
'xstate.init': { type: 'xstate.init' };
};
invokeSrcNameMap: {};
missingImplementations: {
actions: never;
delays: never;
guards: never;
services: never;
};
eventsCausingActions: {
decreaseHype:
| 'xstate.after(1000)#Person.actionFlow.Doing.Drinking'
| 'xstate.after(1000)#Person.actionFlow.Resting.Idle';
drink: 'xstate.after(1000)#Person.actionFlow.Doing.Drinking';
emptyPee: 'xstate.after(1000)#Person.actionFlow.Doing.Drinking';
increaseHype: 'xstate.after(1000)#Person.actionFlow.Doing.Drinking';
pee: 'xstate.after(1000)#Person.actionFlow.Doing.Pissing';
registerHotspot: 'onRegisterHotspot';
unregisterHotspot: 'onUnregisterHotspot';
updateNeeds: 'xstate.after(500)#Person.meterFlow.Active';
};
eventsCausingDelays: {};
eventsCausingGuards: {
canPee: 'xstate.after(1000)#Person.actionFlow.Doing.Pissing';
isActionDrink: 'onDrop';
isActionPiss: 'onDrop';
isPeeEmpty: 'xstate.after(1000)#Person.actionFlow.Doing.Pissing';
isPeeFull: 'xstate.after(1000)#Person.actionFlow.Doing.Drinking';
isThirsty: 'xstate.after(1000)#Person.actionFlow.Doing.Drinking';
};
eventsCausingServices: {};
matchesStates:
| 'actionFlow'
| 'actionFlow.Blocking'
| 'actionFlow.Blocking.PissingHimself'
| 'actionFlow.Doing'
| 'actionFlow.Doing.Drinking'
| 'actionFlow.Doing.Pissing'
| 'actionFlow.Resting'
| 'actionFlow.Resting.Dragging'
| 'actionFlow.Resting.Idle'
| 'meterFlow'
| 'meterFlow.Active'
| 'meterFlow.Inactive'
| {
actionFlow?:
| 'Blocking'
| 'Doing'
| 'Resting'
| {
Blocking?: 'PissingHimself';
Doing?: 'Drinking' | 'Pissing';
Resting?: 'Dragging' | 'Idle';
};
meterFlow?: 'Active' | 'Inactive';
};
tags: never;
}

0 comments on commit 8c368c1

Please sign in to comment.