mkRPG
Public Member Functions | Protected Member Functions | Protected Attributes
GameObject Class Reference

The GameObject class is the base class for every part of games. More...

#include <gameobject.h>

Inheritance diagram for GameObject:
DefaultTypes Game GameObjectInventory GameObjectList< Type > Image InheritableObject World GameObjectType TypedObject< T > TypedObject< CellType > TypedObject< EntityType > TypedObject< MapType > TypedObject< ObjectType > Type< T > Type< CellType > Type< EntityType > Type< MapType > Type< ObjectType > Cell Entity Map Object

Public Member Functions

virtual ~GameObject ()
GameObject int ident () const
virtual bool isEditable () const
const QDateTime & lastInternalEdition () const
const QDateTime & lastChildrenEdition () const
const QDateTime & lastEdition () const
void touch ()
void addReference ()
void removeReference ()
void setParent (GameObject *p)
GameObjectparent () const
virtual void setName (const QString &n)
const QString & name () const
virtual GameObjectchild (const int &id) const
virtual QList< GameObject * > children () const
virtual int getParamMin (const QString &param) const
virtual int getParamMax (const QString &param) const
virtual void setParamMin (const QString &param, int min)
virtual void setParamMax (const QString &param, int max)
virtual void setParamDomain (const QString &param, int min, int max)
virtual int getParam (const QString &param) const
virtual void setParam (const QString &param, int value)
virtual bool hasParam (const QString &param) const
virtual QList< QString > params () const
virtual void renameParam (const QString &param, const QString &newParam)
virtual void addParam (const QString &param, int value=0, int min=0, int max=100)
virtual void removeParam (const QString &param)
virtual bool getFlag (const QString &flag) const
virtual void setFlag (const QString &flag, bool enable)
virtual bool hasFlag (const QString &flag) const
virtual QList< QString > flags () const
virtual void renameFlag (const QString &flag, const QString &newFlag)
virtual void addFlag (const QString &flag, bool enable=true)
virtual void removeFlag (const QString &flag)
virtual bool hasEvent (const QString &event) const
virtual EventgetEvent (const QString &event) const
virtual EventaddEvent (const QString &event)
virtual void removeEvent (const QString &event)
virtual QList< QString > events () const
virtual void renameEvent (const QString &order, const QString &newOrder)
virtual bool hasOrder (const QString &order) const
virtual OrdergetOrder (const QString &order) const
virtual OrderaddOrder (const QString &order)
virtual void removeOrder (const QString &order)
virtual QList< QString > orders () const
virtual void renameOrder (const QString &order, const QString &newOrder)
void addEmittedAction (Action *action)
void removeEmittedAction (Action *action)
void addReceivedAction (Action *action)
void removeReceivedAction (Action *action)
GamegetGame ()

Protected Member Functions

 GameObject (GameObject &parent)
 GameObject (Game *g=nullptr, GameObject *parent=nullptr)
void init (Game *g, GameObject *parent)
virtual bool isValid () const
void copy (GameObject &obj)
virtual void addChild (GameObject *c)
virtual void removeChild (GameObject *c)
void childrenTouched (const QDateTime &d)
QList< QString > filter (QList< QString > l) const

Protected Attributes

GameObjectaParent
QMap< int, GameObject * > aChildren
Gamegame
int nbRef
QMap< QString, ParameteraParams
QMap< QString, bool > aFlags
QMap< QString, Event * > aEvents
QMap< QString, Order * > aOrders
QString aName
QString fileName
QDateTime lastEdit
QDateTime lastChildEdit
QSet< QString > reserved
QList< Action * > aEmittedActions
QList< Action * > aReceivedActions

Detailed Description

The GameObject class is the base class for every part of games.

Each instance is identified by a game-wide unique identifier.

## Object edition notification mechanism

To make the edition easier, each GameObject contains two QDateTime values :

Note:
If the changes that are made in the object have to be detected by display/edition widgets, the touch function should be called.
To prevent the notification chain to be broken, the existing objects should always have a parent (except for the root object). This can be acheived using the init or setParent method, when the parent have not been given in the constructor. (see object.h for details)

## References count

Todo:

Constructor & Destructor Documentation

GameObject::GameObject ( GameObject parent) [protected]

Constructs a new GameObject with parent parent.

GameObject::GameObject ( Game g = nullptr,
GameObject parent = nullptr 
) [protected]

Constructs a new GameObject with parent parent and the reference to the game g.

Note:
If these objects cannot be given to the constructor (case of an array of objects), the init method must be called after the creation to make the GameObject valid.
GameObject::~GameObject ( ) [virtual]

The default destructor destroy every children of the instance


Member Function Documentation

void GameObject::addChild ( GameObject c) [protected, virtual]

Registers a new child.

See also:
removeChild, child, children

Register the GameObject as the emitter of the action action.

This is usefull to avoid dangling references.

