More work towards handling library nodes in scripting

This commit is contained in:
Marianne Gagnon 2015-06-04 20:12:03 -04:00
parent 9531f0b3a4
commit 238578c921
4 changed files with 24 additions and 6 deletions

View File

@ -213,6 +213,8 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
const std::string& getOnItemCollisionFunction() const { return m_on_item_collision; } const std::string& getOnItemCollisionFunction() const { return m_on_item_collision; }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
TrackObject* getTrackObject() { return m_object; }
// Methods usable by scripts // Methods usable by scripts
/** /**

View File

@ -40,6 +40,7 @@
#include "race/race_manager.hpp" #include "race/race_manager.hpp"
#include "scriptengine/script_engine.hpp" #include "scriptengine/script_engine.hpp"
#include "tracks/track.hpp" #include "tracks/track.hpp"
#include "tracks/track_object.hpp"
#include "utils/profiler.hpp" #include "utils/profiler.hpp"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -189,12 +190,24 @@ void Physics::update(float dt)
PhysicalObject* obj = p->getUserPointer(0)->getPointerPhysicalObject(); PhysicalObject* obj = p->getUserPointer(0)->getPointerPhysicalObject();
std::string obj_id = obj->getID(); std::string obj_id = obj->getID();
std::string scripting_function = obj->getOnKartCollisionFunction(); std::string scripting_function = obj->getOnKartCollisionFunction();
TrackObject* to = obj->getTrackObject();
TrackObject* library = to->getParentLibrary();
std::string lib_id;
std::string* lib_id_ptr = NULL;
if (library != NULL)
{
lib_id = library->getID();
lib_id_ptr = &lib_id;
}
if (scripting_function.size() > 0) if (scripting_function.size() > 0)
{ {
script_engine->runFunction("void " + scripting_function + "(int, const string)", script_engine->runFunction("void " + scripting_function + "(int, const string, const string)",
[&](asIScriptContext* ctx) { [&](asIScriptContext* ctx) {
ctx->SetArgDWord(0, kartId); ctx->SetArgDWord(0, kartId);
ctx->SetArgObject(1, &obj_id); ctx->SetArgObject(1, lib_id_ptr);
ctx->SetArgObject(2, &obj_id);
}); });
} }
if (obj->isCrashReset()) if (obj->isCrashReset())

View File

@ -87,11 +87,9 @@ namespace Scripting
*/ */
std::string getScript(std::string fileName) std::string getScript(std::string fileName)
{ {
std::string script_dir = file_manager->getAsset(FileManager::SCRIPT, ""); std::string script_path = World::getWorld()->getTrack()->getTrackFile(fileName);
script_dir += World::getWorld()->getTrack()->getIdent() + "/";
script_dir += fileName; FILE *f = fopen(script_path.c_str(), "rb");
FILE *f = fopen(script_dir.c_str(), "rb");
if (f == NULL) if (f == NULL)
{ {
Log::debug("Scripting", "File does not exist : {0}.as", fileName.c_str()); Log::debug("Scripting", "File does not exist : {0}.as", fileName.c_str());

View File

@ -125,6 +125,11 @@ public:
const Material **material, btVector3 *normal, const Material **material, btVector3 *normal,
bool interpolate_normal) const; bool interpolate_normal) const;
TrackObject* getParentLibrary()
{
return m_parent_library;
}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
/** To finish object constructions. Called after the track model /** To finish object constructions. Called after the track model
* is ready. */ * is ready. */