Skip to content

Commit

Permalink
DynRPG: Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Nov 3, 2024
1 parent 814ec8a commit 1ccac18
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/dynrpg_easyrpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool DynRpg::EasyRpgPlugin::EasyCall(dyn_arg_list args, bool& do_yield, Game_Int
return true;
}

for (auto& plugin: Main_Data::game_dynrpg->plugins) {
for (auto& plugin: instance.plugins) {
if (plugin->Invoke(func_name, args.subspan(1), do_yield, interpreter)) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dynrpg_easyrpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace DynRpg {
*/
class EasyRpgPlugin : public DynRpgPlugin {
public:
EasyRpgPlugin() : DynRpgPlugin("EasyRpgPlugin") {}
EasyRpgPlugin(Game_DynRpg& instance) : DynRpgPlugin("EasyRpgPlugin", instance) {}

bool Invoke(StringView func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) override;
void Load(const std::vector<uint8_t>& buffer) override;
Expand Down
2 changes: 1 addition & 1 deletion src/dynrpg_textplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
namespace DynRpg {
class TextPlugin : public DynRpgPlugin {
public:
TextPlugin() : DynRpgPlugin("DynTextPlugin") {}
TextPlugin(Game_DynRpg& instance) : DynRpgPlugin("DynTextPlugin", instance) {}
~TextPlugin() override;

bool Invoke(StringView func, dyn_arg_list args, bool& do_yield, Game_Interpreter* interpreter) override;
Expand Down
4 changes: 2 additions & 2 deletions src/game_dynrpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ void Game_DynRpg::InitPlugins() {
}

if (Player::IsPatchDynRpg() || Player::HasEasyRpgExtensions()) {
plugins.emplace_back(new DynRpg::EasyRpgPlugin());
plugins.emplace_back(new DynRpg::EasyRpgPlugin(*this));
}

if (Player::IsPatchDynRpg()) {
plugins.emplace_back(new DynRpg::TextPlugin());
plugins.emplace_back(new DynRpg::TextPlugin(*this));
}

plugins_loaded = true;
Expand Down
5 changes: 4 additions & 1 deletion src/game_dynrpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class Game_DynRpg {
/** Base class for implementing a DynRpg Plugins */
class DynRpgPlugin {
public:
explicit DynRpgPlugin(std::string identifier) : identifier(std::move(identifier)) {}
explicit DynRpgPlugin(std::string identifier, Game_DynRpg& instance) : instance(instance), identifier(std::move(identifier)) {}
DynRpgPlugin() = delete;
virtual ~DynRpgPlugin() = default;

Expand All @@ -164,6 +164,9 @@ class DynRpgPlugin {
virtual void Load(const std::vector<uint8_t>&) {}
virtual std::vector<uint8_t> Save() { return {}; }

protected:
Game_DynRpg& instance;

private:
std::string identifier;
};
Expand Down
2 changes: 2 additions & 0 deletions tests/dynrpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ TEST_CASE("easyrpg dynrpg invoke") {
Game_DynRpg dyn;
const MockActor m;

Player::game_config.patch_dynrpg.Set(true);

std::vector<int32_t> vars = {-1};
Main_Data::game_variables->SetData(vars);
Main_Data::game_variables->SetWarning(0);
Expand Down
6 changes: 3 additions & 3 deletions tests/test_mock_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MockActor {
public:
MockActor(int eng = Player::EngineRpg2k3 | Player::EngineEnglish)
{
_engine = Player::game_config.engine;
_config = Player::game_config;
Player::game_config.engine = eng;

InitEmptyDB();
Expand All @@ -100,10 +100,10 @@ class MockActor {
Main_Data::Cleanup();

lcf::Data::data = {};
Player::game_config.engine = _engine;
Player::game_config = _config;
}
private:
int _engine = {};
Game_ConfigGame _config = {};
};

struct MockBattle : public MockActor {
Expand Down

0 comments on commit 1ccac18

Please sign in to comment.