local function escape_texture(str) return str:gsub("[%[%()^:]", "\\%1") end 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] ~= tostring(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=departureboards_station_sign.png\\^(departureboards_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", { sunlight_propagates = true, paramtype = "light", paramtype2 = "facedir", drawtype = "nodebox", node_box = { type = "fixed", 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 = { "default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "default_steel_block.png", "default_steel_block.png", {name="departureboards_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 = { ["departureboards:display"] = { on_display_update = render_depboard, depth = 0.5 - display_api.entity_spacing - 0.1, size = { x = 3, y = 1 }, aspect_ratio = 1/2, maxlines = 1, }, }, light_source = 3, on_place = display_api.on_place, on_construct = function(pos) local ndef = minetest.registered_nodes[minetest.get_node(pos).name] local meta = minetest.get_meta(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 = 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) display_api.update_entities(pos) end, digiline = { receptor = {}, effector = { action = on_digiline_receive }, }, }) minetest.register_abm({ nodenames = {"departureboards:departureboard"}, interval = 5, chance = 1, action = display_api.update_entities, }) if atlatc then atlatc.register_function("departureboard_set", function(pos, tb) departureboards.contents[minetest.hash_node_position(pos)] = tb end) end