From e717f09cb390cc7246030b5742adc0e65149e78a Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sun, 1 Sep 2019 19:03:37 -0600 Subject: [PATCH] stair digging is now possible, if a bit hacky. --- controller.lua | 28 +++-- functions.lua | 65 ++++++++-- geometry.lua | 2 +- locale/template.pot | 276 ++++++++++++++++++++++++++++++++++++++++++ locale/update.bat | 6 + nodes/node_digger.lua | 46 +++---- 6 files changed, 377 insertions(+), 46 deletions(-) create mode 100644 locale/template.pot create mode 100644 locale/update.bat diff --git a/controller.lua b/controller.lua index b9d4802..91d03c1 100644 --- a/controller.lua +++ b/controller.lua @@ -12,6 +12,7 @@ local sequencer_commands = { S("Sequence"), S("Dig Move Build"), + S("Dig Move Down"), S("Move Up"), S("Move Down"), S("Move Left"), @@ -217,6 +218,7 @@ local get_controller_assembled_formspec = function(digtron_id, player_name) .. "field_close_on_enter[digtron_name;false]" .. "field[2.9,0.3;0.7,1;cycles;Cycles;1]" -- TODO persist, actually use .. "button[3.2,0;1,1;execute;Execute]" + .. "button[3.7,0;1,1;execute_down;Dig Down]" .. "container_end[]" .. "container[0,1]" @@ -331,7 +333,11 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end if fields.execute then - digtron.execute_cycle(digtron_id, player_name) + digtron.execute_dig_move_build_cycle(digtron_id, player_name) + end + + if fields.execute_down then + digtron.execute_dig_move_build_cycle(digtron_id, player_name, true) end if fields.key_enter_field == "digtron_name" or fields.digtron_name then @@ -369,7 +375,6 @@ local combine_defs = function(base_def, override_content) end local base_def = { - description = S("Digtron Control Module"), _doc_items_longdesc = nil, _doc_items_usagehelp = nil, -- Note: this is not in the "digtron" group because we do not want it to be incorporated @@ -378,15 +383,6 @@ local base_def = { paramtype = "light", paramtype2= "facedir", is_ground_content = false, - -- Aims in the +Z direction by default - tiles = { - "digtron_plate.png^[transformR90", - "digtron_plate.png^[transformR270", - "digtron_plate.png", - "digtron_plate.png^[transformR180", - "digtron_plate.png", - "digtron_plate.png^digtron_control.png", - }, drawtype = "nodebox", node_box = { type = "fixed", @@ -408,7 +404,16 @@ local base_def = { } minetest.register_node("digtron:controller_unassembled", combine_defs(base_def, { + description = S("Digtron Control Module"), _digtron_assembled_node = "digtron:controller", + tiles = { + "digtron_plate.png^[transformR90", + "digtron_plate.png^[transformR270", + "digtron_plate.png", + "digtron_plate.png^[transformR180", + "digtron_plate.png", + "digtron_plate.png^digtron_control.png", + }, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) local returnstack, success = digtron.on_rightclick(pos, node, clicker, itemstack, pointed_thing) @@ -433,6 +438,7 @@ minetest.register_node("digtron:controller_unassembled", combine_defs(base_def, })) minetest.register_node("digtron:controller", combine_defs(base_def, { + description = S("Digtron Assembly"), tiles = { "digtron_plate.png^[transformR90", "digtron_plate.png^[transformR270", diff --git a/functions.lua b/functions.lua index 7372a78..e268f45 100644 --- a/functions.lua +++ b/functions.lua @@ -2,6 +2,11 @@ local mod_meta = digtron.mod_meta local cache = {} +-- internationalization boilerplate +local MP = minetest.get_modpath(minetest.get_current_modname()) +local S, NS = dofile(MP.."/intllib.lua") + + --minetest.debug(dump(mod_meta:to_table())) -- Wipes mod_meta @@ -60,7 +65,12 @@ end -- Not bothering with a dynamic table store for names, they're just strings with no need for serialization or deserialization local get_name = function(digtron_id) - return mod_meta:get_string(digtron_id..":name") + local digtron_name = mod_meta:get_string(digtron_id..":name") + if digtron_name == "" then + return S("Unnamed Digtron") + else + return digtron_name + end end local set_name = function(digtron_id, digtron_name) @@ -974,6 +984,8 @@ local get_controlling_coordinate = function(facedir) end end +-- Attempts to insert the item list into the digtron inventory, and whatever doesn't fit +-- gets placed as an item at pos local insert_or_eject = function(digtron_id, item_list, pos) local predictive_inv = get_predictive_inventory(digtron_id) if not predictive_inv then @@ -987,20 +999,55 @@ local insert_or_eject = function(digtron_id, item_list, pos) end end -local execute_cycle = function(digtron_id, player_name) +-- TODO: the dig_down parameter is a bit hacky, see if I can come up with a better way to arrange this code +local execute_dig_move_build_cycle = function(digtron_id, player_name, dig_down) local old_root_pos = retrieve_pos(digtron_id) local root_node = minetest.get_node(old_root_pos) local root_facedir = root_node.param2 local controlling_coordinate = get_controlling_coordinate(root_facedir) local dig_leftovers, nodes_to_dig, dig_cost = predict_dig(digtron_id, player_name, controlling_coordinate) - local new_root_pos = vector.add(old_root_pos, digtron.facedir_to_dir(root_facedir)) + local new_root_pos + + if dig_down then + new_root_pos = vector.add(old_root_pos, digtron.facedir_to_down(root_facedir)) + else + new_root_pos = vector.add(old_root_pos, digtron.facedir_to_dir(root_facedir)) + end + local layout = retrieve_layout(digtron_id) - -- TODO: convert nodes_to_dig into a hash map here and pass that in to reduce duplication? local buildable_to, succeeded, failed = digtron.is_buildable_to(digtron_id, layout, new_root_pos, player_name, nodes_to_dig) - local missing_items, built_nodes, build_cost = predict_build(digtron_id, new_root_pos, player_name, nodes_to_dig, controlling_coordinate) + local missing_items, built_nodes, build_cost - if buildable_to and next(missing_items) == nil then + if dig_down then + missing_items = {} + built_nodes = {} + build_cost = 0 + else + missing_items, built_nodes, build_cost = predict_build(digtron_id, new_root_pos, player_name, nodes_to_dig, controlling_coordinate) + end + + if not buildable_to then + clear_predictive_inventory(digtron_id) + digtron.show_buildable_nodes({}, failed) + minetest.sound_play("digtron_squeal", {gain = 0.5, pos=old_root_pos}) + minetest.chat_send_player(player_name, S("@1 at @2 has encountered an obstacle.", + get_name(digtron_id), minetest.pos_to_string(old_root_pos))) + elseif next(missing_items) ~= nil then + clear_predictive_inventory(digtron_id) + local items = {} + for item, count in ipairs(missing_items) do + local item_def = minetest.registered_items[item] + if item_def == nil then -- Shouldn't be a problem, but don't crash if it does happen somehow + table.insert(items, count .. " " .. item) + else + table.insert(items, count .. " " .. item_def.description) + end + end + minetest.chat_send_player(player_name, S("@1 at @2 requires @3 to execute its next build cycle.", + get_name(digtron_id), minetest.pos_to_string(old_root_pos), table.concat(items, ", "))) + minetest.sound_play("digtron_dingding", {gain = 0.5, pos=old_root_pos}) + else digtron.fake_player:update(old_root_pos, player_name) -- Removing old nodes @@ -1033,10 +1080,6 @@ local execute_cycle = function(digtron_id, player_name) commit_predictive_inventory(digtron_id) end - else - clear_predictive_inventory(digtron_id) - digtron.show_buildable_nodes({}, failed) - minetest.sound_play("digtron_squeal", {gain = 0.5, pos=new_root_pos}) end end @@ -1216,6 +1259,6 @@ digtron.is_buildable_to = is_buildable_to digtron.build_to_world = build_to_world digtron.move = move digtron.rotate = rotate -digtron.execute_cycle = execute_cycle +digtron.execute_dig_move_build_cycle = execute_dig_move_build_cycle digtron.recover_digtron_id = recover_digtron_id \ No newline at end of file diff --git a/geometry.lua b/geometry.lua index 0b09e02..203470b 100644 --- a/geometry.lua +++ b/geometry.lua @@ -147,7 +147,7 @@ end digtron.cardinal_dirs = cardinal_dirs -- used by builder entities as well digtron.cardinal_dirs_hash = cardinal_dirs_hash -digtron.facedir_to_dir_map = facedir_to_dir_map +digtron.facedir_to_dir_map = facedir_to_dir_map -- used by get_controlling_coordinate digtron.facedir_to_dir = facedir_to_dir digtron.facedir_to_dir_hash = facedir_to_dir_hash diff --git a/locale/template.pot b/locale/template.pot new file mode 100644 index 0000000..49e49d1 --- /dev/null +++ b/locale/template.pot @@ -0,0 +1,276 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-09-01 18:19-0600\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: digtron\controller.lua:7 +msgid "Main Inventory" +msgstr "" + +#: digtron\controller.lua:8 +msgid "Fuel" +msgstr "" + +#: digtron\controller.lua:13 +msgid "Sequence" +msgstr "" + +#: digtron\controller.lua:14 +msgid "Dig Move Build" +msgstr "" + +#: digtron\controller.lua:15 +msgid "Dig Move Down" +msgstr "" + +#: digtron\controller.lua:16 +msgid "Move Up" +msgstr "" + +#: digtron\controller.lua:17 +msgid "Move Down" +msgstr "" + +#: digtron\controller.lua:18 +msgid "Move Left" +msgstr "" + +#: digtron\controller.lua:19 +msgid "Move Right" +msgstr "" + +#: digtron\controller.lua:20 +msgid "Move Forward" +msgstr "" + +#: digtron\controller.lua:21 +msgid "Move Back" +msgstr "" + +#: digtron\controller.lua:22 +msgid "Yaw Left" +msgstr "" + +#: digtron\controller.lua:23 +msgid "Yaw Right" +msgstr "" + +#: digtron\controller.lua:24 +msgid "Pitch Up" +msgstr "" + +#: digtron\controller.lua:25 +msgid "Pitch Down" +msgstr "" + +#: digtron\controller.lua:26 +msgid "Roll Clockwise" +msgstr "" + +#: digtron\controller.lua:27 +msgid "Roll Widdershins" +msgstr "" + +#: digtron\controller.lua:402 +msgid "Digtron Control Module" +msgstr "" + +#: digtron\controller.lua:436 +msgid "Digtron Assembly" +msgstr "" + +#: digtron\functions.lua:65 +msgid "Unnamed Digtron" +msgstr "" + +#: digtron\functions.lua:1012 +msgid "@1 at @2 has encountered an obstacle." +msgstr "" + +#: digtron\functions.lua:1023 +msgid "@1 at @2 requires @3 to execute its next build cycle." +msgstr "" + +#: digtron\nodes\node_builder.lua:25 +msgid "Extrusion" +msgstr "" + +#: digtron\nodes\node_builder.lua:27 +msgid "" +"Builder will extrude this many blocks in the direction it is facing.\n" +"Can be set from 1 to @1.\n" +"Note that Digtron won't build into unloaded map regions." +msgstr "" + +#: digtron\nodes\node_builder.lua:28 +#: digtron\nodes\node_digger.lua:20 +msgid "Periodicity" +msgstr "" + +#: digtron\nodes\node_builder.lua:30 +msgid "" +"Builder will build once every n steps.\n" +"These steps are globally aligned, so all builders with the\n" +"same period and offset will build on the same location." +msgstr "" + +#: digtron\nodes\node_builder.lua:31 +#: digtron\nodes\node_digger.lua:23 +msgid "Offset" +msgstr "" + +#: digtron\nodes\node_builder.lua:33 +msgid "" +"Offsets the start of periodicity counting by this amount.\n" +"For example, a builder with period 2 and offset 0 builds\n" +"every even-numbered block and one with period 2 and\n" +"offset 1 builds every odd-numbered block." +msgstr "" + +#: digtron\nodes\node_builder.lua:34 +#: digtron\nodes\node_digger.lua:26 +msgid "" +"Save &\n" +"Show" +msgstr "" + +#: digtron\nodes\node_builder.lua:35 +msgid "" +"Saves settings, closes interface, and shows the locations this builder will " +"build to in-world." +msgstr "" + +#: digtron\nodes\node_builder.lua:36 +msgid "Facing" +msgstr "" + +#: digtron\nodes\node_builder.lua:38 +msgid "" +"Value from 0-23. Not all block types make use of this.\n" +"Use the 'Read & Save' button to copy the facing of the block\n" +"currently in the builder output location." +msgstr "" + +#: digtron\nodes\node_builder.lua:39 +msgid "Read" +msgstr "" + +#: digtron\nodes\node_builder.lua:40 +msgid "Reads the facing of the block currently in the build location." +msgstr "" + +#: digtron\nodes\node_builder.lua:130 +#: digtron\nodes\node_storage.lua:73 +#: digtron\nodes\node_storage.lua:178 +#: digtron\nodes\node_storage.lua:305 +msgid "This Digtron is active, interact with it via the controller node." +msgstr "" + +#: digtron\nodes\node_builder.lua:223 +msgid "" +"Builder for @1\n" +"period @2, offset @3, extrusion @4" +msgstr "" + +#: digtron\nodes\node_builder.lua:232 +msgid "Digtron Builder Module" +msgstr "" + +#: digtron\nodes\node_digger.lua:22 +msgid "" +"Digger will dig once every n steps.\n" +"These steps are globally aligned, all diggers with\n" +"the same period and offset will dig on the same location." +msgstr "" + +#: digtron\nodes\node_digger.lua:25 +msgid "" +"Offsets the start of periodicity counting by this amount.\n" +"For example, a digger with period 2 and offset 0 digs\n" +"every even-numbered block and one with period 2 and\n" +"offset 1 digs every odd-numbered block." +msgstr "" + +#: digtron\nodes\node_digger.lua:27 +msgid "Saves settings" +msgstr "" + +#: digtron\nodes\node_digger.lua:35 +msgid "" +"Digger\n" +"period @1, offset @2" +msgstr "" + +#: digtron\nodes\node_digger.lua:71 +#: digtron\nodes\node_digger.lua:103 +msgid "Digtron Digger" +msgstr "" + +#: digtron\nodes\node_digger.lua:128 +#: digtron\nodes\node_digger.lua:160 +msgid "Digtron Dual Digger" +msgstr "" + +#: digtron\nodes\node_misc.lua:7 +msgid "Digtron Structure" +msgstr "" + +#: digtron\nodes\node_misc.lua:41 +msgid "Digtron Light" +msgstr "" + +#: digtron\nodes\node_misc.lua:64 +msgid "Digtron Panel" +msgstr "" + +#: digtron\nodes\node_misc.lua:88 +msgid "Digtron Edge Panel" +msgstr "" + +#: digtron\nodes\node_misc.lua:117 +msgid "Digtron Corner Panel" +msgstr "" + +#: digtron\nodes\node_pipeworks_interface.lua:85 +msgid "Digtron Inventory Interface" +msgstr "" + +#: digtron\nodes\node_storage.lua:9 +#: digtron\nodes\node_storage.lua:213 +msgid "Inventory items" +msgstr "" + +#: digtron\nodes\node_storage.lua:20 +msgid "Digtron Inventory Storage" +msgstr "" + +#: digtron\nodes\node_storage.lua:102 +#: digtron\nodes\node_storage.lua:215 +msgid "Fuel items" +msgstr "" + +#: digtron\nodes\node_storage.lua:113 +msgid "Digtron Fuel Storage" +msgstr "" + +#: digtron\nodes\node_storage.lua:226 +msgid "Digtron Combined Storage" +msgstr "" + +#: digtron\nodes\recipes.lua:6 +msgid "Digtron Core" +msgstr "" diff --git a/locale/update.bat b/locale/update.bat new file mode 100644 index 0000000..e87d44c --- /dev/null +++ b/locale/update.bat @@ -0,0 +1,6 @@ +@echo off +setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION +cd .. +set LIST= +for /r %%X in (*.lua) do set LIST=!LIST! %%X +..\intllib\tools\xgettext.bat %LIST% \ No newline at end of file diff --git a/nodes/node_digger.lua b/nodes/node_digger.lua index f717343..cc3f3ee 100644 --- a/nodes/node_digger.lua +++ b/nodes/node_digger.lua @@ -2,7 +2,7 @@ local MP = minetest.get_modpath(minetest.get_current_modname()) local S, NS = dofile(MP.."/intllib.lua") --- TODO: make global +-- TODO: make global, is used by builders too local player_interacting_with_digtron_pos = {} local get_formspec = function(pos, player_name) @@ -56,6 +56,24 @@ local dual_drill_nodebox = { }, } +local digger_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + local returnstack, success = digtron.on_rightclick(pos, node, clicker, itemstack, pointed_thing) + if returnstack then + return returnstack, success + end + if clicker == nil then return end + local player_name = clicker:get_player_name() + player_interacting_with_digtron_pos[player_name] = pos + minetest.show_formspec(player_name, "digtron:digger", get_formspec(pos, player_name)) +end + +local assembled_digger_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) + if clicker == nil then return end + local player_name = clicker:get_player_name() + minetest.sound_play({name = "digtron_error", gain = 0.1}, {to_player=player_name}) + minetest.chat_send_player(clicker:get_player_name(), S("This Digtron is active, interact with it via the controller node.")) +end + minetest.register_node("digtron:digger", { description = S("Digtron Digger"), _doc_items_longdesc = nil, @@ -86,6 +104,7 @@ minetest.register_node("digtron:digger", { sounds = default.node_sound_metal_defaults(), can_dig = digtron.can_dig, on_blast = digtron.on_blast, + on_rightclick = assembled_digger_on_rightclick, }) minetest.register_node("digtron:digger_static",{ @@ -110,17 +129,7 @@ minetest.register_node("digtron:digger_static",{ sounds = default.node_sound_metal_defaults(), can_dig = digtron.can_dig, on_blast = digtron.on_blast, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local returnstack, success = digtron.on_rightclick(pos, node, clicker, itemstack, pointed_thing) - if returnstack then - return returnstack, success - end - if clicker == nil then return end - local player_name = clicker:get_player_name() - player_interacting_with_digtron_pos[player_name] = pos - minetest.show_formspec(player_name, "digtron:digger", get_formspec(pos, player_name)) - end, + on_rightclick = digger_on_rightclick, }) minetest.register_node("digtron:dual_digger", { @@ -153,6 +162,7 @@ minetest.register_node("digtron:dual_digger", { sounds = default.node_sound_metal_defaults(), can_dig = digtron.can_dig, on_blast = digtron.on_blast, + on_rightclick = assembled_digger_on_rightclick, }) minetest.register_node("digtron:dual_digger_static",{ @@ -177,17 +187,7 @@ minetest.register_node("digtron:dual_digger_static",{ sounds = default.node_sound_metal_defaults(), can_dig = digtron.can_dig, on_blast = digtron.on_blast, - - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - local returnstack, success = digtron.on_rightclick(pos, node, clicker, itemstack, pointed_thing) - if returnstack then - return returnstack, success - end - if clicker == nil then return end - local player_name = clicker:get_player_name() - player_interacting_with_digtron_pos[player_name] = pos - minetest.show_formspec(player_name, "digtron:digger", get_formspec(pos, player_name)) - end, + on_rightclick = digger_on_rightclick, }) minetest.register_on_player_receive_fields(function(player, formname, fields)