This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
smutbook:classes:inventory:generalinventory [2023/08/08 18:08] – created 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 |
- | 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. | + | |
- | + | ||
- | ===== LibEcho.Inventory.InventoryUI ===== | + | |
- | + | ||
- | InventoryUI is a static container holding functions to render the inventory UI, as well as the object details UI (FIXME). | + | |
- | + | ||
- | ==== InventoryUI.render( config ) ==== | + | |
- | + | ||
- | Given a configuration object, this function renders the inventory UI into a DOM container (which is passed as part of the config object). | + | |
- | + | ||
- | This function is called by the InventoryUI macro (see the [[Macro]] documentation | + | |
- | + | ||
- | ==== The Configuration Object ==== | + | |
- | + | ||
- | The configuration object can contain a number of fields. | + | |
- | + | ||
- | For more information, | + | |
- | + | ||
- | === parentElement === | + | |
- | The parent element to render the UI into. | + | |
- | * Type: jQuery DOM Element | + | |
- | * Default: DEFAULT | + | |
- | * Optional | + | |
- | + | ||
- | === leftInventory === | + | |
- | The GeneralInventory (or subclass) or Person that appears on the left side of the inventory UI. This is conventionally the inventory of the person | + | |
- | * Type: GeneralInventory or Person | + | |
- | * Default: None | + | |
- | * Required | + | |
- | + | ||
- | === rightInventory === | + | |
- | The GeneralInventory (or subclass) or Person that appears on the right side of the inventory UI. This is conventionally the inventory from which things are being taken, but it can actually be any inventory or person. | + | |
- | * Type: GeneralInventory or Person | + | |
- | * Default: None | + | |
- | * Required | + | |
- | + | ||
- | === onClose( config ) === | + | |
- | Function to be called when inventory UI is closed. | + | |
- | * Type: Function | + | |
- | * Returns: Void | + | |
- | * //config//: The config object that was passed | + | |
- | * Default: undefined | + | |
- | * Optional | + | |
- | + | ||
- | === allowClose( config ) === | + | |
- | If this function returns a String, that value will be printed in place of the " | + | |
- | * Type: Function | + | |
- | * Returns: String | + | |
- | * Default: undefined | + | |
- | * Optional | + | |
- | + | ||
- | === actor === | + | |
- | The Person interacting | + | |
- | * Type: Person | or Function(config) returning Person | + | |
- | * Default: undefined | + | |
- | * Optional | + | |
- | + | ||
- | === leftAction === | + | |
- | The action label for moving item from left inventory. | + | |
- | * Type: String | Function(config) returning String | + | |
- | * Default: " | + | |
- | * Optional | + | |
- | + | ||
- | === leftActioned === | + | |
- | The left action success word. " | + | |
- | * Type: String | Function(config) returning String | + | |
- | * Default: " | + | |
- | * Optional | + | |
- | + | ||
- | === rightAction === | + | |
- | The action label for moving item from right inventory. | + | |
- | * Type: String | Function(config) returning String | + | |
- | * Default: " | + | |
- | * Optional | + | |
- | + | ||
- | === rightActioned === | + | |
- | The left action success word. " | + | |
- | * Type: String | Function(config) returning String | + | |
- | * Default: " | + | |
- | * Optional | + | |
- | + | ||
- | === canShowOnLeft( item, config ) === | + | |
- | Called to check if the object will be displayed in left inventory at all. | + | |
- | * Type: Function | + | |
- | * Returns: Boolean | + | |
- | * //item//: The item which we are checking whether or not we should show. | + | |
- | * //config//: The config object | + | |
- | * Default: true | + | |
- | * Optional | + | |
- | + | ||
- | === canShowOnRight( item, config ) === | + | |
- | Called to check if the object | + | |
- | * Type: Function | + | |
- | * Returns: Boolean | + | |
- | * //item//: The item which we are checking whether or not we should show. | + | |
- | * //config//: The config object that was passed | + | |
- | * Default: true | + | |
- | * Optional | + | |
- | + | ||
- | === canMoveFromLeft( item, config ) === | + | |
- | The item will be shown in the left inventory, but will we show the control to move it to the right inventory? | + | |
- | * Type: Function | + | |
- | * Returns: Boolean | + | |
- | * //item//: The item which we are checking whether or not we should show. | + | |
- | * //config//: The config object that was passed to InventoryIU.render(). | + | |
- | * Default: true | + | |
- | * Optional | + | |
- | + | ||
- | === canMoveFromRight( item, config ) === | + | |
- | The item will be shown in the right inventory, but will we show the control to move it to the right inventory? | + | |
- | * Type: Function | + | |
- | * Returns: Boolean | + | |
- | * //item//: The item which we are checking whether or not we should show. | + | |
- | * //config//: The config object that was passed to InventoryIU.render(). | + | |
- | * Default: true | + | |
- | * Optional | + | |
- | + | ||
- | === getSortCategory( item, inventory, config ) === | + | |
- | Return object category | + | |
- | * Type: Function | + | |
- | * Returns: String | + | |
- | * //item//: The item which we are checking whether or not we should show. | + | |
- | * // | + | |
- | * //config//: The config object that was passed to InventoryIU.render(). | + | |
- | * Default: item.inventoryCategory | " | + | |
- | * Optional | + | |
- | + | ||
- | === canShowLeftSelector === | + | |
- | Will the left selector be shown? | + | |
- | * Type: Boolean | or Function(config) returning Boolean | + | |
- | * Default: true | + | |
- | * Optional | + | |
- | + | ||
- | === canShowRightSelector === | + | |
- | Will the right selector be shown? | + | |
- | * Type: Boolean | or Function(config) returning Boolean | + | |
- | * Default: true | + | |
- | * Optional | + | |
- | + | ||
- | === moveFromLeft( item, config ) === | + | |
- | Function to call to move item from left to right inventory. If undefined, the built-in implementation will be used. | + | |
- | * Type: Function | + | |
- | * Returns: Void | + | |
- | * //item//: The item which we are checking whether or not we should show. | + | |
- | * //config//: The config object that was passed to InventoryIU.render(). | + | |
- | * Default: the builtin implementation is used if none is defined in the config object | + | |
- | * Optional | + | |
- | + | ||
- | === moveFromRight( item, config ) === | + | |
- | Function to call to move item from right to left inventory. If undefined, the built-in implementation will be used. | + | |
- | * Type: Function | + | |
- | * Returns: Void | + | |
- | * //item//: The item which we are checking whether or not we should show. | + | |
- | * //config//: The config object that was passed to InventoryIU.render(). | + | |
- | * Default: the builtin implementation is used if none is defined in the config object | + | |
- | * Optional | + | |
- | + | ||
- | === leftTitle === | + | |
- | Override the left title. | + | |
- | * Type: String | Function(config) returning String | + | |
- | * Default: if the left inventory is a Person then " | + | |
- | * Optional | + | |
- | + | ||
- | === rightTitle === | + | |
- | Override the right title. | + | |
- | * Type: String | Function(config) returning String | + | |
- | * Default: if the right inventory is a Person then " | + | |
- | * Optional | + | |
- | + | ||
- | === leftName( item, config ) === | + | |
- | Override the left label for item. | + | |
- | * Type: Function | + | |
- | * Returns: String | + | |
- | * //item//: The item which we are checking whether or not we should show. | + | |
- | * //config//: The config object that was passed to InventoryIU.render(). | + | |
- | * Default: the item's AName | + | |
- | * Optional | + | |
- | === rightName( item, config ) === | + | * **Type: |
- | Override the right label for item. | + | |
- | | + | |
- | | + | |
- | | + | |
- | * //config//: The config object that was passed to InventoryIU.render(). | + | |
- | * Default: the item's AName | + | |
- | * Optional | + | |
- | === outerTpl | + | ==== .toString() ==== |
- | Override the builtin outer HTML template. | + | Overridden. |
- | * Type: String | Function(config) returning String | + | |
- | * Default: undefined | + | |
- | * Optional | + | |
- | === listitemTplLeft === | + | * **Type:** Function |
- | Override the builtin left list item HTML template. | + | * **Arguments:** None |
- | | + | * **Returns: |
- | * Default: undefined | + | * **Throws:** Nothing |
- | * Optional | + | |
- | === listitemTplRight | + | ==== .theString() ==== |
- | Override the builtin right list item HTML template. | + | Description. |
- | * Type: String | Function(config) returning String | + | |
- | * Default: undefined | + | |
- | * Optional | + | |
- | === detailsTpl === | + | * **Type:** Function |
- | Override the builtin item details HTML template. | + | * **Arguments:** None |
- | | + | * **Returns: |
- | * Default: undefined | + | * **Throws:** Nothing |
- | * Optional | + | |