Namespace: utils

rat. utils

Util functions necessary for loading rat
Source:

Methods

(static) addProp(obj, name, setter, getter, opsopt) → {Object}

Util function to add props to an object
Parameters:
Name Type Attributes Description
obj Object
name string
setter ?
getter ?
ops Object <optional>
Source:
Returns:
obj
Type
Object

(static) allScriptsAreLoaded() → {bool}

returns true if all queued up script loads are done
Source:
Returns:
loaded
Type
bool

(static) cleanPath()

Clean up a path name. collapse ../ references and ./ references and fix slashes. Note that we can only collapse ../ references if there's a path above that in the string. Also, if a ../ reference comes before another ../ reference, we can't do much about it. So, we clean up from left to right as much as we can, but we can't guarantee no ../ when we're done. Returns cleaned path.
Source:

(static) copyObject(o, deepopt) → {Object}

copy this object useful if you don't want a reference. Do the recursion and array support here work?
Parameters:
Name Type Attributes Description
o Object Object to copy
deep boolean <optional>
perform a deep copy (recursive) (default is false)
Source:
Returns:
newO new Object
Type
Object

(static) deepSet()

Util to find all properties of a certain name, set them all to a certain value. recursively.
Source:

(static) dumpException()

Format an exception for output to the log
Source:

(static) dynamicLoadCompleteCallback(filename)

callback when a script is loaded
Parameters:
Name Type Description
filename string
Source:

(static) encodeID()

utility to encode a number into a shorter alphanumeric ID
Source:

(static) extendClassWith(childClass, parentClass)

Extend a class with another class (sorta-multi inheritance)
Parameters:
Name Type Description
childClass Object
parentClass Object
Source:

(static) extendObject(dest, sources, deepCopyopt) → {Object}

