add a debugging command to insert all registered items into a market for finding other edge cases

This commit is contained in:
FaceDeer 2020-01-10 09:59:16 -07:00
parent af67b830a4
commit db0d0f99db
3 changed files with 50 additions and 18 deletions

View File

@ -55,7 +55,7 @@ local get_icon = function(item)
returnstring = returnstring:sub(1, found_caret-1) returnstring = returnstring:sub(1, found_caret-1)
end end
return returnstring return minetest.formspec_escape(returnstring)
end end
-- Exposed so that the purge_unknowns command can use it. -- Exposed so that the purge_unknowns command can use it.
commoditymarket.get_icon = get_icon commoditymarket.get_icon = get_icon

View File

@ -8,10 +8,15 @@ dofile(MP.."/doc.lua")
dofile(MP.."/default_markets.lua") dofile(MP.."/default_markets.lua")
dofile(MP.."/mapgen_dungeon_markets.lua") dofile(MP.."/mapgen_dungeon_markets.lua")
-- internationalization boilerplate
local MP = minetest.get_modpath(minetest.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")
minetest.register_chatcommand("market.show", { minetest.register_chatcommand("market.show", {
params = "marketname", params = "marketname",
privs = {server=true}, privs = {server=true},
decription = "show market formspec", description = S("show market formspec"),
func = function(name, param) func = function(name, param)
local market = commoditymarket.registered_markets[param] local market = commoditymarket.registered_markets[param]
if market == nil then return end if market == nil then return end
@ -23,7 +28,7 @@ minetest.register_chatcommand("market.show", {
minetest.register_chatcommand("market.list", { minetest.register_chatcommand("market.list", {
params = "", params = "",
privs = {server=true}, privs = {server=true},
decription = "list all registered markets", description = S("list all registered markets"),
func = function(name, param) func = function(name, param)
local list = {} local list = {}
for marketname, def in pairs(commoditymarket.registered_markets) do for marketname, def in pairs(commoditymarket.registered_markets) do

View File

@ -363,6 +363,19 @@ local cancel_buy = function(market, item, order)
minetest.sound_play({name = "commoditymarket_register_closed", gain = 0.1}, {to_player=account.name}) minetest.sound_play({name = "commoditymarket_register_closed", gain = 0.1}, {to_player=account.name})
end end
local initialize_market_item = function(orders_for_items, item)
if orders_for_items[item] == nil then
local lists = {}
lists.buy_orders = {}
lists.sell_orders = {}
lists.buy_volume = 0
lists.sell_volume = 0
lists.item = item
-- leave last_price nil to indicate it's never been sold before
orders_for_items[item] = lists
end
end
----------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------
local remove_market_item = function(market, item) local remove_market_item = function(market, item)
@ -383,14 +396,16 @@ end
minetest.register_chatcommand("market.removeitem", { minetest.register_chatcommand("market.removeitem", {
params = "marketname item", params = "marketname item",
privs = {server=true}, privs = {server=true},
decription = "remove item from market. All existing buys and sells will be canceled.", description = S("remove item from market. All existing buys and sells will be canceled."),
func = function(name, param) func = function(name, param)
local params = param:split(" ") local params = param:split(" ")
if #params ~= 2 then if #params ~= 2 then
minetest.chat_send_player(name, "Incorrect parameter count")
return return
end end
local market = commoditymarket.registered_markets[params[1]] local market = commoditymarket.registered_markets[params[1]]
if market == nil then if market == nil then
minetest.chat_send_player(name, "No such market: " .. params[1])
return return
end end
remove_market_item(market, params[2]) remove_market_item(market, params[2])
@ -400,7 +415,7 @@ minetest.register_chatcommand("market.removeitem", {
minetest.register_chatcommand("market.purge_unknowns", { minetest.register_chatcommand("market.purge_unknowns", {
params = "", params = "",
privs = {server=true}, privs = {server=true},
decription = "removes all unknown items from all markets. All existing buys and sells for those items will be canceled.", description = S("removes all unknown items from all markets. All existing buys and sells for those items will be canceled."),
func = function(name, param) func = function(name, param)
for market_name, market in pairs(commoditymarket.registered_markets) do for market_name, market in pairs(commoditymarket.registered_markets) do
local items_to_remove = {} local items_to_remove = {}
@ -420,21 +435,33 @@ minetest.register_chatcommand("market.purge_unknowns", {
end, end,
}) })
----------------------------------------------------------------------------------------------------------- -- Used during development and debugging to find items that break the market formspecs when added
local debugging_commands = false
local initialize_market_item = function(orders_for_items, item) if debugging_commands then
if orders_for_items[item] == nil then minetest.register_chatcommand("market.addeverything", {
local lists = {} params = "marketname",
lists.buy_orders = {} privs = {server=true},
lists.sell_orders = {} description = S("Add all registered items to the provided market"),
lists.buy_volume = 0 func = function(name, param)
lists.sell_volume = 0 local params = param:split(" ")
lists.item = item if #params ~= 1 then
-- leave last_price nil to indicate it's never been sold before minetest.chat_send_player(name, "Incorrect parameter count")
orders_for_items[item] = lists return
end end
local market = commoditymarket.registered_markets[params[1]]
if market == nil then
minetest.chat_send_player(name, "No such market: " .. params[1])
return
end
for item_name, def in pairs(minetest.registered_items) do
initialize_market_item(market.orders_for_items, item_name)
end
end,
})
end end
-----------------------------------------------------------------------------------------------------------
-- API exposed to the outside world -- API exposed to the outside world
local add_inventory = function(self, player_name, item, quantity) local add_inventory = function(self, player_name, item, quantity)
return add_inventory_to_account(self, get_account(self, player_name), item, quantity) return add_inventory_to_account(self, get_account(self, player_name), item, quantity)