From 4f0cacb224ee0036c986c3668051e03443b3cd22 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sat, 10 Sep 2022 16:04:45 +0200 Subject: [PATCH] Add new signal lamp with color commands --- doc/manual_DE.lua | 2 +- doc/manual_EN.lua | 3 +- locale/techage.de.tr | 6 +- locale/template.txt | 4 +- logic/signallamp.lua | 277 ++++++++++++++++++------------- manuals/manual_ta3_DE.md | 2 +- manuals/manual_ta3_EN.md | 3 +- manuals/ta4_lua_controller_EN.md | 1 + textures/generate.py | 40 +++++ textures/techage_palette256.png | Bin 0 -> 133 bytes textures/techage_signallamp2.png | Bin 0 -> 94 bytes 11 files changed, 216 insertions(+), 122 deletions(-) create mode 100755 textures/generate.py create mode 100644 textures/techage_palette256.png create mode 100644 textures/techage_signallamp2.png diff --git a/doc/manual_DE.lua b/doc/manual_DE.lua index 541de6a..041b4f8 100644 --- a/doc/manual_DE.lua +++ b/doc/manual_DE.lua @@ -1126,7 +1126,7 @@ techage.manual_DE.aText = { "\n".. "\n", "Die Signallampe kann mit 'on'/'off' Kommando ein- bzw. ausgeschaltet werden. Diese Lampe braucht keinen Strom und\n".. - "kann mit der Spritzpistole aus der Mod \"Unified Dyes\" farbig gemacht werden.\n".. + "kann mit der Spritzpistole aus der Mod \"Unified Dyes\" und über Lua/Beduino Kommandos eingefärbt werden.\n".. "\n".. "\n".. "\n", diff --git a/doc/manual_EN.lua b/doc/manual_EN.lua index 5187918..ce0993a 100644 --- a/doc/manual_EN.lua +++ b/doc/manual_EN.lua @@ -1128,8 +1128,7 @@ techage.manual_EN.aText = { "\n".. "\n".. "\n", - "The signal lamp can be switched on or off with the 'on' / 'off' command. This lamp does not need electricity and\n".. - "can be colored with the airbrush tool of the mod Unified Dyes.\n".. + "The signal lamp can be switched on or off with the 'on' / 'off' command. This lamp does not need electricity and can be colored with the airbrush tool from the mod Unified Dyes\" and via Lua/Beduino commands.\n".. "\n".. "\n".. "\n", diff --git a/locale/techage.de.tr b/locale/techage.de.tr index ae31848..97f6ffc 100644 --- a/locale/techage.de.tr +++ b/locale/techage.de.tr @@ -1042,7 +1042,9 @@ no oil=Kein Öl ### pusher.lua ### -Optionally configure@nthe pusher with one item=Der Schieber kann optional@nmit einem Gegenstand@nkonfiguriert werden +Number of items=Anzahl der Elemente +Number of items that are allowed to be pushed=Anzahl der Elemente, die verschoben werden dürfen +Optionally configure@nthe pusher with one item=Der Schieber kann optional@nmit einem Elemente@nkonfiguriert werden Pusher=Schieber ### quarry.lua ### @@ -1166,7 +1168,7 @@ TA5 Fusion Reactor Shell=TA5 Fusionsreaktor Hülle TA4 Wind Turbine Signal Lamp=TA4 Windkraftanlagenlampe TechAge Signal Lamp=TechAge Signallampe -TechAge Signal Lamp (can be colored)=TechAge Signallampe (kann gefärbt werden) +TechAge Signal Lamp 2 =TechAge Signallampe 2 ### signallamp_2x.lua ### diff --git a/locale/template.txt b/locale/template.txt index 8a35f9a..59c4b38 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -1042,6 +1042,8 @@ no oil= ### pusher.lua ### +Number of items= +Number of items that are allowed to be pushed= Optionally configure@nthe pusher with one item= Pusher= @@ -1166,7 +1168,7 @@ TA5 Fusion Reactor Shell= TA4 Wind Turbine Signal Lamp= TechAge Signal Lamp= -TechAge Signal Lamp (can be colored)= +TechAge Signal Lamp 2 = ### signallamp_2x.lua ### diff --git a/logic/signallamp.lua b/logic/signallamp.lua index 982bde2..137538f 100644 --- a/logic/signallamp.lua +++ b/logic/signallamp.lua @@ -8,7 +8,7 @@ AGPL v3 See LICENSE.txt for more information - Colored Signal Lamp (requires unifieddyes) + Colored Signal Lamps (with unifieddyes support) ]]-- @@ -20,127 +20,178 @@ local logic = techage.logic local COLORED = minetest.get_modpath("unifieddyes") and minetest.global_exists("unifieddyes") +local LampsOff = {} +local LampsOn = {} -local function switch_on(pos, node) - node.name = "techage:signal_lamp_on" - minetest.swap_node(pos, node) +local function switch_on(pos, node, player, color) + if player and minetest.is_protected(pos, player:get_player_name()) then + return + end + color = (tonumber(color) or COLORED and 96 or 6) % 256 + if LampsOff[node.name] then + node.name = LampsOff[node.name] + node.param2 = color + minetest.swap_node(pos, node) + elseif LampsOn[node.name] and color ~= node.param2 then + node.param2 = color + minetest.swap_node(pos, node) + end end -local function switch_off(pos, node) - node.name = "techage:signal_lamp_off" - minetest.swap_node(pos, node) +local function switch_off(pos, node, player) + if player and minetest.is_protected(pos, player:get_player_name()) then + return + end + if LampsOn[node.name] then + node.name = LampsOn[node.name] + node.param2 = COLORED and 241 or 35 + minetest.swap_node(pos, node) + end end -minetest.register_node("techage:signal_lamp_off", { - description = S("TechAge Signal Lamp (can be colored)"), - tiles = {"techage_signal_lamp.png^[colorize:#000000:100"}, - drawtype = "nodebox", - node_box = { +local function register_signallamp(name, description, tiles, node_box) + LampsOff[name .. "_off"] = name .. "_on" + LampsOn[name .. "_on"] = name .. "_off" + + minetest.register_node(name .. "_off", { + description = description, + tiles = tiles, + drawtype = node_box and "nodebox", + node_box = node_box, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + logic.after_place_node(pos, placer, name .. "_off", description) + logic.infotext(M(pos), description) + if COLORED then + unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing) + end + end, + + on_rightclick = switch_on, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + techage.remove_node(pos, oldnode, oldmetadata) + if COLORED then + unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger) + else + local node = minetest.get_node(pos) + node.param2 = 35 + minetest.swap_node(pos, node) + end + end, + + on_construct = COLORED and unifieddyes.on_construct or nil, + on_dig = COLORED and unifieddyes.on_dig or nil, + + paramtype = "light", + paramtype2 = "color", + --palette = "techage_palette256.png", + palette = COLORED and "unifieddyes_palette_extended.png" or "techage_palette256.png", + place_param2 = 241, + sunlight_propagates = true, + sounds = default.node_sound_glass_defaults(), + groups = {choppy=2, cracky=1, ud_param2_colorable = 1}, + is_ground_content = false, + drop = name .. "_off" + }) + + minetest.register_node(name .. "_on", { + description = description, + tiles = tiles, + drawtype = node_box and "nodebox", + node_box = node_box, + + on_rightclick = switch_off, + + paramtype = "light", + paramtype2 = "color", + --palette = "techage_palette256.png", + palette = COLORED and "unifieddyes_palette_extended.png" or "techage_palette256.png", + groups = {choppy=2, cracky=1, not_in_creative_inventory=1, ud_param2_colorable = 1}, + + after_dig_node = function(pos, oldnode, oldmetadata, digger) + techage.remove_node(pos, oldnode, oldmetadata) + if COLORED then + unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger) + end + end, + + on_dig = COLORED and unifieddyes.on_dig or nil, + light_source = 10, + is_ground_content = false, + drop = name .. "_off" + }) + + techage.register_node({name .. "_off", name .. "_on"}, { + on_recv_message = function(pos, src, topic, payload) + if topic == "on" then + local node = techage.get_node_lvm(pos) + switch_on(pos, node) + return true + elseif topic == "off" then + local node = techage.get_node_lvm(pos) + switch_off(pos, node) + return true + elseif topic == "color" then + local node = techage.get_node_lvm(pos) + switch_on(pos, node, nil, payload) + return true + else + return "unsupported" + end + end, + on_beduino_receive_cmnd = function(pos, src, topic, payload) + if topic == 1 and payload[1] == 1 then + local node = techage.get_node_lvm(pos) + switch_on(pos, node) + return 0 + elseif topic == 1 and payload[1] == 0 then + local node = techage.get_node_lvm(pos) + switch_off(pos, node) + return 0 + elseif topic == 70 then + local node = techage.get_node_lvm(pos) + switch_on(pos, node, nil, payload[1]) + return 0 + else + return 2 + end + end, + }) +end + + +register_signallamp("techage:signal_lamp", + S("TechAge Signal Lamp"), + {"techage_signal_lamp.png^[colorize:#000000:100"}, + { type = "fixed", fixed = { {-6/16, -6/16, -6/16, 6/16, 6/16, 6/16}, {-4/16, -10/16, -4/16, 4/16, -6/16, 4/16}, - }, - }, + } + } +) - after_place_node = function(pos, placer, itemstack, pointed_thing) - logic.after_place_node(pos, placer, "techage:signal_lamp_off", S("TechAge Signal Lamp")) - logic.infotext(M(pos), S("TechAge Signal Lamp")) - if COLORED then - unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing) - end - end, - - on_rightclick = switch_on, - - after_dig_node = function(pos, oldnode, oldmetadata, digger) - techage.remove_node(pos, oldnode, oldmetadata) - if COLORED then - unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger) - end - end, - - on_construct = COLORED and unifieddyes.on_construct or nil, - on_dig = COLORED and unifieddyes.on_dig or nil, - - paramtype = "light", - paramtype2 = "color", - palette = COLORED and "unifieddyes_palette_extended.png" or 'techage_color16.png', - place_param2 = 241, - sunlight_propagates = true, - sounds = default.node_sound_stone_defaults(), - groups = {choppy=2, cracky=1, ud_param2_colorable = 1}, - is_ground_content = false, - drop = "techage:signal_lamp_off" -}) - - -minetest.register_node("techage:signal_lamp_on", { - description = S("TechAge Signal Lamp"), - tiles = {"techage_signal_lamp.png"}, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-6/16, -6/16, -6/16, 6/16, 6/16, 6/16}, - {-4/16, -10/16, -4/16, 4/16, -6/16, 4/16}, - }, - }, - on_rightclick = switch_off, - - paramtype = "light", - paramtype2 = "color", - palette = COLORED and "unifieddyes_palette_extended.png" or 'techage_color16.png', - groups = {choppy=2, cracky=1, not_in_creative_inventory=1, ud_param2_colorable = 1}, - - on_construct = COLORED and unifieddyes.on_construct or nil, - after_place_node = COLORED and unifieddyes.recolor_on_place or nil, - - after_dig_node = function(pos, oldnode, oldmetadata, digger) - techage.remove_node(pos, oldnode, oldmetadata) - if COLORED then - unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger) - end - end, - - on_dig = COLORED and unifieddyes.on_dig or nil, - light_source = 10, - is_ground_content = false, - drop = "techage:signal_lamp_off" -}) - -techage.register_node({"techage:signal_lamp_off", "techage:signal_lamp_on"}, { - on_recv_message = function(pos, src, topic, payload) - if topic == "on" then - local node = techage.get_node_lvm(pos) - switch_on(pos, node) - elseif topic == "off" then - local node = techage.get_node_lvm(pos) - switch_off(pos, node) - else - return "unsupported" - end - end, - on_beduino_receive_cmnd = function(pos, src, topic, payload) - if topic == 1 and payload[1] == 1 then - local node = techage.get_node_lvm(pos) - switch_on(pos, node) - return 0 - elseif topic == 1 and payload[1] == 0 then - local node = techage.get_node_lvm(pos) - switch_off(pos, node) - return 0 - else - return 2 - end - end, -}) +register_signallamp("techage:signal_lamp2", + S("TechAge Signal Lamp 2 "), + {"techage_signallamp2.png"} +) minetest.register_craft({ - output = "techage:signal_lamp_off", - recipe = { - {"", "wool:white", ""}, - {"", "default:torch", ""}, - {"", "techage:vacuum_tube", ""}, - }, -}) + output = "techage:signal_lamp_off", + recipe = { + {"", "wool:white", ""}, + {"", "default:torch", ""}, + {"", "techage:vacuum_tube", ""}, + }, + }) + +minetest.register_craft({ + output = "techage:signal_lamp2_off", + recipe = { + {"", "default:glass", ""}, + {"", "default:torch", ""}, + {"", "techage:vacuum_tube", ""}, + }, + }) diff --git a/manuals/manual_ta3_DE.md b/manuals/manual_ta3_DE.md index 4ccfcd2..0d806c8 100644 --- a/manuals/manual_ta3_DE.md +++ b/manuals/manual_ta3_DE.md @@ -631,7 +631,7 @@ Im privaten Modus (private) kann das Terminal nur von Spielern verwendet werden, ### TechAge Signallampe / Signal Lamp Die Signallampe kann mit `on`/`off` Kommando ein- bzw. ausgeschaltet werden. Diese Lampe braucht keinen Strom und -kann mit der Spritzpistole aus der Mod "Unified Dyes" farbig gemacht werden. +kann mit der Spritzpistole aus der Mod "Unified Dyes" und über Lua/Beduino Kommandos eingefärbt werden. [ta3_signallamp|image] diff --git a/manuals/manual_ta3_EN.md b/manuals/manual_ta3_EN.md index 3b196f5..4fd9335 100644 --- a/manuals/manual_ta3_EN.md +++ b/manuals/manual_ta3_EN.md @@ -629,8 +629,7 @@ In public mode, all players can use the preconfigured keys. ### TechAge Signal Lamp -The signal lamp can be switched on or off with the `on` / `off` command. This lamp does not need electricity and -can be colored with the airbrush tool of the mod Unified Dyes. +The signal lamp can be switched on or off with the `on` / `off` command. This lamp does not need electricity and can be colored with the airbrush tool from the mod Unified Dyes" and via Lua/Beduino commands. [ta3_signallamp|image] diff --git a/manuals/ta4_lua_controller_EN.md b/manuals/ta4_lua_controller_EN.md index f9a32ad..5387272 100644 --- a/manuals/ta4_lua_controller_EN.md +++ b/manuals/ta4_lua_controller_EN.md @@ -417,6 +417,7 @@ Please note, that this is not a technical distinction, only a logical. | "stop" | nil | Stop command for the TA4 Sequencer. | | "gain" | volume | Set volume of the sound block (`volume` is a value between 0 and 1.0) | | "sound" | index | Select sound sample of the sound block | +| "color" | \ | Set the color of the TechAge Signal Lamp and TechAge Signal Lamp 2 (color = 0..255) | ### Server and Terminal Functions diff --git a/textures/generate.py b/textures/generate.py new file mode 100755 index 0000000..7103ade --- /dev/null +++ b/textures/generate.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# Script to generate the palette PNG file. +# +# Copyright (C) 2022 Joachim Stolberg +# LGPLv2.1+ + +from PIL import Image + +MainColors = [ + 0x000080, 0x008000, 0x800000, 0x008080, 0x808000, 0x800080, + 0x0000FF, 0x00FF00, 0xFF0000, 0x00FFFF, 0xFFFF00, 0xFF00FF, + 0x0080FF, 0x8000FF, 0x80FF00, 0x00FF80, 0xFF8000, 0xFF0080, +] + +def generate(): + img = Image.new("RGB", (18, 15), color='#000000') + + # Main colors + for x in range(0,18): + img.putpixel((x, 0), MainColors[x]) + + # Grey scale + for x in range(0,18): + img.putpixel((x, 1), (x * 15, x * 15, x * 15)) + + # 216 colors palette + idx = 36 + for r in range(0,6): + for g in range(0,6): + for b in range(0,6): + x = idx % 18 + y = int(idx / 18) + img.putpixel((x, y), (r * 0x33, g * 0x33, b * 0x33)) + idx += 1 + + img.save("techage_palette256.png", "PNG") + +generate() diff --git a/textures/techage_palette256.png b/textures/techage_palette256.png new file mode 100644 index 0000000000000000000000000000000000000000..6880d05d21b97c512d9701ecb3a7079a3bb8ec53 GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0vp^LO{&V!2~4Jo^ZGVDIZT4$B>FSZ_jSzYz<&=zWDjT zy~KL~>n57cF%t{>=eFf01LYE?IK1@v9~C8SiI1OuO&uf4-+v iTy6UM-oKY`RoOcf)&KMqxn}^)W$<+Mb6Mw<&;$TLU^2G= literal 0 HcmV?d00001 diff --git a/textures/techage_signallamp2.png b/textures/techage_signallamp2.png new file mode 100644 index 0000000000000000000000000000000000000000..93d5f073a935805f6afaed57092d848f22ffaa15 GIT binary patch literal 94 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnL3?x0byx0z;*aCb)T(@uE{`>duCo$W<0Y!v8 qT^vI=t|uojH2(Vk|39xC6AMGHZ$|d{9er&;X$DVMKbLh*2~7aB!X4HC literal 0 HcmV?d00001