Skip to content

Extended Component Mappers

Daan van Yperen edited this page Oct 2, 2015 · 6 revisions

Out of date, some of this functionality has been merged with odb-core

Why?

Easily create and remove components, helps you write shorter code.

   if ( !mPhysics.has(e) ) { e.edit().add(Physics.class); } 
   Physics p = mPhysics.get(e);

becomes

  Physics p = mPhysics.create(e);

Features

Identical to ComponentMapper, but adds:

  • #create(entity) Creates component, or returns existing.
  • #remove(entity) Removes component, does nothing when already removed.
  • #getSafe(entity,passthrough) Returns component, or passthrough if missing.
  • #set(entity, boolean) Toggle components, useful for tag components.

Uses Transmuters behind the scenes.

Setup

  WorldConfiguration myConfig = new WorldConfigurationBuilder()
                .with(new ExtendedComponentMapperPlugin())
                .build();
  new World (myConfig);

Wiring

@Wire
public class ExampleSystem extends EntityProcessingSystem {
    protected M<Pos> mPos;
    protected M<Color> mColor;
}