See also:
removeEmittedAction, addReceivedAction
Event & GameObject::addEvent ( const QString &  event) [virtual]

Create a new event named event.

Note:
If the a event name event already exists, it will be discarded.
See also:
removeEvent, addOrder
void GameObject::addFlag ( const QString &  flag,
bool  enable = true 
) [virtual]

Inserts a new falg flag.

Note:
If the requested flag already exist, it is replaced by the new one.
See also:
renameFlag, removeFlag
Order & GameObject::addOrder ( const QString &  order) [virtual]

Create a new order named order.

Note:
If the a order name order already exists, it will be discarded.
See also:
removeOrder, addEvent
void GameObject::addParam ( const QString &  param,
int  value = 0,
int  min = 0,
int  max = 100 
) [virtual]

Inserts a new param parameter.

Note:
If the requested parameter already exist, it is replaced by the new one.
See also:
renameParam, removeParam

Register the GameObject as one of the receivers of the action action.

This is usefull to avoid dangling references.

See also:
removeReceivedAction, addEmittedAction

Increases the references counter

See also:
removeReference
virtual GameObject* GameObject::child ( const int &  id) const [inline, virtual]

Returns the child with identifier i if any.

See also:
children;
virtual QList<GameObject*> GameObject::children ( ) const [inline, virtual]

Returns the list of the instance's children.

See also:
child

Reimplemented in Map.

void GameObject::childrenTouched ( const QDateTime &  d) [protected]

Registers a change in one of the child of the object.

void GameObject::copy ( GameObject obj) [protected]

Loads the content of obj in the current instance.

QList< QString > GameObject::events ( ) const [virtual]

Returns the list of event's names of the object.

See also:
getEvent, getOrders

Reimplemented in InheritableObject.

QList< QString > GameObject::filter ( QList< QString >  l) const [protected]

Removes the protected parameters/flags for the user visible lists.

QList< QString > GameObject::flags ( ) const [virtual]

Returns the list of the registered flags

See also:
getFlag, setFlag, params

Reimplemented in InheritableObject.

Event & GameObject::getEvent ( const QString &  event) const [virtual]

Returns the event named event.

Note:
If the requested event does not exist, an empty Event is inserted.
See also:
getEvents, getOrder

Reimplemented in InheritableObject.

bool GameObject::getFlag ( const QString &  flag) const [virtual]

Returns the value of the flag flag.

Note:
If the requested parameter does not exists, a false value is returned, and the flags map stay unchanged
See also:
flags, hasFlag, setFlag, getParam

Reimplemented in InheritableObject.

Game* GameObject::getGame ( ) [inline]

Returns the Game from which the GameObject is part.

Order & GameObject::getOrder ( const QString &  order) const [virtual]

Returns the order named order.

Note:
If the requested order does not exist, an empty Order object is inserted.
See also:
getOrders, getEvent

Reimplemented in InheritableObject.

int GameObject::getParam ( const QString &  param) const [virtual]

Returns the value of the param parameter.

Note:
If the requested parameter does not exists, a null value is returned, and the parameters map stay unchanged
See also:
params, hasParam, setParam, getFlag

Reimplemented in InheritableObject.

int GameObject::getParamMax ( const QString &  param) const [virtual]

Returns the upper bound of the param parameter.

Note:
If the requested parameter does not exists, a default value is returned (100), and the parameters stay unchanged.
See also:
setParamMax, getParamMin

Reimplemented in InheritableObject.

int GameObject::getParamMin ( const QString &  param) const [virtual]

Returns the lower bound of the param parameter.

Note:
If the requested parameter does not exists, a default value is returned (0), and the parameters stay unchanged.
See also:
setParamMin, getParamMax

Reimplemented in InheritableObject.

bool GameObject::hasEvent ( const QString &  event) const [virtual]

Return true if the GameObject has a event named event.

See also:
getEvent, getEvents, hasOrder

Reimplemented in InheritableObject.

bool GameObject::hasFlag ( const QString &  flag) const [virtual]

Returns true if the falg flag is register in the object's flags.

See also:
getFlag, setFlag, hasParam

Reimplemented in InheritableObject.

bool GameObject::hasOrder ( const QString &  order) const [virtual]

Return true if the GameObject has a order named order.

See also:
getOrder, getOrders, hasEvent

Reimplemented in InheritableObject.

bool GameObject::hasParam ( const QString &  param) const [virtual]

Returns true if the parameter param is register in the object's parameters.

See also:
getParam, setParam, hasFlag

Reimplemented in InheritableObject.

GameObject int GameObject::ident ( ) const [inline]

Returns the name wide unique identifier of the object.

See also:
init, GameObject
void GameObject::init ( Game g,
GameObject parent 
) [protected]

Initialises the object in case it had been construct with a NULL pointer (array of objects)

See also:
isValid, GameObject
virtual bool GameObject::isEditable ( ) const [inline, virtual]

Returns true if the GameObject is editable by the user.

