1- import { Effect , Schema } from "effect"
21import { Machine } from "@typeonce/effect-machine"
2+ import { Effect , Schema } from "effect"
33
44// Domain schemas are shared by state payloads and the public physics protocol.
55export const Axis = Schema . Literals ( [ - 1 , 0 , 1 ] )
@@ -127,12 +127,11 @@ const initialCharacter = () =>
127127 character
128128 . locomotion ( State . cases . Locomotion . make ( { } ) , ( locomotion ) =>
129129 locomotion . Grounded ( State . cases . Grounded . make ( { } ) , ( grounded ) =>
130- grounded . Standing ( State . cases . Standing . make ( { } ) )
131- )
132- )
133- . facing ( State . cases . Facing . make ( { } ) , ( facing ) => facing . Right ( State . cases . Right . make ( { } ) ) )
134- . contact ( State . cases . WallContact . make ( { } ) , ( contact ) => contact . NoWall ( State . cases . NoWall . make ( { } ) ) )
135- )
130+ grounded . Standing ( State . cases . Standing . make ( { } ) ) ) )
131+ . facing ( State . cases . Facing . make ( { } ) , ( facing ) =>
132+ facing . Right ( State . cases . Right . make ( { } ) ) )
133+ . contact ( State . cases . WallContact . make ( { } ) , ( contact ) =>
134+ contact . NoWall ( State . cases . NoWall . make ( { } ) ) ) )
136135
137136export const CharacterMachine = Machine . make ( {
138137 id : "PlatformerCharacter" ,
@@ -159,22 +158,17 @@ export const CharacterMachine = Machine.make({
159158 . motion ( State . cases . Motion . make ( { } ) , ( motion ) =>
160159 motion . Jumping (
161160 State . cases . Jumping . make ( { startedAt : event . at , push : 0 , kind : "Ground" } )
162- )
163- )
161+ ) )
164162 . airJump ( State . cases . AirJump . make ( { } ) , ( airJump ) =>
165- airJump . AirJumpGroundLock ( State . cases . AirJumpGroundLock . make ( { } ) )
166- )
167- )
168- )
169- . facing ( State . cases . Facing . make ( { } ) , ( facing ) => facing . Right ( State . cases . Right . make ( { } ) ) )
163+ airJump . AirJumpGroundLock ( State . cases . AirJumpGroundLock . make ( { } ) ) ) ) )
164+ . facing ( State . cases . Facing . make ( { } ) , ( facing ) =>
165+ facing . Right ( State . cases . Right . make ( { } ) ) )
170166 . contact ( State . cases . WallContact . make ( { } ) , ( contact ) =>
171167 event . wall === - 1
172168 ? contact . LeftWall ( State . cases . LeftWall . make ( { } ) )
173169 : event . wall === 1
174- ? contact . RightWall ( State . cases . RightWall . make ( { } ) )
175- : contact . NoWall ( State . cases . NoWall . make ( { } ) )
176- )
177- )
170+ ? contact . RightWall ( State . cases . RightWall . make ( { } ) )
171+ : contact . NoWall ( State . cases . NoWall . make ( { } ) ) ) )
178172 } ,
179173 states : {
180174 Standing : {
@@ -220,7 +214,7 @@ export const CharacterMachine = Machine.make({
220214 } ,
221215 Airborne : {
222216 on : {
223- JumpPressed : Effect . fn ( function * ( { event, runtime } ) {
217+ JumpPressed : Effect . fn ( function * ( { event, runtime } ) {
224218 const machine = yield * runtime
225219 const push = awayFrom ( event . wall )
226220 yield * machine . raise (
@@ -230,14 +224,16 @@ export const CharacterMachine = Machine.make({
230224 )
231225 } ) ,
232226 Landed : ( { event, target } ) =>
233- target . branch . Character . locomotion . Grounded ( State . cases . Grounded . make ( { } ) , ( grounded ) =>
234- grounded . Landing (
235- State . cases . Landing . make ( {
236- impact : event . impact ,
237- resumeAxis : event . axis ,
238- landedAt : event . at
239- } )
240- )
227+ target . branch . Character . locomotion . Grounded (
228+ State . cases . Grounded . make ( { } ) ,
229+ ( grounded ) =>
230+ grounded . Landing (
231+ State . cases . Landing . make ( {
232+ impact : event . impact ,
233+ resumeAxis : event . axis ,
234+ landedAt : event . at
235+ } )
236+ )
241237 )
242238 } ,
243239 states : {
@@ -274,8 +270,7 @@ export const CharacterMachine = Machine.make({
274270 on : {
275271 WallJump : {
276272 reenter : true ,
277- transition : ( { target } ) =>
278- target . local . AirJumpWallLock ( State . cases . AirJumpWallLock . make ( { } ) )
273+ transition : ( { target } ) => target . local . AirJumpWallLock ( State . cases . AirJumpWallLock . make ( { } ) )
279274 }
280275 } ,
281276 states : {
@@ -284,22 +279,20 @@ export const CharacterMachine = Machine.make({
284279 id : "ground-air-jump-unlock"
285280 } ) ,
286281 on : {
287- AirJumpUnlocked : ( { target } ) =>
288- target . local . AirJumpReady ( State . cases . AirJumpReady . make ( { } ) )
282+ AirJumpUnlocked : ( { target } ) => target . local . AirJumpReady ( State . cases . AirJumpReady . make ( { } ) )
289283 }
290284 } ,
291285 AirJumpWallLock : {
292286 invoke : Machine . after ( "240 millis" , InternalEvent . cases . AirJumpUnlocked . make ( { } ) , {
293287 id : "wall-air-jump-unlock"
294288 } ) ,
295289 on : {
296- AirJumpUnlocked : ( { target } ) =>
297- target . local . AirJumpReady ( State . cases . AirJumpReady . make ( { } ) )
290+ AirJumpUnlocked : ( { target } ) => target . local . AirJumpReady ( State . cases . AirJumpReady . make ( { } ) )
298291 }
299292 } ,
300293 AirJumpReady : {
301294 on : {
302- TryAirJump : Effect . fn ( function * ( { event, runtime, target } ) {
295+ TryAirJump : Effect . fn ( function * ( { event, runtime, target } ) {
303296 const machine = yield * runtime
304297 yield * machine . raise ( InternalEvent . cases . DoubleJump . make ( { at : event . at } ) )
305298 return target . local . AirJumpSpent ( State . cases . AirJumpSpent . make ( { } ) )
@@ -325,8 +318,7 @@ export const CharacterMachine = Machine.make({
325318 } ,
326319 Right : {
327320 on : {
328- Move : ( { event, target } ) =>
329- event . axis === - 1 ? target . local . Left ( State . cases . Left . make ( { } ) ) : undefined ,
321+ Move : ( { event, target } ) => event . axis === - 1 ? target . local . Left ( State . cases . Left . make ( { } ) ) : undefined ,
330322 WallJump : ( { event, target } ) =>
331323 event . push === - 1 ? target . local . Left ( State . cases . Left . make ( { } ) ) : undefined
332324 }
@@ -339,8 +331,8 @@ export const CharacterMachine = Machine.make({
339331 event . wall === - 1
340332 ? target . local . LeftWall ( State . cases . LeftWall . make ( { } ) )
341333 : event . wall === 1
342- ? target . local . RightWall ( State . cases . RightWall . make ( { } ) )
343- : target . local . NoWall ( State . cases . NoWall . make ( { } ) )
334+ ? target . local . RightWall ( State . cases . RightWall . make ( { } ) )
335+ : target . local . NoWall ( State . cases . NoWall . make ( { } ) )
344336 } ,
345337 states : {
346338 NoWall : { } ,
0 commit comments