aboutsummaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorfluxionary <25628292+fluxionary@users.noreply.github.com>2023-01-25 23:25:46 -0800
committerGitHub <noreply@github.com>2023-01-26 08:25:46 +0100
commit18155b3ebedd24fba5c3cbf109063f64f882d8a6 (patch)
tree5d5d67f8108aa963bb229ee3d282f0eb5a18ca1d /commands
parent675e1e1943598893acf3d652caca18b0193746d9 (diff)
downloadmesecons_debug-18155b3ebedd24fba5c3cbf109063f64f882d8a6.tar.gz
mesecons_debug-18155b3ebedd24fba5c3cbf109063f64f882d8a6.zip
some more updates (#9)
* add proper settings (untested) * more constants -> settings * normalize whitespace between code files * refactor globalsteps in order to simplify logic * minor refactoring * rename file * use mod_storage for persistent data; optimize context initialization * refactoring (moving files around) * rewrite penalty * add settings; document; allow changing while game is running * add command to update settings * update init after splitting commands into files * fix bugs; add debugging tools; too much for one commit... * fix whitelist conversion * add adjustable blinky plant to timer overrides * add some more mesecons nodes with repeating timers * resolve luacheck warnings * tweak hud * Update documentation; parameterize more things; refactor some logic for readability * update lag even when mesecons isn't active * update lag even when mesecons isn't active * tweak default settings * move hud so it doesn't interfere w/ areas * tweak default settings * put the HUD in a place which doesn't conflict w/ areas mod * ensure that actions have a valid position to avoid a crash * stylua * make sure we don't update the wrong HUD * spaces not tabs Co-authored-by: AliasAlreadyTaken <aliasalreadytaken@noreply.example.org3>
Diffstat (limited to 'commands')
-rw-r--r--commands/admin_commands.lua26
-rw-r--r--commands/clear_penalty.lua6
-rw-r--r--commands/create_lag.lua3
-rw-r--r--commands/flush.lua2
-rw-r--r--commands/user_commands.lua25
5 files changed, 27 insertions, 35 deletions
diff --git a/commands/admin_commands.lua b/commands/admin_commands.lua
index 19a7cb6..56b9e05 100644
--- a/commands/admin_commands.lua
+++ b/commands/admin_commands.lua
@@ -6,7 +6,7 @@ minetest.register_chatcommand("mesecons_enable", {
mesecon.queue.actions = {}
mesecons_debug.mesecons_enabled = true
return true, "mesecons enabled"
- end
+ end,
})
minetest.register_chatcommand("mesecons_disable", {
@@ -15,7 +15,7 @@ minetest.register_chatcommand("mesecons_disable", {
func = function()
mesecons_debug.mesecons_enabled = false
return true, "mesecons disabled"
- end
+ end,
})
minetest.register_chatcommand("mesecons_whitelist_get", {
@@ -29,15 +29,9 @@ minetest.register_chatcommand("mesecons_whitelist_get", {
count = count + 1
end
- return true, (
- "mesecons whitelist:\n" ..
- "%s\n" ..
- "%i mapblocks whitelisted"
- ):format(
- table.concat(list, "\n"),
- count
- )
- end
+ return true,
+ ("mesecons whitelist:\n" .. "%s\n" .. "%i mapblocks whitelisted"):format(table.concat(list, "\n"), count)
+ end,
})
minetest.register_chatcommand("mesecons_whitelist_add", {
@@ -55,7 +49,7 @@ minetest.register_chatcommand("mesecons_whitelist_add", {
mesecons_debug.storage:set_string(hash, "1")
return true, "mapblock whitlisted"
- end
+ end,
})
minetest.register_chatcommand("mesecons_whitelist_remove", {
@@ -73,7 +67,7 @@ minetest.register_chatcommand("mesecons_whitelist_remove", {
mesecons_debug.storage:set_string(hash, "")
return true, "mapblock removed from whitelist"
- end
+ end,
})
minetest.register_chatcommand("mesecons_debug_set", {
@@ -86,7 +80,7 @@ minetest.register_chatcommand("mesecons_debug_set", {
return false
end
- local setting, value = params:match('^([a-zA-Z0-9_-]+)%s+(.*)$')
+ local setting, value = params:match("^([a-zA-Z0-9_-]+)%s+(.*)$")
value = tonumber(value)
if not setting or not value then
return false
@@ -99,7 +93,7 @@ minetest.register_chatcommand("mesecons_debug_set", {
mesecons_debug.settings.modify_setting(setting, value)
return true, "setting updated"
- end
+ end,
})
minetest.register_chatcommand("mesecons_debug_get", {
@@ -118,5 +112,5 @@ minetest.register_chatcommand("mesecons_debug_get", {
else
return false, "unknown setting"
end
- end
+ end,
})
diff --git a/commands/clear_penalty.lua b/commands/clear_penalty.lua
index cf64103..e887ed9 100644
--- a/commands/clear_penalty.lua
+++ b/commands/clear_penalty.lua
@@ -3,10 +3,8 @@ local penalty_clear_cooldown = mesecons_debug.settings.penalty_clear_cooldown
-- playername => time-of-last-cooldown
local cooldown_expiry_by_name = {}
-
minetest.register_chatcommand("mesecons_clear_penalty", {
- description = "clears the penalty in the current mapblock " ..
- "(cooldown: " .. penalty_clear_cooldown .. ")",
+ description = "clears the penalty in the current mapblock " .. "(cooldown: " .. penalty_clear_cooldown .. ")",
func = function(name)
local player = minetest.get_player_by_name(name)
if not player then
@@ -29,5 +27,5 @@ minetest.register_chatcommand("mesecons_clear_penalty", {
ctx.penalty = 0
return true, "penalty reset"
- end
+ end,
})
diff --git a/commands/create_lag.lua b/commands/create_lag.lua
index 6598910..9f095da 100644
--- a/commands/create_lag.lua
+++ b/commands/create_lag.lua
@@ -3,13 +3,12 @@ local lag_chance = 0
local wait = mesecons_debug.wait
-
minetest.register_chatcommand("create_lag", {
description = "foce a wait of <duration> us for 1 / <chance> server steps",
params = "<duration> <chance>",
privs = { mesecons_debug = true },
func = function(_name, setting)
- local lag, chance = setting:match('^(%S+)%s+(%S+)$')
+ local lag, chance = setting:match("^(%S+)%s+(%S+)$")
lag = tonumber(lag)
chance = tonumber(chance)
if not (lag and chance) then
diff --git a/commands/flush.lua b/commands/flush.lua
index ba3f3cd..2988691 100644
--- a/commands/flush.lua
+++ b/commands/flush.lua
@@ -4,5 +4,5 @@ minetest.register_chatcommand("mesecons_flush", {
func = function(name)
minetest.log("warning", "Player " .. name .. " flushes mesecon actionqueue")
mesecon.queue.actions = {}
- end
+ end,
})
diff --git a/commands/user_commands.lua b/commands/user_commands.lua
index 5836373..b0e3c14 100644
--- a/commands/user_commands.lua
+++ b/commands/user_commands.lua
@@ -1,3 +1,5 @@
+local f = string.format
+
minetest.register_chatcommand("mesecons_hud", {
description = "mesecons_hud toggle",
func = function(name)
@@ -8,7 +10,7 @@ minetest.register_chatcommand("mesecons_hud", {
else
return true, "mesecons hud disabled"
end
- end
+ end,
})
minetest.register_chatcommand("mesecons_global_stats", {
@@ -26,10 +28,8 @@ minetest.register_chatcommand("mesecons_global_stats", {
local txt
if top_ctx then
- txt = (
- "Most prominent mesecons usage at mapblock %s" ..
- " with %f seconds penalty and %i us average use"
- ):format(
+ txt = f(
+ "Most prominent mesecons usage at mapblock %s" .. " with %f seconds penalty and %i us average use",
minetest.pos_to_string(minetest.get_position_from_hash(top_hash)),
top_ctx.penalty,
top_ctx.avg_micros_per_second
@@ -39,7 +39,7 @@ minetest.register_chatcommand("mesecons_global_stats", {
end
return true, txt
- end
+ end,
})
minetest.register_chatcommand("mesecons_stats", {
@@ -51,10 +51,11 @@ minetest.register_chatcommand("mesecons_stats", {
end
local ctx = mesecons_debug.get_context(player:get_pos())
- return true, ("Mapblock usage: %i us/s (across %i mapblocks)"):format(
- ctx.avg_micros_per_second,
- mesecons_debug.context_store_size
- )
- end
+ return true,
+ f(
+ "Mapblock usage: %i us/s (across %i mapblocks)",
+ ctx.avg_micros_per_second,
+ mesecons_debug.context_store_size
+ )
+ end,
})
-