diff options
author | BuckarooBanzay <BuckarooBanzay@users.noreply.github.com> | 2021-05-14 14:02:53 +0200 |
---|---|---|
committer | BuckarooBanzay <BuckarooBanzay@users.noreply.github.com> | 2021-05-14 14:02:53 +0200 |
commit | 8cd02607bb1f76032970e9d7cf0dadbd17b3cf76 (patch) | |
tree | 2844b3b40bc50ef4d5ada6f7dfd7f195c431ef57 | |
parent | 8f5d9113040726456dc816f2a353cd6708d64d74 (diff) | |
download | mesecons_debug-8cd02607bb1f76032970e9d7cf0dadbd17b3cf76.tar.gz mesecons_debug-8cd02607bb1f76032970e9d7cf0dadbd17b3cf76.zip |
add "mesecons_debug:penalty_controller"
-rw-r--r-- | .luacheckrc | 3 | ||||
-rw-r--r-- | README.md | 28 | ||||
-rw-r--r-- | init.lua | 4 | ||||
-rw-r--r-- | mod.conf | 2 | ||||
-rw-r--r-- | penalty_controller.lua | 74 | ||||
-rw-r--r-- | textures/penalty_controller_top.png | bin | 0 -> 3435 bytes |
6 files changed, 109 insertions, 2 deletions
diff --git a/.luacheckrc b/.luacheckrc index 1faa5e9..50f0eeb 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -14,5 +14,6 @@ read_globals = { "vector", "ItemStack", "dump", - "monitoring" + "monitoring", + "digiline" } @@ -30,3 +30,31 @@ All of these commands require the `mesecons_debug` privilege. * `/mesecons_whitelist_get` shows the list of whitelisted mapblocks * `/mesecons_whitelist_add` adds the current mapblock to the whitelist * `/mesecons_whitelist_remove` removes the current mapblock from the whitelist + +## Penalty controller + +Can query the penalty and usage values of the placed-in mapblock (requires the `digiline` mod) + +Example code to query it with the luacontroller: + +```lua +if event.type == "program" then + digiline_send("penalty_ctrl", "GET") +end + +if event.type == "digiline" and event.channel == "penalty_ctrl" then + --[[ + event.msg = { + micros = 0, + avg_micros = 0, + penalty = 0, + whitelisted = false + } + --]] +end +``` + +# License + +* textures/penalty_controller_top.png + * CC BY-SA 3.0 https://cheapiesystems.com/git/digistuff @@ -37,6 +37,10 @@ dofile(MP.."/luacontroller.lua") dofile(MP.."/chatcommands.lua") dofile(MP.."/hud.lua") +if minetest.get_modpath("digilines") then + dofile(MP.."/penalty_controller.lua") +end + mesecons_debug.load_whitelist() print("[OK] mesecons_debug loaded") @@ -1,3 +1,3 @@ name = mesecons_debug depends = mesecons, mesecons_blinkyplant, mesecons_luacontroller -optional_depends = monitoring +optional_depends = monitoring, digilines diff --git a/penalty_controller.lua b/penalty_controller.lua new file mode 100644 index 0000000..37d83a8 --- /dev/null +++ b/penalty_controller.lua @@ -0,0 +1,74 @@ + +minetest.register_node("mesecons_debug:penalty_controller", { + description = "Mesecons penalty controller", + groups = { + cracky=3 + }, + + 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, + penalty = ctx.penalty, + whitelisted = ctx.whitelisted + }) + end + end + } + } +}) diff --git a/textures/penalty_controller_top.png b/textures/penalty_controller_top.png Binary files differnew file mode 100644 index 0000000..da49613 --- /dev/null +++ b/textures/penalty_controller_top.png |