TSTK Reference: Common Utilities

From RGWiki

Jump to: navigation, search

Contents

TSTK Reference: common - utilities

actionmap.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/actionmap.cs.

ActionMap::bindMulti( %this, %device, %action, %object, %callback )

Description: Bind a specified %callback on a specified %object such that it is called whenever %device + %action occurs.
This is different from normal binds in that multiple objects and/or callbacks can be bound to the same %device + %action.
Note: If %object is 0 or "", then %callback is treated as a plain function.

Top

ActionMap::unbindMulti( %this, %device, %action, %object, %callback )

Description: Unbind a specified %callback on a specified %object which was previously bound to %device + %action.
EFM - Not yet implemented.

Top

createMultiBinder( %bindEventFunction, %objID, %callbackName )

Description: Internal only. Creates a special 'multiBinder' object used to create multi-binding routers.

Top

createMultiBindRouter( %objID, %callbackName )

Description: Internal only. Used to connect input events to multiple object->callbacks and/or functions.

Top

multiBindRouter::executeCallback( %this, %val )

Description: Internal only. Execute the callback specified for this router and pass in the input actoin %val.

Top

multiBinder::executeCallbacks(%this, %bindEventFunction, %val )

Description: Internal only. Execute all callbacks associated with the specific binding event.

Top

ArrayObject.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/ArrayObject.cs.

createArrayObject( %name )

Description: Create new array object with optionally specified %name.

Top

arrayObject::onAdd( %this )

Description: Internal only. Callback that initializes all array objects.

Top

arrayObject::addEntry( %this , %entry )

Description: Add new %entry to this array object.

Top

arrayObject::getCount( %this )

Description: Get number of entries in array object.

Top

arrayObject::sort( %this , %Decreasing )

Description: Sort the entries in array object. By default this sort is in increasing order, but by specifying true in the %Decreasing (second) argument, the direction can be changed.

Top

arrayObject::getEntry( %this , %index )

Description: Return entry in array object at specified %index.

Top

Fields.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/Fields.cs.

swapFields( %fields, %first, %second )

Description: Locate fields %first and %second and swap their position in %fields.

Top

randomizeFields( %fields , %iterations )

Description: Randomize the locations of fields with the field list %fields. (Optionally specify the number of %iterations to use while sorting.)

Top

sortFields( %fields , %descending )

Description: Sort list of %fields (optionally sort in descending order).

Top

isUniqueField( %fields , %newField )

Description: Return true if %newField does not exist in the list of %fields.

Top

addUniqueField( %fields , %newField )

Description: Add %newField to list %fields if %newField does not already exist in list.

Top

replaceField( %fields , %oldField, %newField )

Description: Find %oldField in list %fields and replace it with %newField.

Top

addField( %fields, %newField )

Description: Add %newField to (end of) list %fields.

Top

removeNamedField( %fields , %oldField , %firstOnly )

Description: Locate all instances of %oldField from list %fields. Optionally specify that only the first instance (starting at position 0) of %oldField be removed.

Top

pushFieldFront( %fields , %newField )

Description: Add %newField to list %fields, in position 0.

Top

pushFieldBack( %fields , %newField )

Description: Add %newField to list %fields, in position 'fieldCount'.

Top

popFieldFront( %fields )

Description: Remove field 0 from list %fields and return the resultant list.

Top

popFieldBack( %fields )

Description: Remove field 'fieldcount-1' from list %fields and return the resultant list.

Top

File.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/File.cs.

readFile( %fileName )

Description: Read the entire contents of file %fileName and return as a string.
WARNING: Will crash engine for files containing more than about 4K characters.

Top

writeFile( %fileName , %data )

Description: Write the contents of %string into %fileName.

Top

appendToFile( %fileName , %data )

Description: Append the contents of %string to %fileName.

Top

