Skip to content

Commit

Permalink
Updated ro.po by @1NSH4N3, scripting, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Nov 22, 2023
1 parent 4efef9b commit a3a5f14
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 245 deletions.
Binary file modified Content/Translations/ro.mo
Binary file not shown.
53 changes: 46 additions & 7 deletions Content/Translations/ro.po
Original file line number Diff line number Diff line change
Expand Up @@ -1432,11 +1432,11 @@ msgstr "Joacă Niveluri Customizate"

#: Sources/Jazz2/UI/Menu/BeginSection.cpp:47
msgid "Connect To Server"
msgstr ""
msgstr "Conectare la server"

#: Sources/Jazz2/UI/Menu/BeginSection.cpp:48
msgid "Create Server"
msgstr ""
msgstr "Creați un server"

#. TRANSLATORS: Menu item in main menu
#: Sources/Jazz2/UI/Menu/BeginSection.cpp:52
Expand Down Expand Up @@ -1506,7 +1506,7 @@ msgstr "Comenzi Tactile"
#: Sources/Jazz2/UI/Menu/ControlsOptionsSection.cpp:22
#: Sources/Jazz2/UI/Menu/InputDiagnosticsSection.cpp:59
msgid "Input Diagnostics"
msgstr ""
msgstr "Diagnosticarea intrărilor"

#. TRANSLATORS: Menu item in Options > Controls section (Android only)
#: Sources/Jazz2/UI/Menu/ControlsOptionsSection.cpp:25
Expand Down Expand Up @@ -1617,7 +1617,7 @@ msgstr "Scripturi"
#. TRANSLATORS: Menu item in Options > Gameplay section
#: Sources/Jazz2/UI/Menu/GameplayOptionsSection.cpp:40
msgid "Browse \"Source\" Directory"
msgstr ""
msgstr "Răsfoiți directorul sursa \"Source\""

#. TRANSLATORS: Menu item in Options > Gameplay section
#: Sources/Jazz2/UI/Menu/GameplayOptionsSection.cpp:44
Expand Down Expand Up @@ -1704,7 +1704,7 @@ msgstr "Niciun episod nou nu a fost importat!"

#: Sources/Jazz2/UI/Menu/InputDiagnosticsSection.cpp:74
msgid "No gamepads are detected!"
msgstr ""
msgstr "Nu sunt detectate gamepad-uri!"

#. TRANSLATORS: Menu item in Options section
#: Sources/Jazz2/UI/Menu/OptionsSection.cpp:21
Expand Down Expand Up @@ -1863,12 +1863,12 @@ msgstr "Poți ajusta poziția zonelor tactile prin a le trage și fixa."

#: Sources/Main.cpp:260 Sources/Main.cpp:322
msgid "Creating server..."
msgstr ""
msgstr "Crearea serverului..."

#: Sources/Main.cpp:275 Sources/Main.cpp:335
#, c-format
msgid "Connecting to %s:%u..."
msgstr ""
msgstr "Conectare la %s:%u..."

#: Sources/Main.cpp:503 Sources/Main.cpp:541
msgid ""
Expand All @@ -1891,6 +1891,10 @@ msgid ""
"\n"
"Your client version is not compatible with the server."
msgstr ""
"\f[c:0x704a4a]Nu se poate conecta la server!\f[c]\n"
"\n"
"\n"
"Versiunea clientului dvs. nu este compatibilă cu serverul."

#: Sources/Main.cpp:634
msgid ""
Expand All @@ -1900,6 +1904,11 @@ msgid ""
"Server capacity is full.\n"
"Please try it later."
msgstr ""
"\f[c:0x704a4a]Nu se poate conecta la server!\f[c]\n"
"\n"
"\n"
"Capacitatea serverului este completă.\n"
"Vă rugăm să încercați mai târziu."

#: Sources/Main.cpp:635
msgid ""
Expand All @@ -1909,6 +1918,12 @@ msgid ""
"Server is not in a state where it can process your request.\n"
"Please try again in a few seconds."
msgstr ""
"\f[c:0x704a4a]Nu se poate conecta la server!\f[c]\n"
"\n"
"\n"
"Serverul nu se află într-o stare în care să poată procesa cererea "
"dumneavoastră.\n"
"Vă rugăm să încercați din nou în câteva secunde."

