Basics
There are two types of rules, Reflow Rules and Collision Rules. Reflow rules are invoked when the state of cells is being updated while Collision rules are called when two things collide.
Writing a Reflow Rule
To write a reflow rule, you extend the class Element.ReflowRule and implement the apply(Element self) method:
class MyRule extends Element.ReflowRule {
public void apply(Element self) {
// Code here, self refers to the element being reflowed.
}
}
Writing a Collision Rule
This is similar except the class name is Element.CollisionRule and the method has two arguments: apply(Element self, Element other):
class MyRule extends Element.CollisionRule {
public void apply(Element self, Element other) {
// Code here, self refers to the leftmost element in the collision and other refers to the rightmost
}
}
Note that in a collision, ALL of the collision rules for BOTH of the elements that collided will be applied, so before you write a collision rule you probably need to write some if statements to make sure that the rule is applicable. The left-most collision rule is caused first.
Priority of Rules
By default, each rule has the same priority. However, you can set the variable called priority. The highest priority rules are called first for each Element.
Interfacing with Elements
Elements are just objects with a property listing. To access properties, you use the get() and set() methods of the element. For example,
Coordinate = (Coordinate)(self.get('coordinate'));
Note that you have to cast to the type you want because get() returns generic Objects. So just use the format above. This command returned a Coordinate object, which you can look at to see what you can do with (getLeft(), setLeft(), etc. for the element.)
Creating a new Element
To create an element, you need to extend the Element class. Use the following template:
TODO
