$ show chickensoft-games/LogicBlocks
LogicBlocks is a C# library for building hierarchical state machines (statecharts) with a focus on performance, serialization, and testability. It provides a `LogicBlock` base class that manages state transitions via input handlers (`IGet<TInput>`), supports pushdown automaton history, async task integration, and observable bindings. The library includes an `AutoBlock` extension for automatic state preallocation and serialization using Chickensoft's introspection and serialization frameworks, and a Roslyn source generator (`DiagramGenerator`) that produces PlantUML state diagrams from annotated state classes. The codebase is well-structured with extensive unit tests, clean separation of concerns, and a fluent API for bindings. It is designed for AOT environments and game development (Godot). The repository also contains a tutorial and a vending machine example.
The LLM identified 3 files worth highlighting for reuse:
Implements a bounded history stack for state types using Nito.Collections.Deque. Supports configurable max capacity, push/pop/peek, enumeration, and ToArray. Clean, self-contained, and reusable for any scenario requiring a fixed-size LIFO collection with optional unbounded growth.
Thread-safe task tracker that aggregates multiple async operations into a single Task. Uses a lock and a TaskCompletionSource to signal completion when all tracked tasks finish. Reusable pattern for any system that needs to wait for a set of in-flight operations.
Fluent wrapper around Task<T> that allows chaining success, error, and cancellation handlers that deliver inputs back to a state machine. Handles synchronization context and status checks. Demonstrates a clean pattern for bridging async operations into synchronous state machine inputs.