Академический Документы
Профессиональный Документы
Культура Документы
//------------------------------------------------------------------------------
// Check if a script file exists, compiled or not.
function isScriptFile(%path)
{
if( isFile(%path @ ".dso") || isFile(%path) )
return true;
return false;
}
function loadMaterials()
{
// Load any materials files for which we only have DSOs.
for( %file = findFirstFile( "*/materials.cs.dso" );
%file !$= "";
%file = findNextFile( "*/materials.cs.dso" ))
{
// Only execute, if we don't have the source file.
%csFileName = getSubStr( %file, 0, strlen( %file ) - 4 );
if( !isFile( %csFileName ) )
exec( %csFileName );
}
// Load all source material files.
for( %file = findFirstFile( "*/materials.cs" );
%file !$= "";
%file = findNextFile( "*/materials.cs" ))
{
exec( %file );
}
// Load all materials created by the material editor if
// the folder exists
if( IsDirectory( "materialEditor" ) )
{
for( %file = findFirstFile( "materialEditor/*.cs.dso" );
%file !$= "";
%file = findNextFile( "materialEditor/*.cs.dso" ))
{
// Only execute, if we don't have the source file.
%csFileName = getSubStr( %file, 0, strlen( %file ) - 4 );
if( !isFile( %csFileName ) )
exec( %csFileName );
}
for( %file = findFirstFile( "materialEditor/*.cs" );
%file !$= "";
%file = findNextFile( "materialEditor/*.cs" ))
{
exec( %file );
}
}
}
function reloadMaterials()
{
reloadTextures();
loadMaterials();
reInitMaterials();
}
function loadDatablockFiles( %datablockFiles, %recurse )
{
if ( %recurse )
{
recursiveLoadDatablockFiles( %datablockFiles, 9999 );
return;
}
%count = %datablockFiles.count();
for ( %i=0; %i < %count; %i++ )
{
%file = %datablockFiles.getKey( %i );
if ( !isFile(%file @ ".dso") && !isFile(%file) )
continue;
exec( %file );
}
//------------------------------------------------------------------------------
// An Aggregate Control is a plain GuiControl that contains other controls,
// which all share a single job or represent a single value.
//------------------------------------------------------------------------------
// AggregateControl.setValue( ) propagates the value to any control that has an
// internal name.
function AggregateControl::setValue(%this, %val, %child)
{
for(%i = 0; %i < %this.getCount(); %i++)
{
%obj = %this.getObject(%i);
if( %obj == %child )
continue;
if(%obj.internalName !$= "")
setValueSafe(%obj, %val);
}
}
// AggregateControl.getValue() uses the value of the first control that has an
// internal name, if it has not cached a value via .setValue
function AggregateControl::getValue(%this)
{
for(%i = 0; %i < %this.getCount(); %i++)
{
%obj = %this.getObject(%i);
if(%obj.internalName !$= "")
{
//error("obj = " @ %obj.getId() @ ", " @ %obj.getName() @ ", " @ %obj.i
nternalName );
//error(" value = " @ %obj.getValue());
return %obj.getValue();
}
}
}
// AggregateControl.updateFromChild( ) is called by child controls to propagate
// a new value, and to trigger the onAction() callback.
function AggregateControl::updateFromChild(%this, %child)
{
%val = %child.getValue();
if(%val == mCeil(%val)){
%val = mCeil(%val);
}else{
if ( %val <= -100){
%val = mCeil(%val);
}else if ( %val <= -10){
%val = mFloatLength(%val, 1);
}else if ( %val < 0){
%val = mFloatLength(%val, 2);
}else if ( %val >= 1000){
%val = mCeil(%val);
}else if ( %val >= 100){
%val = mFloatLength(%val, 1);
}else if ( %val >= 10){
%val = mFloatLength(%val, 2);
}else if ( %val > 0){
%val = mFloatLength(%val, 3);
}
}
%this.setValue(%val, %child);
%this.onAction();
}
// default onAction stub, here only to prevent console spam warnings.
function AggregateControl::onAction(%this)
{
}
// call a method on all children that have an internalName and that implement th
e method.
function AggregateControl::callMethod(%this, %method, %args)
{
for(%i = 0; %i < %this.getCount(); %i++)
{
%obj = %this.getObject(%i);
if(%obj.internalName !$= "" && %obj.isMethod(%method))
eval(%obj @ "." @ %method @ "( " @ %args @ " );");
}
}
//------------------------------------------------------------------------------
// Altered Version of TGB's QuickEditDropDownTextEditCtrl
//------------------------------------------------------------------------------
function QuickEditDropDownTextEditCtrl::onRenameItem( %this )
{
}
function QuickEditDropDownTextEditCtrl::updateFromChild( %this, %ctrl )
{
if( %ctrl.internalName $= "PopUpMenu" )
{
%this->TextEdit.setText( %ctrl.getText() );
}
else if ( %ctrl.internalName $= "TextEdit" )
{
%popup = %this->PopupMenu;
%popup.changeTextById( %popup.getSelected(), %ctrl.getText() );
%this.onRenameItem();
}
}
// Writes out all script functions to a file.
function writeOutFunctions()
{
new ConsoleLogger(logger, "scriptFunctions.txt", false);
dumpConsoleFunctions();
logger.delete();
}
// Writes out all script classes to a file.
function writeOutClasses()
{
new ConsoleLogger(logger, "scriptClasses.txt", false);
dumpConsoleClasses();
logger.delete();
}
//
function compileFiles(%pattern)
{
%path = filePath(%pattern);
%saveDSO = $Scripts::OverrideDSOPath;
%saveIgnore = $Scripts::ignoreDSOs;
$Scripts::OverrideDSOPath = %path;
$Scripts::ignoreDSOs = false;
%mainCsFile = makeFullPath("main.cs");
for (%file = findFirstFileMultiExpr(%pattern); %file !$= ""; %file = findNext
FileMultiExpr(%pattern))
{
// we don't want to try and compile the primary main.cs
if(%mainCsFile !$= %file)
compile(%file, true);
}
$Scripts::OverrideDSOPath = %saveDSO;
$Scripts::ignoreDSOs = %saveIgnore;
}
function displayHelp()
{
// Notes on logmode: console logging is written to console.log.
// -log 0 disables console logging.
// -log 1 appends to existing logfile; it also closes the file
// (flushing the write buffer) after every write.
// -log 2 overwrites any existing logfile; it also only closes
// the logfile when the application shuts down. (default)
error(
"Torque Demo command line options:\n"@
" -log <logmode> Logging behavior; see main.cs comments for detai
ls\n"@
" -game <game_name> Reset list of mods to only contain <game_name>\n
"@
" <game_name> Works like the -game argument\n"@
" -dir <dir_name> Add <dir_name> to list of directories\n"@
" -console Open a separate console\n"@
" -jSave <file_name> Record a journal\n"@
" -jPlay <file_name> Play back a journal\n"@
" -help Display this help message\n"
);
}
// Execute startup scripts for each mod, starting at base and working up
function loadDir(%dir)
{
pushback($userDirs, %dir, ";");
if (isScriptFile(%dir @ "/main.cs"))
exec(%dir @ "/main.cs");
}
function loadDirs(%dirPath)
{
%dirPath = nextToken(%dirPath, token, ";");
if (%dirPath !$= "")
loadDirs(%dirPath);
if(exec(%token @ "/main.cs") != true)
{
error("Error: Unable to find specified directory: " @ %token );
$dirCount--;
}
}
//------------------------------------------------------------------------------
// Utility remap functions:
//------------------------------------------------------------------------------
function ActionMap::copyBind( %this, %otherMap, %command )
{
if ( !isObject( %otherMap ) )
{
error( "ActionMap::copyBind - \"" @ %otherMap @ "\" is not an object!" );
return;
}
%bind = %otherMap.getBinding( %command );
if ( %bind !$= "" )
{
%device = getField( %bind, 0 );
%action = getField( %bind, 1 );
%flags = %otherMap.isInverted( %device, %action ) ? "SDI" : "SD";
%deadZone = %otherMap.getDeadZone( %device, %action );
%scale = %otherMap.getScale( %device, %action );
%this.bind( %device, %action, %flags, %deadZone, %scale, %command );
}
}
//------------------------------------------------------------------------------
function ActionMap::blockBind( %this, %otherMap, %command )
{
if ( !isObject( %otherMap ) )
{
error( "ActionMap::blockBind - \"" @ %otherMap @ "\" is not an object!" );
return;
}
%bind = %otherMap.getBinding( %command );
if ( %bind !$= "" )
%this.bind( getField( %bind, 0 ), getField( %bind, 1 ), "" );
}
//Dev helpers
/// Shortcut for typing dbgSetParameters with the default values torsion uses.
function dbgTorsion()
{
dbgSetParameters( 6060, "password", false );
}
/// Reset the input state to a default of all-keys-up.
/// A helpful remedy for when Torque misses a button up event do to your breakpo
ints
/// and can't stop shooting / jumping / strafing.
function mvReset()
{
for ( %i = 0; %i < 6; %i++ )
setVariable( "mvTriggerCount" @ %i, 0 );
$mvUpAction = 0;
$mvDownAction = 0;
$mvLeftAction = 0;
$mvRightAction = 0;