Skip to content

Commit 553fdc6

Browse files
committed
Added explanations to the workflow.
1 parent 028bec3 commit 553fdc6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/glhf-fsm/README.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Finite State Machine
2+
> Finite State Machine that supports registering custom states, state priority and queued states.
3+
> This is a package part of the glhf.js library but can be used independently.
4+
5+
6+
## Usage
7+
8+
**Registering states**
9+
10+
```typescript
11+
import StateManager from "./StateManager";
12+
13+
const sm = new StateManager();
14+
sm.registerState(new IdleState('idle', 99, true)); // default state.
15+
sm.registerState(new IdleState('attack', 1));
16+
sm.registerState(new IdleState('walk', 2));
17+
18+
sm.update();
19+
```
20+
21+
Registered states have to extend the class `State` where you can implement your custom actions by extending the methods:
22+
23+
```
24+
enter(...args: any[]);
25+
exit()
26+
update()
27+
```
28+
29+
**Triggering a State**
30+
31+
```typescript
32+
sm.triggerState('attack', ...params);
33+
```
34+
35+
**Queueing states**
36+
37+
```typescript
38+
sm.queueState('tell_story_a', ...params);
39+
sm.queueState('smoke_a_cigar', ...params);
40+
```

0 commit comments

Comments
 (0)