Skip to content

Commit

Permalink
plugins: Allow plugins to customize their log colors (#823)
Browse files Browse the repository at this point in the history
Allows plugins to specify a custom colour for their indicator in the logs
  • Loading branch information
uniboi authored Oct 14, 2024
1 parent 42d9702 commit 27e1711
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions primedev/plugins/interfaces/IPluginId.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class PluginString : int
enum class PluginField : int
{
CONTEXT = 0,
COLOR = 1,
};

// an interface that is required from every plugin to query data about it
Expand Down
10 changes: 9 additions & 1 deletion primedev/plugins/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bool isValidSquirrelIdentifier(std::string s)

Plugin::Plugin(std::string path)
: m_location(path)
, m_logColor(NS::Colors::PLUGIN)
{
HMODULE pluginModule = GetModuleHandleA(path.c_str());

Expand Down Expand Up @@ -69,6 +70,13 @@ Plugin::Plugin(std::string path)
m_runOnServer = context & PluginContext::DEDICATED;
m_runOnClient = context & PluginContext::CLIENT;

int64_t logColor = m_pluginId->GetField(PluginField::COLOR);
// Apply custom colour if plugin has specified one
if ((logColor & 0xFFFFFF) != 0)
{
m_logColor = Color((int)(logColor & 0xFF), (int)((logColor >> 8) & 0xFF), (int)((logColor >> 16) & 0xFF));
}

if (!name)
{
NS::log::PLUGINSYS->error("Could not load name of plugin at '{}'", path);
Expand Down Expand Up @@ -105,7 +113,7 @@ Plugin::Plugin(std::string path)
return;
}

m_logger = std::make_shared<ColoredLogger>(m_logName, NS::Colors::PLUGIN);
m_logger = std::make_shared<ColoredLogger>(m_logName, m_logColor);
RegisterLogger(m_logger);

if (IsDedicatedServer() && !m_runOnServer)
Expand Down
1 change: 1 addition & 0 deletions primedev/plugins/plugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Plugin
std::string m_location; // path of the dll
bool m_runOnServer;
bool m_runOnClient;
Color m_logColor;

public:
HMODULE m_handle;
Expand Down

0 comments on commit 27e1711

Please sign in to comment.