Skip to content

Commit

Permalink
Add a default clock mod
Browse files Browse the repository at this point in the history
This mod renders a clock in the top-right corner
and is always available (disabled by default).

It is useful to have a mod available by default
as we work on mod support.
  • Loading branch information
glebm committed Jan 10, 2025
1 parent 4b38771 commit 7668de3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMake/Assets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ set(devilutionx_assets
lua_internal/get_lua_function_signature.lua
lua/devilutionx/events.lua
lua/inspect.lua
lua/mods/clock/init.lua
lua/repl_prelude.lua
nlevels/cutl5w.clx
nlevels/cutl6w.clx
Expand Down
10 changes: 9 additions & 1 deletion Source/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1829,7 +1829,15 @@ std::vector<ModOptions::ModEntry> &ModOptions::GetModEntries()
if (modEntries)
return *modEntries;

std::vector<std::string> modNames = ini->getKeys(name);
std::vector<std::string> modNames = ini->getKeys(key);

// Add mods available by default:
for (const std::string_view modName : { "clock" }) {
if (c_find(modNames, modName) != modNames.end()) continue;
ini->set(key, modName, false);
modNames.emplace_back(modName);
}

std::vector<ModOptions::ModEntry> &newModEntries = modEntries.emplace();
for (auto &modName : modNames) {
newModEntries.emplace_back(modName);
Expand Down
6 changes: 6 additions & 0 deletions assets/lua/mods/clock/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local events = require("devilutionx.events")
local render = require("devilutionx.render")

events.GameDrawComplete.add(function()
render.string(os.date('%H:%M:%S', os.time()), render.screen_width() - 69, 6)
end)

0 comments on commit 7668de3

Please sign in to comment.