Echo Hollow

Gender-Bending Interactive Stories! :D

User Tools

Site Tools


libtf:documentation:api:inventory

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
libtf:documentation:api:inventory [2018/02/25 13:10] leelibtf:documentation:api:inventory [2018/09/24 18:07] (current) – removed lee
Line 1: Line 1:
-[[libtf:documentation:api:start|<-- Back]] 
- 
- 
-====== LibTF.Inventory====== 
- 
-**Inherits From:** [[libtf:documentation:api:persistentobject|LibTF.PersistentObject]] 
- 
-An Inventory is an object that contains other things.  An inventory is used to track items that a Person carries.  A different specialized inventory is used to track what Apparel a Person is wearing.  A trunk or bookshelf might use an Inventory to track what is held within on on it.  In a more traditional sort of location-based Twine IF, each location might even use an inventory to track what items the player can find or has dropped there. 
- 
- 
-===== Fields ===== 
- 
-**Inherited from [[libtf:documentation:api:persistentobject|LibTF.PersistentObject]]:** id, parentId, parent, name, aName, nameIsProper, nameIrregularArticle 
- 
- 
-===== Methods ===== 
- 
-**Inherited from [[libtf:documentation:api:persistentobject|LibTF.PersistentObject]]:** hasPersistent(), getPersistent(), setPersistent(), resetPersistent() 
- 
- 
-==== (Inventory).add( itemOrId ) ==== 
- 
-  * **Arguments:** 
-    * **//itemOrId ://** the thing to be added to the inventory. 
-  * **Returns:** Nothing, although it probably ought to return the thing that was added, or null if it wasn't added... 
-  * **Throws:** Error if: //itemOrId// is invalid or malformed, or if the //preAdd()// callback does not return a proper Boolean value. 
- 
-This method adds the given //itemOrId// to the inventory.  It **does not** remove it from any other inventories that might also contain it.  //itemOrId// may be a persistence id string, or a fully instantiated PersistentObject (or subclass thereof). 
- 
-<code javascript> 
-tf("joe").inventory.add( "some_widget" ); 
-</code> 
- 
- 
-==== (Inventory).remove( itemOrId ) ==== 
- 
-  * **Arguments:** 
-    * **//itemOrId://** the thing to be removed from the inventory. 
-  * **Returns:** Nothing, although it probably ought to return the thing that was removed, or null if it wasn't removed... 
-  * **Throws:** Error if: //itemOrId// is invalid or malformed, or if the //preRemove()// callback does not return a proper Boolean value. 
- 
-This method removes the given //itemOrId// from the inventory.  //itemOrId// may be a persistence id string, or a fully instantiated PersistentObject (or subclass thereof). 
- 
-<code javascript> 
-tf("joe").inventory.remove( "some_widget" ); 
-</code> 
- 
- 
-==== (Inventory).has( itemOrId ) ==== 
- 
-  * **Arguments:** 
-    * **//itemOrId://** the thing to be checked for in the inventory. 
-  * **Returns:** (Boolean)  True if the inventory contains the specified thing, or False if not. 
-  * **Throws:** Error if: //itemOrId// is invalid or malformed. 
- 
-This method checks to see if the inventory contains the given //itemOrId// //itemOrId// may be a persistence id string, or a fully instantiated PersistentObject (or subclass thereof). 
- 
-<code javascript> 
-if( tf("joe").inventory.has("some_widget") ) 
- alert( "Joe has a widget!" ); 
-</code> 
- 
- 
-==== (Inventory).get() ==== 
- 
-  * **Arguments:** None. 
-  * **Returns:** (Array)  An array of fully instantiated PersistentObjects (or subclasses thereof). 
-  * **Throws:** Nothing. 
- 
-Returns an array of fully instantiated PersistentObjects (or subclasses thereof) contained in the inventory. 
- 
-FIXME: We ought to have a method that just returns ids, too... 
- 
-<code javascript> 
-alert( "Joe is carrying " + LibTF.Util.commaList(tf("joe").inventory.get()) + " Kinky." ); 
-// prints "Joe is carrying a ball of string, an octopus, and a European swallow.  Kinky." 
-</code> 
- 
- 
-==== (Inventory).getListString( examineLink = true ) ==== 
- 
-  * **Arguments:** 
-    * **//examineLink://** set to True to include links to object passages in the returned value. 
-  * **Returns:** (String)  A string listing the contents of the inventory, or "Nothing" if the inventory is empty. 
-  * **Throws:** Nothing. 
- 
-Returns a natural language string describing the contents of the inventory. 
- 
-If //examineLink// is True, the returned string will contain links to any "examine passages" available for objects in the inventory.  For example, if there is an object with the id "octopus", and you create a passage titled "Examine.octopus" (note the dot there), then a link to that passage will be included in the returned string.  This is useful for examining or manipulating objects in inventory. 
- 
-Note that this means that the returned value will need to be wikified before it is output. 
- 
-FIXME: Need to provide for a way for this to work right with non-Sugarcube-like story formats.  Probably something with _init() same as we did for handling the story format's persistence engine. 
- 
-<code javascript> 
-// Assuming that there is a passaged titled "Examine.octopus", but none for the ball of string or the swallow... 
-alert( "Joe is carrying " + tf("joe").inventory.getListString() + " Kinky." ); 
-// prints "Joe is carrying a ball of string, [[an octopus->Examine.octupus]], and a European swallow.  Kinky." 
-</code> 
- 
- 
-==== (Inventory).sort( a, b ) ==== 
- 
-  * **Arguments:** 
-    * **//a://** a thing in the inventory. 
-    * **//b://** another thing in the inventory. 
-  * **Returns:** (Integer)  <0 if a<b, >0 if a>b, or 0 if a==b. 
-  * **Throws:** Nothing. 
- 
-This is the function used by //.get()// to sort the inventory.  It follows the rules of Javascript's (Array).sort().  The default implementation sorts alphabetically, ignoring case. 
- 
-//This function is generally only used by derived classes that need to sort the inventory differently.  Unless you are extending the library, you'll probably never need to use it.// 
- 
- 
-==== (Inventory).preAdd( id ) ==== 
- 
-  * **Arguments:** 
-    * **//id://** the persistence id of the thing being added to the inventory. 
-  * **Returns:** (Boolean)  True to allow the item to be added, False to deny it. 
-  * **Throws:** Nothing. 
- 
-This callback method is called before //id// is added to the inventory.  Returning True allows the add to continue, while False will cancel it. 
- 
-//This method is meant to be overridden by derived classes that can only contain certain sorts of things or exhibit special behaviors.  Unless you are extending the library, you'll probably never need to use this method.// 
- 
- 
-==== (Inventory).postAdd( id ) ==== 
- 
-  * **Arguments:** 
-    * **//id://** the persistence id of the thing that was added to the inventory. 
-  * **Returns:** Nothing. 
-  * **Throws:** Nothing. 
- 
-This callback method is called after //id// has been added to the inventory. 
- 
-//This method is meant to be overridden by derived classes that can only contain certain sorts of things or exhibit special behaviors.  Unless you are extending the library, you'll probably never need to use this method.// 
- 
- 
-==== (Inventory).preRemove( id ) ==== 
- 
-  * **Arguments:** 
-    * **//id://** the persistence id of the thing being removed from the inventory. 
-  * **Returns:** (Boolean)  True to allow the item to be removed, False to deny it. 
-  * **Throws:** Nothing. 
- 
-This callback method is called before //id// is removed from the inventory.  Returning True allows the removal to continue, while False will cancel it. 
- 
-//This method is meant to be overridden by derived classes that can only contain certain sorts of things or exhibit special behaviors.  Unless you are extending the library, you'll probably never need to use this method.// 
- 
- 
-==== (Inventory).postRemove( id ) ==== 
- 
-  * **Arguments:** 
-    * **//id://** the persistence id of the thing that was removed from the inventory. 
-  * **Returns:** Nothing. 
-  * **Throws:** Nothing. 
- 
-This callback method is called after //id// has been removed from the inventory. 
- 
-//This method is meant to be overridden by derived classes that can only contain certain sorts of things or exhibit special behaviors.  Unless you are extending the library, you'll probably never need to use this method.// 
- 
- 
-[[libtf:documentation:api:start|<-- Back]] 
  
libtf/documentation/api/inventory.1519593024.txt.gz · Last modified: 2018/02/25 13:10 by lee