Torque3D/Templates/BaseGame/game/data/ExampleModule/ExampleModule.tscript
JeffR dff83182e2 Added sanity check to ensure that the requested file to be scaled via saveScaledImage actually exists
Shifts integration of other modules with the OptionsMenu so other modules can inject their own options categories to a callOnModules hook
Updated ExampleModule to use new options menu integration angle to show example option
Deleted unneeded dropdown_textEdit_image asset def from baseUI
Fixed incorrect internal values for the terrainIcon_image asset def that made it present as a redundant terrain material asset
Cleaned up old, bad loadFilters calls and replaced them with the proper refresh() calls.
Removed old, bad calls for jumping through the asset browser's tree from when it was still hardcoded organization, which cuts down a lot of error spam
Cleaned up some of the asset type's preview image assignment code to be more reliable
Made terrain materials now use a similar preview proxy shape as regular materials
Fixed erroneous duplicate GuiInspectorTypeShapeAssetPtr::onControlDropped, which was breaking drag-n-drop actions of shapeAssets into inspector fields
Added proper logic for drag-n-drop actions of imageAssets into inspector fields
Add sanity check after creating new asset to avoid redundant attempts at initialization of the new asset
Fixed ConvexShape Editor tooling so you can now use the UI to apply the selected material to the selected surface
Added tools menu to the menubar with the Project Importer entry so the PI can be launched from either tool
Implemented ability to drag-n-drop imageAssets onto MaterialEditor map fields and have it work
Implemented ability to drag-n-drop imageAssets onto TerrainMaterial Editor map fields and have it work
Made the TerrainMaterial editor dialogue have a non-modal background so you can interact with the editor as normal while it's up
Add sanity check to avoid attempting to mark EditorTree items if we couldn't find it's id
renamed BaseMap references in terrain material editor to diffuseMap for consistency
2022-03-27 03:05:48 -05:00

123 lines
6.4 KiB
Plaintext

//This is our create function. It's pointed to, by name, via a field defined in
//the ExampleModule.module file, which contains our module definition. It is called
//when the module is initially loaded by the engine. Generally, only common, base-level
//stuff is created(or destroyed, in the companion function), like things utilized or
//shared on both the client and server, or things that need to be loaded before anything
//else.
function ExampleModule::onCreate(%this)
{
}
//Similar to the create function, this is defined in thye module file, and called
//when the module is destroyed, usually as part of the game shutting down.
function ExampleModule::onDestroy(%this)
{
}
//This is called when the server part of the application is initially created. Torque3D
//assumes, even in a single player context, that there is ultimately a 'server' and a 'client'
//So during initial launch and startup of the engine, the server side is initialized in
//core/clientServer/scripts/server/server.tscript - in the initServer() function where this is called.
//This is called on all modules that have this function defined. This is important for
//any persistant parts of the server that always need to run such as gameplay scripts
//
//Importantly, when the gane session server is created, several functions are called to as part of the gamemode logic
//The script below contains the callbacks so the gamemode can actually be set up, but the server-side callbacks in question:
//ExampleGameMode::onMissionStart
//ExampleGameMode::onMissionEnded
//ExampleGameMode::onMissionReset
//Are called during the startup, shut down, and resetting of any and all active gamemodes, as informed by the loaded scenes
//when the game server is processed.
//These callbacks are activated in core/clientServer/scripts/server/levelLoad.tscript
function ExampleModule::initServer(%this)
{
//This script contains our ExampleGameMode logic
%this.queueExec("./scripts/ExampleGamemodeScript");
}
//This is called when a game session server is actually created so the game may be played. It's called
//from core/clientServer/scripts/server/server.tscript - in the createServer() function, which is called when
//A game session is actually launched, and the server is generated so game clients can connect to it.
//This is utilized to set up common things that need to be set up each time the game session server is
//created, such as common variables, datablocks to be transmitted to the client, etc.
function ExampleModule::onCreateGameServer(%this)
{
//In particular, the default client/server module handles the transmission of datablocks from
//server to client automatically as part of the connection and prepping process alongside
//validation and tramission of level objects. It does this in an abstracted way by adding
//the file paths to a master DatablockFilesList array as per below. When the server is created in
//onServerCreated(), it loads the datablocks via this array, and when when the server goes
//to pass data to the client, it iterates over this list and processes it, ensuring all datablocks
//are the most up to date possible for transmission to the connecting client
//%this.registerDatablock("./datablocks/ExampleDatablock." @ $TorqueScriptFileExtension);
}
//This is called when a game session server is destroyed, when the game shuts down. It's called from
//core/clientServer/scripts/server/server.tscript - in the destroyServer() function, which just cleans up anything
//The module may have set up as part of the game server being created.
function ExampleModule::onDestroyGameServer(%this)
{
}
//Similar to initServer, this is called during the initial launch of the application and the client component
//is set up. The difference is that the client may not actually be created, such as in the case for dedicated servers
//Where no UI or gameplay interface is required. It's called from core/clientServer/scripts/client/client.tscript -
//in the initClient() function. It sets up common elements that the client will always need, such as scripts, GUIs
//and the like
function ExampleModule::initClient(%this)
{
AssetDatabase.acquireAsset("ExampleModule:exampleDatablock");
AssetDatabase.acquireAsset("ExampleModule:examplePostEffect");
AssetDatabase.acquireAsset("ExampleModule:exampleGUI");
//client scripts
//Here, we exec out keybind scripts so the player is able to move when they get into a game
%this.queueExec("./scripts/default.keybinds");
%prefPath = getPrefpath();
if(isFile(%prefPath @ "/keybinds." @ $TorqueScriptFileExtension))
exec(%prefPath @ "/keybinds." @ $TorqueScriptFileExtension);
%this.queueExec("./scripts/inputCommands");
}
//This is called when a game session client successfuly connects to a game server.
//It's called from core/clientServer/scripts/client/connectionToServer.tscript - in the GameConnection::onConnectionAccepted() function
//It's used for any client-side specific game session stuff that the client needs to load or pass to the server, such as profile data
//account progress, preferences, etc.
//
//When a client is connected, the gamemode logic also has a callback activated - ExampleGameMode::onClientEnterGame().
function ExampleModule::onCreateClientConnection(%this)
{
//This will push our keybind movemap onto the input stack, so we can control our camera in our ExampleGameMode
ExampleMoveMap.push();
}
//This is called when a client game session disconnects from a game server
//It's called from core/clientServer/scripts/client/connectionToServer.tscript - in the disconnectedCleanup() function
//It's used to clean up and potentially write out any client-side stuff that needs housekeeping when disconnecting for any reason.
//It will be called if the connection is manually terminated, or lost due to any sort of connection issue.
//
//When a client disconnects, the gamemode logic has a callback activated - ExampleGameMode::onClientLeaveGame().
function ExampleModule::onDestroyClientConnection(%this)
{
//This will pop the keybind, cleaning it up from the input stack, as it no longer applies
ExampleMoveMap.pop();
}
function ExampleModule::populateOptionsMenuCategories(%this)
{
addOptionsMenuCategory("Example Options", "testExampleOptions();");
}
function testExampleOptions()
{
OptionsMenuSettingsList.clear();
OptionName.setText("");
OptionDescription.setText("");
addListOption("Test Option", "This is a test option", $testOptionValue, "OptionA\tOptionB");
}