getFileList( %pattern ) {

Description: Return space-separated list of paths to all files matching %pattern.

Top

findStringInFile( %fileName , %string )

Description: Search contents of file %fileName for %string and return true if found, false otherwise.

Top

extractFileSegment( %fileName, %startKey, %endKey )

Description: Return all content in file %fileName between delimiters %startKey and %endKey.
If not found, %startKey defaults to begining of file and %endKey defaults to end of file.

Top

extractFileLinesContaining( %fileName, %searchKey )

Description: Return newline-separated list all lines in file containing %searchKey.
WARNING: Will crash engine for cumulative lines greater than about 4K characters.

Top

openFileForRead( %fileName )

Description: Open a file for reading and return the handle to that file (or 0 for failure)

Top

closeFileHandle( %handle )

Description: Close file specified by %handle.

Top

getNextFileLineInSegment( %handle, %startKey, %endKey )

Description: Search previously opened file specified by %handle and return all contents delimiters %startKey and %endKey.
If not found, %startKey defaults to begining of file and %endKey defaults to end of file.
WARNING: Will still crash engine for cumulative segments greater than about 4K characters.

Top

getNextFileLineContaining( %handle, %searchKey )

Description: Search previously opened file specified by %handle and return next line containing %searchKey string.

Top


GUI.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/GUI.cs.

GuiMLTextCtrl::fillFromFile( %theControl , %textFile , %clear ) {

Description: Dump the contents of file %testFile into GUIMLTextCtrl %theControl.
(Optionally %clear the control before dumping file contents into it.)

Top

Math.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/Math.cs.

checkPointInBox( %point , %box , %scale )

Return true if point "x y" is in the 2D box specified by %box ("ulx uly lrx lry").
(Optionally scale the %box before doing the comparison.)
//EFM - move to TGB section

Top

angleToVector( %angle )

Description: Convert %angle to an x-y vector.

Top

vectorToAngle( %vector )

Description: Convert x-y vector into a angle.
//EFM - move to TGB section

Top

inv( %val )

Description: Invert %value.
FOR CONSOLE: Since you can't type ~

Top

calculateCentroid( %pointList )

Description: Calculate the centroid based on a list containing one or more x-y-z points.
WARNING!!! N >= 4 REQUIRES TRAVERSAL OF CONSECUTIVE EDGES, WILL FAIL FOR RANDOM TRAVERSALS
Based on algorithm found here: http://www.saltspring.com/brochmann/math/centroid/centroid.html

Top

RotateVectorOnZ(%Vec,%angle)

Description: Rotate x-y-z vector by %angle degrees about Z-axis.
Provided by Ryan M. of the GarageGames.com community.

Top

RotateVectorOnY(%Vec,%angle)

Description: Rotate x-y-z vector by %angle degrees about Y-axis.
Provided by Ryan M. of the GarageGames.com community.

Top

RotateVectorOnX(%Vec,%angle)

Description: Rotate x-y-z vector by %angle degrees about X-axis.
Provided by Ryan M. of the GarageGames.com community.

Top

getUniqueNumber()

Description: Return a guaranteed unique number.

Top

resetUniqueNumbers()

Description: Reset the unique number 'generator'.

Top

Objects.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/Objects.cs.

getAllDatablocksByClassName( %className )

Description: Search the engine created SimGroup datablockGroup for all datablocks of a specified class and return them in a SimSet.

Top

findFirstInstanceByClassName( %className )

Description: Search the SimGroups rootGroup, missionGroup, and missionCleanup for the first object created with class %className and return that object.

Top

findAllByClassName( %set, %searchSet , %className )

Description: Search the %searchSet for all objects created with class %className and return them in a SimSet.

Top

findAllByFieldValue( %set, %searchSet , %fieldName, %fieldValue )

Description: Search the %searchSet for all objects containing a field %fieldName, set to the value %fieldValue and return them in a SimSet.

Top

safelyDelete( %object )

Description: Safely delete an object by defering that delete till the next free sim cycle. This insures the object won't be in use by the scripting engine when it is deleted.

Top

Records.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/Records.cs.

swapRecords( %records, %first, %second )

Description: Locate records %first and %second and swap their position in %records.

Top

randomizeRecords( %records , %iterations )

Description: Randomize the locations of records with the record list %records. (Optionally specify the number of %iterations to use while sorting.)

Top

sortRecords( %records , %descending )

Description: Sort list of %records (optionally sort in descending order).

Top

isUniqueRecord( %records , %newRecord )

Description: Return true if %newRecord does not exist in the list of %records.

Top

addUniqueRecord( %records , %newRecord )

Description: Add %newRecord to list %records if %newRecord does not already exist in list.

Top

replaceRecord( %records , %oldRecord, %newRecord )

Description: Find %oldRecord in list %records and replace it with %newRecord.

Top

addRecord( %records, %newRecord )

Description: Add %newRecord to (end of) list %records.

Top

removeNamedRecord( %records , %oldRecord , %firstOnly )

Description: Locate all instances of %oldRecord from list %records. Optionally specify that only the first instance (starting at position 0) of %oldRecord be removed.

Top

pushRecordFront( %records , %newRecord )

Description: Add %newRecord to list %records, in position 0.

Top

pushRecordBack( %records , %newRecord )

Description: Add %newRecord to list %records, in position 'recordCount'.

Top

popRecordFront( %records )

Description: Remove record 0 from list %records and return the resultant list.

Top

popRecordBack( %records )

Description: Remove record 'recordcount-1' from list %records and return the resultant list.

Top

SimSet.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/SimSet.cs.

SimSet::forEach( %theSet, %function, %isMethod, %printEval)

Description:
For each object in 'theSet', %function is executed in one of two ways:
%isMethod == false => function(%obj); // executed as function, %obj is passed manually
%isMethod == true => %obj.function(); // executed as method, %obj is passed automatically
If you are having trouble using this utility, enable %printEval by setting it to true
and check your results. You may have a typo and it should show up here.

Top

SimSet::forEachStmt( %theSet, %statement, %token, %printEval)

Description:
This is very like the above forEach, except a string is passed to this method
specifying tokens (passed as %token) where the ID of the current object should be
inserted in place of the token. The resultant string is then executed like a flat
statement.
If you are having trouble using this utility, enable %printEval by setting it to true
and check your results. You may have a typo and it should show up here.
Usage:
$x.forEachStmt("echo( tok.getID() );", tok );

Top

SimSet::deleteSet( %theSet, %selfDestruct)

Description: Delete every object in %theSet. (Optionally delete %theSet if %selfDestruct is set to true.)

Top

SimSet::copyToSet( %theSet, %destSet )

Description: Copy all entries from the calling %theSet into %destSet.

Top

SimSet::getRandomObject( %theSet )

Description: Returns a random entry from the %theSet.
Note: Does not modify the order of the calling set.

Top

SimSet::sort( %theSet , %fieldName , %Decreasing )

Description: Sort the objects in %theSet based on the values in each object's field, where %fieldName is the name of the field to look in.
Sort in ascending (increasing) order by default.
Warning: Uses proxy object of class GuiTextListCtrl to do work.

Top

Strings.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/Strings.cs.

strContains( %string, %subStr )

Description: Return true if %string contains %subStr. (Case insensitve).

Top

removeAlpha( %string )

Description: Remove all letters from %string and return the resulting string.

Top

removeNumeric( %string )

Description: Remove all numbers from %string and return the resulting string.

Top

removeWhiteSpace( %string )

Description: Remove all white space (spaces, tabs, and newlines) from %string and return the resulting string.

Top

getSubStrMarker( %string, %startMarker, %endMarker )

Description: Search %string for a substring delimited by %startMarker and %endMarker.
Does not return markers as part of result.
If %startMarker is found, but %endMarker is not found, returns all data after %startMarker.
If %startMarker is no found, but %endMarker is found , returns all data from beginning of string to character before %endMarker.

Top

Words.cs

The following section documents all of the functions found in the file: TSTK/common/utilities/Words.cs.

swapWords( %words, %first, %second )

Description: Locate words %first and %second and swap their position in %words.

Top

randomizeWords( %words , %iterations )

Description: Randomize the locations of words with the word list %words. (Optionally specify the number of %iterations to use while sorting.)

Top

sortWords( %words , %descending )

Description: Sort list of %words (optionally sort in descending order).

Top

isUniqueWord( %words , %newWord )

Description: Return true if %newWord does not exist in the list of %words.

Top

addUniqueWord( %words , %newWord )

Description: Add %newWord to list %words if %newWord does not already exist in list.

Top

replaceWord( %words , %oldWord, %newWord )

Description: Find %oldWord in list %words and replace it with %newWord.

Top

addWord( %words, %newWord )

Description: Add %newWord to (end of) list %words.

Top

removeNamedWord( %words , %oldWord , %firstOnly )

Description: Locate all instances of %oldWord from list %words. Optionally specify that only the first instance (starting at position 0) of %oldWord be removed.

Top

pushWordFront( %words , %newWord )

Description: Add %newWord to list %words, in position 0.

Top

pushWordBack( %words , %newWord )

Description: Add %newWord to list %words, in position 'wordCount'.

Top

popWordFront( %words )

Description: Remove word 0 from list %words and return the resultant list.

Top

popWordBack( %words )

Description: Remove word 'wordcount-1' from list %words and return the resultant list.

Top

Personal tools