Added script triggering at startup via start.as - meant to customize track object settings, and to create triggers / set their initial states as necessary

This commit is contained in:
Sachith Hasaranga Seneviratne 2014-06-17 18:50:55 +05:30
parent a6e2884456
commit 77ee20a5e2
7 changed files with 31 additions and 2 deletions

6
data/scripts/start.as Normal file
View File

@ -0,0 +1,6 @@
void onUpdate()
{
displayMessage("Track Loaded");
}

View File

@ -1,6 +1,6 @@
void onUpdate()
{
displayMessage("Haybail deactivated");
//displayMessage("Haybail deactivated");
}

View File

@ -119,10 +119,14 @@ void ScriptEngine::runScript(std::string scriptName)
{
func = Scripting::Physics::registerScriptCallbacks(m_engine);
}
if (scriptName == "update")
else if (scriptName == "update")
{
func = Scripting::Track::registerUpdateScriptCallbacks(m_engine);
}
else if (scriptName == "start")
{
func = Scripting::Track::registerStartScriptCallbacks(m_engine);
}
else
{
func = Scripting::Track::registerScriptCallbacks(m_engine);

View File

@ -51,6 +51,9 @@ namespace Scripting
asIScriptFunction*
registerUpdateScriptCallbacks(asIScriptEngine *engine);
asIScriptFunction*
registerStartScriptCallbacks(asIScriptEngine *engine);
}
class ScriptEngine

View File

@ -38,6 +38,12 @@ namespace Scripting
func = engine->GetModule(0)->GetFunctionByDecl("void onTrigger()");
return func;
}
asIScriptFunction* registerStartScriptCallbacks(asIScriptEngine *engine)
{
asIScriptFunction *func;
func = engine->GetModule(0)->GetFunctionByDecl("void onUpdate()");
return func;
}
asIScriptFunction* registerUpdateScriptCallbacks(asIScriptEngine *engine)
{
asIScriptFunction *func;

View File

@ -134,6 +134,7 @@ Track::Track(const std::string &filename)
m_ident=="overworld";
m_minimap_x_scale = 1.0f;
m_minimap_y_scale = 1.0f;
m_startup_run = false;
m_all_nodes.clear();
m_all_physics_only_nodes.clear();
m_all_cached_meshes.clear();
@ -256,6 +257,7 @@ void Track::reset()
CheckManager::get()->reset(*this);
ItemManager::get()->reset();
m_track_object_manager->reset();
m_startup_run = false;
} // reset
//-----------------------------------------------------------------------------
@ -1392,6 +1394,12 @@ void Track::handleAnimatedTextures(scene::ISceneNode *node, const XMLNode &xml)
*/
void Track::update(float dt)
{
if (!m_startup_run) // first time running update = good point to run startup script
{
Scripting::ScriptEngine* script_engine = World::getWorld()->getScriptEngine();
script_engine->runScript("start");
m_startup_run = true;
}
m_track_object_manager->update(dt);
for(unsigned int i=0; i<m_animated_textures.size(); i++)

View File

@ -176,6 +176,8 @@ private:
std::string m_description;
core::stringw m_designer;
/* For running the startup script */
bool m_startup_run;
/** The full filename of the config (xml) file. */
std::string m_filename;