Skip to content
Daan van Yperen edited this page May 31, 2019 · 4 revisions

Singleton plugin

Handles singleton component lifecycle and injection. Makes it easy to locate and access singleton components.

Using this plugin can help decouple systems, follow a stateless/pure behavior system pattern, and make it easier to serialize system state.

Some example singletons: Configuration, Map, Keybindings, Console, Score, Player, Camera.

Artifact

  <parent>
        <groupId>net.mostlyoriginal.artemis-odb</groupId>
        <artifactId>contrib-plugin-singleton</artifactId>
        <version>2.5.0-SNAPSHOT</version>
    </parent>

Usage

@Singleton
class KeyBindingComponent extends Component {
     ...
}

class PlayerControlSystem extends BaseSystem {
     private KeyBindingComponent keybindings; // auto injected.
     ...
}

see also

https://youtu.be/W3aieHjyNvw?t=735