This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
smutbook:classes:inventory:generalinventory [2023/08/08 18:09] – lee | smutbook:classes:inventory:generalinventory [2023/08/08 19:16] (current) – lee | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== GeneralInventory ====== | ====== GeneralInventory ====== | ||
+ | **Extends: | ||
+ | GeneralInventory is the base Inventory implementation from which all other Inventory types are derived. | ||
+ | ===== Usage Notes ===== | ||
+ | STUFF | ||
+ | ===== Static Properties/ | ||
+ | ==== .move( item, srcInventory, | ||
+ | As //actor//, try to move //item// from // | ||
+ | * **Type:** Function | ||
+ | * **Arguments: | ||
+ | * //item//: The PersistentObject (or subclass) to be moved. | ||
+ | * // | ||
+ | * // | ||
+ | * //actor//: The Person doing the moving. | ||
+ | * **Returns: | ||
+ | * **Throws:** Nothing | ||
+ | ===== Constructor( id ) ===== | ||
+ | //**Do not ever use " | ||
+ | ===== Properties/ | ||
+ | ==== .contents ==== | ||
+ | An array of the id fields of all the things (PersistentObjects and subclasses) contained in this inventory. | ||
+ | * **Type:** Array of strings, or empty array | ||
+ | ==== .add( item, actor=undefined, | ||
+ | Adds the given item to the inventory. | ||
+ | It **does not** remove it from any other inventories that might already contain it. You probably usually want to use InventoryUI or .move() instead. | ||
+ | Before the item is added to the inventory, preAdd(item, | ||
+ | However, if the item was successfully added to the inventory, postAdd(item, | ||
+ | * **Type:** Function | ||
+ | * **Arguments: | ||
+ | * //item//: the thing to be added to the Inventory. | ||
+ | * //actor//: the (optional) Person that is doing the adding. | ||
+ | * //force//: if true, the pre- and post- functions will not be called, and item will be added regardless. | ||
+ | * **Returns: | ||
+ | * **Throws:** Nothing | ||
- | * Inherits | + | ==== .remove( item, actor=undefined, |
+ | Removes the given item from the inventory. | ||
- | GeneralInventory | + | Before the item is removed from the inventory, preRemove(item, |
- | ==== Properties ==== | + | However, if the item was successfully removed from the inventory, postRemove(item, |
- | === .contents === | + | * **Type:** Function |
- | An array of the id fields of all the things | + | * **Arguments: |
+ | * // | ||
+ | * // | ||
+ | * //force//: if true, the pre- and post- functions will not be called, and item will be removed regardless. | ||
+ | * **Returns: | ||
+ | * **Throws:** Nothing | ||
- | * Type: Array of strings, or empty array | + | ==== .has( item ) ==== |
- | * Required | + | Checks to see if the inventory contains the given item. |
- | === .add( item, actor=null, force=false ) === | + | * **Type:** Function |
- | This method adds the given item to the inventory. It **does not** remove it from any other inventories that might already contain | + | * **Arguments: |
+ | * //item//: the thing to be checked for in the Inventory. | ||
+ | | ||
+ | * **Throws:** Nothing | ||
- | * item: the thing to be added to the Inventory. | + | ==== .isEmpty() ==== |
- | * actor: the (optional, can be null) Person that is doing the adding. | + | |
- | * force: if true, the pre- and post- functions will not be called, and item will be added regardless. | + | |
- | + | ||
- | * Returns: true if the item was added or was already in the inventory, or false if the item could not be added to the inventory. | + | |
- | * Throws: nothing. | + | |
- | + | ||
- | === .remove( item, actor=null, force=false ) === | + | |
- | This method removes the given item from the inventory. | + | |
- | + | ||
- | * item: the thing to be removed from the Inventory. | + | |
- | * actor: the (optional, can be null) Person that is doing the removal. | + | |
- | * force: if true, the pre- and post- functions will not be called, and item will be removed regardless. | + | |
- | + | ||
- | * Returns: true if the item was removed or was not in the inventory to begin with, or false if the item could not be removed from the inventory. | + | |
- | * Throws: nothing. | + | |
- | + | ||
- | === .has( item ) === | + | |
- | This method checks to see if the inventory contains the given item. | + | |
- | + | ||
- | * item: the thing to be checked for in the Inventory. | + | |
- | + | ||
- | * Returns: true if the inventory contains the specified item, or false if it does not. | + | |
- | * Throws: nothing. | + | |
- | + | ||
- | === .isEmpty() | + | |
Check if the inventory is empty. | Check if the inventory is empty. | ||
- | * Returns: true if the inventory contains no items. | + | |
- | * Throws: | + | * **Arguments: |
+ | * **Returns:** true if the inventory contains no items, false otherwise. | ||
+ | | ||
- | === .get( filterClass=undefined, | + | ==== .get( filterClass=undefined, |
Returns the fully-instantiated contents of the Inventory. | Returns the fully-instantiated contents of the Inventory. | ||
If a class is passed to filterClass, | If a class is passed to filterClass, | ||
- | If a function is passed to filterFunction, | + | If a function is passed to filterFunction, |
- | * filterClass: | + | * **Type:** Function |
- | * filterFunction: | + | * **Arguments: |
+ | * //filterClass//: an optional filter class. | ||
+ | * //filterFunction(item)//: an optional filter function. | ||
+ | * **Returns: | ||
+ | * **Throws:** Nothing | ||
- | * Returns: an array containing | + | ==== .sort( a, b ) ==== |
- | * Throws: nothing. | + | An optional function used by .get() to sort the inventory |
- | === .override === | + | //This function is generally only used by derived classes that need to sort differently. Unless you are extending |
- | When not undefined, | + | |
- | This is useful for minor characters and objects who do not actually need a fully-featured inventory, as it avoids all the hassle of defining flavor objects to populate | + | * **Type:** Function |
+ | * **Arguments: | ||
+ | * //a//: a thing in the inventory. | ||
+ | * //b//: another thing in the inventory. | ||
+ | * **Returns: | ||
+ | * **Throws:** Nothing | ||
- | * Type: String | + | ==== .override ==== |
- | | + | When defined, the override value sets the value that .toString() returns, ignoring the actual contents (if any) of the inventory. |
- | === .toString() === | + | This is useful for minor characters and objects who do not actually need a fully-featured inventory, as it avoids all the hassle |
- | Overridden | + | |
- | + | ||
- | * Returns: | + | |
- | + | ||
- | === .theString() === | + | |
- | * Returns: a serial-comma-separated-list of the inventory' | + | |
- | === .sort( a, b ) === | + | * **Type:** string |
- | This is the function used by .get() to sort the inventory contents. It follows the rules of Javascript' | + | ==== .toString() ==== |
+ | Overridden. | ||
- | //This function is generally only used by derived classes that need to sort the {@link LibEcho.Inventory|Inventory} differently. Unless you are extending the library, you'll probably never need to use it.// | + | * **Type:** Function |
+ | * **Arguments: | ||
+ | * **Returns: | ||
+ | * **Throws:** Nothing | ||
- | * a: a thing in the inventory. | + | ==== .theString() ==== |
- | * b: another thing in the inventory. | + | Description. |
- | * Returns: | + | |
+ | * **Arguments: | ||
+ | * **Returns:** a serial-comma-separated-list of the inventory' | ||
+ | * **Throws:** Nothing | ||