Scripting work
This commit is contained in:
@@ -16,16 +16,17 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include <assert.h> // assert()
|
||||
#include <assert.h>
|
||||
#include <angelscript.h>
|
||||
#include "io/file_manager.hpp"
|
||||
#include <iostream> // cout
|
||||
#include "karts/kart.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "script_engine.hpp"
|
||||
#include "scriptstdstring.hpp"
|
||||
#include "scriptvec3.hpp"
|
||||
#include <string.h> // strstr()
|
||||
#include "scriptengine/script_engine.hpp"
|
||||
#include "scriptengine/script_gui.hpp"
|
||||
#include "scriptengine/script_track.hpp"
|
||||
#include "scriptengine/scriptstdstring.hpp"
|
||||
#include "scriptengine/scriptvec3.hpp"
|
||||
#include <string.h>
|
||||
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
|
||||
#include "tracks/track_object_manager.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
@@ -255,7 +256,8 @@ void ScriptEngine::cleanupCache()
|
||||
{
|
||||
for (auto curr : m_script_cache)
|
||||
{
|
||||
curr.second->Release();
|
||||
if (curr.second != NULL)
|
||||
curr.second->Release();
|
||||
}
|
||||
m_script_cache.clear();
|
||||
}
|
||||
@@ -268,17 +270,16 @@ void ScriptEngine::configureEngine(asIScriptEngine *engine)
|
||||
{
|
||||
// Register the script string type
|
||||
RegisterStdString(engine); //register std::string
|
||||
RegisterStdStringUtils(engine);
|
||||
RegisterVec3(engine); //register Vec3
|
||||
|
||||
Scripting::Track::registerScriptFunctions(m_engine);
|
||||
|
||||
Scripting::Track::registerScriptEnums(m_engine);
|
||||
|
||||
Scripting::Kart::registerScriptFunctions(m_engine);
|
||||
|
||||
Scripting::Physics::registerScriptFunctions(m_engine);
|
||||
|
||||
Scripting::GUI::registerScriptFunctions(m_engine);
|
||||
Scripting::GUI::registerScriptEnums(m_engine);
|
||||
|
||||
// It is possible to register the functions, properties, and types in
|
||||
// configuration groups as well. When compiling the scripts it can then
|
||||
|
||||
214
src/scriptengine/script_gui.cpp
Normal file
214
src/scriptengine/script_gui.cpp
Normal file
@@ -0,0 +1,214 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "script_track.hpp"
|
||||
|
||||
#include "animations/three_d_animation.hpp"
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input_device.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "modes/world.hpp"
|
||||
#include "states_screens/dialogs/tutorial_message_dialog.hpp"
|
||||
#include "tracks/track.hpp"
|
||||
#include "tracks/track_object.hpp"
|
||||
#include "tracks/track_object_manager.hpp"
|
||||
|
||||
#include <angelscript.h>
|
||||
#include "scriptarray.hpp"
|
||||
|
||||
#include <assert.h>
|
||||
#include <iostream> //debug
|
||||
|
||||
namespace Scripting
|
||||
{
|
||||
namespace GUI
|
||||
{
|
||||
//getter for key binding for player action enums
|
||||
void getKeyBinding(asIScriptGeneric *gen)
|
||||
{
|
||||
int Enum_value = (int)gen->GetArgDWord(0);
|
||||
InputDevice* device = input_manager->getDeviceManager()->getLatestUsedDevice();
|
||||
DeviceConfig* config = device->getConfiguration();
|
||||
irr::core::stringw control;
|
||||
PlayerAction ScriptAction = (PlayerAction)Enum_value;
|
||||
control = config->getBindingAsString(ScriptAction);
|
||||
std::string key = std::string(irr::core::stringc(control).c_str());
|
||||
void *key_pointer = &key;
|
||||
gen->SetReturnObject(key_pointer);
|
||||
}
|
||||
|
||||
// Displays the message specified in displayMessage( string message ) within the script
|
||||
void displayMessage(asIScriptGeneric *gen)
|
||||
{
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
irr::core::stringw out = StringUtils::utf8_to_wide(input->c_str());
|
||||
new TutorialMessageDialog((out), true);
|
||||
}
|
||||
|
||||
|
||||
void translate(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
|
||||
irr::core::stringw out = translations->fribidize(translations->w_gettext(input->c_str()));
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) std::string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void insertValues1(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
std::string *arg1 = (std::string*)gen->GetArgAddress(1);
|
||||
|
||||
irr::core::stringw out = StringUtils::insertValues(StringUtils::utf8_to_wide(input->c_str()),
|
||||
StringUtils::utf8_to_wide(arg1->c_str()));
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) std::string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void insertValues2(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
std::string *arg1 = (std::string*)gen->GetArgAddress(1);
|
||||
std::string *arg2 = (std::string*)gen->GetArgAddress(2);
|
||||
|
||||
irr::core::stringw out = StringUtils::insertValues(StringUtils::utf8_to_wide(input->c_str()),
|
||||
StringUtils::utf8_to_wide(arg1->c_str()),
|
||||
StringUtils::utf8_to_wide(arg2->c_str()));
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) std::string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void insertValues3(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
std::string *arg1 = (std::string*)gen->GetArgAddress(1);
|
||||
std::string *arg2 = (std::string*)gen->GetArgAddress(2);
|
||||
std::string *arg3 = (std::string*)gen->GetArgAddress(3);
|
||||
|
||||
irr::core::stringw out = StringUtils::insertValues(StringUtils::utf8_to_wide(input->c_str()),
|
||||
StringUtils::utf8_to_wide(arg1->c_str()),
|
||||
StringUtils::utf8_to_wide(arg2->c_str()),
|
||||
StringUtils::utf8_to_wide(arg3->c_str()));
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) std::string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void translateAndInsertValues1(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
std::string *arg1 = (std::string*)gen->GetArgAddress(1);
|
||||
|
||||
irr::core::stringw out = translations->w_gettext(input->c_str());
|
||||
|
||||
out = StringUtils::insertValues(out,
|
||||
StringUtils::utf8_to_wide(arg1->c_str()));
|
||||
|
||||
out = translations->fribidize(out);
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) std::string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void translateAndInsertValues2(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
std::string *arg1 = (std::string*)gen->GetArgAddress(1);
|
||||
std::string *arg2 = (std::string*)gen->GetArgAddress(2);
|
||||
|
||||
irr::core::stringw out = translations->w_gettext(input->c_str());
|
||||
|
||||
out = StringUtils::insertValues(out,
|
||||
StringUtils::utf8_to_wide(arg1->c_str()),
|
||||
StringUtils::utf8_to_wide(arg2->c_str()));
|
||||
|
||||
out = translations->fribidize(out);
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) std::string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void translateAndInsertValues3(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
std::string *arg1 = (std::string*)gen->GetArgAddress(1);
|
||||
std::string *arg2 = (std::string*)gen->GetArgAddress(2);
|
||||
std::string *arg3 = (std::string*)gen->GetArgAddress(3);
|
||||
|
||||
irr::core::stringw out = translations->w_gettext(input->c_str());
|
||||
|
||||
out = StringUtils::insertValues(out,
|
||||
StringUtils::utf8_to_wide(arg1->c_str()),
|
||||
StringUtils::utf8_to_wide(arg2->c_str()),
|
||||
StringUtils::utf8_to_wide(arg3->c_str()));
|
||||
|
||||
out = translations->fribidize(out);
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) std::string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void registerScriptFunctions(asIScriptEngine *engine)
|
||||
{
|
||||
int r; // of type asERetCodes
|
||||
engine->SetDefaultNamespace("GUI");
|
||||
r = engine->RegisterGlobalFunction("void displayMessage(string &in)", asFUNCTION(displayMessage), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string getKeyBinding(int input)", asFUNCTION(getKeyBinding), asCALL_GENERIC); assert(r >= 0);
|
||||
|
||||
r = engine->RegisterGlobalFunction("string translate(const string &in)", asFUNCTION(translate), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string translate(const string &in, const string &in)", asFUNCTION(translateAndInsertValues1), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string translate(const string &in, const string &in, const string &in)", asFUNCTION(translateAndInsertValues2), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string translate(const string &in, const string &in, const string &in, const string &in)", asFUNCTION(translateAndInsertValues3), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in)", asFUNCTION(insertValues1), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in)", asFUNCTION(insertValues2), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in, const string &in)", asFUNCTION(insertValues3), asCALL_GENERIC); assert(r >= 0);
|
||||
}
|
||||
|
||||
void registerScriptEnums(asIScriptEngine *engine)
|
||||
{
|
||||
engine->RegisterEnum("PA");
|
||||
engine->RegisterEnumValue("PA", "STEER_LEFT", PA_STEER_LEFT);
|
||||
engine->RegisterEnumValue("PA", "STEER_RIGHT", PA_STEER_RIGHT);
|
||||
engine->RegisterEnumValue("PA", "ACCEL", PA_ACCEL);
|
||||
engine->RegisterEnumValue("PA", "BRAKE", PA_BRAKE);
|
||||
engine->RegisterEnumValue("PA", "NITRO", PA_NITRO);
|
||||
engine->RegisterEnumValue("PA", "DRIFT", PA_DRIFT);
|
||||
engine->RegisterEnumValue("PA", "RESCUE", PA_RESCUE);
|
||||
engine->RegisterEnumValue("PA", "FIRE", PA_FIRE);
|
||||
engine->RegisterEnumValue("PA", "LOOK_BACK", PA_LOOK_BACK);
|
||||
engine->RegisterEnumValue("PA", "PAUSE_RACE", PA_PAUSE_RACE);
|
||||
engine->RegisterEnumValue("PA", "MENU_UP", PA_MENU_UP);
|
||||
engine->RegisterEnumValue("PA", "MENU_DOWN", PA_MENU_DOWN);
|
||||
engine->RegisterEnumValue("PA", "MENU_LEFT", PA_MENU_LEFT);
|
||||
engine->RegisterEnumValue("PA", "MENU_RIGHT", PA_MENU_RIGHT);
|
||||
engine->RegisterEnumValue("PA", "MENU_SELECT", PA_MENU_SELECT);
|
||||
engine->RegisterEnumValue("PA", "MENU_CANCEL", PA_MENU_CANCEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/scriptengine/script_gui.hpp
Normal file
38
src/scriptengine/script_gui.hpp
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2014-2015 SuperTuxKart Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#ifndef HEADER_SCRIPT_GUI_HPP
|
||||
#define HEADER_SCRIPT_GUI_HPP
|
||||
|
||||
#include <angelscript.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Scripting
|
||||
{
|
||||
namespace GUI
|
||||
{
|
||||
//script engine functions
|
||||
void registerScriptFunctions(asIScriptEngine *engine);
|
||||
asIScriptFunction*
|
||||
registerScriptCallbacks(asIScriptEngine *engine, std::string scriptName);
|
||||
void registerScriptEnums(asIScriptEngine *engine);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -112,6 +112,7 @@ namespace Scripting
|
||||
void registerScriptFunctions(asIScriptEngine *engine)
|
||||
{
|
||||
int r;
|
||||
engine->SetDefaultNamespace("Karts");
|
||||
r = engine->RegisterGlobalFunction("void squashKart(int id, float time)", asFUNCTION(squashKart), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void teleportKart(int id, Vec3 &in)", asFUNCTION(teleportKart), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void setVelocity(int id, Vec3 &in)", asFUNCTION(setVelocity), asCALL_GENERIC); assert(r >= 0);
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace Scripting
|
||||
void registerScriptFunctions(asIScriptEngine *engine)
|
||||
{
|
||||
int r;
|
||||
engine->SetDefaultNamespace("Physics");
|
||||
r = engine->RegisterGlobalFunction("uint getCollidingKart1()", asFUNCTION(getCollidingKart1), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterGlobalFunction("uint getCollidingKart2()", asFUNCTION(getCollidingKart2), asCALL_GENERIC); assert( r >= 0 );
|
||||
r = engine->RegisterGlobalFunction("string getCollisionType()", asFUNCTION(getCollisionType), asCALL_GENERIC); assert(r >= 0);
|
||||
|
||||
@@ -207,15 +207,13 @@ namespace Scripting
|
||||
{
|
||||
int r;
|
||||
|
||||
r = engine->RegisterGlobalFunction("void displayMessage(string &in)", asFUNCTION(displayMessage), asCALL_GENERIC); assert(r >= 0);
|
||||
engine->SetDefaultNamespace("Track");
|
||||
r = engine->RegisterGlobalFunction("void disable(string &in)", asFUNCTION(disableTrackObject), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void enable(string &in)", asFUNCTION(enableTrackObject), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void enableTrigger(string &in)", asFUNCTION(enableTrigger), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void disableTrigger(string &in)", asFUNCTION(disableTrigger), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("void createTrigger(string &in,Vec3 &in, float distance)",
|
||||
asFUNCTION(createTrigger), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string getKeyBinding(int input)", asFUNCTION(getKeyBinding), asCALL_GENERIC); assert(r >= 0);
|
||||
|
||||
|
||||
/*
|
||||
//Test singleton, and various calling conventions
|
||||
@@ -275,35 +273,6 @@ namespace Scripting
|
||||
r = engine->RegisterObjectMethod("Animator", "void setPaused(bool mode)", asFUNCTION( setPaused ), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
|
||||
r = engine->RegisterGlobalFunction("void runScript(string &in)", asFUNCTION(runScript), asCALL_GENERIC); assert(r >= 0);
|
||||
|
||||
}
|
||||
|
||||
void registerScriptEnums(asIScriptEngine *engine)
|
||||
{
|
||||
|
||||
engine->RegisterEnum("PA");
|
||||
engine->RegisterEnumValue("PA", "STEER_LEFT", PA_STEER_LEFT);
|
||||
engine->RegisterEnumValue("PA", "STEER_RIGHT", PA_STEER_RIGHT);
|
||||
engine->RegisterEnumValue("PA", "ACCEL", PA_ACCEL);
|
||||
engine->RegisterEnumValue("PA", "BRAKE", PA_BRAKE);
|
||||
engine->RegisterEnumValue("PA", "NITRO", PA_NITRO);
|
||||
engine->RegisterEnumValue("PA", "DRIFT", PA_DRIFT);
|
||||
engine->RegisterEnumValue("PA", "RESCUE", PA_RESCUE);
|
||||
engine->RegisterEnumValue("PA", "FIRE", PA_FIRE);
|
||||
engine->RegisterEnumValue("PA", "LOOK_BACK", PA_LOOK_BACK);
|
||||
engine->RegisterEnumValue("PA", "PAUSE_RACE", PA_PAUSE_RACE);
|
||||
engine->RegisterEnumValue("PA", "MENU_UP", PA_MENU_UP);
|
||||
engine->RegisterEnumValue("PA", "MENU_DOWN", PA_MENU_DOWN);
|
||||
engine->RegisterEnumValue("PA", "MENU_LEFT", PA_MENU_LEFT);
|
||||
engine->RegisterEnumValue("PA", "MENU_RIGHT", PA_MENU_RIGHT);
|
||||
engine->RegisterEnumValue("PA", "MENU_SELECT", PA_MENU_SELECT);
|
||||
engine->RegisterEnumValue("PA", "MENU_CANCEL", PA_MENU_CANCEL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,25 +25,19 @@
|
||||
|
||||
namespace Scripting
|
||||
{
|
||||
|
||||
namespace Track
|
||||
{
|
||||
|
||||
//script engine functions
|
||||
void registerScriptFunctions(asIScriptEngine *engine);
|
||||
asIScriptFunction*
|
||||
registerScriptCallbacks(asIScriptEngine *engine , std::string scriptName);
|
||||
void registerScriptEnums(asIScriptEngine *engine);
|
||||
|
||||
|
||||
//script-bound functions
|
||||
void displayMessage(asIScriptGeneric *gen);
|
||||
void disableAnimation(asIScriptGeneric *gen);
|
||||
void enableAnimation(asIScriptGeneric *gen);
|
||||
void enableTrigger(asIScriptGeneric *gen);
|
||||
void disableTrigger(asIScriptGeneric *gen);
|
||||
void createTrigger(asIScriptGeneric *gen);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "scriptarray.hpp"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -45,19 +44,19 @@ static CScriptArray *StringSplit(const string &delim, const string &str)
|
||||
asIScriptEngine *engine = ctx->GetEngine();
|
||||
|
||||
// TODO: This should only be done once
|
||||
// TODO: This assumes that CScriptArray was already registered
|
||||
asIObjectType *arrayType = engine->GetObjectTypeById(engine->GetTypeIdByDecl("array<string>"));
|
||||
// TODO: This assumes that CScriptArray was already registered
|
||||
asIObjectType *arrayType = engine->GetObjectTypeById(engine->GetTypeIdByDecl("array<string>"));
|
||||
|
||||
// Create the array object
|
||||
CScriptArray *array = new CScriptArray(0, arrayType);
|
||||
|
||||
// Find the existence of the delimiter in the input string
|
||||
int pos = 0, prev = 0, count = 0;
|
||||
while( (pos = (int)str.find(delim, prev)) != (int)string::npos )
|
||||
while ((pos = (int)str.find(delim, prev)) != (int)string::npos)
|
||||
{
|
||||
// Add the part to the array
|
||||
array->Resize(array->GetSize()+1);
|
||||
((string*)array->At(count))->assign(&str[prev], pos-prev);
|
||||
array->Resize(array->GetSize() + 1);
|
||||
((string*)array->At(count))->assign(&str[prev], pos - prev);
|
||||
|
||||
// Find the next part
|
||||
count++;
|
||||
@@ -65,16 +64,16 @@ static CScriptArray *StringSplit(const string &delim, const string &str)
|
||||
}
|
||||
|
||||
// Add the remaining part
|
||||
array->Resize(array->GetSize()+1);
|
||||
array->Resize(array->GetSize() + 1);
|
||||
((string*)array->At(count))->assign(&str[prev]);
|
||||
|
||||
return array;
|
||||
return array;
|
||||
}
|
||||
|
||||
static void StringSplit_Generic(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
string *str = (string*)gen->GetObject();
|
||||
string *str = (string*)gen->GetObject();
|
||||
string *delim = *(string**)gen->GetAddressOfArg(0);
|
||||
|
||||
// Return the array by handle
|
||||
@@ -100,20 +99,20 @@ static string StringJoin(const CScriptArray &array, const string &delim)
|
||||
{
|
||||
// Create the new string
|
||||
string str = "";
|
||||
if( array.GetSize() )
|
||||
{
|
||||
int n;
|
||||
for( n = 0; n < (int)array.GetSize() - 1; n++ )
|
||||
{
|
||||
str += *(string*)array.At(n);
|
||||
str += delim;
|
||||
}
|
||||
if (array.GetSize())
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < (int)array.GetSize() - 1; n++)
|
||||
{
|
||||
str += *(string*)array.At(n);
|
||||
str += delim;
|
||||
}
|
||||
|
||||
// Add the last part
|
||||
str += *(string*)array.At(n);
|
||||
}
|
||||
// Add the last part
|
||||
str += *(string*)array.At(n);
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
}
|
||||
|
||||
static void StringJoin_Generic(asIScriptGeneric *gen)
|
||||
@@ -126,110 +125,22 @@ static void StringJoin_Generic(asIScriptGeneric *gen)
|
||||
new(gen->GetAddressOfReturnLocation()) string(StringJoin(*array, *delim));
|
||||
}
|
||||
|
||||
void translate(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
|
||||
irr::core::stringw out = translations->fribidize(translations->w_gettext(input->c_str()));
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void insertValues1(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
std::string *arg1 = (std::string*)gen->GetArgAddress(1);
|
||||
|
||||
irr::core::stringw out = StringUtils::insertValues(StringUtils::utf8_to_wide(input->c_str()),
|
||||
StringUtils::utf8_to_wide(arg1->c_str()));
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void insertValues2(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
std::string *arg1 = (std::string*)gen->GetArgAddress(1);
|
||||
std::string *arg2 = (std::string*)gen->GetArgAddress(2);
|
||||
|
||||
irr::core::stringw out = StringUtils::insertValues(StringUtils::utf8_to_wide(input->c_str()),
|
||||
StringUtils::utf8_to_wide(arg1->c_str()),
|
||||
StringUtils::utf8_to_wide(arg2->c_str()));
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
void insertValues3(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
std::string *arg1 = (std::string*)gen->GetArgAddress(1);
|
||||
std::string *arg2 = (std::string*)gen->GetArgAddress(2);
|
||||
std::string *arg3 = (std::string*)gen->GetArgAddress(3);
|
||||
|
||||
irr::core::stringw out = StringUtils::insertValues(StringUtils::utf8_to_wide(input->c_str()),
|
||||
StringUtils::utf8_to_wide(arg1->c_str()),
|
||||
StringUtils::utf8_to_wide(arg2->c_str()),
|
||||
StringUtils::utf8_to_wide(arg3->c_str()));
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) string(StringUtils::wide_to_utf8(out.c_str()));
|
||||
}
|
||||
|
||||
/*
|
||||
void insertValues(asIScriptGeneric *gen)
|
||||
{
|
||||
// Get the arguments
|
||||
std::string *input = (std::string*)gen->GetArgAddress(0);
|
||||
CScriptArray *array = *(CScriptArray**)gen->GetAddressOfArg(1);
|
||||
|
||||
int size = array->GetSize();
|
||||
vector<string> all_values;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
string* curr = (string*)array->At(i);
|
||||
all_values.push_back(curr);
|
||||
}
|
||||
|
||||
StringUtils::insertValues(*input, all_values);
|
||||
|
||||
irr::core::stringw out = translations->fribidize(translations->w_gettext(input->c_str()));
|
||||
|
||||
// Return the string
|
||||
new(gen->GetAddressOfReturnLocation()) string(irr::core::stringc(out).c_str());
|
||||
}
|
||||
*/
|
||||
|
||||
// This is where the utility functions are registered.
|
||||
// The string type must have been registered first.
|
||||
void RegisterStdStringUtils(asIScriptEngine *engine)
|
||||
{
|
||||
int r;
|
||||
int r;
|
||||
|
||||
//if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY"))
|
||||
//{
|
||||
//r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit_Generic), asCALL_GENERIC); assert(r >= 0);
|
||||
//r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin_Generic), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string translate(const string &in)", asFUNCTION(translate), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in)", asFUNCTION(insertValues1), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in)", asFUNCTION(insertValues2), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &in, const string &in, const string &in)", asFUNCTION(insertValues3), asCALL_GENERIC); assert(r >= 0);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// //r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
// //r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin), asCALL_CDECL); assert(r >= 0);
|
||||
// r = engine->RegisterGlobalFunction("string translate(const string &in)", asFUNCTION(translate), asCALL_CDECL); assert(r >= 0);
|
||||
// r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &arg1)", asFUNCTION(insertValues1), asCALL_CDECL); assert(r >= 0);
|
||||
// r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &arg1, const string &arg2)", asFUNCTION(insertValues2), asCALL_CDECL); assert(r >= 0);
|
||||
// r = engine->RegisterGlobalFunction("string insertValues(const string &in, const string &arg1, const string &arg2, const string &arg3)", asFUNCTION(insertValues3), asCALL_CDECL); assert(r >= 0);
|
||||
//}
|
||||
if (strstr(asGetLibraryOptions(), "AS_MAX_PORTABILITY"))
|
||||
{
|
||||
r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit_Generic), asCALL_GENERIC); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin_Generic), asCALL_GENERIC); assert(r >= 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = engine->RegisterObjectMethod("string", "array<string>@ split(const string &in) const", asFUNCTION(StringSplit), asCALL_CDECL_OBJLAST); assert(r >= 0);
|
||||
r = engine->RegisterGlobalFunction("string join(const array<string> &in, const string &in)", asFUNCTION(StringJoin), asCALL_CDECL); assert(r >= 0);
|
||||
}
|
||||
}
|
||||
|
||||
END_AS_NAMESPACE
|
||||
END_AS_NAMESPACE
|
||||
@@ -921,123 +921,6 @@ void TrackObjectPresentationActionTrigger::onTriggerItemApproached(Item* who)
|
||||
_("Complete all challenges to unlock the big door!"), true);
|
||||
}
|
||||
}
|
||||
/*
|
||||
else if (m_action == "tutorial_drive")
|
||||
{
|
||||
//if (World::getWorld()->getPhase() == World::RACE_PHASE)
|
||||
{
|
||||
m_action_active = false;
|
||||
//World::getWorld()->getRaceGUI()->clearAllMessages();
|
||||
|
||||
InputDevice* device = input_manager->getDeviceManager()
|
||||
->getLatestUsedDevice();
|
||||
DeviceConfig* config = device->getConfiguration();
|
||||
irr::core::stringw accel = config->getBindingAsString(PA_ACCEL);
|
||||
irr::core::stringw left = config->getBindingAsString(PA_STEER_LEFT);
|
||||
irr::core::stringw right = config->getBindingAsString(PA_STEER_RIGHT);
|
||||
|
||||
new TutorialMessageDialog(_("Accelerate with <%s> and steer with "
|
||||
"<%s> and <%s>", accel, left, right),
|
||||
false);
|
||||
}
|
||||
}
|
||||
else if (m_action == "tutorial_bananas")
|
||||
{
|
||||
m_action_active = false;
|
||||
|
||||
new TutorialMessageDialog(_("Avoid bananas!"), true);
|
||||
}
|
||||
else if (m_action == "tutorial_giftboxes")
|
||||
{
|
||||
m_action_active = false;
|
||||
InputDevice* device = input_manager->getDeviceManager()
|
||||
->getLatestUsedDevice();
|
||||
DeviceConfig* config = device->getConfiguration();
|
||||
irr::core::stringw fire = config->getBindingAsString(PA_FIRE);
|
||||
|
||||
new TutorialMessageDialog(_("Collect gift boxes, and fire the weapon "
|
||||
"with <%s> to blow away these boxes!",
|
||||
fire),true);
|
||||
}
|
||||
else if (m_action == "tutorial_backgiftboxes")
|
||||
{
|
||||
m_action_active = false;
|
||||
InputDevice* device = input_manager->getDeviceManager()
|
||||
->getLatestUsedDevice();
|
||||
DeviceConfig* config = device->getConfiguration();
|
||||
irr::core::stringw fire = config->getBindingAsString(PA_FIRE);
|
||||
irr::core::stringw back = config->getBindingAsString(PA_LOOK_BACK);
|
||||
|
||||
new TutorialMessageDialog(
|
||||
_("Press <%s> to look behind, and fire the weapon with <%s> while "
|
||||
"pressing <%s> to fire behind!", back, fire, back),
|
||||
true);
|
||||
}
|
||||
else if (m_action == "tutorial_nitro_collect")
|
||||
{
|
||||
m_action_active = false;
|
||||
|
||||
new TutorialMessageDialog(_("Collect nitro bottles (we will use them "
|
||||
"after the curve)"), true);
|
||||
}
|
||||
else if (m_action == "tutorial_nitro_use")
|
||||
{
|
||||
m_action_active = false;
|
||||
InputDevice* device = input_manager->getDeviceManager()
|
||||
->getLatestUsedDevice();
|
||||
DeviceConfig* config = device->getConfiguration();
|
||||
irr::core::stringw nitro = config->getBindingAsString(PA_NITRO);
|
||||
|
||||
new TutorialMessageDialog(_("Use the nitro you collected by "
|
||||
"pressing <%s>!", nitro), true);
|
||||
}
|
||||
else if (m_action == "tutorial_rescue")
|
||||
{
|
||||
m_action_active = false;
|
||||
InputDevice* device = input_manager->getDeviceManager()
|
||||
->getLatestUsedDevice();
|
||||
DeviceConfig* config = device->getConfiguration();
|
||||
irr::core::stringw rescue = config->getBindingAsString(PA_RESCUE);
|
||||
|
||||
new TutorialMessageDialog(_("Oops! When you're in trouble, press <%s> "
|
||||
"to be rescued", rescue),
|
||||
false);
|
||||
}
|
||||
else if (m_action == "tutorial_skidding")
|
||||
{
|
||||
m_action_active = false;
|
||||
//World::getWorld()->getRaceGUI()->clearAllMessages();
|
||||
|
||||
InputDevice* device = input_manager->getDeviceManager()
|
||||
->getLatestUsedDevice();
|
||||
DeviceConfig* config = device->getConfiguration();
|
||||
irr::core::stringw skid = config->getBindingAsString(PA_DRIFT);
|
||||
|
||||
|
||||
new TutorialMessageDialog(_("Accelerate and press the <%s> key while "
|
||||
"turning to skid. Skidding for a short "
|
||||
"while can help you turn faster to take "
|
||||
"sharp turns.", skid),
|
||||
true);
|
||||
}
|
||||
else if (m_action == "tutorial_skidding2")
|
||||
{
|
||||
m_action_active = false;
|
||||
World::getWorld()->getRaceGUI()->clearAllMessages();
|
||||
|
||||
new TutorialMessageDialog(_("Note that if you manage to skid for "
|
||||
"several seconds, you will receive a bonus "
|
||||
"speedup as a reward!"),
|
||||
true);
|
||||
}
|
||||
else if (m_action == "tutorial_endmessage")
|
||||
{
|
||||
m_action_active = false;
|
||||
World::getWorld()->getRaceGUI()->clearAllMessages();
|
||||
|
||||
new TutorialMessageDialog(_("You are now ready to race. Good luck!"),
|
||||
true);
|
||||
}*/
|
||||
else if (m_action == "tutorial_exit")
|
||||
{
|
||||
// TODO: move to scripting
|
||||
|
||||
Reference in New Issue
Block a user