Echo Hollow

Because Pr0n is the Highest Form of Art.

User Tools

Site Tools


libecho:classes:inventory

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
libecho:classes:inventory [2022/05/22 12:15] – [rightActioned] leelibecho:classes:inventory [2023/08/08 19:19] (current) – removed lee
Line 1: Line 1:
-====== LibEcho.Inventory ====== 
- 
-An Inventory is an object that contains other things.  It is used to track what items are in a container, or which items a Person carries.  A different specialized inventory is used to track what apparel a person is wearing (see LibEcho.Apparel). 
- 
-A trunk or bookshelf might use an inventory to track what is held within or upon 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. 
- 
-===== LibEcho.Apparel.GeneralInventory ===== 
- 
-  * Inherits from: PersistentObject 
- 
-GeneralInventory is the base Inventory implementation from which all other Inventory types are derived.  It provides default functionality which can be overridden in derived classes. 
- 
-==== Properties ==== 
- 
-=== .contents === 
-An array of the id fields of all the things (PersistentObjects and subclasses) contained in this inventory.  Duplicates are not allowed.  Order does not matter. 
- 
-  * 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 item will be added regardless of the result of the pre- functions. 
- 
-  * 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 item will be removed regardless of the result of the pre- functions. 
- 
-  * 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, filterFunction=undefined ) === 
-Returns the fully-instantiated contents of the Inventory. 
- 
-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. 
- 
-If a function is passed to filterFunction, that function will be called once for every item in the inventory.  If this function returns true, the item will be included in the returned array.  If the function returns false, the item will not be included. 
- 
-  * filterClass: an optional filter class. 
-  * filterFunction: an optional filter function. 
- 
-  * 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's contents' .aName fields. 
- 
-=== .theString() === 
-  * Returns: a serial-comma-separated-list of the inventory's contents' .theName fields. 
- 
-=== .sort( a, b ) === 
- 
-This is the function used by .get() to sort the inventory contents. 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 {@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 for more details).  You probably don't want to use this function directly unless you are extending LibEcho itself. 
- 
-==== The Configuration Object ==== 
- 
-The configuration object can contain a number of fields.  The values of some of these fields can be a literal or a function.  In the case of a function it is called with the listed arguments and the return value is used as the configuration value. 
- 
-For more information, see the InventoryUI Macro source code. 
- 
-=== 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 who is picking things up, or the inventory that things are being picked up and put into, but it can actually be any inventory or 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.  The InventoryUI macro uses this to evaluate the tweecode in the contents of the macro body when the InventoryUI dialog is closed. 
-  * Type: Function 
-  * Returns: Void 
-  * //config//: The config object that was passed to InventoryIU.render(). 
-  * Default: undefined 
-  * Optional 
- 
-=== allowClose( config ) === 
-If this function returns a String, that value will be printed in place of the "Done" link at the bottom of the inventory modal (preventing the modal from being closed).  This can be used to prevent the inventory from being able to be closed until certain items have been taken or dropped, for example.  If the return value is a falsy value, the regular "Done" link will be displayed, allowing the modal to be closed. 
-  * Type: Function 
-  * Returns: String 
-  * Default: undefined 
-  * Optional 
- 
-=== actor === 
-The Person interacting with the inventory. 
-  * 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: "Drop" 
-  * Optional 
- 
-=== leftActioned === 
-The left action success word.  "ObjectName: dropped." 
-  * Type: String | Function(config) returning String 
-  * Default: "dropped" 
-  * Optional 
- 
-=== rightAction === 
-The action label for moving item from right inventory. 
-  * Type: String | Function(config) returning String 
-  * Default: "Take" 
-  * Optional 
- 
-=== rightActioned === 
-The left action success word.  "ObjectName: taken." 
-  * Type: String | Function(config) returning String 
-  * Default: "taken" 
-  * Optional 
- 
-=== canShowOnLeft === 
-Called to check if the object will be displayed in left inventory at all. 
-  * Type: Boolean 
-  * Default: true 
-  * Optional 
- 
-=== canShowOnRight === 
-Called to check if the object will be displayed in right inventory at all. 
-  * Type: Boolean 
-  * Default: true 
-  * Optional 
- 
-=== canMoveFromLeft === 
-The item will be shown in the left inventory, but will we show the control to move it to the right inventory? 
-  * Type: Boolean 
-  * Default: true 
-  * Optional 
- 
-=== canMoveFromRight === 
-The item will be shown in the right inventory, but will we show the control to move it to the right inventory? 
-  * Type: Boolean 
-  * Default: true 
-  * Optional 
- 
-=== getSortCategory === 
-Return object category for the sort selector. 
-  * Type: String 
-  * Default: item.inventoryCategory | "Other" 
-  * Optional 
- 
-=== canShowLeftSelector === 
-Will the left selector be shown? 
-  * Type: Boolean 
-  * Default: true 
-  * Optional 
- 
-=== canShowRightSelector === 
-Will the right selector be shown? 
-  * Type: Boolean 
-  * Default: true 
-  * Optional 
- 
-=== moveFromLeft === 
-Function to call to move item from left to right inventory. If undefined, the built-in implementation will be used. 
-  * Type: Function (returning void) 
-  * Default: undefined 
-  * Optional 
- 
-=== moveFromRight === 
-Function to call to move item from right to left inventory. If undefined, the built-in implementation will be used. 
-  * Type: Function (returning void) 
-  * Default: undefined 
-  * Optional 
- 
-=== outerTpl === 
-Override the builtin outer HTML template. 
-  * Type: String 
-  * Default: undefined 
-  * Optional 
- 
-=== listitemTplLeft === 
-Override the builtin left list item HTML template. 
-  * Type: String 
-  * Default: undefined 
-  * Optional 
- 
-=== listitemTplRight === 
-Override the builtin right list item HTML template. 
-  * Type: String 
-  * Default: undefined 
-  * Optional 
- 
-=== leftTitle === 
-Override the left title. 
-  * Type: String 
-  * Default: undefined 
-  * Optional 
- 
-=== rightTitle === 
-Override the right title. 
-  * Type: String 
-  * Default: undefined 
-  * Optional 
  
libecho/classes/inventory.1653246909.txt.gz · Last modified: 2022/05/22 12:15 by lee