-
Notifications
You must be signed in to change notification settings - Fork 0
Manipulators
Jamie Mansfield edited this page Nov 2, 2015
·
15 revisions
The following page will try to explain what a manipulator is and how to use them.
A Manipulator is a standalone object, that can be manipulated. It is used for holding meta.
import uk.jamierocks.meta.api.manipulator.MetaManipulator;
public class TimeMeta implements MetaManipulator {
int time();
}
The above example has one value - time. The value can be manipulated by using the value functions provided.
meta.offer(Keys.TIME, 5);
The manipulator will now have time down as being 5, however this does NOT mean the holder will have been changed. To change the MetaHolder you will have to apply the manipulator to it.
You may notice the above example makes use of a 'Keys' class - the creation of Keys will be covered in another page.
holder.applyMeta(meta);
To implement a manipulator you will need to implement the interface, and create two constructors.
import uk.jamierocks.lexteam.ygd.core.meta.MetaContainer;
import uk.jamierocks.meta.impl.manipulator.AbstractMeta;
import uk.jamierocks.lexteam.ygd.game.impl.meta.LexMetaContainer;
public class ExampleTimeMeta extends AbstractMeta implements TimeMeta {
private int time; // See how this is NOT final
// This is the first constructor
public ExampleTimeMeta(int time) {
this.time = time;
this.registerGettersAndSetters();
}
// Notice how this constructor takes no arguments
// The constructor calls the first constructor with default values
// You may want to consider creating a MetaConstants object, to store
// all the default values.
public ExampleTimeMeta() {
this(5);
}
@Override
public int time() {
return this.time;
}
public void setTime(int time) {
this.time = time;
}
@Override
protected void registerGettersAndSetters() {
this.registerGetter(Keys.TIME, ExampleTimeMeta.this::time);
this.registerSetter(Keys.TIME, ExampleTimeMeta.this::setTime);
}
@Override
public MetaContainer toContainer() {
return new LexMetaContainer()
.set(Keys.TIME, this.time);
}
}