Class: DpObject
SOURCE LOCATION: /dpuniverse/std/DpObject.php
Class Overview
|
The standard object which is built upon by all other objects
Creates the following DutchPIPE properties:
- string uniqueId - Unique Id for this instance, for example
'object_436'
- integer resetTime - UNIX timestamp of next reset
- string location - Location in dpuniverse, for example
'/page/manual.php'
- string sublocation - Optional sublocation, for example
'introduction'
- int|float credits - Credits contained, integer or float depending
on type, initially 0
- string template - Optional replacement for dpdefault.tpl,
absolute path on server
- string title - Title for this object, "beer", used for object
labels, etc.
- string titleDefinite - Definite title for this object, "the beer"
- string titleIndefinite - Indefinite title for this object, "a beer"
- string titleType - Type of this object's title
- string titleImg - URL for the avatar or other image representing
this object
- int titleImgWidth - Width of the title image in pixels, you can
optionally set this by hand for extra speed but it is not mandatory
- int titleImgHeight - Height of the title image in pixels, you can
optionally set this by hand for extra speed but it is not mandatory
- boolean isDraggable - Can we be dragged on the screen by a given
user? Experimental
- string body - HTML content of this object
- integer creationTime - UNIX timestamp when this object instance was
created
- integer lastEventTime - UNIX timestamp of last event, used by
cleanup mechanism
- string navigationTrailHtml - HTML with a navigation trail for this
page
- int|float value - Monetary value, integer or float depending on
type, initially 0
- boolean isRemoved - TRUE if removed from universe but not destructed
yet by PHP
- integer lastActionTime - UNIX timestamp of last action performed by
this object
DpProperties
|
--DpObject
|
METHODS:
|
Direct Descendants
| Note |
A small note that users can read
|
| DpDrink |
A common drink which can be turned into beers, wine, etc.
|
| DpPage |
A DutchPIPE enabled web page
|
| DpLiving |
An object which is "alive", common code shared between users and NPCs
|
| DpHeap |
A heap of credits, stones, etc., represented by one object
|
Methods Summary
| void |
__destruct() |
Called by PHP when this object is destroyed, handles events |
| void |
addAction() |
Adds an action to the object |
| void |
addId() |
Adds one or more ids for this object |
| void |
addItem() |
Adds an examinable 'item' to this object |
| void |
addMapAreaAction() |
Adds an action to a map area so it becomes clickable there |
| void |
event() |
Reports an event |
| void |
getActionsMenu() |
Tells the current user the HTML with the action menu for this object |
| string |
getBody() |
Gets the HTML content of this object |
| int|float |
getCredits() |
Gets the amount of credits in the inventory of this object |
| mixed |
&getEnvironment() |
Gets the object reference to the environment of this object |
| array |
getIds() |
Gets the array of ids for this object, or an empty array for no ids |
| array |
&getInventory() |
Gets an array with object references to all objects in our inventory |
| array |
getItem() |
Gets an array with data about an item |
| array |
getItems() |
Gets an array with all item data added to this object |
| mixed |
getMapArea() |
Gets data of one, multiple or all imagemap areas |
| array |
getMapAreaActions() |
Gets all map area actions for all areas or for a given area |
| string |
getMapAreaHtml() |
Gets HTML for all imagemaps or the given imagemap for inclusion in page |
| string |
getTitle() |
Gets the object's title with optional prefixes such as 'a' and 'the' |
| void |
handleCleanUp() |
Called by the universe object, checks if this object can be removed. |
| boolean |
isDraggable() |
Can we be dragged on the screen by the given user? |
| boolean |
isId() |
Checks if the given id is a valid id for this object |
| boolean |
isPresent() |
Checks if an object is present in this object's inventory |
| boolean |
isValidClientCall() |
May the given method be called in this object from the DutchPIPE client? |
| void |
makePresent() |
Makes sure an object is present in this object's inventory |
| int |
moveDpObject() |
Moves this object into the inventory of another object |
| void |
removeId() |
Removes one or more ids for this object |
| void |
reportMove() |
Reports graphical movement of this object to other objects |
| void |
setBody() |
Sets the HTML content of this object |
| boolean |
setCredits() |
Sets the amount of credits in the inventory of this object |
| boolean |
setHeapAmount() |
Sets a heap object of a given amount in this object |
| void |
setIds() |
Sets an array of names used to refer to this object |
| void |
setMapArea() |
Creates a new imagemap area which can be used by actions |
| void |
setTimeout() |
Calls the given method after the given number of seconds |
| void |
setTitle() |
Sets the title for this object, "beer", used for object labels, etc. |
| void |
tell() |
Tells data (message, window, location, ...) to this object |
Methods
Destructor __destruct [line 378]
void __destruct(
)
Called by PHP when this object is destroyed, handles events
Called by PHP when this object is destroyed. removeDpObject should be called in this object to remove it from the universe. Don't use unset to remove objects. On a PHP level, __destruct will then be called in this object. Calls the event method in this object and its environment, if any, when defined, using constants from events.php. Triggers the EVENT_LEFT_INV event in the environment of this object with "from" ($this) and "to" (0) parameters: $environment->event(EVENT_LEFT_INV, $this, 0); Triggers the EVENT_CHANGED_ENV event in this object with "from" (the environment) and "to" (0) parameters: $this->event(EVENT_CHANGED_ENV, $environment, 0); If the object had no environment, the above two events are not called, instead the EVENT_CHANGED_ENV event is triggered in this object with only a "from" (0) parameter: $this->event(EVENT_CHANGED_ENV, 0); Last, the EVENT_DESTROYING_OBJ event is triggered in this object: $this->event(EVENT_DESTROYING_OBJ);
void addAction(
mixed
$actionMenu , mixed
$actionVerb , mixed
$actionMethod , [mixed
$actionOperant = DP_ACTION_OPERANT_MENU] , [mixed
$actionTarget = DP_ACTION_TARGET_SELF] , [mixed
$actionAuthorized = DP_ACTION_AUTHORIZED_ALL] , [mixed
$actionScope = DP_ACTION_SCOPE_ALL] , [mixed
$mapArea = NULL] , [string
$mapAreaAction = NULL]
)
Adds an action to the object
Use this method to have actions added to the menus you get when clicking on items (the "action menu"), and at the same time to add actions you can type. See DpLiving.php for some good examples. Because of the complexity of this method, it has its own manual page. See Action System for further information.
| PARAMETERS: |
mixed |
$actionMenu |
title of clickable menu item |
| mixed |
$actionVerb |
alternative verb to type |
| mixed |
$actionMethod |
method called to perform action |
| mixed |
$actionOperant |
on who/what does it have effect? |
| mixed |
$actionTarget |
where should menu item appear? |
| mixed |
$actionAuthorized |
who may perform this action? |
| mixed |
$actionScope |
who sees action to begin with? |
| mixed |
$mapArea |
imagemap area id or definition |
| string |
$mapAreaAction |
specific action to use |
| ACCESS: | public |
| SEE: | DpObject::removeAction(), DpObject::getActionData(), DpObject::getActionsMenu(), DpObject::setMapArea() |
| TUTORIAL: | Action System |
void addId(
string|array
$id
)
Adds one or more ids for this object
A single id can be added at a time, or an array with ids can be given, or multiple arguments can be given (strings or array of strings).
void addItem(
mixed
$item , string
$description , [mixed
$method = NULL] , [mixed
$mapArea = NULL] , [mixed
$mapAreaActionMenu = NULL]
)
Adds an examinable 'item' to this object
'Items' in objects allow you to perform some basic actions, such as examine, without making new objects. For example, consider this page with the following description: You are in front of a house. You see a sign. The following call will make the house examinable: add_item('house', 'It is a big, brick house.<br />');
The $item can be an identifier string or an array with strings with identifiers, for example array('house', 'brick house'). Such aliases can be used from the command line, for example 'examine brick house'. The $description should be a string with the textual description. The $method is optional and should be a string containing a method or an array with two elements: an object to call and a string with the method. This method is called at runtime to obtain the description. It should be defined like this: function <methodName>($item)
and return a string. When the $description is NULL, only the result from this method will be shown. With the $description is a normal string, the result of the method is appended. When the description has the %s token in it, the result of the method is inserted there. Example: add_item('door', 'A solid door. It is %s.', 'getOpenOrClosed');
The optional $mapArea can be given to make this item accessible on an imagemap, so people can click on it to examine it. Otherwise the item can only be examined by using the command line. It should be a map area id if you set one earlier with setMapArea, or an array with the arguments to setMapArea to define a new one (see setMapArea documentation for more information). If a map area is used, the action on the imagemap is labelled 'examine'. This can be overruled by supplying $mapAreaActionMenu, which should be a string with an alternative label.
addMapAreaAction [line 2596]
void addMapAreaAction(
string
$mapAreaId , string
$actionMenuTitle , string
$action , [string
$actionVerb = NULL] , [string
$actionVerbKey = NULL]
)
Adds an action to a map area so it becomes clickable there
Creates a menu item labelled $actionMenuTitle on the imagemap area with id $mapAreaId. When clicked, executes $action for that user. Can optionally be associated with an existing action by giving an $actionVerb and $actionVerbKey. Normal map area menu actions always appear. By associating it to a regular action, all its settings such as scope, target and authorization are used. Use addAction to set up such a map area action, as addAction will call addMapAreaAction with the right verb and verb key (a verb key is needed because there can be multiple indentical verbs).
addValidClientCall [line 3049]
void addValidClientCall(
string
$methodName
)
Makes the given method callable from the DutchPIPE client
createDpObject [line 315]
void createDpObject(
)
Sets this object up at the time it is created
An empty function which can be redefined by the class extending on DpObject. When the object is created, it has no title, HTML body, etc., so here methods such as $this->setTitle() are called. Building blocks extending on DpObject may define their own create function. For example, DpPage defines createDpPage.
void event(
object
$name , mixed
$args
)
Reports an event
Called when certain events occur, given with $name. The property lastEventTime is set to a unix time stamp. Calls eventDpObject.
| PARAMETERS: |
object |
$name |
Name of event |
| mixed |
$args |
One or more arguments, depends on event |
eventDpObject [line 2882]
void eventDpObject(
object
$name , mixed
$args
)
Reports an event
Called when certain events occur, given with $name.
getActionData [line 1827]
array getActionData(
[boolean
$actionVerb = NULL] , [
$actionNr = NULL] , integer
&$actionNr
)
Gets data of one, multiple or all actions
Without arguments, an array is returned with each element of pair consisting of: verb => array(menulabel, method, operant, target, authorized, scope) with operant one of DP_ACTION_OPERANT_, target one of DP_ACTION_TARGET_, authorized one of DP_ACTION_AUTHORIZED_ and scope one of DP_ACTION_SCOPE_ from dpuniverse/include/actions.php, for example: 'read' => array('read me!', 'actionRead', DP_ACTION_OPERANT_MENU, DP_ACTION_TARGET_SELF, DP_ACTION_AUTHORIZED_ALL, DP_ACTION_SCOPE_ALL) You can narrow the result set down by supplying a verb, in which case an array with one or more results is returned, or FALSE if the given verb is not defined as an action. Narrow it down further by giving a number, usually 0, to get the data at the index of the array you would get without supplying a number.
getActionsMenu [line 1853]
void getActionsMenu(
)
Tells the current user the HTML with the action menu for this object
getAppearance [line 1226]
string getAppearance(
[int
$level = 0] , [boolean
$include_div = TRUE] , [object
$from = NULL] , [string
$displayMode = 'abstract'] , [boolean
$displayTitlebar = TRUE] , [boolean
$elementId = 'dppage']
)
Gets the HTML "appearance" of this object
Gets HTML to represent the object to another objects. That is, other objects call this method in order to "see" it, and HTML is returned. How an object is seen depends on how the object is related to the object that is viewing it in terms of "physical" location. In other words, a level of 0 means this object is seen by something in its inventory (a user sees a page). Level 1 means this object is seen by an object in its environment (a user sees another user). Level 2 means this object is in the inventory of the object that is seeing it.
| PARAMETERS: |
int |
$level |
level of visibility |
| boolean |
$include_div |
include div with id around HTML? |
| object |
$from |
experimental |
| string |
$displayMode |
'abstract' or 'graphical' |
| boolean |
$displayTitlebar |
display title bar for pages? |
| boolean |
$elementId |
to be used as html element id |
| RETURNS: | string | HTML "appearance" of this object |
| ACCESS: | public |
| SEE: | DpObject::getAppearanceTitle() |
getAppearanceInventory [line 1466]
string getAppearanceInventory(
[int
$level = 0] , [boolean
$include_div = TRUE] , [object
$from = NULL] , [string
$displayMode = 'abstract'] , [
$displayTitlebar = TRUE] , [
$elementId = 'dppage']
)
Gets the HTML "appearance" of all objects in this object's inventory
Gets HTML to represents the all objects in this object's inventory using getAppearance.
| PARAMETERS: |
int |
$level |
level of visibility of this object |
| boolean |
$include_div |
include div with id around HTML? |
| object |
$from |
expiremental |
| string |
$displayMode |
'abstract' or 'graphical' |
| |
$displayTitlebar |
|
| |
$elementId |
|
| RETURNS: | string | HTML "appearances" of this object's inventory |
getAppearanceTitle [line 1405]
string getAppearanceTitle(
object
&$user
)
Gets the graphical appearance in HTML for this object
Returns the HTML with the image and the title of the object. The method filterAppearance($level, &$from, $appearance, &$user) is called in the environments of the object if defined. $level is 1, $from is an array starting with this object, followed by elements defining a path to the current object being called, $appearance the default appearance HTML and $user the user for which we're getting the appearance of the object. If you define it, it should return a string with the HTML for the appearance, just like getAppearanceTitle does itself.
| PARAMETERS: |
object |
&$user |
performer of actions |
| RETURNS: | string | the graphical appearance in HTML for this object |
| SEE: | DpObject::getAppearanceTitle() |
| SINCE: | DutchPIPE 0.3.0 |
string getBody(
)
Gets the HTML content of this object
int|float getCredits(
)
Gets the amount of credits in the inventory of this object
getEnvironment [line 766]
mixed &getEnvironment(
)
Gets the object reference to the environment of this object
| RETURNS: | mixed | object reference or FALSE for no environment |
getHeapAmount [line 3002]
int|float getHeapAmount(
string
$idProperty
)
Gets the amount of a given heap object
| PARAMETERS: |
string |
$idProperty |
unique property to identify heap object |
| RETURNS: | int|float | amount, depends on heap type |
| SINCE: | DutchPIPE 0.2.0 |
array getIds(
)
Gets the array of ids for this object, or an empty array for no ids
array &getInventory(
)
Gets an array with object references to all objects in our inventory
If this object contains no other objects, an empty array is returned.
| RETURNS: | array | object references to objects in our inventory |
array getItem(
string
$item
)
Gets an array with data about an item
An array is returned with two elements: the item description and the item method. Either can be NULL. If the item was not found, FALSE is returned.
getItemDescription [line 1617]
mixed getItemDescription(
string
$item
)
Gets the description of a given item
Returns the description of the given item, or FALSE if no such item was found. Items can be added with a method to call (see addItem), here this method is processed.
array getItems(
)
Gets an array with all item data added to this object
mixed getMapArea(
[string
$mapName = NULL] , [string
$mapAreaId = NULL]
)
Gets data of one, multiple or all imagemap areas
If no arguments are given data of all imagemap areas is returned. If an imagemap name is given, all data for that map is returned, or FALSE if the imagemap is not defined. If both the map name and an id of the area in the map are given, data for that area is returned, or FALSE if not defined.
|
|