From d6be0812c41b489a20c1457768a11a1c1b4a9230 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Fri, 9 Jun 2023 16:31:22 +0200 Subject: [PATCH] Add flip-flop --- basis/submenu.lua | 2 +- doc/items.lua | 1 + doc/manual_DE.lua | 9 ++ doc/manual_EN.lua | 9 ++ init.lua | 2 +- logic/command_converter.lua | 2 +- logic/flipflop.lua | 147 ++++++++++++++++++++++++++ manuals/manual_ta3_DE.md | 8 ++ manuals/manual_ta3_EN.md | 8 +- manuals/toc_DE.md | 1 + manuals/toc_EN.md | 1 + settingtypes.txt | 3 - textures/techage_appl_flipflop.png | Bin 0 -> 126 bytes textures/techage_appl_flipflop_on.png | Bin 0 -> 126 bytes 14 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 logic/flipflop.lua create mode 100644 textures/techage_appl_flipflop.png create mode 100644 textures/techage_appl_flipflop_on.png diff --git a/basis/submenu.lua b/basis/submenu.lua index afe89e1..dba7378 100644 --- a/basis/submenu.lua +++ b/basis/submenu.lua @@ -311,4 +311,4 @@ end function techage.dropdown_index(sChoices, selected_value) local l = sChoices:split(",") return index(l, selected_value) or 1 -end \ No newline at end of file +end diff --git a/doc/items.lua b/doc/items.lua index 9f96199..f376b78 100644 --- a/doc/items.lua +++ b/doc/items.lua @@ -127,6 +127,7 @@ techage.Items = { ta3_motor = "techage:ta3_motor_off", ta3_injector = "techage:ta3_injector_pas", ta3_command_converter = "techage:ta3_command_converter_off", + ta3_flipflop = "techage:ta3_flipflop_off", ---------------------------- techage_ta4 = "techage_ta4.png", techage_ta4c = "techage_ta4c.png", diff --git a/doc/manual_DE.lua b/doc/manual_DE.lua index 790e36d..ca20ba6 100644 --- a/doc/manual_DE.lua +++ b/doc/manual_DE.lua @@ -108,6 +108,7 @@ techage.manual_DE.aTitel = { "2,Logik-/Schalt-Blöcke", "3,TA3 Taster/Schalter / Button/Switch", "3,TA3 Kommando Konverter / Command Converter", + "3,TA3 Flipflop / Flip-Flop", "3,TA3 Logikblock / Logic Block", "3,TA3 Wiederholer / Repeater", "3,TA3 Sequenzer / Sequencer", @@ -1067,6 +1068,12 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", + "Das TA3 Flipflop wechselt seinen Zustand mit jedem empfangenen 'on' Kommando. Empfangene 'off' Kommandos werden ignortiert. Damit werden abhängig vom Zustandswechsel abwechselnd 'on' / 'off' Kommandos gesendet. Die Nummer des Zielblockes bzw. die Nummern der Zielblöcke müssen eingegeben werden. Die Nummern können auch mit Hilfe des Techage Programmers programmiert werden.\n".. + "\n".. + "Damit lassen sich bspw. Lampen mit Hilfe von Tastern ein- und wieder ausschalten.\n".. + "\n".. + "\n".. + "\n", "Den TA3 Logikblock kann man so programmieren\\, dass ein oder mehrere Eingangskommandos zu einem Ausgangskommando verknüpft und gesendet werden. Dieser Block kann daher diverse Logik-Elemente wie AND\\, OR\\, NOT\\, XOR usw. ersetzen.\n".. "Eingangkommandos für den Logikblock sind 'on'/'off' Kommandos.\n".. "Eingangskommandos werden über die Nummer referenziert\\, also bspw. '1234' für das Kommando vom Sender mit der Nummer 1234.\n".. @@ -2312,6 +2319,7 @@ techage.manual_DE.aItemName = { "ta3_logic", "ta3_button", "ta3_command_converter", + "ta3_flipflop", "ta3_logic", "ta3_repeater", "ta3_sequencer", @@ -2605,6 +2613,7 @@ techage.manual_DE.aPlanTable = { "", "", "", + "", "ta4_windturbine", "", "", diff --git a/doc/manual_EN.lua b/doc/manual_EN.lua index 67a31f5..e92dbae 100644 --- a/doc/manual_EN.lua +++ b/doc/manual_EN.lua @@ -109,6 +109,7 @@ techage.manual_EN.aTitel = { "2,Logic / Switching Blocks", "3,TA3 Button / Switch", "3,TA3 Command Converter", + "3,TA3 Flip-Flop", "3,TA3 Logic Block", "3,TA3 Repeater", "3,TA3 Sequencer", @@ -1075,6 +1076,12 @@ techage.manual_EN.aText = { "\n".. "\n".. "\n", + "The TA3 flip-flop changes its state with each received 'on' command. Received 'off' commands are ignored. Depending on the status change\\, 'on' / 'off' commands are sent alternately. The number of the target block or the numbers of the target blocks must be entered. The numbers can also be programmed using the Techage programmer.\n".. + "\n".. + "For example\\, lamps can be switched on and off with the help of buttons.\n".. + "\n".. + "\n".. + "\n", "The TA3 logic block can be programmed in such a way that one or more input commands are linked to one output command and sent. This block can therefore replace various logic elements such as AND\\, OR\\, NOT\\, XOR etc. \n".. "Input commands for the logic block are 'on' /'off' commands.\n".. "Input commands are referenced via the number\\, e.g. '1234' for the command from the sender with the number 1234. \n".. @@ -2323,6 +2330,7 @@ techage.manual_EN.aItemName = { "ta3_logic", "ta3_button", "ta3_command_converter", + "ta3_flipflop", "ta3_logic", "ta3_repeater", "ta3_sequencer", @@ -2618,6 +2626,7 @@ techage.manual_EN.aPlanTable = { "", "", "", + "", "ta4_windturbine", "", "", diff --git a/init.lua b/init.lua index f2457cf..2b3ec6a 100644 --- a/init.lua +++ b/init.lua @@ -52,7 +52,6 @@ techage.NodeDef = {} -- node registration info techage.max_num_forceload_blocks = tonumber(minetest.settings:get("techage_max_num_forceload_blocks")) or 24 -techage.basalt_stone_enabled = minetest.settings:get_bool("techage_basalt_stone_enabled") ~= false techage.ore_rarity = tonumber(minetest.settings:get("techage_ore_rarity")) or 1 techage.modified_recipes_enabled = minetest.settings:get_bool("techage_modified_recipes_enabled") ~= false techage.collider_min_depth = tonumber(minetest.settings:get("techage_collider_min_depth")) or -28 @@ -292,6 +291,7 @@ dofile(MP.."/logic/light_detector.lua") dofile(MP.."/logic/player_detector.lua") dofile(MP.."/logic/gaze_sensor.lua") dofile(MP.."/logic/command_converter.lua") +dofile(MP.."/logic/flipflop.lua") dofile(MP.."/logic/mba_detector.lua") dofile(MP.."/logic/cart_detector.lua") dofile(MP.."/logic/charge_detector.lua") diff --git a/logic/command_converter.lua b/logic/command_converter.lua index 59106ec..16af99d 100644 --- a/logic/command_converter.lua +++ b/logic/command_converter.lua @@ -179,4 +179,4 @@ techage.register_node({ end end, } -) \ No newline at end of file +) diff --git a/logic/flipflop.lua b/logic/flipflop.lua new file mode 100644 index 0000000..756ec6b --- /dev/null +++ b/logic/flipflop.lua @@ -0,0 +1,147 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2017-2023 Joachim Stolberg + + AGPL v3 + See LICENSE.txt for more information + + TA3 Flip-flop + +]]-- + +-- for lazy programmers +local M = minetest.get_meta +local S = techage.S +local DESCR = S("TA3 Flip-Flop") + +local logic = techage.logic + +local function switch_on(pos) + logic.swap_node(pos, "techage:ta3_flipflop_on") + logic.send_on(pos, M(pos)) +end + +local function switch_off(pos) + logic.swap_node(pos, "techage:ta3_flipflop_off") + logic.send_off(pos, M(pos)) +end + +local function formspec(meta) + local numbers = meta:get_string("numbers") or "" + + return "formspec_version[4]size[10,3.5]".. + "box[0.2,0.2;9.6,0.6;#c6e8ff]" .. + "label[0.4,0.5;" .. minetest.colorize( "#000000", DESCR) .. "]" .. + + "field[1.0,1.5;8,0.6;numbers;" .. S("Insert destination node number(s)") .. ";" .. numbers .. "]" .. + + "button_exit[3.5,2.7;3,0.6;exit;" .. S("Save") .. "]" +end + +local function techage_set_numbers(pos, numbers, player_name) + local meta = M(pos) + local res = logic.set_numbers(pos, numbers, player_name, DESCR) + meta:set_string("formspec", formspec(meta)) + return true --res +end + +local function after_dig_node(pos, oldnode, oldmetadata, digger) + techage.remove_node(pos, oldnode, oldmetadata) + techage.del_mem(pos) +end + +local function on_receive_fields(pos, formname, fields, player) + if minetest.is_protected(pos, player:get_player_name()) then + return + end + + local meta = minetest.get_meta(pos) + if fields.exit and fields.exit ~= "" then + if techage.check_numbers(fields.numbers, player:get_player_name()) then + meta:set_string("numbers", fields.numbers) + logic.infotext(M(pos), DESCR) + end + meta:set_string("formspec", formspec(meta)) + elseif fields.exit == "close" then + meta:set_string("formspec", formspec(meta)) + end +end + +minetest.register_node("techage:ta3_flipflop_off", { + description = DESCR, + tiles = { + -- up, down, right, left, back, front + "techage_filling_ta3.png^techage_frame_ta3_top.png", + "techage_filling_ta3.png^techage_frame_ta3_top.png", + "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_flipflop.png", + }, + after_place_node = function(pos, placer) + local meta = M(pos) + logic.after_place_node(pos, placer, "techage:ta3_flipflop_off", DESCR) + logic.infotext(meta, DESCR) + meta:set_string("formspec", formspec(meta)) + end, + + on_timer = function (pos, elapsed) + switch_on(pos) + end, + + on_receive_fields = on_receive_fields, + techage_set_numbers = techage_set_numbers, + after_dig_node = after_dig_node, + paramtype2 = "facedir", + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) + +minetest.register_node("techage:ta3_flipflop_on", { + description = DESCR, + tiles = { + -- up, down, right, left, back, front + "techage_filling_ta3.png^techage_frame_ta3_top.png", + "techage_filling_ta3.png^techage_frame_ta3_top.png", + "techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_flipflop_on.png", + }, + + on_timer = function (pos, elapsed) + switch_off(pos) + end, + + on_receive_fields = on_receive_fields, + techage_set_numbers = techage_set_numbers, + after_dig_node = after_dig_node, + paramtype2 = "facedir", + groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), + drop = "techage:ta3_flipflop_off" +}) + +minetest.register_craft({ + output = "techage:ta3_flipflop_off", + recipe = { + {"", "group:wood", ""}, + {"default:mese_crystal_fragment", "default:steel_ingot", "techage:vacuum_tube"}, + {"", "group:wood", ""}, + }, +}) + +techage.register_node({ + "techage:ta3_flipflop_off", "techage:ta3_flipflop_on" + }, { + on_recv_message = function(pos, src, topic, payload) + if topic == "on" then + minetest.get_node_timer(pos):start(0.1) + return true + elseif topic == "off" then + return true + else + return "unsupported" + end + end, + } +) diff --git a/manuals/manual_ta3_DE.md b/manuals/manual_ta3_DE.md index 51028e4..70c5c1a 100644 --- a/manuals/manual_ta3_DE.md +++ b/manuals/manual_ta3_DE.md @@ -544,6 +544,14 @@ Die Nummern können auch mit Hilfe des Techage Programmers programmiert werden. [ta3_command_converter|image] +### TA3 Flipflop / Flip-Flop + +Das TA3 Flipflop wechselt seinen Zustand mit jedem empfangenen `on` Kommando. Empfangene `off` Kommandos werden ignortiert. Damit werden abhängig vom Zustandswechsel abwechselnd `on` / `off` Kommandos gesendet. Die Nummer des Zielblockes bzw. die Nummern der Zielblöcke müssen eingegeben werden. Die Nummern können auch mit Hilfe des Techage Programmers programmiert werden. + +Damit lassen sich bspw. Lampen mit Hilfe von Tastern ein- und wieder ausschalten. + +[ta3_flipflop|image] + ### TA3 Logikblock / Logic Block Den TA3 Logikblock kann man so programmieren, dass ein oder mehrere Eingangskommandos zu einem Ausgangskommando verknüpft und gesendet werden. Dieser Block kann daher diverse Logik-Elemente wie AND, OR, NOT, XOR usw. ersetzen. diff --git a/manuals/manual_ta3_EN.md b/manuals/manual_ta3_EN.md index b11234e..9e3e14a 100644 --- a/manuals/manual_ta3_EN.md +++ b/manuals/manual_ta3_EN.md @@ -537,7 +537,6 @@ Note: With the programmer, block numbers can be easily collected and configured. [ta3_button|image] - ### TA3 Command Converter With the TA3 command converter, `on` / `off` commands can be converted into other commands, and forwarding can be prevented or delayed. @@ -547,6 +546,13 @@ The numbers can also be programmed using the Techage programmer. [ta3_command_converter|image] +### TA3 Flip-Flop + +The TA3 flip-flop changes its state with each received `on` command. Received `off` commands are ignored. Depending on the status change, `on` / `off` commands are sent alternately. The number of the target block or the numbers of the target blocks must be entered. The numbers can also be programmed using the Techage programmer. + +For example, lamps can be switched on and off with the help of buttons. + +[ta3_flipflop|image] ### TA3 Logic Block diff --git a/manuals/toc_DE.md b/manuals/toc_DE.md index 04668d8..0a63664 100644 --- a/manuals/toc_DE.md +++ b/manuals/toc_DE.md @@ -107,6 +107,7 @@ - [Logik-/Schalt-Blöcke](./manual_ta3_DE.md#logik-schalt-blöcke) - [TA3 Taster/Schalter / Button/Switch](./manual_ta3_DE.md#ta3-tasterschalter--buttonswitch) - [TA3 Kommando Konverter / Command Converter](./manual_ta3_DE.md#ta3-kommando-konverter--command-converter) + - [TA3 Flipflop / Flip-Flop](./manual_ta3_DE.md#ta3-flipflop--flip-flop) - [TA3 Logikblock / Logic Block](./manual_ta3_DE.md#ta3-logikblock--logic-block) - [TA3 Wiederholer / Repeater](./manual_ta3_DE.md#ta3-wiederholer--repeater) - [TA3 Sequenzer / Sequencer](./manual_ta3_DE.md#ta3-sequenzer--sequencer) diff --git a/manuals/toc_EN.md b/manuals/toc_EN.md index de29a92..b8a20c5 100644 --- a/manuals/toc_EN.md +++ b/manuals/toc_EN.md @@ -108,6 +108,7 @@ - [Logic / Switching Blocks](./manual_ta3_EN.md#logic--switching-blocks) - [TA3 Button / Switch](./manual_ta3_EN.md#ta3-button--switch) - [TA3 Command Converter](./manual_ta3_EN.md#ta3-command-converter) + - [TA3 Flip-Flop](./manual_ta3_EN.md#ta3-flip-flop) - [TA3 Logic Block](./manual_ta3_EN.md#ta3-logic-block) - [TA3 Repeater](./manual_ta3_EN.md#ta3-repeater) - [TA3 Sequencer](./manual_ta3_EN.md#ta3-sequencer) diff --git a/settingtypes.txt b/settingtypes.txt index be6d993..a118e13 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,9 +1,6 @@ # Maximim number of Forceload Blocks per player (default 20) techage_max_num_forceload_blocks (Max. number of Forceload Blocks) int 20 -# Enable Basalt Stone (and disable ore generation via cobble generator) -techage_basalt_stone_enabled (Basalt Stone enabled) bool false - # Rarity factor to find ores when sieving with the Gravel Sieve # 1.0 is according to the mapgen generator # 2.0 means half as many ores as result diff --git a/textures/techage_appl_flipflop.png b/textures/techage_appl_flipflop.png new file mode 100644 index 0000000000000000000000000000000000000000..a0194c398e300aedaac669aae038ad70cfdaa71e GIT binary patch literal 126 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnL3?x0byx0z;*aCb)T-^(N>}+kD<2_Pw-;ZxG_`F-VG2?U^x=LwQ4|B1cQyj>;BB2Dx}y V#}#M0_XBk>c)I$ztaD0e0sugOB2NGS literal 0 HcmV?d00001 diff --git a/textures/techage_appl_flipflop_on.png b/textures/techage_appl_flipflop_on.png new file mode 100644 index 0000000000000000000000000000000000000000..73d09e918a8add504cef6202ec38fd7b881fcf65 GIT binary patch literal 126 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnL3?x0byx0z;*aCb)T-^(N4zaOqvN&=ED8g70 zIg~eaDsr^M?Wk;FWRQ!O VbzE__dp}SIgQu&X%Q~loCIF87BT)bV literal 0 HcmV?d00001