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

In artemis-odb-contrib 2.5.0-SNAPSHOT, release planned for artemis-odb 2.3.0. All platforms.

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.
     ...
}

Components are instanced at the moment of the first injection.

see also

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