Better migrate options, fix 'default' dependency

This commit is contained in:
SmallJoker 2018-07-08 10:04:45 +02:00
parent 89d08b907b
commit 130389705b
5 changed files with 45 additions and 29 deletions

View File

@ -41,7 +41,7 @@ local function list_add_list(inv, list_name, list)
return leftover_list
end
local function migrate_shop_node(pos, node)
function exchange_shop.migrate_shop_node(pos, node)
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local title = meta:get_string("infotext")
@ -76,22 +76,24 @@ local function migrate_shop_node(pos, node)
minetest.swap_node(pos, node)
end
minetest.register_lbm({
label = "currency shop to exchange shop migration",
name = "exchange_shop:currency_migrate",
nodenames = { "currency:shop" },
run_at_every_load = true, -- TODO this for testing only
action = migrate_shop_node
})
if exchange_shop.migrate.use_lbm then
minetest.register_lbm({
label = "currency shop to exchange shop migration",
name = "exchange_shop:currency_migrate",
nodenames = { "currency:shop" },
run_at_every_load = false,
action = exchange_shop.migrate_shop_node
})
-- Clean up garbage
minetest.register_on_joinplayer(function(player)
local inv = player:get_inventory()
for i, name in pairs({"customer_gives", "customer_gets"}) do
if inv:get_size(name) > 0 then
local leftover = list_add_list(inv, "main", inv:get_list(name))
list_add_list(inv, "craft", leftover)
inv:set_size(name, 0)
-- Clean up garbage
minetest.register_on_joinplayer(function(player)
local inv = player:get_inventory()
for i, name in pairs({"customer_gives", "customer_gets"}) do
if inv:get_size(name) > 0 then
local leftover = list_add_list(inv, "main", inv:get_list(name))
list_add_list(inv, "craft", leftover)
inv:set_size(name, 0)
end
end
end
end)
end)
end

View File

@ -1,8 +1,5 @@
local def = table.copy(minetest.registered_nodes["currency:shop"])
def.groups.not_in_creative_inventory = 1
minetest.override_item("currency:shop", {
groups = def.groups,
on_construct = function() end,
after_place_node = function(pos, ...)
local node = minetest.get_node(pos)
@ -14,6 +11,10 @@ minetest.override_item("currency:shop", {
new_def.on_construct(pos)
end
new_def.after_place_node(pos, unpack({...}))
end,
on_rightclick = function(pos, node, ...)
exchange_shop.migrate_shop_node(pos, node)
local new_def = minetest.registered_nodes[exchange_shop.shopname]
new_def.on_rightclick(pos, node, unpack({...}))
end
})
})

View File

@ -1,3 +1,4 @@
default
currency?
bitchange?
wrench?

View File

@ -5,23 +5,34 @@ exchange_shop.shopname = "exchange_shop:shop"
local modpath = minetest.get_modpath("exchange_shop")
local has_currency = minetest.get_modpath("currency")
local has_bitchange = minetest.get_modpath("bitchange")
local migrate_currency = true -- TODO testing!
local slow_migrate_currency = false
-- Currency migrate options
exchange_shop.migrate = {
use_lbm = false,
-- ^ Runs once on each unique loaded mapblock
on_interact = true
-- ^ Converts shop nodes "on the fly"
}
if has_bitchange then
minetest.register_alias("exchange_shop:shop", "bitchange:shop")
exchange_shop.shopname = "bitchange:shop"
else
minetest.register_alias("bitchange:shop", "exchange_shop:shop")
dofile(modpath .. "/shop_functions.lua")
dofile(modpath .. "/shop.lua")
end
if has_currency then
if migrate_currency then
dofile(modpath .. "/currency_migrate.lua")
end
if slow_migrate_currency then
local new_groups = table.copy(minetest.registered_nodes["currency:shop"].groups)
new_groups.not_in_creative_inventory = 1
minetest.override_item("currency:shop", {
groups = new_groups
})
dofile(modpath .. "/currency_migrate.lua")
if exchange_shop.migrate.on_interact then
dofile(modpath .. "/currency_override.lua")
end
end

View File

@ -1,2 +1,3 @@
name = exchange_shop
depends = default
optional_depends = currency, bitchange, wrench