Class Index | File Index

Classes


Class com.jiffeegames.Traits

A Traits object manages the state of the game, all of which is stored in noun/trait/value slots in a master table. Rules about set/change/get:

The Traits object needs to know about the Encoding and Scheduler objects so that it can notify them whenever the value of a slot changes.
Defined in: jiffee-traits.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Create a Traits object.
Method Summary
Method Attributes Method Name and Description
 
addArb(trait)
Add an "arbitrary" trait to the game.
 
addEnum(trait, values)
Add an "enumeration" trait to the game.
 
addNoun(noun)
Create a noun with the given name.
 
addRange(trait, max)
Add a "range" trait to the game.
 
addRef(trait)
Add a "reference" trait to the game.
<private>  
addSlot_(noun, trait)
Create a new Slot object.
<private>  
For each slot that has been created, add a corresponding variable to the Encoding object and associate the variable number with the slot.
<private>  
arrDex_(arr, value)
Find the index of a value in an Array.
<private>  
asInt_(trait, value)
Convert a trait value to the corresponding integer.
 
findNouns(trait, value)
Find the set of all nouns with a given trait/value pair.
 
freeze(noun, trait, value)
Set the value of a slot.
 
get(noun, trait)
Get the value of a slot.
 
Find the set of all things.
 
Return the current change sequence number.
 
Retrieve the values of all changeable slots from the encoding, discarding the current slot values.
 
init(locate, language)
 
isNoun(name)
Check whether a noun with the given name exists.
 
isTrait(name)
Check whether a trait with the given name exists.
 
set(noun, trait, value)
Set the value of a slot.
 
Set the game State to "started".
<private>  
Make a sure a new name is legal for a noun or a trait.
Class Detail
com.jiffeegames.Traits()
Create a Traits object. The normal call is
var traits = new com.jiffeegames.Traits();
Requires:
com.jiffeegames.Checks
Method Detail
{void} addArb(trait)
Add an "arbitrary" trait to the game. The values of this trait are unrestricted (may be of arbitrary type), but can only be set with "freeze()", never with "set()".
Parameters:
{String} trait
The name of the trait.

{void} addEnum(trait, values)
Add an "enumeration" trait to the game. The values of this trait are restricted to the specified (enumerated) values. Example:
traits.addEnum('precipitation', 'none', 'rain', 'sleet', 'snow', 'fog');
Parameters:
{String} trait
The name of the trait.
{anytype} values
A list of the possible values

{void} addNoun(noun)
Create a noun with the given name.
Parameters:
{String} noun
The name to use.

{void} addRange(trait, max)
Add a "range" trait to the game. The values of this trait are restricted to integers between [0 ... max].
Parameters:
{String} trait
The name of the trait.
{integer} max
The maximum allowed value (the minimum is always zero).

{void} addRef(trait)
Add a "reference" trait to the game. The values of this trait are restricted to the names of nouns.
Parameters:
{String} trait
The name of the trait.

<private> {Object} addSlot_(noun, trait)
Create a new Slot object. The real work is just to do error-checking on the names.
Parameters:
{String} noun
The name of the noun.
{String} trait
The name of the trait.
Returns:
The Slot object created.

<private> {void} addVarsToEncoding_()
For each slot that has been created, add a corresponding variable to the Encoding object and associate the variable number with the slot.

<private> {integer} arrDex_(arr, value)
Find the index of a value in an Array.
Parameters:
{Array} arr
The Array to be searched.
value
The value to be searched for.
Returns:
The index within the Array, or undefined if "val" does not appear.

<private> {integer} asInt_(trait, value)
Convert a trait value to the corresponding integer.
Parameters:
{String} trait
The name of the trait.
value
The value to be converted.
Returns:
The integer equivalent (which is what gets encoded into the cookie).

{HashTable_of_NounNames} findNouns(trait, value)
Find the set of all nouns with a given trait/value pair.
Parameters:
{String} trait
The name of the trait.
value
The value you are looking for.
Returns:
A hash table of all the nouns which have what you're looking for.

{void} freeze(noun, trait, value)
Set the value of a slot. Using this method freezes the value of the slot for all time.
Parameters:
{String} noun
The name of the noun.
{String} trait
The name of the trait.
value
The value of the slot.

{Any} get(noun, trait)
Get the value of a slot.
Parameters:
{String} noun
The name of the noun.
{String} trait
The name of the trait.
Returns:
The value of that slot.

getAllThings()
Find the set of all things. Example call:
var thingList = things.getAllThings();
Returns:
A list of all the thing names.

{int} getSeq()
Return the current change sequence number.

{void} getVarsFromEncoding()
Retrieve the values of all changeable slots from the encoding, discarding the current slot values. Do not notify the Scheduler of the changes, because this is done only to implement a "restore" or "restart".

init(locate, language)
Parameters:
locate
language

{boolean} isNoun(name)
Check whether a noun with the given name exists.
Parameters:
{String} name
The name to check.
Returns:
true if the noun exists, else false.

{boolean} isTrait(name)
Check whether a trait with the given name exists.
Parameters:
{String} name
The name to check.
Returns:
true if the trait exists, else false.

{void} set(noun, trait, value)
Set the value of a slot. Using this method allows the value of the slot to change throughout the course of the game (unless the trait is Arbitrary, in which case set() actually calls freeze().
Parameters:
{String} noun
The name of the noun.
{String} trait
The name of the trait.
value
The value of the slot.

{void} start()
Set the game State to "started". This means that "freeze()" is no longer legal.

<private> {void} validateName_(str)
Make a sure a new name is legal for a noun or a trait.
Parameters:
{String} str
The name to be checked.
Throws:
Error if the name is not legal

Documentation generated by JsDoc Toolkit 2.3.2 on Sun Jul 25 2010 13:49:31 GMT-0700 (PDT)