diff --git a/.luacheckrc b/.luacheckrc index 51b0d21..4339ca0 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -17,6 +17,7 @@ read_globals = { "christmas", "digilines", "drawers", + "fancy_vend", "jumpdrive", "locator", "mesecon", diff --git a/init.lua b/init.lua index 3b6d156..35e94c8 100644 --- a/init.lua +++ b/init.lua @@ -38,6 +38,7 @@ local mods = { "digistuff", "digtron", "drawers", + "fancy_vend", "easyvend", "jumpdrive", "locator", diff --git a/mod.conf b/mod.conf index 0daa279..801aae3 100644 --- a/mod.conf +++ b/mod.conf @@ -17,6 +17,7 @@ optional_depends = """ digiscreen, digistuff, drawers, + fancy_vend, easyvend, jumpdrive, locator, diff --git a/nodes/fancy_vend.lua b/nodes/fancy_vend.lua new file mode 100644 index 0000000..8bfe43a --- /dev/null +++ b/nodes/fancy_vend.lua @@ -0,0 +1,42 @@ + +-- Register wrench support for the fancy_vend mod + +for _, vendor in ipairs({ + "fancy_vend:player_vendor", + "fancy_vend:player_depo", + "fancy_vend:admin_vendor", + "fancy_vend:admin_depo", + }) do + wrench.register_node(vendor, { + lists = { "given_item", "main", "wanted_item" }, + metas = { + alerted = wrench.META_TYPE_STRING, + configured = wrench.META_TYPE_STRING, + infotext = wrench.META_TYPE_IGNORE, + item = wrench.META_TYPE_STRING, + log = wrench.META_TYPE_STRING, + message = wrench.META_TYPE_STRING, + owner = wrench.META_TYPE_STRING, + settings = wrench.META_TYPE_STRING, + }, + after_pickup = function(pos, node, meta_table, player) + local above_node_pos = table.copy(pos) + above_node_pos.y = above_node_pos.y + 1 + core.remove_node(above_node_pos) + fancy_vend.remove_item(above_node_pos) + end, + after_place = function(pos) + -- This happens during vendor's on_place function is being run! + -- So we need to hack around that race condition. + -- At this time wrench has already set the meta, so we can stash + -- it from the node with fancy_vend function + local settings = fancy_vend.get_vendor_settings(pos) + core.after(0, function(p, s) + -- Use fancy_vend's own function to apply the stashed settings + fancy_vend.set_vendor_settings(p, s) + fancy_vend.refresh_vendor(p) + end, pos, settings) + end, + }) +end +