#: Sources/Main.cpp:636
msgid ""
Expand All @@ -1918,6 +1933,11 @@ msgid ""
"Server is shutting down.\n"
"Please try it later."
msgstr ""
"\f[c:0x704a4a]Conexiunea a fost închisă!\f[c]\n"
"\n"
"\n"
"Serverul se închide.\n"
"Vă rugăm să încercați mai târziu."

#: Sources/Main.cpp:637
msgid ""
Expand All @@ -1927,6 +1947,11 @@ msgid ""
"Please try it again and if the problem persists,\n"
"check your network connection."
msgstr ""
"\f[c:0x704a4a]Conexiunea a fost pierdută!\f[c]\n"
"\n"
"\n"
"Vă rugăm să încercați din nou și dacă problema persistă,\n"
"verificați conexiunea de rețea."

#: Sources/Main.cpp:638
msgid ""
Expand All @@ -1935,6 +1960,10 @@ msgid ""
"\n"
"The server is not responding for connection request."
msgstr ""
"\f[c:0x704a4a]Nu se poate conecta la server!\f[c]\n"
"\n"
"\n"
"Serverul nu răspunde la cererea de conectare."

#: Sources/Main.cpp:639
msgid ""
Expand All @@ -1944,6 +1973,11 @@ msgid ""
"You have been \f[c:0x907050]kicked\f[c] off the server.\n"
"Contact server administrators for more information."
msgstr ""
"\f[c:0x704a4a]Conexiunea a fost închisă!\f[c]\n"
"\n"
"\n"
"Ați fost \f[c:0x90705050]dat afară\f[c] de pe server.\n"
"Contactați administratorii serverului pentru mai multe informații."

#: Sources/Main.cpp:640
msgid ""
Expand All @@ -1953,6 +1987,11 @@ msgid ""
"You have been \f[c:0x725040]banned\f[c] off the server.\n"
"Contact server administrators for more information."
msgstr ""
"\f[c:0x704a4a]Conexiunea a fost închisă!\f[c]\n"
"\n"
"\n"
"Ați fost \f[c:0x725040]banat\f[c] de pe server.\n"
"Contactați administratorii serverului pentru mai multe informații."

#~ msgid "Error"
#~ msgstr "Eroare"
93 changes: 69 additions & 24 deletions Sources/Jazz2/Scripting/LevelScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,27 @@ namespace Jazz2::Scripting
}

LevelScriptLoader::LevelScriptLoader(LevelHandler* levelHandler, const StringView& scriptPath)
:
_levelHandler(levelHandler),
_onLevelUpdate(nullptr),
_onLevelUpdateLastFrame(-1)
: _levelHandler(levelHandler), _onLevelUpdate(nullptr), _onLevelUpdateLastFrame(-1), _onDrawAmmo(nullptr),
_onDrawHealth(nullptr), _onDrawLives(nullptr), _onDrawPlayerTimer(nullptr), _onDrawScore(nullptr), _onDrawGameModeHUD(nullptr)
{
// Try to load the script
HashMap<String, bool> DefinedSymbols = {
#if defined(DEATH_TARGET_EMSCRIPTEN)
{ "TARGET_EMSCRIPTEN"_s, true },
#elif defined(DEATH_TARGET_ANDROID)
#if defined(DEATH_TARGET_ANDROID)
{ "TARGET_ANDROID"_s, true },
#elif defined(DEATH_TARGET_APPLE)
{ "TARGET_APPLE"_s, true },
# if defined(DEATH_TARGET_IOS)
{ "TARGET_IOS"_s, true },
# endif
#elif defined(DEATH_TARGET_EMSCRIPTEN)
{ "TARGET_EMSCRIPTEN"_s, true },
#elif defined(DEATH_TARGET_WINDOWS)
{ "TARGET_WINDOWS"_s, true },
# if defined(DEATH_TARGET_WINDOWS_RT)
{ "TARGET_WINDOWS_RT"_s, true },
# endif
#elif defined(DEATH_TARGET_SWITCH)
{ "TARGET_SWITCH"_s, true },
#elif defined(DEATH_TARGET_UNIX)
{ "TARGET_UNIX"_s, true },
#endif
Expand All @@ -91,6 +91,9 @@ namespace Jazz2::Scripting
#if defined(WITH_OPENMPT)
{ "WITH_OPENMPT"_s, true },
#endif
#if defined(WITH_IMGUI)
{ "WITH_IMGUI"_s, true },
#endif
#if defined(WITH_THREADS)
{ "WITH_THREADS"_s, true },
#endif
Expand All @@ -115,14 +118,21 @@ namespace Jazz2::Scripting
break;
}

int r = Build(); RETURN_ASSERT_MSG(r >= 0, "Cannot compile the script. Please correct the code and try again.");
std::int32_t r = Build(); RETURN_ASSERT_MSG(r >= 0, "Cannot compile the script. Please correct the code and try again.");

switch (_scriptContextType) {
case ScriptContextType::Legacy:
_onLevelUpdate = _module->GetFunctionByDecl("void onMain()");
_onDrawAmmo = _module->GetFunctionByDecl("bool onDrawAmmo(jjPLAYER@ player, jjCANVAS@ canvas)");
_onDrawHealth = _module->GetFunctionByDecl("bool onDrawHealth(jjPLAYER@ player, jjCANVAS@ canvas)");
_onDrawLives = _module->GetFunctionByDecl("bool onDrawLives(jjPLAYER@ player, jjCANVAS@ canvas)");
_onDrawPlayerTimer = _module->GetFunctionByDecl("bool onDrawPlayerTimer(jjPLAYER@ player, jjCANVAS@ canvas)");
_onDrawScore = _module->GetFunctionByDecl("bool onDrawScore(jjPLAYER@ player, jjCANVAS@ canvas)");
_onDrawGameModeHUD = _module->GetFunctionByDecl("bool onDrawGameModeHUD(jjPLAYER@ player, jjCANVAS@ canvas)");
break;
case ScriptContextType::Standard:
_onLevelUpdate = _module->GetFunctionByDecl("void onLevelUpdate(float)");
// TODO: Add draw callbacks
break;
}
}
Expand Down Expand Up @@ -159,7 +169,7 @@ namespace Jazz2::Scripting
asIScriptContext* ctx = _engine->RequestContext();

