working add/remove
This commit is contained in:
parent
7d2210649e
commit
0b0c9af925
@ -16,13 +16,13 @@ minetest.register_node("missions:mission", {
|
||||
local meta = minetest.get_meta(pos)
|
||||
local playername = placer:get_player_name() or ""
|
||||
meta:set_string("owner", playername)
|
||||
meta:set_int("selected_step", 1)
|
||||
end,
|
||||
|
||||
can_dig = missions.only_owner_can_dig,
|
||||
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("steps", minetest.serialize({}))
|
||||
missions.set_steps(pos, {})
|
||||
end,
|
||||
|
||||
on_rightclick = missions.form.missionblock
|
||||
|
@ -4,23 +4,27 @@ local FORMNAME = "mission_block_main"
|
||||
missions.form.missionblock = function(pos, node, player)
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local steps = minetest.deserialize(meta:get_string("steps"))
|
||||
local selected_step = meta:get_int("selected_step")
|
||||
|
||||
print(meta:get_string("steps"))
|
||||
print(meta:get_string("steps")) --XXX
|
||||
|
||||
local steps = missions.get_steps(pos)
|
||||
|
||||
-- steps list
|
||||
local steps_list = "textlist[0,1;5,6;steps;"
|
||||
for i,step in pairs(steps) do
|
||||
steps_list = i .. ": " .. step.name .. ","
|
||||
for i,step in ipairs(steps) do
|
||||
steps_list = steps_list .. i .. ": " .. step.name .. ","
|
||||
end
|
||||
steps_list = steps_list .. "]";
|
||||
steps_list = steps_list .. ";" .. selected_step .. "]";
|
||||
|
||||
|
||||
local formspec = "size[8,8;]" ..
|
||||
"label[0,0;Mission editor]" ..
|
||||
"button_exit[6,1;2,1;add;Add]" ..
|
||||
"button[6,2;2,1;up;Up]" ..
|
||||
"button[6,3;2,1;down;Down]" ..
|
||||
"button[6,4;2,1;remove;Remove]" ..
|
||||
"button_exit[6,2;2,1;edit;Edit]" ..
|
||||
"button[6,3;2,1;up;Up]" ..
|
||||
"button[6,4;2,1;down;Down]" ..
|
||||
"button_exit[6,5;2,1;remove;Remove]" ..
|
||||
steps_list
|
||||
|
||||
minetest.show_formspec(player:get_player_name(),
|
||||
@ -40,6 +44,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
|
||||
local pos = minetest.string_to_pos(parts[2])
|
||||
local meta = minetest.get_meta(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if fields.add then
|
||||
@ -48,8 +53,38 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end)
|
||||
end
|
||||
|
||||
print(dump(pos)) --XXX
|
||||
print(dump(fields))
|
||||
if fields.remove then
|
||||
local steps = missions.get_steps(pos)
|
||||
local selected_step = meta:get_int("selected_step")
|
||||
table.remove(steps, selected_step)
|
||||
missions.set_steps(pos, steps)
|
||||
|
||||
minetest.after(0.1, function()
|
||||
missions.form.missionblock(pos, node, player)
|
||||
end)
|
||||
end
|
||||
|
||||
if fields.edit then
|
||||
--TODO
|
||||
end
|
||||
|
||||
if fields.up then
|
||||
--TODO
|
||||
end
|
||||
|
||||
if fields.down then
|
||||
--TODO
|
||||
end
|
||||
|
||||
if fields.steps then
|
||||
parts = fields.steps:split(":")
|
||||
if parts[1] == "CHG" then
|
||||
local selected_step = tonumber(parts[2])
|
||||
meta:set_int("selected_step", selected_step)
|
||||
end
|
||||
end
|
||||
|
||||
print(dump(fields)) --XXX
|
||||
|
||||
end)
|
||||
|
||||
|
@ -27,8 +27,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
if fields.walkto then
|
||||
local steps = missions.get_steps(pos)
|
||||
print(#steps)
|
||||
|
||||
table.insert(steps, {
|
||||
type="walkto",
|
||||
name="Walk to",
|
||||
time=300,
|
||||
pos=nil
|
||||
})
|
||||
|
||||
missions.set_steps(pos, steps)
|
||||
local stepnumber = #steps+1
|
||||
|
||||
minetest.after(0.1, function()
|
||||
missions.form.walkto(pos, node, player)
|
||||
missions.form.walkto(pos, node, player, stepnumber)
|
||||
end)
|
||||
end
|
||||
|
||||
|
@ -5,21 +5,38 @@ local get_inv_name = function(player)
|
||||
return FORMNAME .. "_" .. player:get_player_name()
|
||||
end
|
||||
|
||||
local get_inv = function(player)
|
||||
return minetest.get_inventory({type="detached",name=get_inv_name(player)})
|
||||
end
|
||||
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local playername = player:get_player_name()
|
||||
local inv = minetest.create_detached_inventory(get_inv_name(player))
|
||||
local inv = minetest.create_detached_inventory(get_inv_name(player), {
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if stack:get_name() == "missions:wand_position" then
|
||||
return 1
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
})
|
||||
inv:set_size("main", 1)
|
||||
end)
|
||||
|
||||
missions.form.walkto = function(pos, node, player)
|
||||
missions.form.walkto = function(pos, node, player, stepnumber)
|
||||
local formspec = "size[8,8;]" ..
|
||||
"label[0,0;Step Walk to]" ..
|
||||
--"list[detached;" .. get_inv_name(player) .. ";0,1;1,1;]" ..
|
||||
"label[0,0;Walk to (Step #" .. stepnumber .. ")]" ..
|
||||
|
||||
"list[detached:" .. get_inv_name(player) .. ";main;0,1;1,1;]" ..
|
||||
"list[current_player;main;0,2;8,1;]"
|
||||
"button_exit[1,1;4,1;read;Read position]" ..
|
||||
|
||||
"label[0,2;My label]" ..
|
||||
|
||||
"list[current_player;main;0,3;8,1;]"
|
||||
|
||||
minetest.show_formspec(player:get_player_name(),
|
||||
FORMNAME .. ";" .. minetest.pos_to_string(pos),
|
||||
FORMNAME .. ";" .. minetest.pos_to_string(pos) .. ";" .. stepnumber,
|
||||
formspec
|
||||
)
|
||||
|
||||
@ -36,6 +53,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
|
||||
local pos = minetest.string_to_pos(parts[2])
|
||||
local node = minetest.get_node(pos)
|
||||
local stepnumber = tonumber(parts[3])
|
||||
|
||||
if fields.read then
|
||||
local inv = get_inv(player)
|
||||
local stack = inv:get_stack("main", 1)
|
||||
|
||||
if not stack:is_empty() then
|
||||
local meta = stack:get_meta()
|
||||
local pos = minetest.string_to_pos(meta:get_string("pos"))
|
||||
local name = meta:get_string("name")
|
||||
|
||||
print("Name: " .. name .. " in step: " .. stepnumber)--XXX
|
||||
--TODO: how to handle used wand: give it back to user?
|
||||
end
|
||||
end
|
||||
|
||||
print(dump(pos)) --XXX
|
||||
print(dump(fields))
|
||||
|
@ -1,6 +1,6 @@
|
||||
local has_xp_redo_mod = minetest.get_modpath("xp_redo")
|
||||
|
||||
|
||||
-- running player missions
|
||||
missions.save_missions = function()
|
||||
-- TODO
|
||||
end
|
||||
@ -9,6 +9,19 @@ missions.load_missions = function()
|
||||
-- TODO
|
||||
end
|
||||
|
||||
-- mission steps setter/getter
|
||||
missions.get_steps = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local steps = minetest.deserialize(meta:get_string("steps"))
|
||||
|
||||
return steps
|
||||
end
|
||||
|
||||
missions.set_steps = function(pos, steps)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("steps", minetest.serialize(steps))
|
||||
end
|
||||
|
||||
|
||||
-- timeout check
|
||||
local timer = 0
|
||||
@ -26,11 +39,14 @@ minetest.register_globalstep(function(dtime)
|
||||
end
|
||||
end)
|
||||
|
||||
-- node register helper
|
||||
missions.only_owner_can_dig = function(pos, player)
|
||||
if not player then
|
||||
return false
|
||||
end
|
||||
|
||||
--TODO: check protection_bypass
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local playername = player:get_player_name() or ""
|
||||
return meta:get_string("owner") == playername
|
||||
|
Loading…
x
Reference in New Issue
Block a user