https://github.com/team2537/state-machine
Code that will hopefully make writing subsystems as State Machines easier
https://github.com/team2537/state-machine
Last synced: 3 months ago
JSON representation
Code that will hopefully make writing subsystems as State Machines easier
- Host: GitHub
- URL: https://github.com/team2537/state-machine
- Owner: Team2537
- License: mit
- Created: 2024-03-12T23:08:48.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-13T00:02:28.000Z (about 1 year ago)
- Last Synced: 2025-01-11T15:41:38.191Z (4 months ago)
- Language: Kotlin
- Size: 47.5 MB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# State-Machine
Code that will hopefully make writing subsystems as State Machines easier* [State-Machine](#state-machine)
* [Quick Start](#quick-start)
* [Creating a State-Based Subsystem](#creating-a-state-based-subsystem)# Quick Start
## Creating a State-Based Subsystem
A state-based subsystem really is just a fancy subsystem. That's why I made you
a special interface for it. Creating one of these is just as simple as creating
a subsystem as normal, except that the state-based version requires its own type
as a type-parameter. It will look like the following:---
Java:
```java
import lib.states.*;public final class ExampleSubsystem implements StateSubsystem {
/* ... */
}
```---
Kotlin:
```kotlin
import lib.states.*object ExampleSubsystem : StateSubsystem {
/* ... */
}
```---
However, this interface still requires quite a bit of boilerplate
in order to actually set up the state machine. So I wrote that for
you as well. Instead of trying to implement the state subsystem
yourself, you can simply extend off of an abstract state subsystem:---
Java:
```java
import lib.states.*;public final class ExampleSubsystem implements AbstractStateSubsystem {
/* ... */
}
```---
Kotlin:
```kotlin
import lib.states.*object ExampleSubsystem : AbstractStateSubsystem() {
/* ... */
}
```---
Now you have only a few things to worry about. Some basic information
and event handling mostly, but that's easy enough.# Terminal States
Sometimes, state machines will have a *Terminal State*,
or a state that, once reached, signals the end of the
machine's processing.There are two information methods relating to terminal states for
state subsystems, `isTerminal` and `isTerminable`.