ctx->Prepare(func);
int r = ctx->Execute();
std::int32_t r = ctx->Execute();
if (r == asEXECUTION_EXCEPTION) {
OnException(ctx);
}
Expand All @@ -177,7 +187,7 @@ namespace Jazz2::Scripting
asIScriptContext* ctx = _engine->RequestContext();

ctx->Prepare(func);
int r = ctx->Execute();
std::int32_t r = ctx->Execute();
if (r == asEXECUTION_EXCEPTION) {
OnException(ctx);
}
Expand All @@ -195,7 +205,7 @@ namespace Jazz2::Scripting
asIScriptContext* ctx = _engine->RequestContext();

ctx->Prepare(func);
int r = ctx->Execute();
std::int32_t r = ctx->Execute();
if (r == asEXECUTION_EXCEPTION) {
OnException(ctx);
}
Expand All @@ -210,34 +220,33 @@ namespace Jazz2::Scripting
asIScriptFunction* onPlayer = _module->GetFunctionByName("void onPlayer(jjPLAYER@)");

if (_onLevelUpdate == nullptr && onPlayer == nullptr) {
_onLevelUpdateLastFrame = (int32_t)_levelHandler->_elapsedFrames;
_onLevelUpdateLastFrame = (std::int32_t)_levelHandler->_elapsedFrames;
return;
}

// Legacy context requires fixed frame count per second
asIScriptContext* ctx = _engine->RequestContext();