Reimplemented in GameObjectInventory, GameObjectList< Type >, and DefaultTypes.

virtual bool GameObject::isValid ( ) const [inline, protected, virtual]

Returns true if the object has been initialised

See also:
init, GameObject

Reimplemented in Image.

const QDateTime& GameObject::lastChildrenEdition ( ) const [inline]

Returns the last time one of the object's children has been modified.

See also:
lastEdition, lastInternalEdition
const QDateTime& GameObject::lastEdition ( ) const [inline]

Returns the last time a modification was made on the object or one of its children.

See also:
lastInternalEdition, lastChildrenEdition
const QDateTime& GameObject::lastInternalEdition ( ) const [inline]

Returns the last edition time.

See also:
lastEdition, lastChildrenEdition
const QString& GameObject::name ( ) const [inline]

Returns the name of the object.

See also:
setName
QList< QString > GameObject::orders ( ) const [virtual]

Returns the list of order's names of the object.

See also:
getOrder, getEvents

Reimplemented in InheritableObject.

QList< QString > GameObject::params ( ) const [virtual]

Returns the list of the registered paramters

See also:
getParam, setParam, flags

Reimplemented in InheritableObject.

GameObject* GameObject::parent ( ) const [inline]

Returns the parent of the object.

See also:
setParent
void GameObject::removeChild ( GameObject c) [protected, virtual]

Removes a child from the children list.

Note:
This method does not destroy the child.
See also:
addChild, child, children

Free the GameObject from the action action as its emitter.

This is usefull to avoid dangling references.

See also:
addEmittedAction, removeReceivedAction
void GameObject::removeEvent ( const QString &  event) [virtual]

Delete the event named event, if exists.

See also:
addEvent, removeOrder
void GameObject::removeFlag ( const QString &  flag) [virtual]

Erases the flag flag.

Note:
If the requested flag does not exists, the falgs stay unchanged.
See also:
renameFlag, addFlag
void GameObject::removeOrder ( const QString &  order) [virtual]

Delete the order named order, if exists.

See also:
addOrder, removeEvent
void GameObject::removeParam ( const QString &  param) [virtual]

Erases the param parameter.

Note:
If the requested parameter does not exists, the parameters stay unchanged.
See also:
renameParam, addParam

Free the GameObject from the action action as one of its receivers.

This is usefull to avoid dangling references.

See also:
addReceivedAction, removeEmittedAction

Decreases the references counter

See also:
addReference
void GameObject::renameEvent ( const QString &  order,
const QString &  newOrder 
) [virtual]

Changes the name of the event event to newEvent.

Note:
If the requested event does not exist, a new event is created.
See also:
addEvent, removeEvent
void GameObject::renameFlag ( const QString &  flag,
const QString &  newFlag 
) [virtual]

Changes the name of the flag flag to newFlag.

Note:
If the requested flag does not exist, a new flag is created.
See also:
addFlag, removeFlag
void GameObject::renameOrder ( const QString &  order,
const QString &  newOrder 
) [virtual]

Changes the name of the order order to newOrder.

Note:
If the requested order does not exist, a new order is created.
See also:
addOrder, removeOrder
void GameObject::renameParam ( const QString &  param,
const QString &  newParam 
) [virtual]

Changes the name of the param parameter to newParam.

Note:
If the requested parameter does not exist, a new parameter is created.
See also:
addParam, removeParam
void GameObject::setFlag ( const QString &  flag,
bool  enable 
) [virtual]

Set the value of the flag flag.

Note:
If the requested flag does not exists, it is created.
See also:
flags, hasFlag, getFlag, setParam
void GameObject::setName ( const QString &  n) [virtual]

Defines the name of the object.

See also:
name
void GameObject::setParam ( const QString &  param,
int  value 
) [virtual]

Set the value of the param parameter.

Note:
If the requested parameter does not exists, it is created.
See also:
params, hasParam, getParam, setFlag

Reimplemented in InheritableObject.

void GameObject::setParamDomain ( const QString &  param,
int  min,
int  max 
) [virtual]

Sets the lower and upper bound of the param parameter.

Note:
If the requested parameter does not exists, the parameters stay unchanged.
See also:
getParamMin, getParamMax, setParamMin, setParamMax
void GameObject::setParamMax ( const QString &  param,
int  max 
) [virtual]

Sets the upper bound of the param parameter.

Note:
If the requested parameter does not exists, the parameters stay unchanged.
See also:
getParamMax, setParamMin, setParamDomain
void GameObject::setParamMin ( const QString &  param,
int  min 
) [virtual]

Sets the lower bound of the param parameter.

Note:
If the requested parameter does not exists, the parameters stay unchanged.
See also:
getParamMin, setParamMax, setParamDomain

Defines the parent of the object.

See also:
parent

Notify the object and its parent that it has been modified.

See also:
lastInternalEdition, lastChildrenEdition, lastEdition.

The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Defines