From a219585a4191df793964774cc46febba1cefe654 Mon Sep 17 00:00:00 2001 From: Sachith Hasaranga Seneviratne Date: Tue, 24 Jun 2014 08:45:27 +0530 Subject: [PATCH] Started adding configuration key bindings to scripting to move all tutorial messages to scripting --- data/scripts/greenvalley/sheep_approach.as | 11 +++++++++++ data/scripts/greenvalley/sheep_dance.as | 10 ++++++++++ data/scripts/greenvalley/start.as | 8 ++++++++ data/scripts/greenvalley/update.as | 10 ++++++++++ src/scriptengine/script_track.cpp | 16 ++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 data/scripts/greenvalley/sheep_approach.as create mode 100644 data/scripts/greenvalley/sheep_dance.as create mode 100644 data/scripts/greenvalley/start.as create mode 100644 data/scripts/greenvalley/update.as diff --git a/data/scripts/greenvalley/sheep_approach.as b/data/scripts/greenvalley/sheep_approach.as new file mode 100644 index 000000000..a89bf4c23 --- /dev/null +++ b/data/scripts/greenvalley/sheep_approach.as @@ -0,0 +1,11 @@ +void onTrigger() +{ + + //TrackObject @t_obj = getTrackObject("anim_sheep2.b3d"); + //t_obj.setEnable(false); + //Mesh @sheepMesh = t_obj.getMesh(); + //displayMessage("moo"); + //sheepMesh.setLoop(6,9); //rapid-nod sheep + runScript("sheep_dance"); + +} diff --git a/data/scripts/greenvalley/sheep_dance.as b/data/scripts/greenvalley/sheep_dance.as new file mode 100644 index 000000000..fc20db229 --- /dev/null +++ b/data/scripts/greenvalley/sheep_dance.as @@ -0,0 +1,10 @@ +void onTrigger() +{ + + TrackObject @t_obj = getTrackObject("anim_sheep2.b3d"); + //t_obj.setEnable(false); + Mesh @sheepMesh = t_obj.getMesh(); + //displayMessage("moo"); + sheepMesh.setLoop(1,3); //rapid-nod sheep + //runScript("sheep_approach"); +} diff --git a/data/scripts/greenvalley/start.as b/data/scripts/greenvalley/start.as new file mode 100644 index 000000000..f77f0dc7b --- /dev/null +++ b/data/scripts/greenvalley/start.as @@ -0,0 +1,8 @@ +void onStart() +{ + + displayMessage("Track Loaded"); + //For green valley sheep test. See sheep_approach.as + createTrigger("sheep_approach",-5.48,7.21,0.49,20.0); + +} diff --git a/data/scripts/greenvalley/update.as b/data/scripts/greenvalley/update.as new file mode 100644 index 000000000..08af6e065 --- /dev/null +++ b/data/scripts/greenvalley/update.as @@ -0,0 +1,10 @@ +void onUpdate() +{ + + TrackObject @t_obj = getTrackObject("anim_sheep2.b3d"); + Mesh @sheepMesh = t_obj.getMesh(); + if (sheepMesh.getCurrentFrame()==2){ + sheepMesh.setLoop(8,48); + sheepMesh.setCurrentFrame(9); + } +} diff --git a/src/scriptengine/script_track.cpp b/src/scriptengine/script_track.cpp index bf98cf4d9..d1e31ab37 100644 --- a/src/scriptengine/script_track.cpp +++ b/src/scriptengine/script_track.cpp @@ -26,6 +26,8 @@ #include "tracks/track.hpp" #include "animations/three_d_animation.hpp" #include //debug +#include "input/input_manager.hpp" +#include "input/device_manager.hpp" namespace Scripting { @@ -79,6 +81,16 @@ namespace Scripting { ((TrackObjectPresentationMesh*)(memory))->getCurrentFrame(); } + void getKeyBinding(asIScriptGeneric *gen) + { + //currently just test if it works + std::string *str = (std::string*)gen->GetArgAddress(0); + InputDevice* device = input_manager->getDeviceList()->getLatestUsedDevice(); + DeviceConfig* config = device->getConfiguration(); + irr::core::stringw skid = config->getBindingAsString(PA_DRIFT); + std::string key = std::string(irr::core::stringc(skid).c_str()); + gen->SetReturnObject(&key); + } void getTrackObject(asIScriptGeneric *gen) { std::string *str = (std::string*)gen->GetArgAddress(0); @@ -99,6 +111,7 @@ namespace Scripting void registerScriptFunctions(asIScriptEngine *engine) { int r; + void getKeyBinding(asIScriptGeneric *gen) r = engine->RegisterGlobalFunction("void displayMessage(string &in)", asFUNCTION(displayMessage), asCALL_GENERIC); assert(r >= 0); r = engine->RegisterGlobalFunction("void disableAnimation(string &in)", asFUNCTION(disableAnimation), asCALL_GENERIC); assert(r >= 0); @@ -107,6 +120,9 @@ namespace Scripting r = engine->RegisterGlobalFunction("void disableTrigger(string &in)", asFUNCTION(disableTrigger), asCALL_GENERIC); assert(r >= 0); r = engine->RegisterGlobalFunction("void createTrigger(string &in,float x,float y,float z, float distance)", asFUNCTION(createTrigger), asCALL_GENERIC); assert(r >= 0); + r = engine->RegisterGlobalFunction("void getKeyBinding(string &in)", asFUNCTION(displayMessage), asCALL_GENERIC); assert(r >= 0); + + /* //Test singleton, and various calling conventions // Register the track object manager as a singleton. The script will access it through the global property