Skip to content

Commit

Permalink
minor code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OgelGames committed Jun 14, 2021
1 parent c9d302c commit fe47407
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 182 deletions.
18 changes: 8 additions & 10 deletions awards.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-- Awards
if minetest.get_modpath("awards") then
awards.register_award("fancy_vend:getting_fancy",{
awards.register_award("fancy_vend:getting_fancy", {
title = "Getting Fancy",
description = "Craft a fancy vendor.",
trigger = {
Expand All @@ -11,8 +11,7 @@ if minetest.get_modpath("awards") then
},
icon = "player_vend_front.png^awards_level1.png",
})

awards.register_award("fancy_vend:wizard",{
awards.register_award("fancy_vend:wizard", {
title = "You're a Wizard",
description = "Craft a copy tool.",
trigger = {
Expand All @@ -22,33 +21,32 @@ if minetest.get_modpath("awards") then
},
icon = "copier.png",
})

awards.register_award("fancy_vend:trader",{
awards.register_award("fancy_vend:trader", {
title = "Trader",
description = "Configure a depositor.",
icon = "player_depo_front.png",
})
awards.register_award("fancy_vend:seller",{
awards.register_award("fancy_vend:seller", {
title = "Seller",
description = "Configure a vendor.",
icon = "player_vend_front.png^awards_level2.png",
})
awards.register_award("fancy_vend:shop_keeper",{
awards.register_award("fancy_vend:shop_keeper", {
title = "Shop Keeper",
description = "Configure 10 vendors or depositors.",
icon = "player_vend_front.png^awards_level3.png",
})
awards.register_award("fancy_vend:merchant",{
awards.register_award("fancy_vend:merchant", {
title = "Merchant",
description = "Configure 25 vendors or depositors.",
icon = "player_vend_front.png^awards_level4.png",
})
awards.register_award("fancy_vend:super_merchant",{
awards.register_award("fancy_vend:super_merchant", {
title = "Super Merchant",
description = "Configure 100 vendors or depositors. How do you even have this much stuff to sell?",
icon = "player_vend_front.png^awards_level5.png",
})
awards.register_award("fancy_vend:god_merchant",{
awards.register_award("fancy_vend:god_merchant", {
title = "God Merchant",
description = "Configure 9001 vendors or depositors. Ok wot.",
icon = "player_vend_front.png^awards_level6.png",
Expand Down
13 changes: 5 additions & 8 deletions copy_tool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ local function get_vendor_pos_and_settings(pointed_thing)
node = minetest.get_node(pos)
end
if not fancy_vend.is_vendor(node.name) then return false end

local settings = fancy_vend.get_vendor_settings(pos)

return pos, settings
end

minetest.register_tool("fancy_vend:copy_tool",{
minetest.register_tool("fancy_vend:copy_tool", {
inventory_image = "copier.png",
description = "Geminio Wand (For copying vendor settings, right click to"..
"copy settings, left click to paste settings.)",
Expand All @@ -42,9 +40,8 @@ minetest.register_tool("fancy_vend:copy_tool",{
local node_meta = minetest.get_meta(pos)
local new_settings = minetest.deserialize(meta:get_string("settings"))
if not new_settings then
minetest.chat_send_player(
user:get_player_name(),
"No settings to set with. Right-click first on the vendor you want to copy settings from."
minetest.chat_send_player(user:get_player_name(),
"No settings to set with. Right-click first on the vendor you want to copy settings from."
)
return
end
Expand All @@ -57,14 +54,14 @@ minetest.register_tool("fancy_vend:copy_tool",{
new_settings.output_item_qty = current_settings.output_item_qty

-- Admin vendor priv check
if not minetest.check_player_privs(node_meta:get_string("owner"), {admin_vendor=true}) and
if not minetest.check_player_privs(node_meta:get_string("owner"), {admin_vendor = true}) and
new_settings.admin_vendor then
new_settings.admin_vendor = current_settings.admin_vendor
end

fancy_vend.set_vendor_settings(pos, new_settings)
fancy_vend.refresh_vendor(pos)
minetest.chat_send_player(user:get_player_name(), "Settings set.")
minetest.chat_send_player(user:get_player_name(), "Settings set at "..minetest.pos_to_string(pos)..".")
else
minetest.chat_send_player(user:get_player_name(), "You cannot modify this vendor.")
end
Expand Down
11 changes: 6 additions & 5 deletions disable_global.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@


-- Craftitem to display when vendor is inactive (Use just image for this???)
minetest.register_craftitem("fancy_vend:inactive",{inventory_image = "inactive.png",})


minetest.register_craftitem("fancy_vend:inactive", {
description = "Fancy Vendor Inactive Item (you hacker you!)",
inventory_image = "inactive.png",
groups = {not_in_creative_inventory = 1},
})

local modstorage = minetest.get_mod_storage()

Expand All @@ -15,7 +16,7 @@ fancy_vend.all_inactive_force = fancy_vend.stb(modstorage:get_string("all_inacti

minetest.register_chatcommand("disable_all_vendors", {
description = "Toggle vendor inactivity.",
privs = {disable_vendor=true},
privs = {disable_vendor = true},
func = function()
if fancy_vend.all_inactive_force then
fancy_vend.all_inactive_force = false
Expand Down
9 changes: 5 additions & 4 deletions display_item.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

local tmp = {}

minetest.register_entity("fancy_vend:display_item",{
minetest.register_entity("fancy_vend:display_item", {
hp_max = 1,
visual = "wielditem",
visual_size = {x = 0.33, y = 0.33},
Expand All @@ -16,7 +16,7 @@ minetest.register_entity("fancy_vend:display_item",{
tmp.texture = nil
else
if staticdata ~= nil and staticdata ~= "" then
local data = staticdata:split(';')
local data = staticdata:split(";")
if data and data[1] and data[2] then
self.nodename = data[1]
self.texture = data[2]
Expand All @@ -30,7 +30,7 @@ minetest.register_entity("fancy_vend:display_item",{
end,
get_staticdata = function(self)
if self.nodename ~= nil and self.texture ~= nil then
return self.nodename .. ';' .. self.texture
return self.nodename..";"..self.texture
end
return ""
end,
Expand All @@ -51,7 +51,8 @@ function fancy_vend.update_item(pos, node)
pos.y = pos.y + 1
fancy_vend.remove_item(pos)
if minetest.get_node(pos).name ~= "fancy_vend:display_node" then
minetest.log("warning", "[fancy_vend]: Placing display item inside "..
minetest.log("warning",
"[fancy_vend]: Placing display item inside "..
minetest.get_node(pos).name.." at "..minetest.pos_to_string(pos)..
" is not permitted, aborting"
)
Expand Down
1 change: 1 addition & 0 deletions display_node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ display_node_def.drop = ""
display_node_def.pointable = false
display_node_def.groups.not_in_creative_inventory = 1
display_node_def.description = "Fancy Vendor Display Node (you hacker you!)"

if pipeworks then
display_node_def.digiline = {
wire = {
Expand Down
57 changes: 28 additions & 29 deletions formspecs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ function fancy_vend.get_vendor_buyer_fs(pos, _, lots)
"item_image_button[0,1.7;1,1;"..settings.output_item..";ignore;]"..
"label[0.9,1.9;"..settings.output_item_qty.." "..output_desc.."]"

local status_str
if status then
status_str = "active"
else
local status_str = "active"
if not status then
status_str = "inactive"..fancy_vend.make_inactive_string(errorcode)
end

local status_fs =
"label[4,0.4;Vendor status: "..status_str.."]"..
"label[4,0.8;Message: "..meta:get_string("message").."]"..
"label[4,0;Vendor owned by: "..meta:get_string("owner").."]"
"label[4,0.4;Vendor status: "..status_str.."]"..
"label[4,0.8;Message: "..meta:get_string("message").."]"..
"label[4,0;Vendor owned by: "..meta:get_string("owner").."]"

local setting_specific = ""
if not settings.accept_worn_input then
Expand Down Expand Up @@ -98,10 +97,10 @@ function fancy_vend.get_vendor_settings_fs(pos)

-- Admin vendor checkbox only if owner is admin
local meta = minetest.get_meta(pos)
if minetest.check_player_privs(meta:get_string("owner"), {admin_vendor=true}) or settings.admin_vendor then
if minetest.check_player_privs(meta:get_string("owner"), {admin_vendor = true}) or settings.admin_vendor then
checkboxes = checkboxes..
"checkbox[5,2.2;admin_vendor;Set vendor to an admin vendor.;"..
fancy_vend.bts(settings.admin_vendor).."]"
fancy_vend.bts(settings.admin_vendor).."]"
end


Expand All @@ -111,9 +110,9 @@ function fancy_vend.get_vendor_settings_fs(pos)
"checkbox[1,1.7;currency_eject;Eject incoming currency.;"..fancy_vend.bts(settings.currency_eject).."]"
if minetest.get_modpath("pipeworks") then
checkboxes = checkboxes..
"checkbox[5,1.3;accept_output_only;Accept for-sale item only.;"..
"checkbox[5,1.3;accept_output_only;Accept for-sale item only.;"..
fancy_vend.bts(settings.accept_output_only).."]"..
"checkbox[1,1.3;split_incoming_stacks;Split incoming stacks.;"..
"checkbox[1,1.3;split_incoming_stacks;Split incoming stacks.;"..
fancy_vend.bts(settings.split_incoming_stacks).."]"
end
end
Expand Down Expand Up @@ -150,14 +149,14 @@ function fancy_vend.get_vendor_default_fs(pos, player)
local settings_btn
if fancy_vend.can_modify_vendor(pos, player) then
settings_btn =
"image_button[0,1.3;1,1;debug_btn.png;button_settings;]"..
"item_image_button[0,2.3;1,1;default:book;button_log;]"..
"item_image_button[0,3.3;1,1;default:gold_ingot;button_buy;]"
"image_button[0,1.3;1,1;debug_btn.png;button_settings;]"..
"item_image_button[0,2.3;1,1;default:book;button_log;]"..
"item_image_button[0,3.3;1,1;default:gold_ingot;button_buy;]"
else
settings_btn =
"image[0,1.3;1,1;debug_btn.png]"..
"item_image[0,2.3;1,1;default:book]"..
"item_image[0,3.3;1,1;default:gold_ingot;button_buy;]"
"image[0,1.3;1,1;debug_btn.png]"..
"item_image[0,2.3;1,1;default:book]"..
"item_image[0,3.3;1,1;default:gold_ingot;button_buy;]"
end

local fs = base..inv_lists..settings_btn
Expand All @@ -183,7 +182,7 @@ function fancy_vend.get_vendor_log_fs(pos)
base = base.."item_image_button[0,0.3;1,1;default:chest;button_inv;]"
end

if not logs then logs = {"Error loading logs",} end
if not logs then logs = {"Error loading logs"} end
local logs_tl =
"textlist[1,0.5;7.8,8.6;logs;"..table.concat(logs, ",").."]"..
"label[1,0;Showing (up to "..fancy_vend.max_logs..") recent log entries:]"
Expand All @@ -193,26 +192,26 @@ function fancy_vend.get_vendor_log_fs(pos)
end

function fancy_vend.show_buyer_formspec(player, pos)
minetest.show_formspec(player:get_player_name(), "fancy_vend:buyer;"..
minetest.pos_to_string(pos), fancy_vend.get_vendor_buyer_fs(pos, player, nil)
minetest.show_formspec(player:get_player_name(),
"fancy_vend:buyer;"..minetest.pos_to_string(pos),
fancy_vend.get_vendor_buyer_fs(pos, player, nil)
)
end

function fancy_vend.show_vendor_formspec(player, pos)
local settings = fancy_vend.get_vendor_settings(pos)
if fancy_vend.can_access_vendor_inv(player, pos) then
local status, errorcode = fancy_vend.get_vendor_status(pos)
if (
(not status and errorcode == "unconfigured")
and
fancy_vend.can_modify_vendor(pos, player)
) or settings.admin_vendor then
minetest.show_formspec(player:get_player_name(), "fancy_vend:settings;"..
minetest.pos_to_string(pos), fancy_vend.get_vendor_settings_fs(pos)
if ((not status and errorcode == "unconfigured")
and fancy_vend.can_modify_vendor(pos, player)) or settings.admin_vendor then
minetest.show_formspec(player:get_player_name(),
"fancy_vend:settings;"..minetest.pos_to_string(pos),
fancy_vend.get_vendor_settings_fs(pos)
)
else
minetest.show_formspec(player:get_player_name(), "fancy_vend:default;"..
minetest.pos_to_string(pos), fancy_vend.get_vendor_default_fs(pos, player)
minetest.show_formspec(player:get_player_name(),
"fancy_vend:default;"..minetest.pos_to_string(pos),
fancy_vend.get_vendor_default_fs(pos, player)
)
end
else
Expand Down
9 changes: 4 additions & 5 deletions functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ end

function fancy_vend.can_buy_from_vendor(pos, player)
local settings = fancy_vend.get_vendor_settings(pos)
local banned_buyers = string.split((settings.banned_buyers or ""),",")
local banned_buyers = string.split((settings.banned_buyers or ""), ",")
for i in pairs(banned_buyers) do
if banned_buyers[i] == player:get_player_name() then
return false
Expand All @@ -76,21 +76,20 @@ function fancy_vend.can_modify_vendor(pos, player)
local meta = minetest.get_meta(pos)
local is_owner = false
if meta:get_string("owner") == player:get_player_name() or
minetest.check_player_privs(player, {protection_bypass=true}) then
minetest.check_player_privs(player, {protection_bypass = true}) then
is_owner = true
end
return is_owner
end

function fancy_vend.can_dig_vendor(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("main") and fancy_vend.can_modify_vendor(pos, player)
end

function fancy_vend.can_access_vendor_inv(player, pos)
local meta = minetest.get_meta(pos)
if minetest.check_player_privs(player, {protection_bypass=true}) or
if minetest.check_player_privs(player, {protection_bypass = true}) or
meta:get_string("owner") == player:get_player_name() then
return true
end
Expand Down
1 change: 1 addition & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

-- /$$$$$$$$ /$$ /$$ /$$
-- | $$_____/ | $$ | $$ | $$
-- | $$ /$$$$$$ /$$$$$$$ /$$$$$$$ /$$ /$$ | $$ | $$ /$$$$$$ /$$$$$$$ /$$$$$$$
Expand Down
24 changes: 5 additions & 19 deletions integrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ local tell_loaded = minetest.get_modpath("tell")
local mail_loaded = minetest.get_modpath("mail")

function fancy_vend.alert_owner_if_empty(pos)
if fancy_vend.no_alerts then
return
end
if fancy_vend.no_alerts then return end

local meta = minetest.get_meta(pos)
local settings = fancy_vend.get_vendor_settings(pos)
local owner = meta:get_string("owner")
local alerted = fancy_vend.stb(meta:get_string("alerted") or "false") -- check
local alerted = fancy_vend.stb(meta:get_string("alerted") or "false")
local status, errorcode = fancy_vend.get_vendor_status(pos)

-- Message to send
Expand All @@ -26,7 +24,6 @@ function fancy_vend.alert_owner_if_empty(pos)
" has just run out of stock."

if not alerted and not status and errorcode == "no_output" then
-- Rubenwardy's Email Mod: https://github.com/rubenwardy/email
if mail_loaded then
local inbox = {}

Expand Down Expand Up @@ -55,7 +52,6 @@ function fancy_vend.alert_owner_if_empty(pos)
if message then
-- Set the message as unread
message.unread = true

-- Append to the end
message.body = message.body..stock_msg.."\n"
else
Expand All @@ -70,27 +66,17 @@ function fancy_vend.alert_owner_if_empty(pos)
elseif mail.apiversion >= 1.1 then
-- webmail fork https://github.com/thomasrudin-mt/mail
mail.setMessages(owner, inbox)

end

meta:set_string("alerted", "true")

return

elseif email_loaded then
-- Rubenwardy's Email Mod: https://github.com/rubenwardy/email
email.send_mail("Fancy Vend", owner, stock_msg)

meta:set_string("alerted", "true")

return

elseif tell_loaded then
-- octacians tell mod https://github.com/octacian/tell
tell.add(owner, "Fancy Vend", stock_msg)

meta:set_string("alerted", "true")

return
end

meta:set_string("alerted", "true")
end
end
Loading

0 comments on commit fe47407

Please sign in to comment.