Echo Hollow

Gender-Bending Interactive Stories! :D

User Tools

Site Tools


libtf:documentation:api:inventory

This is an old revision of the document!


<-- Back

LibTF.Something

Inherits From: LibTF.PersistentObject

Blurb.

Fields

Inherited from LibTF.PersistentObject: someField, someOtherField

(SomeClass).someField

  • Access: access.
  • Type: type.

Description.

Methods

Inherited from LibTF.PersistentObject: someMethod(), someOtherMethod()

(SomeClass).someMethod( arg )

  • Arguments:
    • arg: a thing.
  • Returns: (Type) Details.
  • Throws: Error if: Stuff.

Description.

// Example code.

<-- Back

	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 )
	{
	}
libtf/documentation/api/inventory.1519583679.txt.gz ยท Last modified: 2018/02/25 10:34 by lee