Extend one object with another data (possibly doing a deep copy of that data
Parameters:
Name Type Attributes Description
dest Object
sources Object
deepCopy boolean <optional>
(default is false)
Source:
Returns:
dest
Type
Object

(static) get(obj, path) → {?}

get a deep value in an object, returning undefined if the desired path doesn't match the object
Parameters:
Name Type Description
obj Object
path string
Source:
Returns:
value deep value in object
Type
?

(static) getPath()

Grab just the path from a filename
Source:

(static) getResource(filename, completeCallback, fileType)

generic function that will go out and get a file of any type it does use the script system callback to make sure all file loads are complete
Parameters:
Name Type Description
filename string
completeCallback function
fileType string
Source:

(static) getWindowSize() → {Object}

get current browser window size this is usually what we want - just usable space, not including things like menu bar or chrome debugger panel
Source:
Returns:
windowSize (w, h | x, y)
Type
Object

(static) inheritClassFrom(childClass, parentClass) → {Object}

general inheritance support Usage: declare constructor for class A then declare constructor for class B then AFTER B constructor function, do this: (function(){ Rat.inheritClassFrom(B,A); })(); Also recommended: In B constructor, call B.prototype.parentConstructor.call(this);
Parameters:
Name Type Description
childClass Object
parentClass Object
Source:
Returns:
childClass
Type
Object

(static) interpolate(a, b, i) → {number}

given an interpolation value from 0 to 1, find the appropriate blend of a and b
Parameters:
Name Type Description
a number
b number
i number [0.0, 1.0]
Source:
Returns:
interpolated_value [a, b]
Type
number

(static) interpolateClamped(a, b, i) → {number}

given an interpolation value from 0 to 1, find the appropriate blend of a and b and clamp to [0,1]
Parameters:
Name Type Description
a number
b number
i number [0.0, 1.0]
Source:
Returns:
interpolated_value [a, b]
Type
number

(static) interpolatePos(posA, posB) → {Object}

given an interpolation value from 0 to 1, find the appropriate point between A and B
Parameters:
Name Type Attributes Description
posA Object
posB Object
0.0, 1.0 number <optional>
Source:
Returns:
interpolated_position [posA, posB]
Type
Object

(static) launchSystemHelpUI(forUserID)

Launches Help UI
Parameters:
Name Type Description
forUserID
Source:

(static) limit(x, min, max) → {number}

limit to these values, inclusive
Parameters:
Name Type Description
x number
min number
max number
Source:
Returns:
x [min, max]
Type
number

(static) loadCSS()

Util to load CSS file (async?). You MUST specifiy an id for this element, since we use that to track if it's already loaded, and to support unloading. Won't load something already loaded. No callback system. You can query if it's loaded by using isCSSLoaded() below If you *really* want a callback, we could implement a timer system internally that does the query occasionally and eventually calls the callback.
Source:

(static) loadJSON(filename, completeCallback, stripComments)

load one JSON file with this callback on success This is the function clients should use, one at a time for desired JSON files. This is different from the above, I know. The thing is, each time we load a JSON file, it needs to get assigned to a variable, which implies the completion callback really needs to be unique per item... e.g. rat.utils.loadJSON("mydata.json", function(data) { myvar = data; });
Parameters:
Name Type Description
filename string
completeCallback function
stripComments boolean
Source:

(static) loadJSONObject(dname) → {Object}

util to load json file SYNCHRONOUSLY Generally, you should use loadJSONObjectAsync instead.
Parameters:
Name Type Description
dname string domain name
Source:
To Do:
  • refactor with function above - which is more correct?
Returns:
my_JSON_object
Type
Object

(static) loadJSONObjectAsync()

util to load json doc asynchronously Callback will be called with status (true if OK, false if error) and data object.
Source:

(static) loadResources(options)

Load in a list of resources (JS, JSON, XML(Not yet supported)), with a callback when they are all completed
Parameters:
Name Type Description
options ?
Source:

(static) loadResourcesSync(optionsopt)

Load in a series of files (or file sets) in a synchronous manner. This will load one set and then the next. This differs from rat.utils.loadResources in that each file (or file set) is downloaded and processed one at a time
Parameters:
Name Type Attributes Description
options Object <optional>
Source:

(static) loadScripts(scripts, clientCallbackopt, optionsopt)

Dynamic script loading support Note that for this to work in chrome locally, you might need to launch chrome with --allow-file-access-from-files. That won't be a problem for a version of the game hosted on line. This is the function you generally want to use: Pass in either a single filename or an array of files to load
Parameters:
Name Type Attributes Description
scripts string | Array.<string> the scripts to load
clientCallback function <optional>
options Object <optional>
{async = true}
Source:

(static) loadScriptWithCallback(errorCallback)

load one script with this callback (generally, you want to use loadResources() above)
Parameters:
Name Type Description
errorCallback ?
Source:

(static) loadXML(filename, completeCallback)

Loads an XML file
Parameters:
Name Type Description
filename string
completeCallback function
Source:

(static) loadXMLDoc(dname) → {Object}

util to load xml doc
Parameters:
Name Type Description
dname string the domain name
Source:
Returns:
responseXML The xml response from a get request
Type
Object

(static) makeID(len) → {string}

utility to make a random ID out of characters and numbers
Parameters:
Name Type Description
len length
Source:
Returns:
text
Type
string

(static) makeUniqueID()

Utility to make a unique player/system ID At least, we try pretty hard. Not guaranteed to be unique.
Source:

(static) objectToString(o, nameopt, addToStringopt, depthopt) → {string}

Write this object to a string. Is this useful? Consider using JSON utils instead!
Parameters:
Name Type Attributes Description
o Object
name string <optional>
addToString string <optional>
depth number <optional>
Source:
Returns:
addToString
Type
string

(static) randomInList(list, skip) → {?}

return random entry in this array (pick random) if a "skip" is provided, avoid that entry when picking a random entry. (skip can be an individual index, or an array of indices to skip, or not provided)
Parameters:
Name Type Description
list Array
skip Array | number
Source:
Returns:
list_item
Type
?

(static) randomInRange(min, max) → {number}

Get a random number between a certain range TODO: make sure these do what we want...
Parameters:
Name Type Description
min number
max number
Source:
Returns:
random_number
Type
number

(static) randomIntInRange(min, max) → {number}

Get a random whole number between a certain range limit to these values, inclusive
Parameters:
Name Type Description
min number
max number
Source:
Returns:
random_number
Type
number

(static) randomizeList(list) → {Array}

reorder this list randomly
Parameters:
Name Type Description
list Array
Source:
Returns:
list
Type
Array

(static) scriptIndex(filename) → {number}

return index of script in list to load, or -1 if not found
Parameters:
Name Type Description
filename string
Source:
Returns:
j
Type
number

(static) searchArrayFor() → {number}

Utility function to find an object in an array using a custom compare method
Source:
Returns:
index
Type
number

(static) set(obj, path, value)

set a deep value in an object, adding subobject structure if necessary
Parameters:
Name Type Description
obj Object
path string
value ? deep value in object to set
Source:

(static) stripPath()

Grab filename without path (strip path from filename)
Source:

(static) unloadCSS()

Unload a CSS file by id.
Source: