Echo Hollow

Gender-Bending Interactive Stories! :D

User Tools

Site Tools


libtf:documentation:api: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
libtf:documentation:api:inventory [2018/02/25 10:33] leelibtf:documentation:api:inventory [2018/09/24 18:07] (current) – removed lee
Line 1: Line 1:
-[[libtf:documentation:api:start|<-- Back]] 
  
- 
-====== LibTF.Something====== 
- 
-**Inherits From:** [[SomeClass]] 
- 
-Blurb. 
- 
- 
-===== Fields ===== 
- 
-**Inherited from [[SomeClass]]:** someField, someOtherField 
- 
-==== (SomeClass).someField ==== 
- 
-  * **Access:** access. 
-  * **Type:** type. 
- 
-Description. 
- 
- 
-===== Methods ===== 
- 
-**Inherited from [[SomeClass]]:** someMethod(), someOtherMethod() 
- 
-==== (SomeClass).someMethod( arg ) ==== 
- 
-  * **Arguments:** 
-    * **//arg://** a thing. 
-  * **Returns:** (Type)  Details. 
-  * **Throws:** Error if: Stuff. 
- 
-Description. 
- 
-<code javascript> 
-// Example code. 
-</code> 
- 
- 
-[[libtf:documentation:api:start|<-- Back]] 
- 
- 
- 
- 
- 
-<code javascript> 
- add( itemOrId ) 
- { 
- var id = validateItemOrId( "add", itemOrId ); 
-  
- if( !this.has(id) ) 
- { 
- var pre = this.preAdd( id ); 
- if( pre != true && pre != false ) 
- doThrow( "add", "preAdd() did not return boolean!" ); 
- if( pre ) 
- { 
- var inventory = Persistence.get( this.id ) || []; 
- inventory.push( id ); 
- Persistence.set( this.id, inventory ); 
- this.postAdd( id ); 
- } 
- } 
- } 
-  
- remove( itemOrId ) 
- { 
- var id = validateItemOrId( "remove", itemOrId ); 
-  
- var pre = this.preRemove( id ); 
- if( pre != true && pre != false ) 
- doThrow( "remove", "preRemove() did not return boolean!" ); 
- if( pre ) 
- { 
- var inventory = Persistence.get( this.id ) || []; 
- var pos; 
- while( (pos=$.inArray(id,inventory)) >= 0 ) 
- inventory.splice(pos,1); 
- Persistence.set( this.id, inventory ); 
- this.postRemove( id ); 
- } 
- } 
-  
- has( itemOrId ) 
- { 
- var id = validateItemOrId( "has", itemOrId ); 
-  
- var inventory = Persistence.get( this.id ) || []; 
- return $.inArray(id,inventory) >= 0; 
- } 
-  
- get() 
- { 
- var inventory = Persistence.get( this.id ) || []; 
- let a = []; 
- for( let i=0; i<inventory.length; i++ ) 
- a.push( Persistence.instantiate(inventory[i]) ); 
- return a.sort( this.sort); 
- } 
-  
- getListString( examineLink = true ) 
- { 
- let l = []; 
- for( let a of this.get() ) 
- { 
- let examinePassage = "Examine."+a.id; 
- if( examineLink && Story.has(examinePassage) ) 
- l.push( "[["+a.aName+"->"+examinePassage+"]]" ); 
- else 
- l.push( a.aName ); 
- } 
- return Util.commaList( l ); 
- } 
-  
- sort( a, b ) 
- { 
- return a.name.toLowerCase().localeCompare( b.name.toLowerCase() ); 
- } 
-  
- preAdd( id ) 
- { 
- return true; 
- } 
-  
- postAdd( id ) 
- { 
- } 
-  
- preRemove( id ) 
- { 
- return true; 
- } 
-  
- postRemove( id ) 
- { 
- } 
-</code> 
libtf/documentation/api/inventory.1519583636.txt.gz · Last modified: 2018/02/25 10:33 by lee