playback/recording with id
This commit is contained in:
parent
50f59ba6e7
commit
de32f08be7
@ -49,7 +49,7 @@ end
|
||||
function pick_and_place.configure(pos1, pos2, name, id)
|
||||
pos1, pos2 = pick_and_place.sort_pos(pos1, pos2)
|
||||
id = id or pick_and_place.create_id()
|
||||
pick_and_place.register_template(name, pos1, pos2)
|
||||
pick_and_place.register_template(pos1, pos2, name, id)
|
||||
|
||||
for _, cpos in ipairs(pick_and_place.get_outer_corners(pos1, pos2)) do
|
||||
local node = minetest.get_node(cpos)
|
||||
|
@ -125,7 +125,7 @@ minetest.register_lbm({
|
||||
action = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
migrate_handle(pos, meta)
|
||||
local pos1, pos2, name = pick_and_place.get_template_data_from_handle(pos, meta)
|
||||
pick_and_place.register_template(name, pos1, pos2)
|
||||
local pos1, pos2, name, id = pick_and_place.get_template_data_from_handle(pos, meta)
|
||||
pick_and_place.register_template(pos1, pos2, name, id)
|
||||
end
|
||||
})
|
@ -38,6 +38,7 @@ minetest.register_tool("pick_and_place:place", {
|
||||
-- placement
|
||||
local disable_replacements = controls.zoom
|
||||
local name = meta:get_string("name")
|
||||
local id = meta:get_string("id")
|
||||
local rotation = meta:get_int("rotation")
|
||||
local encoded_schematic = meta:get_string("schematic")
|
||||
local schematic, err = pick_and_place.decode_schematic(encoded_schematic)
|
||||
@ -50,7 +51,7 @@ minetest.register_tool("pick_and_place:place", {
|
||||
minetest.chat_send_player(playername, "Placement error: " .. msg)
|
||||
else
|
||||
if name ~= "" then
|
||||
pick_and_place.record_placement(pos1, pos2, rotation, name)
|
||||
pick_and_place.record_placement(pos1, pos2, rotation, name, id)
|
||||
end
|
||||
notify_change(pos1, pos2)
|
||||
end
|
||||
|
10
playback.lua
10
playback.lua
@ -1,7 +1,7 @@
|
||||
local playback_active = false
|
||||
|
||||
local function get_cache_key(name, rotation)
|
||||
return name .. "/" .. rotation
|
||||
local function get_cache_key(id, rotation)
|
||||
return id .. "/" .. rotation
|
||||
end
|
||||
|
||||
local function playback(ctx)
|
||||
@ -22,9 +22,9 @@ local function playback(ctx)
|
||||
end
|
||||
|
||||
if entry.type == "place" then
|
||||
local tmpl = pick_and_place.get_template(entry.name)
|
||||
local tmpl = pick_and_place.get_template(entry.id)
|
||||
if tmpl then
|
||||
local key = get_cache_key(entry.name, entry.rotation)
|
||||
local key = get_cache_key(entry.id, entry.rotation)
|
||||
local schematic = ctx.cache[key]
|
||||
|
||||
if not schematic then
|
||||
@ -38,7 +38,7 @@ local function playback(ctx)
|
||||
local abs_pos1 = vector.add(ctx.origin, entry.pos1)
|
||||
pick_and_place.deserialize(abs_pos1, schematic)
|
||||
else
|
||||
minetest.chat_send_player(ctx.playername, "pnp playback: template not found: '" .. entry.name .. "'")
|
||||
minetest.chat_send_player(ctx.playername, "pnp playback: template not found: '" .. entry.id .. "'")
|
||||
end
|
||||
elseif entry.type == "remove" then
|
||||
local abs_pos1 = vector.add(ctx.origin, entry.pos1)
|
||||
|
@ -169,7 +169,7 @@ function pick_and_place.record_removal(pos1, pos2)
|
||||
end
|
||||
end
|
||||
|
||||
function pick_and_place.record_placement(pos1, pos2, rotation, name)
|
||||
function pick_and_place.record_placement(pos1, pos2, rotation, name, id)
|
||||
if not state or not origin then
|
||||
return
|
||||
end
|
||||
@ -184,6 +184,7 @@ function pick_and_place.record_placement(pos1, pos2, rotation, name)
|
||||
pos1 = rel_pos1,
|
||||
pos2 = rel_pos2,
|
||||
rotation = rotation,
|
||||
name = name
|
||||
name = name,
|
||||
id = id
|
||||
})
|
||||
end
|
10
registry.lua
10
registry.lua
@ -1,12 +1,12 @@
|
||||
|
||||
-- registry of templates
|
||||
-- name => { pos1 = {}, pos2 = {} }
|
||||
-- id => { pos1 = {}, pos2 = {}, name = "" }
|
||||
local registry = {}
|
||||
|
||||
function pick_and_place.register_template(name, pos1, pos2)
|
||||
registry[name] = { pos1=pos1, pos2=pos2 }
|
||||
function pick_and_place.register_template(pos1, pos2, name, id)
|
||||
registry[id] = { pos1=pos1, pos2=pos2, name=name }
|
||||
end
|
||||
|
||||
function pick_and_place.get_template(name)
|
||||
return registry[name]
|
||||
function pick_and_place.get_template(id)
|
||||
return registry[id]
|
||||
end
|
@ -49,6 +49,10 @@ minetest.register_node("pick_and_place:replacement", {
|
||||
})
|
||||
|
||||
function pick_and_place.get_replacement_nodeid(ctx, metadata)
|
||||
if not metadata then
|
||||
return
|
||||
end
|
||||
|
||||
local group = metadata.fields.group
|
||||
local selected_name
|
||||
if group and group ~= "" and ctx[group] then
|
||||
|
Loading…
x
Reference in New Issue
Block a user