// It should update at 70 FPS instead of 60 FPS
int32_t currentFrame = (int32_t)(_levelHandler->_elapsedFrames * (70.0f / 60.0f));
std::int32_t currentFrame = (std::int32_t)(_levelHandler->_elapsedFrames * (70.0f / 60.0f));
while (_onLevelUpdateLastFrame <= currentFrame) {
if (_onLevelUpdate != nullptr) {
ctx->Prepare(_onLevelUpdate);
int r = ctx->Execute();
std::int32_t r = ctx->Execute();
if (r == asEXECUTION_EXCEPTION) {
OnException(ctx);
// Don't call the method again if an exception occurs
_onLevelUpdate = nullptr;
}
}
if (onPlayer != nullptr) {
for (auto player : _levelHandler->_players) {
for (auto* player : _levelHandler->_players) {
ctx->Prepare(onPlayer);

void* mem = asAllocMem(sizeof(jjPLAYER));
jjPLAYER* playerWrapper = new(mem) jjPLAYER(this, player);
jjPLAYER* playerWrapper = new(asAllocMem(sizeof(jjPLAYER))) jjPLAYER(this, player);
ctx->SetArgObject(0, playerWrapper);

int r = ctx->Execute();
std::int32_t r = ctx->Execute();
if (r == asEXECUTION_EXCEPTION) {
OnException(ctx);
// Don't call the method again if an exception occurs
Expand All @@ -263,7 +272,7 @@ namespace Jazz2::Scripting
asIScriptContext* ctx = _engine->RequestContext();
ctx->Prepare(_onLevelUpdate);
ctx->SetArgFloat(0, timeMult);
int r = ctx->Execute();
std::int32_t r = ctx->Execute();
if (r == asEXECUTION_EXCEPTION) {
LOGE("An exception \"%s\" occurred in \"%s\". Please correct the code and try again.", ctx->GetExceptionString(), ctx->GetExceptionFunction()->GetDeclaration());
// Don't call the method again if an exception occurs
Expand All @@ -286,14 +295,13 @@ namespace Jazz2::Scripting
ctx->Prepare(func);

jjPLAYER* playerWrapper = nullptr;
int paramIdx = 0;
int typeId = 0;
std::int32_t paramIdx = 0;
std::int32_t typeId = 0;
if (func->GetParam(paramIdx, &typeId) >= 0) {
if ((typeId & (asTYPEID_OBJHANDLE | asTYPEID_APPOBJECT)) == (asTYPEID_OBJHANDLE | asTYPEID_APPOBJECT)) {
asITypeInfo* typeInfo = _engine->GetTypeInfoById(typeId);
if (typeInfo->GetName() == "jjPLAYER"_s) {
void* mem = asAllocMem(sizeof(jjPLAYER));
playerWrapper = new(mem) jjPLAYER(this, _levelHandler->_players[0]);
playerWrapper = new(asAllocMem(sizeof(jjPLAYER))) jjPLAYER(this, _levelHandler->_players[0]);
ctx->SetArgObject(0, playerWrapper);
}
paramIdx++;
Expand All @@ -306,7 +314,7 @@ namespace Jazz2::Scripting
}
}

int r = ctx->Execute();
std::int32_t r = ctx->Execute();
if (r == asEXECUTION_EXCEPTION) {
LOGE("An exception \"%s\" occurred in \"%s\". Please correct the code and try again.", ctx->GetExceptionString(), ctx->GetExceptionFunction()->GetDeclaration());
}
Expand Down Expand Up @@ -364,6 +372,43 @@ namespace Jazz2::Scripting
LOGW("Callback function \"%s\" was not found in the script. Please correct the code and try again.", funcName);
}

bool LevelScriptLoader::OnDraw(UI::HUD* hud, DrawType type)
{
asIScriptFunction* func;
switch (type) {
case DrawType::WeaponAmmo: func = _onDrawAmmo; break;
case DrawType::Health: func = _onDrawHealth; break;
case DrawType::Lives: func = _onDrawLives; break;
case DrawType::PlayerTimer: func = _onDrawPlayerTimer; break;
case DrawType::Score: func = _onDrawScore; break;
case DrawType::GameModeHUD: func = _onDrawGameModeHUD; break;
default: func = nullptr; break;
}

bool overrideDraw = false;
if (func != nullptr) {
asIScriptContext* ctx = _engine->RequestContext();
ctx->Prepare(func);

jjPLAYER* playerWrapper = new(asAllocMem(sizeof(jjPLAYER))) jjPLAYER(this, _levelHandler->_players[0]);
ctx->SetArgObject(0, playerWrapper);

jjCANVAS* canvasWrapper = new(asAllocMem(sizeof(jjCANVAS))) jjCANVAS(); // TODO
ctx->SetArgObject(1, canvasWrapper);

std::int32_t r = ctx->Execute();
if (r == asEXECUTION_FINISHED) {
overrideDraw = (ctx->GetReturnByte() != 0);
} else if (r == asEXECUTION_EXCEPTION) {
OnException(ctx);
}

_engine->ReturnContext(ctx);
}

return overrideDraw;
}

void LevelScriptLoader::RegisterBuiltInFunctions(asIScriptEngine* engine)
{
RegisterMath(engine);
Expand Down
Loading

0 comments on commit a3a5f14

Please sign in to comment.