From ad414ec5c9066d294b09dd18b7ac4bc08cc46abb Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 14 Jul 2022 00:29:56 +0200 Subject: [PATCH] call onInit on hot-reload, cleanup, remove warnings onInit is now called on hot-reload, for the whole plugin. Arguably, this is not expected behavior, since only one file is being reloaded, but this is the easiest way to do it, and the entire hot-reload process is only for development purposes. Open an issue if this breaks your stuff :^) --- include/TConfig.h | 2 +- src/TConfig.cpp | 4 ++-- src/TPluginMonitor.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/TConfig.h b/include/TConfig.h index fe43d5c..d9d6045 100644 --- a/include/TConfig.h +++ b/include/TConfig.h @@ -19,7 +19,7 @@ public: void FlushToFile(); private: - void CreateConfigFile(std::string_view name); + void CreateConfigFile(); void ParseFromFile(std::string_view name); void PrintDebug(); void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, std::string& OutValue); diff --git a/src/TConfig.cpp b/src/TConfig.cpp index b9503b5..fc3a1d1 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -62,7 +62,7 @@ TConfig::TConfig(const std::string& ConfigFileName) Application::SetSubsystemStatus("Config", Application::Status::Starting); if (!fs::exists(mConfigFileName) || !fs::is_regular_file(mConfigFileName)) { beammp_info("No config file found! Generating one..."); - CreateConfigFile(mConfigFileName); + CreateConfigFile(); } if (!mFailed) { if (fs::exists("Server.cfg")) { @@ -138,7 +138,7 @@ void TConfig::FlushToFile() { std::fclose(File); } -void TConfig::CreateConfigFile(std::string_view name) { +void TConfig::CreateConfigFile() { // build from old config Server.cfg try { diff --git a/src/TPluginMonitor.cpp b/src/TPluginMonitor.cpp index 5c940be..4cae6a0 100644 --- a/src/TPluginMonitor.cpp +++ b/src/TPluginMonitor.cpp @@ -47,8 +47,8 @@ void TPluginMonitor::operator()() { TLuaChunk Chunk(Contents, Pair.first, fs::path(Pair.first).parent_path().string()); auto StateID = mEngine->GetStateIDForPlugin(fs::path(Pair.first).parent_path()); auto Res = mEngine->EnqueueScript(StateID, Chunk); - // TODO: call onInit mEngine->AddResultToCheck(Res); + mEngine->ReportErrors(mEngine->TriggerLocalEvent(StateID, "onInit")); } else { // TODO: trigger onFileChanged event beammp_trace("Change detected in file \"" + Pair.first + "\", event trigger not implemented yet");