Marauroa Core API: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
imported>Hendrik Brummermann
Line 156: Line 156:


== RPObject and RPSlot ==
== RPObject and RPSlot ==
RPObjects are the containters of data in Arianne. An RPObject is an (''isa'' function) Attributes element with a list of RPSlots attached. <br>
RPObjects are the containters of data in Arianne. An RPObject is an Attributes element with a list of RPSlots attached.

RPSlots are slots on objects that items can be placed on/in, such as backpacks, pockets, boxes, ...<br>
RPSlots are slots owned by an RPObject into which other RPObjects can be placed (like items in a backpack)

The methods of the RPObject to modify slots are:
The methods of the RPObject to modify slots are:
<source lang="java">
* ''void addSlot(RPSlot slot)''
public void addSlot(RPSlot slot)
* ''RPSlot getSlot(String name)''
* ''void removeSlot(String name)''
public RPSlot getSlot(String name)
* ''boolean hasSlot(String name)''
public void removeSlot(String name)
public boolean hasSlot(String name)
* ''Iterator slotIterator()''
public Iterator slotIterator()
</source>
The above methods are used to add a slot to the object, retrieve it, remove it and test if the slot exists. Finally the slot iterator is used to visit all the slots in the object.
The above methods are used to add a slot to the object, retrieve it, remove it and test if the slot exists. Finally the slot iterator is used to visit all the slots in the object.


<source lang="java">
* ''RPObject.ID getID()''
public RPObject.ID getID()
</source>
This is a helper method to get the unique ID of the object.
This is a helper method to get the unique ID of the object.


RPSlot class elements also have a simple API:
RPSlot has a simple API:
<source lang="java">
* void add(RPObject object)
* RPObject get(RPObject.ID id)
public void add(RPObject object)
* boolean has(RPObject.ID id)
public RPObject get(RPObject.ID id)
* RPObject remove(RPObject.ID id)
public boolean has(RPObject.ID id)
public RPObject remove(RPObject.ID id)
* void clear()
public void clear()
These methods modify objects in the RPSlot.
</source>
The clear() method removes all the objects in the slot.


These methods modify objects in the RPSlot. The clear() method removes all the objects in the slot.
* Iterator iterator()

<source lang="java">
public Iterator iterator()
</source>


It is used to visit all the objects of the slot.
It is used to visit all the objects of the slot.


<source lang="java">
<pre>
RPObject object=new RPObject(RPClass.getRPClass("player"));
// create an object of RPClass player and set some attribute values
object.put("name","example");
RPObject object = new RPObject("player");
object.put("score",0);
object.put("name", "example");
object.put("score", 0);


RPSlot slot=new RPSlot("backpack");
// create a slot called backpack
RPObject coin=new RPObject();
RPSlot slot = new RPSlot("backpack");
coin.put("type","coin");
slot.add(coin);
object.addSlot(slot);
object.addSlot(slot);

</pre>
// create an object of RPClass "coin" and put it into the slot
RPObject coin = new RPObject("coin");
slot.add(coin);
</source>


Now for the complex part. Where it all becomes a little nuts!: IRPZone and IRPRuleProcessor interfaces
Now for the complex part. Where it all becomes a little nuts!: IRPZone and IRPRuleProcessor interfaces