Echo Hollow

Gender-Bending Interactive Stories! :D

User Tools

Site Tools


libecho:classes:util

Differences

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

Link to this comparison view

Next revision
Previous revision
libecho:classes:util [2022/05/20 19:12] – created leelibecho: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 "and", or "nothing" if the list is empty. 
- 
-[ "a two-dollar pistol", "a Stetson hat", "a shotgun" ].commaList() returns "a two-dollar pistol, a Stetson hat, and a shotgun". 
- 
-[ "a two-dollar pistol", "a Stetson hat" ].commaList() returns "a two-dollar pistol and a Stetson hat". 
- 
-[ "a two-dollar pistol" ].commaList() returns "a two-dollar pistol". 
- 
-[].commaList() returns "nothing". 
- 
-==== Array.prototype.aList ====  
- 
-Assuming an array of PersistentObjects (or subclasses), returns a serial-comma-separated description like .commaList(), but using those objects' .aName fields. 
- 
-==== Array.prototype.theList ====  
- 
-Assuming an array of PersistentObjects (or subclasses), returns a serial-comma-separated description like .commaList(), but using those objects' .theName fields. 
- 
-===== 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.  If Sugarcube is not in debug mode, it does nothing. 
- 
-===== 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.  May change as we rejigger the UIs. 
- 
-FIXME 
- 
-===== String Prototypes ===== 
- 
-==== String.prototype.capitalize() ==== 
- 
-Returns the string with the first character capitalized. 
- 
-FIXME: This doesn't work if the first character is a quotation mark or other punctuation, or a number. Does it need to? 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
- 
-  * 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.  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 ===== 
- 
-  * Inherits from: Nothing 
- 
-FIXME todo once the code is refactored. 
- 
-==== Properties ==== 
- 
-=== .someProp === 
-Desc 
-  * Type: type 
-  * Required Optional 
- 
  
libecho/classes/util.1653099125.txt.gz · Last modified: 2022/05/20 19:12 by lee