diff options
author | fluxionary <25628292+fluxionary@users.noreply.github.com> | 2022-02-13 06:54:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-13 15:54:41 +0100 |
commit | 2651262fa3134415f349f63840c89486fabd9063 (patch) | |
tree | 3fa7f2ac228e662b4e9bc8071acc2f0650c44e65 /nodes | |
parent | 1a41379e1d7ae69347f0e6ee6a997234f7590793 (diff) | |
download | mesecons_debug-2651262fa3134415f349f63840c89486fabd9063.tar.gz mesecons_debug-2651262fa3134415f349f63840c89486fabd9063.zip |
rework mesecons debug to be more flexible (#7)
* 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
Diffstat (limited to 'nodes')
-rw-r--r-- | nodes/mesecons_lagger.lua | 59 | ||||
-rw-r--r-- | nodes/penalty_controller.lua | 75 |
2 files changed, 134 insertions, 0 deletions
diff --git a/nodes/mesecons_lagger.lua b/nodes/mesecons_lagger.lua new file mode 100644 index 0000000..e4d966e --- /dev/null +++ b/nodes/mesecons_lagger.lua @@ -0,0 +1,59 @@ + +local wait = mesecons_debug.wait + +mesecon.queue:add_function("create_lag", function(_pos, duration) + wait(duration) +end) + + +minetest.register_node("mesecons_debug:mesecons_lagger", { + description = "machine for adding artificial mesecons lag", + group = { + not_in_creative_inventory = 1, + unbreakable = 1, + }, + tiles = {"default_mese_block.png^[colorize:#F00:128"}, + on_blast = function() end, + drop = "", + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_float("lag", 0.0) + meta:set_float("chance", 0.0) + meta:set_string("formspec", + ("field[lag;Lag (in us);%s]field[chance;Chance;%s]"):format(0.0, 0.0)) + + local timer = minetest.get_node_timer(pos) + timer:start(0) + end, + + on_receive_fields = function(pos, _formname, fields, sender) + if not minetest.check_player_privs(sender, "mesecons_debug") then + return + end + local meta = minetest.get_meta(pos) + if fields.lag then + meta:set_float("lag", fields.lag) + end + if fields.chance then + meta:set_float("chance", fields.chance) + end + meta:set_string("formspec", + ("field[lag;Lag (in us);%s]field[chance;Chance;%s]"):format( + meta:get_float("lag"), meta:get_float("chance"))) + + end, + + on_timer = function(pos, _elapsed) + local meta = minetest.get_meta(pos) + local lag = meta:get_float("lag") + local chance = meta:get_float("chance") + if lag > 0 and chance > 0 then + if math.random() < 1 / chance then + mesecon.queue:add_action(pos, "create_lag", { lag }) + end + end + + return true + end, +}) diff --git a/nodes/penalty_controller.lua b/nodes/penalty_controller.lua new file mode 100644 index 0000000..6e160c1 --- /dev/null +++ b/nodes/penalty_controller.lua @@ -0,0 +1,75 @@ +minetest.register_node("mesecons_debug:penalty_controller", { + description = "Mesecons penalty controller", + groups = { + cracky = 3, + not_in_creative_inventory = 1, + }, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", "field[channel;Channel;${channel}") + end, + + tiles = { + "penalty_controller_top.png", + "jeija_microcontroller_bottom.png", + "jeija_microcontroller_sides.png", + "jeija_microcontroller_sides.png", + "jeija_microcontroller_sides.png", + "jeija_microcontroller_sides.png" + }, + + inventory_image = "penalty_controller_top.png", + drawtype = "nodebox", + selection_box = { + --From luacontroller + type = "fixed", + fixed = { -8 / 16, -8 / 16, -8 / 16, 8 / 16, -5 / 16, 8 / 16 }, + }, + node_box = { + --From Luacontroller + type = "fixed", + fixed = { + { -8 / 16, -8 / 16, -8 / 16, 8 / 16, -7 / 16, 8 / 16 }, -- Bottom slab + { -5 / 16, -7 / 16, -5 / 16, 5 / 16, -6 / 16, 5 / 16 }, -- Circuit board + { -3 / 16, -6 / 16, -3 / 16, 3 / 16, -5 / 16, 3 / 16 }, -- IC + } + }, + + paramtype = "light", + sunlight_propagates = true, + + on_receive_fields = function(pos, _, fields, sender) + local name = sender:get_player_name() + if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, { protection_bypass = true }) then + minetest.record_protection_violation(pos, name) + return + end + local meta = minetest.get_meta(pos) + if fields.channel then + meta:set_string("channel", fields.channel) + end + end, + + digiline = { + receptor = {}, + effector = { + action = function(pos, _, channel, msg) + local meta = minetest.get_meta(pos) + if meta:get_string("channel") ~= channel then + return + end + if msg == "GET" then + local ctx = mesecons_debug.get_context(pos) + -- copy and send values + digiline:receptor_send(pos, digiline.rules.default, channel, { + micros = ctx.micros, + avg_micros = ctx.avg_micros_per_second, + penalty = ctx.penalty, + whitelisted = ctx.whitelisted + }) + end + end + } + } +}) |