This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
libtf:documentation:api:inventory [2018/02/25 11:23] – lee | libtf:documentation:api:inventory [2018/09/24 18:07] (current) – removed lee | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | [[libtf: | ||
- | |||
- | |||
- | ====== LibTF.Inventory====== | ||
- | |||
- | **Inherits From:** [[libtf: | ||
- | |||
- | An Inventory is an object that contains other things. | ||
- | |||
- | |||
- | ===== Fields ===== | ||
- | |||
- | **Inherited from [[libtf: | ||
- | |||
- | |||
- | ===== Methods ===== | ||
- | |||
- | **Inherited from [[libtf: | ||
- | |||
- | |||
- | ==== (Inventory).add( itemOrId ) ==== | ||
- | |||
- | * **Arguments: | ||
- | * **// | ||
- | * **Returns: | ||
- | * **Throws:** Error if: // | ||
- | |||
- | This method adds the given // | ||
- | |||
- | <code javascript> | ||
- | tfGet(" | ||
- | </ | ||
- | |||
- | |||
- | ==== (Inventory).remove( itemOrId ) ==== | ||
- | |||
- | * **Arguments: | ||
- | * **// | ||
- | * **Returns: | ||
- | * **Throws:** Error if: // | ||
- | |||
- | This method removes the given // | ||
- | |||
- | <code javascript> | ||
- | tfGet(" | ||
- | </ | ||
- | |||
- | |||
- | ==== (Inventory).has( itemOrId ) ==== | ||
- | |||
- | * **Arguments: | ||
- | * **// | ||
- | * **Returns: | ||
- | * **Throws:** Error if: // | ||
- | |||
- | This method checks to see if the inventory contains the given // | ||
- | |||
- | <code javascript> | ||
- | if( tfGet(" | ||
- | alert( "Joe has a widget!" | ||
- | </ | ||
- | |||
- | |||
- | ==== (Inventory).get() ==== | ||
- | |||
- | * **Arguments: | ||
- | * **Returns: | ||
- | * **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(tfGet(" | ||
- | // prints "Joe is carrying a ball of string, an octopus, and a European swallow. | ||
- | </ | ||
- | |||
- | |||
- | ==== (Inventory).getListString( examineLink = true ) ==== | ||
- | |||
- | * **Arguments: | ||
- | * **// | ||
- | * **Returns: | ||
- | * **Throws:** Nothing. | ||
- | |||
- | Returns a natural language string describing the contents of the inventory. | ||
- | |||
- | If // | ||
- | |||
- | <code javascript> | ||
- | // Assuming that there is a passaged titled " | ||
- | alert( "Joe is carrying " + tfGet(" | ||
- | // prints "Joe is carrying a ball of string, [[an octopus-> | ||
- | </ | ||
- | |||
- | |||
- | ==== (Inventory).sort( a, b ) ==== | ||
- | |||
- | * **Arguments: | ||
- | * **//a://** a thing in the inventory. | ||
- | * **//b://** another thing in the inventory. | ||
- | * **Returns: | ||
- | * **Throws:** Nothing. | ||
- | |||
- | This is the function used by //.get()// to sort the inventory. | ||
- | |||
- | //This function is generally only used by derived classes that need to sort the inventory differently. | ||
- | |||
- | |||
- | ==== (Inventory).preAdd( id ) ==== | ||
- | |||
- | * **Arguments: | ||
- | * **//id://** the persistence id of the thing being added to the inventory. | ||
- | * **Returns: | ||
- | * **Throws:** Nothing. | ||
- | |||
- | This callback method is called before //id// is 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. | ||
- | |||
- | |||
- | ==== (Inventory).postAdd( id ) ==== | ||
- | |||
- | * **Arguments: | ||
- | * **//id://** the persistence id of the thing that was added to the inventory. | ||
- | * **Returns: | ||
- | * **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. | ||
- | |||
- | |||
- | ==== (Inventory).preRemove( id ) ==== | ||
- | |||
- | * **Arguments: | ||
- | * **//id://** the persistence id of the thing being removed from the inventory. | ||
- | * **Returns: | ||
- | * **Throws:** Nothing. | ||
- | |||
- | This callback method is called before //id// is 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. | ||
- | |||
- | |||
- | ==== (Inventory).postRemove( id ) ==== | ||
- | |||
- | * **Arguments: | ||
- | * **//id://** the persistence id of the thing that was removed from the inventory. | ||
- | * **Returns: | ||
- | * **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. | ||
- | |||
- | |||
- | [[libtf: | ||