Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnTW committed Dec 16, 2024
2 parents 2a94e13 + cca3570 commit dca54b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
43 changes: 24 additions & 19 deletions M2TWEOP Code/M2TWEOP library/luaPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ int initLuaPlugin(bool isReload)
exit(0);
}
plugData::data.luaAll.addLegacy();
plugData::data.luaAll.loadLuaScript(luaFile);
plugData::data.luaAll.onPluginLoadF();

if (isReload) {
Expand All @@ -67,6 +68,26 @@ int initLuaPlugin(bool isReload)
return 1;
}

void luaPlugin::loadLuaScript(std::string& luaFilePath)
{
UINT defaultFlags = MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION; // Default type with exclamation icon
// This checks the syntax of the script, but does not execute it
sol::load_result fileRes = luaState.load_file(luaFilePath);
if (!fileRes.valid())
{
sol::error luaError = fileRes;
int result = MessageBoxA(nullptr, luaError.what(), "Lua syntax error!", defaultFlags);
console::handleMessageBoxResult(result);
return;
}
if (sol::protected_function_result result1 = fileRes(); !result1.valid())
{
sol::error luaError = result1;
int result = MessageBoxA(nullptr, luaError.what(), "Lua execution error!", defaultFlags);
console::handleMessageBoxResult(result);
return;
}
}
void reloadLua()
{
const std::string luaFile = globals::dataS.modPath + R"(\eopData\eopScripts\luaPluginScript.lua)";
Expand Down Expand Up @@ -180,22 +201,6 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
return nullptr;
}

// This checks the syntax of the script, but does not execute it
sol::load_result fileRes = luaState.load_file(luaFilePath);
if (!fileRes.valid())
{
sol::error luaError = fileRes;
int result = MessageBoxA(nullptr, luaError.what(), "Lua syntax error!", defaultFlags);
console::handleMessageBoxResult(result);
return nullptr;
}
if (sol::protected_function_result result1 = fileRes(); !result1.valid())
{
sol::error luaError = result1;
int result = MessageBoxA(nullptr, luaError.what(), "Lua execution error!", defaultFlags);
console::handleMessageBoxResult(result);
return nullptr;
}

///M2TWEOP
//@section m2tweopTable
Expand Down Expand Up @@ -904,7 +909,7 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
tables.M2TWEOP.set_function("getFactionRecordNum", &factionHelpers::getFactionRecordNum);

/***
Hides tooltips for unknown units, only use if you use empty card instead of question mark as the UI.
Hides tooltips for unknown units, only use if you use empty card instead of question mark as the UI. Disabled by default.
@function M2TWEOP.hideUnknownUnitTooltips
@tparam bool set
@usage
Expand All @@ -913,7 +918,7 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
tables.M2TWEOP.set_function("hideUnknownUnitTooltips", &m2tweopOptions::setHideUnknownUnitTooltips);

/***
Faction specific unit cards are always chosen if found.
Faction specific unit cards are always chosen if found. Enabled by default.
@function M2TWEOP.handleUnitCards
@tparam bool set
@usage
Expand All @@ -922,7 +927,7 @@ sol::state* luaPlugin::init(std::string& luaFilePath, std::string& modPath)
tables.M2TWEOP.set_function("handleUnitCards", &m2tweopOptions::setHandleUnitCards);

/***
Factions without a family tree or a teutonic one still get marriage offers and produce children.
Factions without a family tree or a teutonic one still get marriage offers and produce children. Enabled by default.
@function M2TWEOP.enableFamilyEventsWithoutTree
@tparam bool set
@usage
Expand Down
2 changes: 1 addition & 1 deletion M2TWEOP Code/M2TWEOP library/luaPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class luaPlugin

//lua functions and events controllers
void onPluginLoadF();

void loadLuaScript(std::string& luaFilePath);
sol::state luaState;
void fillHashMaps();
void fillHashMapsNonCampaign();
Expand Down

0 comments on commit dca54b1

Please sign in to comment.