Skip to content

Commit

Permalink
Add [fancy_vend] support (#21)
Browse files Browse the repository at this point in the history
Co-authored-by: Buckaroo Banzai <[email protected]>
  • Loading branch information
SwissalpS and BuckarooBanzay authored Dec 31, 2024
1 parent 9714875 commit c02568e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ read_globals = {
"christmas",
"digilines",
"drawers",
"fancy_vend",
"jumpdrive",
"locator",
"mesecon",
Expand Down
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ local mods = {
"digistuff",
"digtron",
"drawers",
"fancy_vend",
"easyvend",
"jumpdrive",
"locator",
Expand Down
1 change: 1 addition & 0 deletions mod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ optional_depends = """
digiscreen,
digistuff,
drawers,
fancy_vend,
easyvend,
jumpdrive,
locator,
Expand Down
42 changes: 42 additions & 0 deletions nodes/fancy_vend.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c02568e

Please sign in to comment.