This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
smutbook:classes:inventory:generalinventory [2023/08/08 18:39] – lee | smutbook:classes:inventory:generalinventory [2023/08/08 19:16] (current) – lee | ||
---|---|---|---|
Line 3: | Line 3: | ||
**Extends: | **Extends: | ||
- | DESCRIPTION | + | GeneralInventory is the base Inventory implementation from which all other Inventory types are derived. |
===== Usage Notes ===== | ===== Usage Notes ===== | ||
Line 11: | Line 11: | ||
===== Static Properties/ | ===== Static Properties/ | ||
- | PROBABLY_NONE | + | ==== .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 ) ===== | ===== Constructor( id ) ===== | ||
Line 19: | Line 30: | ||
===== Properties/ | ===== Properties/ | ||
- | ==== .someProperty | + | ==== .contents |
- | Description. | + | An array of the id fields of all the things (PersistentObjects and subclasses) contained in this inventory. |
- | * **Type: | + | * **Type: |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | ==== .someProperty | + | ==== .add( item, actor=undefined, |
- | Description. | + | 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. |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | ==== .someProperty ==== | + | Before the item is added to the inventory, preAdd(item, |
- | Description. | + | |
- | * **Type:** void | + | However, if the item was successfully added to the inventory, postAdd(item,thisInventory, |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | + | ||
- | ==== .someProperty ==== | + | |
- | Description. | + | |
- | + | ||
- | * **Type:** void | + | |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | + | ||
- | ==== .someProperty ==== | + | |
- | Description. | + | |
- | + | ||
- | * **Type:** void | + | |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | + | ||
- | ==== .someProperty ==== | + | |
- | Description. | + | |
- | + | ||
- | * **Type:** void | + | |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | + | ||
- | ==== .someProperty ==== | + | |
- | Description. | + | |
- | + | ||
- | * **Type:** void | + | |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | + | ||
- | ==== .someProperty ==== | + | |
- | Description. | + | |
- | + | ||
- | * **Type:** void | + | |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | + | ||
- | ==== .someProperty ==== | + | |
- | Description. | + | |
- | + | ||
- | * **Type:** void | + | |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | + | ||
- | ==== .someProperty ==== | + | |
- | Description. | + | |
- | + | ||
- | * **Type:** void | + | |
- | * **Automatic** | + | |
- | * **ReadOnly** | + | |
- | + | ||
- | ==== .someFunction( arg1, ... ) ==== | + | |
- | Description. | + | |
* **Type:** Function | * **Type:** Function | ||
* **Arguments: | * **Arguments: | ||
- | * //arg1//: desc | + | * //item//: the thing to be added to the Inventory. |
- | * //arg2//: desc | + | * //actor//: the (optional) Person that is doing the adding. |
- | * //arg3//: desc | + | * //force//: if true, the pre- and post- functions will not be called, and item will be added regardless. |
- | * //arg4//: desc | + | * **Returns: |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
* **Throws:** Nothing | * **Throws:** Nothing | ||
- | Example:< | + | ==== .remove( item, actor=undefined, |
- | FIXME | + | Removes the given item from the inventory. |
- | </ | + | |
- | ==== .someFunction( arg1, ... ) ==== | + | Before the item is removed from the inventory, preRemove(item,thisInventory, |
- | Description. | + | |
+ | However, if the item was successfully removed from the inventory, postRemove(item, | ||
* **Type:** Function | * **Type:** Function | ||
* **Arguments: | * **Arguments: | ||
- | * //arg1//: desc | + | * //item//: the thing to be removed from the Inventory. |
- | * //arg2//: desc | + | * //actor//: the (optional) Person that is doing the removal. |
- | * //arg3//: desc | + | * //force//: if true, the pre- and post- functions will not be called, and item will be removed regardless. |
- | * //arg4//: desc | + | * **Returns: |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
* **Throws:** Nothing | * **Throws:** Nothing | ||
- | Example:< | + | ==== .has( item ) ==== |
- | FIXME | + | Checks to see if the inventory contains the given item. |
- | </ | + | |
- | + | ||
- | ==== .someFunction( arg1, ... ) ==== | + | |
- | Description. | + | |
* **Type:** Function | * **Type:** Function | ||
* **Arguments: | * **Arguments: | ||
- | * //arg1//: desc | + | * //item//: the thing to be checked for in the Inventory. |
- | * //arg2//: desc | + | * **Returns: |
- | * //arg3//: desc | + | |
- | * //arg4//: desc | + | |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
* **Throws:** Nothing | * **Throws:** Nothing | ||
- | Example:< | + | ==== .isEmpty() ==== |
- | FIXME | + | Check if the inventory is empty. |
- | </ | + | |
- | + | ||
- | ==== .someFunction( arg1, ... ) ==== | + | |
- | Description. | + | |
* **Type:** Function | * **Type:** Function | ||
- | * **Arguments: | + | * **Arguments: |
- | * //arg1//: desc | + | * **Returns: |
- | * //arg2//: desc | + | |
- | * //arg3//: desc | + | |
- | * //arg4//: desc | + | |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
* **Throws:** Nothing | * **Throws:** Nothing | ||
- | Example:< | + | ==== .get( filterClass=undefined, |
- | FIXME | + | Returns the fully-instantiated contents of the Inventory. |
- | </ | + | |
- | ==== .someFunction( arg1, ... ) ==== | + | If a class is passed to filterClass, only items that are of that class (or a subclass thereof) will be included in the returned array. |
- | Description. | + | |
- | * **Type:** Function | + | If a function is passed to filterFunction, |
- | * **Arguments: | + | |
- | * //arg1//: desc | + | |
- | * //arg2//: desc | + | |
- | * //arg3//: desc | + | |
- | * //arg4//: desc | + | |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
- | * **Throws:** Nothing | + | |
- | + | ||
- | Example:< | + | |
- | FIXME | + | |
- | </ | + | |
- | + | ||
- | ==== .someFunction( arg1, ... ) ==== | + | |
- | Description. | + | |
* **Type:** Function | * **Type:** Function | ||
* **Arguments: | * **Arguments: | ||
- | * //arg1//: desc | + | * //filterClass//: an optional filter class. |
- | * //arg2//: desc | + | * //filterFunction(item)//: an optional filter function. |
- | * //arg3//: desc | + | * **Returns: |
- | * //arg4//: desc | + | |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
* **Throws:** Nothing | * **Throws:** Nothing | ||
- | Example:< | + | ==== .sort( a, b ) ==== |
- | FIXME | + | An optional function used by .get() to sort the inventory contents. It follows the rules of Javascript' |
- | </ | + | |
- | ==== .someFunction( arg1, ... ) ==== | + | //This function is generally only used by derived classes that need to sort differently. Unless you are extending the library, you'll probably never need to define or call it.// |
- | Description. | + | |
* **Type:** Function | * **Type:** Function | ||
* **Arguments: | * **Arguments: | ||
- | * //arg1//: desc | + | * //a//: a thing in the inventory. |
- | * //arg2//: desc | + | * //b//: another thing in the inventory. |
- | * //arg3//: desc | + | * **Returns: |
- | * //arg4//: desc | + | |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
* **Throws:** Nothing | * **Throws:** Nothing | ||
- | Example:< | + | ==== .override ==== |
- | FIXME | + | When defined, the override value sets the value that .toString() returns, ignoring the actual contents (if any) of the inventory. |
- | </ | + | |
- | ==== .someFunction( arg1, ... ) ==== | + | 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 the inventory with, that the protagonist will otherwise never be able to interact with. See the [[Tutorial]] for details. |
- | Description. | + | |
- | * **Type: | + | * **Type: |
- | * **Arguments: | + | |
- | * //arg1//: desc | + | |
- | * //arg2//: desc | + | |
- | * //arg3//: desc | + | |
- | * //arg4//: desc | + | |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
- | * **Throws:** Nothing | + | |
- | Example:< | + | ==== .toString() ==== |
- | FIXME | + | Overridden. |
- | </ | + | |
- | + | ||
- | ==== .someFunction( arg1, ... ) ==== | + | |
- | Description. | + | |
* **Type:** Function | * **Type:** Function | ||
- | * **Arguments: | + | * **Arguments: |
- | * //arg1//: desc | + | * **Returns: |
- | * //arg2//: desc | + | |
- | * //arg3//: desc | + | |
- | * //arg4//: desc | + | |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
* **Throws:** Nothing | * **Throws:** Nothing | ||
- | Example:< | + | ==== .theString() ==== |
- | FIXME | + | |
- | </ | + | |
- | + | ||
- | ==== .someFunction( arg1, ... ) ==== | + | |
Description. | Description. | ||
* **Type:** Function | * **Type:** Function | ||
- | * **Arguments: | + | * **Arguments: |
- | * //arg1//: desc | + | * **Returns: |
- | * //arg2//: desc | + | |
- | * //arg3//: desc | + | |
- | * //arg4//: desc | + | |
- | * //arg5//: desc | + | |
- | * //arg6//: desc | + | |
- | * **Returns: | + | |
* **Throws:** Nothing | * **Throws:** Nothing | ||
- | |||
- | Example:< | ||
- | FIXME | ||
- | </ | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | * Inherits from: PersistentObject | ||
- | |||
- | GeneralInventory is the base Inventory implementation from which all other Inventory types are derived. | ||
- | |||
- | ==== 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 | ||
- | * Required | ||
- | |||
- | === .add( item, actor=null, force=false ) === | ||
- | This method 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. | ||
- | |||
- | * item: the thing to be added to the Inventory. | ||
- | * 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. | ||
- | |||
- | * Returns: true if the inventory contains no items. | ||
- | * Throws: nothing. | ||
- | |||
- | === .get( filterClass=undefined, | ||
- | Returns the fully-instantiated contents of the Inventory. | ||
- | |||
- | If a class is passed to filterClass, | ||
- | |||
- | If a function is passed to filterFunction, | ||
- | |||
- | * filterClass: | ||
- | * filterFunction: | ||
- | |||
- | * Returns: an array containing the fully instantiated contents of the inventory, less those filtered out. | ||
- | * Throws: nothing. | ||
- | |||
- | === .override === | ||
- | When not undefined, the override value sets the value that .toString() returns, ignoring the actual contents (if any) of the inventory. | ||
- | |||
- | 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 the inventory with, that the protagonist will otherwise never be able to interact with. See the [[Tutorial]] for details. | ||
- | |||
- | * Type: String | ||
- | * Optional | ||
- | |||
- | === .toString() === | ||
- | Overridden | ||
- | |||
- | * Returns: a serial-comma-separated-list of the inventory' | ||
- | |||
- | === .theString() === | ||
- | * Returns: a serial-comma-separated-list of the inventory' | ||
- | |||
- | === .sort( a, b ) === | ||
- | |||
- | This is the function used by .get() to sort the inventory contents. It follows the rules of Javascript' | ||
- | |||
- | //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.// | ||
- | |||
- | * a: a thing in the inventory. | ||
- | * b: another thing in the inventory. | ||
- | |||
- | * Returns: <0 if a<b, >0 if a>b, or 0 if a==b. | ||