More work towards handling library nodes in scripting
This commit is contained in:
parent
9531f0b3a4
commit
238578c921
@ -213,6 +213,8 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
const std::string& getOnItemCollisionFunction() const { return m_on_item_collision; }
|
||||
// ------------------------------------------------------------------------
|
||||
TrackObject* getTrackObject() { return m_object; }
|
||||
|
||||
// Methods usable by scripts
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "race/race_manager.hpp"
|
||||
#include "scriptengine/script_engine.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_object.hpp"
|
||||
#include "utils/profiler.hpp"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -189,12 +190,24 @@ void Physics::update(float dt)
|
||||
PhysicalObject* obj = p->getUserPointer(0)->getPointerPhysicalObject();
|
||||
std::string obj_id = obj->getID();
|
||||
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)
|
||||
{
|
||||
script_engine->runFunction("void " + scripting_function + "(int, const string)",
|
||||
script_engine->runFunction("void " + scripting_function + "(int, const string, const string)",
|
||||
[&](asIScriptContext* ctx) {
|
||||
ctx->SetArgDWord(0, kartId);
|
||||
ctx->SetArgObject(1, &obj_id);
|
||||
ctx->SetArgObject(1, lib_id_ptr);
|
||||
ctx->SetArgObject(2, &obj_id);
|
||||
});
|
||||
}
|
||||
if (obj->isCrashReset())
|
||||
|
@ -87,11 +87,9 @@ namespace Scripting
|
||||
*/
|
||||
std::string getScript(std::string fileName)
|
||||
{
|
||||
std::string script_dir = file_manager->getAsset(FileManager::SCRIPT, "");
|
||||
script_dir += World::getWorld()->getTrack()->getIdent() + "/";
|
||||
std::string script_path = World::getWorld()->getTrack()->getTrackFile(fileName);
|
||||
|
||||
script_dir += fileName;
|
||||
FILE *f = fopen(script_dir.c_str(), "rb");
|
||||
FILE *f = fopen(script_path.c_str(), "rb");
|
||||
if (f == NULL)
|
||||
{
|
||||
Log::debug("Scripting", "File does not exist : {0}.as", fileName.c_str());
|
||||
|
@ -125,6 +125,11 @@ public:
|
||||
const Material **material, btVector3 *normal,
|
||||
bool interpolate_normal) const;
|
||||
|
||||
TrackObject* getParentLibrary()
|
||||
{
|
||||
return m_parent_library;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** To finish object constructions. Called after the track model
|
||||
* is ready. */
|
||||
|
Loading…
Reference in New Issue
Block a user