Package marauroa.common.game
Class RPClass
java.lang.Object
marauroa.common.game.RPClass
- All Implemented Interfaces:
Serializable
An RPClass is a entity that define the attributes, events and slots of an
Object.
TODO: Creating a new RPClass does in fact add it to a global list of RPClasses.
Search for a way of making this in a different way so test added for equality works.
The idea behind RPClass is not define members as a OOP language but to save bandwidth usage by replacing these members text definitions with a short integer.
Also RPClass define a set of properties over attributes, events and slots, like being private, hidden or volatile.
It is very important that if you extend a class with isA, you completely
define the superclass before calling isA method.
For example:
RPClass foo=new RPClass("foo"); foo.add(....) foo.add(....) foo.add(....) RPClass bar=new RPClass("bar"); bar.isA(foo); bar.add(....) bar.add(....)
- Author:
- miguel
- See Also:
Definition
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add(Definition.DefinitionClass clazz, String name, byte flags)
Adds a definition of an event or rplink with the given flags.void
add(Definition.DefinitionClass clazz, String name, int capacity, byte flags)
Adds a definition of an slot with the given capacity and flags.void
add(Definition.DefinitionClass clazz, String name, String value, byte flags)
Adds a static definition of an attribute that will be set for any object of the class.void
add(Definition.DefinitionClass clazz, String name, Definition.Type type)
Adds a definition of an attribute with the given type and with the standard flags ( STORABLE and VISIBLE )void
add(Definition.DefinitionClass clazz, String name, Definition.Type type, byte flags)
Adds a definition of an attribute with the given type and flags.void
addAttribute(String name, Definition.Type type)
Adds a definition of an attribute with the given type and standard flags: VISIBLE and STORABLE.void
addAttribute(String name, Definition.Type type, byte flags)
Adds a definition of an attribute with the given type and flags.void
addRPEvent(String name, byte flags)
Adds a definition of an event with the given flags.void
Adds a definition of a rplink with the given flags.void
Adds a definition of an slot with the given capacity and standard flags: VISIBLE and STORABLEvoid
Adds a definition of an slot with the given capacity and flags.void
addStaticAttribute(String name, String value, byte flags)
Adds a static definition of an attribute that will be set for any object of the class.void
bake()
Bakes the RPClass by including copies of all the definitions of the parent class to improve performance.static void
bakeAll()
Bales all RPClasses to optimize performance.boolean
Returns true if two objects are exactly equalstatic RPClass
Returns a default rpclass for lazy developers.short
getCode(Definition.DefinitionClass clazz, String name)
Returns the code of the attribute/event/slot whose name is name for this rpclassgetDefinition(Definition.DefinitionClass clazz, String name)
Returns the definition object itself.Returns a list of all definitions of this class (not including parent classes)getName()
Returns the name of the rpclassgetName(Definition.DefinitionClass clazz, short code)
Returns the name of the attribute whose code is code for this rpclassgets the parent class ornull
if this is a root class.static RPClass
getRPClass(String name)
Returns the name rpclass from the global listboolean
hasDefinition(Definition.DefinitionClass clazz, String name)
Returns true if name attributes, slot, event or rplink exists in this RPClass or any of its ancestors.int
hashCode()
static boolean
hasRPClass(String name)
Returns true if the global list contains the name rpclassvoid
This method sets the parent of this rpclassvoid
This method sets the parent of this rpclassiterator()
Iterates over the global list of rpclassesvoid
Fill the object from data deserialized from the serializerstatic int
size()
Returns the size of the rpclass global listboolean
subclassOf(String parentClass)
This method returns true if it is a subclass of parentClass or if it is the class itself.toString()
void
writeObject(OutputSerializer out)
Serialize the object into the output
-
Constructor Details
-
RPClass
public RPClass()Constructor Only used in serialization. -
RPClass
Constructor. It adds the RPClass to a global list of rp classes.- Parameters:
name
- the class name
-
-
Method Details
-
toString
-
hasRPClass
Returns true if the global list contains the name rpclass- Parameters:
name
- the class name to query- Returns:
- true if the global list contains the name rpclass
-
getRPClass
Returns the name rpclass from the global list- Parameters:
name
- the name of the class- Returns:
- the class or null if it doesn't exist.
-
isA
This method sets the parent of this rpclass- Parameters:
parent
- the super class of this class.
-
isA
This method sets the parent of this rpclass- Parameters:
parent
- the super class of this class.
-
subclassOf
This method returns true if it is a subclass of parentClass or if it is the class itself.- Parameters:
parentClass
- the super class of this class- Returns:
- true if it is a subclass of parentClass or if it is the class itself.
-
getName
Returns the name of the rpclass- Returns:
- the name of the rpclass
-
getParent
gets the parent class ornull
if this is a root class.- Returns:
- RPClass or
null
.
-
add
Adds a definition of an attribute with the given type and with the standard flags ( STORABLE and VISIBLE )- Parameters:
clazz
- type of definition ( attribute, event or slot )name
- name of the definitiontype
- type or capacity if it is an slot
-
add
Adds a definition of an attribute with the given type and flags.- Parameters:
clazz
- type of definition ( attribute, event or slot )name
- name of the definitiontype
- type or capacity if it is an slotflags
- like visibility, storability, etc...
-
add
Adds a definition of an event or rplink with the given flags.- Parameters:
clazz
- type of definition ( attribute, event or slot )name
- name of the definitionflags
- like visibility, storability, etc...
-
add
Adds a definition of an slot with the given capacity and flags.- Parameters:
clazz
- type of definition ( attribute, event or slot )name
- name of the definitioncapacity
- capacity if it is an slotflags
- like visibility, storability, etc...
-
add
Adds a static definition of an attribute that will be set for any object of the class. Its value must be set as a string, but it can be accessed later using Attributes.get method. NOTE: This type of attributes can't be set.- Parameters:
clazz
- It must be DefinitionClass.STATICname
- name of the static attributevalue
- value of the attributeflags
- like visibility, storability, etc...
-
addAttribute
Adds a definition of an attribute with the given type and flags.- Parameters:
name
- name of the definitiontype
- type or capacity if it is an slotflags
- like visibility, storability, etc...
-
addAttribute
Adds a definition of an attribute with the given type and standard flags: VISIBLE and STORABLE.- Parameters:
name
- name of the definitiontype
- type or capacity if it is an slot
-
addStaticAttribute
Adds a static definition of an attribute that will be set for any object of the class. Its value must be set as a string, but it can be accessed later using Attributes.get method. NOTE: This type of attributes can't be set.- Parameters:
name
- name of the static attributevalue
- value of the attributeflags
- like visibility, storability, etc...
-
addRPSlot
Adds a definition of an slot with the given capacity and flags.- Parameters:
name
- name of the definitioncapacity
- capacity if it is an slotflags
- like visibility, storability, etc...
-
addRPSlot
Adds a definition of an slot with the given capacity and standard flags: VISIBLE and STORABLE- Parameters:
name
- name of the definitioncapacity
- capacity if it is an slot
-
addRPLink
Adds a definition of a rplink with the given flags.- Parameters:
name
- name of the definitionflags
- like visibility, storability, etc...
-
addRPEvent
Adds a definition of an event with the given flags.- Parameters:
name
- name of the definitionflags
- like visibility, storability, etc...
-
getDefinition
Returns the definition object itself.- Parameters:
clazz
- type of definition ( attribute, event or slot )name
- name of the definition- Returns:
- this definition object or null if it is not found
-
getDefinitions
Returns a list of all definitions of this class (not including parent classes)- Returns:
- list of definitions
-
bake
public void bake()Bakes the RPClass by including copies of all the definitions of the parent class to improve performance. -
bakeAll
public static void bakeAll()Bales all RPClasses to optimize performance. -
hasDefinition
Returns true if name attributes, slot, event or rplink exists in this RPClass or any of its ancestors.- Parameters:
clazz
- type of definition ( attribute, event or slot )name
- name of the definition- Returns:
- returns true if name attributes, slot, event or rplink exists in this RPClass or any of its ancestors.
-
getCode
Returns the code of the attribute/event/slot whose name is name for this rpclass- Parameters:
clazz
- type of definition ( attribute, event or slot )name
- name of the definition- Returns:
- definition code
- Throws:
SyntaxException
- if the definition is not found.
-
getName
Returns the name of the attribute whose code is code for this rpclass- Parameters:
clazz
- type of definition ( attribute, event or slot )code
- definition code- Returns:
- name of the definition
- Throws:
SyntaxException
- if the definition is not found.
-
writeObject
Serialize the object into the output- Specified by:
writeObject
in interfaceSerializable
- Parameters:
out
- the output serializer- Throws:
IOException
- if there is any problem serializing.
-
readObject
Fill the object from data deserialized from the serializer- Specified by:
readObject
in interfaceSerializable
- Parameters:
in
- input serializer- Throws:
IOException
- if there is any problem in the serialization.
-
iterator
Iterates over the global list of rpclasses- Returns:
- an iterator
-
size
public static int size()Returns the size of the rpclass global list- Returns:
- number of defined classes.
-
getBaseRPObjectDefault
Returns a default rpclass for lazy developers. You won't get any advantages on the engine by using it.- Returns:
- RPClass
-
hashCode
public int hashCode() -
equals
Returns true if two objects are exactly equal
-