Skip to content

LaurenceWarne/artemis-odb-component-lookup

Repository files navigation

artemis-odb-component-lookup

Build Status

artemis-odb-component-lookup is an artemis-odb plugin which allows access of components through their attributes.

Usage

...
final WorldConfigurationBuilder setup = new WorldConfigurationBuilder();
setup.with(new ComponentLookupPlugin());
// Register other systems and plugins
...

Now take some component:

public class MonsterTemplate extends Component {
    private String name;
    ...
}

Then we can use the @FieldLookup annotation to obtain MonsterTemplate components from their name:

@All(Spawn.class)
public class MonsterSpawningSystem extends IteratingSystem {

	private ComponentMapper<Spawn> mSpawn;
	private ComponentMapper<MonsterTemplate> mTemplate;

	// Injected on world intialization
	@FieldLookup(component=MonsterTemplate.class, field="name")
	private ObjectIntMap<String> templateLookup;

    @Override
    public void process(int id) {
        final Spawn spawn = mSpawn.get(id);
        final int templateId = templateLookup.get(spawn.getTemplateName());
        final MonsterTemplate template = mTemplate.get(templateId);
        // do something with component
    }
}

And so we can obtain components via unique (and immutable) fields rather than just ids.

Getting Started

Gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.LaurenceWarne:artemis-odb-component-lookup:v1.0'
}