fix name preservation, add stop button

This commit is contained in:
FaceDeer 2020-02-23 23:39:01 -07:00
parent 1e776defd5
commit 6745446fcd
3 changed files with 23 additions and 18 deletions

@ -65,7 +65,7 @@ digtron.default_sequence = function()
end
-----------------------------------------------------------------------------------------
--- Maniupulating sequences
--- Manipulating sequences
-- searches down through the sequence tree to find the next command that can be executed
local find_next_item_to_execute = function(sequence)
@ -360,9 +360,14 @@ local sequence_tab = function(digtron_id)
if sequence.cur == 0 then
table.insert(list_out, "box[0.75,0.1;0.7,0.5;#FF000088]")
end
if is_cycling(digtron_id) then
table.insert(list_out, "button[1.5,0.1;1,0.5;stop;"..S("Stop").."]")
else
table.insert(list_out, "button[1.5,0.1;1,0.5;execute;"..S("Execute").."]")
end
table.insert(list_out,
"label[0.8,0.35;" .. S("@1 left", sequence.cur) .."]"
.. "button[1.5,0.1;1,0.5;execute;"..S("Execute").."]" -- TODO pause
.. "button[2.5,0.1;1,0.5;reset;"..S("Reset").."]"
.. "container_end[]"
.. "container[0.2,1]"
@ -444,6 +449,10 @@ local update_sequence = function(digtron_id, fields, player_name)
start_command(digtron_id, "seq", 1, player_name)
end
if fields.stop and is_cycling(digtron_id) then
cancel_command(digtron_id)
end
if fields.reset then
cancel_command(digtron_id)
reset_sequence(sequence)
@ -828,7 +837,7 @@ minetest.register_node("digtron:controller", combine_defs(base_def, {
local stack = ItemStack({name=node.name, count=1, wear=0})
local stack_meta = stack:get_meta()
stack_meta:set_string("digtron_id", digtron_id)
stack_meta:set_string("description", meta:get_string("infotext"))
stack_meta:set_string("description", digtron.get_name(digtron_id))
local inv = digger:get_inventory()
local stack = inv:add_item("main", stack)
if stack:get_count() > 0 then
@ -892,6 +901,9 @@ minetest.register_node("digtron:controller", combine_defs(base_def, {
for _, built_pos in ipairs(built_positions) do
minetest.check_for_falling(built_pos)
end
local meta = minetest.get_meta(target_pos)
meta:set_string("infotext", digtron.get_name(digtron_id))
minetest.sound_play("digtron_machine_assemble", {gain = 0.5, pos=target_pos})
-- Note: DO NOT RESPECT CREATIVE MODE here.
@ -918,18 +930,6 @@ minetest.register_node("digtron:controller", combine_defs(base_def, {
end
end,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local stack_meta = itemstack:get_meta()
local title = stack_meta:get_string("description")
local digtron_id = stack_meta:get_string("digtron_id")
local meta = minetest.get_meta(pos)
meta:set_string("infotext", title)
meta:set_string("digtron_id", digtron_id)
meta:mark_as_private("digtron_id")
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local returnstack, success = digtron.on_rightclick(pos, node, clicker, itemstack, pointed_thing)
if returnstack then

@ -16,7 +16,7 @@ local damage_hp = digtron.config.damage_hp
-- see predict_dig for how punch_data gets calculated
local damage_creatures = function(root_pos, punch_data, items_dropped)
local target_pos = punch_data[2]
local objects = minetest.env:get_objects_inside_radius(target_pos, 1.0)
local objects = minetest.get_objects_inside_radius(target_pos, 1.0)
if objects ~= nil then
local source_pos = vector.add(minetest.get_position_from_hash(punch_data[1]), root_pos)
for _, obj in ipairs(objects) do
@ -52,7 +52,7 @@ local damage_creatures = function(root_pos, punch_data, items_dropped)
end
end
-- If we killed any mobs they might have dropped some stuff, vacuum that up now too.
objects = minetest.env:get_objects_inside_radius(target_pos, 1.0)
objects = minetest.get_objects_inside_radius(target_pos, 1.0)
if objects ~= nil then
for _, obj in ipairs(objects) do
if not obj:is_player() then
@ -422,7 +422,8 @@ local assemble = function(root_pos, player_name)
local layout = {}
for hash, node in pairs(digtron_nodes) do
local relative_hash = minetest.hash_node_position(vector.subtract(minetest.get_position_from_hash(hash), root_pos))
local pos = minetest.get_position_from_hash(hash)
local relative_hash = minetest.hash_node_position(vector.subtract(pos, root_pos))
local current_meta
if hash == root_hash then
@ -462,6 +463,9 @@ local assemble = function(root_pos, player_name)
node.param1 = nil -- we don't care about param1, wipe it to save space
layout[relative_hash] = {meta = current_meta_table, node = node}
local meta = minetest.get_meta(pos)
-- track this so that we can interact with individual node settings in the assembled digtron
meta:set_string("digtron_relative_hash", relative_hash)
end
persist_inventory(digtron_id)

@ -40,6 +40,7 @@ Roll@nClockwise=
Roll@nWiddershins=
Rotate=
Sequence=
Stop=
Up=
Yaw Left=
Yaw Right=