diff options
author | gpcf <gpcf@gpcf.eu> | 2023-05-14 14:02:03 +0200 |
---|---|---|
committer | gpcf <gpcf@gpcf.eu> | 2023-05-14 14:02:03 +0200 |
commit | bc3740c670621fe2443eeb56bf27db0e689da47d (patch) | |
tree | e6f03819abcc9cb4521e91c6f34181a67cf07e72 /init.lua | |
parent | e0cb875a9f356207ad327558ce335adab54c2531 (diff) | |
download | departureboards-bc3740c670621fe2443eeb56bf27db0e689da47d.tar.gz departureboards-bc3740c670621fe2443eeb56bf27db0e689da47d.tar.bz2 departureboards-bc3740c670621fe2443eeb56bf27db0e689da47d.zip |
Add digilines support, animation when changing
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 88 |
1 files changed, 70 insertions, 18 deletions
@@ -2,21 +2,56 @@ local function escape_texture(str) return str:gsub("[%[%()^:]", "\\%1") end -function render_depboard(pos, objref) - local font = font_api.get_font("metro") - local line = font:render("10", font:get_height(1)*15, font:get_height(1), {halign="left", color="#ffffff"}) - local dest = font:render("Origin Marcuse", font:get_height(1)*15, font:get_height(1), {halign="left", color="#ffffff"}) - local remark = font:render("5 minutes Delay", font:get_height(1)*15, font:get_height(1), {halign="left", color="#ff0000"}) - local m = font:render("10", font:get_height(1)*15, font:get_height(1), {halign="left", color="#ffffff"}) - local s = font:render("40", font:get_height(1)*15, font:get_height(1), {halign="left", color="#ffffff"}) - local line_color = "#00ffff" - objref:set_properties({ textures= {"[combine:256x256:0,0=station_sign.png\\^(line_bg.png\\^\\[colorize\\:"..line_color.."\\:150)\\^\\[resize\\:256x256:200,100="..escape_texture(line)..":10,100="..escape_texture(dest)..":200,127="..escape_texture(m)..":228,127="..escape_texture(s)..":10,127="..escape_texture(remark)}, - visual_size = {x=3, y=3} }) +departureboards = {} + +departureboards.contents = {} +local cts = departureboards.contents +local function render_depboard(pos, objref) + local c = cts[minetest.hash_node_position(pos)] + local meta = minetest.get_meta(pos) + local changed = false + local tb = {} + if meta then + tb = minetest.deserialize(meta:get_string("contents") or "") or {} + if not c then + c = tb + end + for k,v in pairs(c) do + if not tb[k] or tb[k] ~= v then + changed = true + end + tb[k] = tostring(v) + end + meta:set_string("contents", minetest.serialize(tb)) + end + if not c then + c = {} + end + local font = font_api.get_font("metro") + local line = font:render(tb.line or "", font:get_height(1)*15, font:get_height(1), {halign="left", color=tb.lfg or "#ff0000"}) + local dest = font:render(tb.dest or "", font:get_height(1)*15, font:get_height(1), {halign="left", color="#ffffff"}) + local remark = font:render(tb.rem or "", font:get_height(1)*15, font:get_height(1), {halign="left", color=tb.remcolor or "#ff0000"}) + local m = font:render(tb.m or "", font:get_height(1)*15, font:get_height(1), {halign="left", color="#ffffff"}) + local s = font:render(tb.s or "", font:get_height(1)*15, font:get_height(1), {halign="left", color="#ffffff"}) + local line_color = tb.lbg or "#00ffff" + local delay = 0 + if changed then + delay = 1 -- add here splitflap sound + end + objref:set_properties({ is_visible=false }) + minetest.after(delay, function () objref:set_properties({ textures= {"[combine:256x256:0,0=station_sign.png\\^(line_bg.png\\^\\[colorize\\:"..line_color.."\\:150)\\^\\[resize\\:256x256:200,100="..escape_texture(line)..":10,100="..escape_texture(dest)..":200,127="..escape_texture(m)..":228,127="..escape_texture(s)..":10,127="..escape_texture(remark)}, + visual_size = {x=3, y=3}, is_visible=true }) end) end + +local function on_digiline_receive(pos, _, channel, msg) + cts[minetest.hash_node_position(pos)] = msg + display_api.update_entities(pos) +end + display_api.register_display_entity("departureboards:display") minetest.register_node("departureboards:departureboard", { @@ -26,12 +61,16 @@ minetest.register_node("departureboards:departureboard", { drawtype = "nodebox", node_box = { type = "fixed", - fixed = {-3/2, -1/2, 0.5, - 3/2, 1/2, 0.5 - 0.1}, + fixed = {-3/6, -1/6, 0.5/3, + 3/6, 1/6, 0.5/3 - 0.03}, }, + selection_box = { + type = "fixed", + fixed={-1.5,-1/2, 0.5, 1.5, 1/2, 0.5-0.1}}, + visual_scale=3, tiles = { "signs_road_sides.png", "signs_road_sides.png", - "signs_road_sides.png", "signs_road_sides.png", - "signs_road_sides.png", "signs_road_sides.png" }, + "signs_road_sides.png", "signs_road_sides.png", "signs_road_sides.png", + {name="animation_frames.png", animation={type="vertical_frames", aspect_w=96, aspect_h=96, length=1.0}}}, groups = {choppy=2, dig_immediate=2, not_blocking_trains=1, display_api=1}, sounds = default.node_sound_defaults(), display_entities = { @@ -48,16 +87,29 @@ minetest.register_node("departureboards:departureboard", { on_construct = function(pos) local ndef = minetest.registered_nodes[minetest.get_node(pos).name] local meta = minetest.get_meta(pos) - meta:set_string("font", ndef.display_entities.font_name or - font_api.get_default_font_name()) - signs_api.set_formspec(pos) + meta:set_string("contents", minetest.serialize({})) + meta:set_string("formspec", "field[channel;Channel;${channel}]") display_api.on_construct(pos) end, on_destruct = display_api.on_destruct, on_rotate = signs_api.on_rotate, - on_receive_fields = signs_api.on_receive_fields, + 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 + return + end + if (fields.channel) then + minetest.get_meta(pos):set_string("channel", fields.channel) + end + end, on_punch = function(pos, node, player, pointed_thing) signs_api.set_formspec(pos) display_api.update_entities(pos) end, + digiline = { + receptor = {}, + effector = { + action = on_digiline_receive + }, + }, }) |