This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
libecho:classes:util [2022/05/20 19:12] – created lee | libecho:classes:util [2023/08/06 18:54] (current) – removed lee | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== LibEcho.Util ====== | ||
- | |||
- | Miscellaneous internal utility functions that don't seem to fit anywhere else. You probably won't every need to use any of these, except maybe String.capitalize(). | ||
- | |||
- | ===== Array Prototypes ===== | ||
- | |||
- | ==== Array.prototype.commaList() ==== | ||
- | |||
- | Assuming that it is an array of strings, returns a proper serial-comma-separated description of the list including " | ||
- | |||
- | [ "a two-dollar pistol", | ||
- | |||
- | [ "a two-dollar pistol", | ||
- | |||
- | [ "a two-dollar pistol" | ||
- | |||
- | [].commaList() returns " | ||
- | |||
- | ==== Array.prototype.aList ==== | ||
- | |||
- | Assuming an array of PersistentObjects (or subclasses), | ||
- | |||
- | ==== Array.prototype.theList ==== | ||
- | |||
- | Assuming an array of PersistentObjects (or subclasses), | ||
- | |||
- | ===== LibEcho.Util.log( logName, message ) ===== | ||
- | |||
- | If Sugarcube has been put in debug mode (Config.debug = true), logs the given logName and message to the JS console. | ||
- | |||
- | ===== LibEcho.Util.MessageQueue ===== | ||
- | |||
- | A global message queue system to allow the story author to more easily hook into the Inventory and Apparel UIs and display various flavor texts and do other processing while a player is fooling around with Inventory and Apparel. | ||
- | |||
- | Not fully implemented. | ||
- | |||
- | FIXME | ||
- | |||
- | ===== String Prototypes ===== | ||
- | |||
- | ==== String.prototype.capitalize() ==== | ||
- | |||
- | Returns the string with the first character capitalized. | ||
- | |||
- | FIXME: This doesn' | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | * Inherits from: PersistentObject | ||
- | |||
- | FIXME todo once the code is refactored. | ||
- | |||
- | ==== 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 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, | ||
- | 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. | ||
- | |||
- | ===== LibEcho.Inventory.InventoryUI ===== | ||
- | |||
- | * Inherits from: Nothing | ||
- | |||
- | FIXME todo once the code is refactored. | ||
- | |||
- | ==== Properties ==== | ||
- | |||
- | === .someProp === | ||
- | Desc | ||
- | * Type: type | ||
- | * Required Optional | ||
- | |||