forked from minetest-mods/global_exchange
Compare commits
9 Commits
ce33c159fd
...
master
Author | SHA1 | Date | |
---|---|---|---|
868213081f | |||
969571f559 | |||
15bba05412 | |||
10b438c2b7 | |||
3517409a1a | |||
8430e9fab5 | |||
6989f6a00e | |||
9c8f62320e | |||
b22b72f5c2 |
@ -1 +0,0 @@
|
||||
default?
|
@ -1 +0,0 @@
|
||||
Adds a server-wide commodities (item) exchange.
|
@ -1066,13 +1066,13 @@ function ex_methods.sell(self, p_name, ex_name, item_name, wear, amount, rate)
|
||||
|
||||
local red_del_stmt
|
||||
|
||||
if row_sold < row_amount and not out_of_funds then
|
||||
if row_sold < row_amount then
|
||||
red_stmt:bind_names({
|
||||
id = row.Id,
|
||||
delta = row_sold,
|
||||
})
|
||||
red_del_stmt = red_stmt
|
||||
else -- row_sold == row_amount or out_of_funds
|
||||
else
|
||||
del_stmt:bind_values(row.Id)
|
||||
red_del_stmt = del_stmt
|
||||
end
|
||||
|
@ -9,14 +9,15 @@ local S = minetest.get_translator("global_exchange")
|
||||
|
||||
-- NALC split() function
|
||||
local function split(str, sep)
|
||||
if not str then return nil end
|
||||
if not str then return "Item doesn't exist" end
|
||||
local result = {}
|
||||
local regex = ("([^%s]+)"):format(sep)
|
||||
for each in str:gmatch(regex) do
|
||||
if #each > 30 then
|
||||
each = string.sub(each, 1, 30).."..."
|
||||
local sub = nil
|
||||
if #each > 34 then
|
||||
sub = string.sub(each, 1, 34).."..."
|
||||
end
|
||||
table.insert(result, each)
|
||||
table.insert(result, sub or each)
|
||||
end
|
||||
return result
|
||||
end
|
||||
@ -50,9 +51,9 @@ local function mk_summary_fs()
|
||||
local all_items = minetest.registered_items
|
||||
for i, row in ipairs(exchange:market_summary()) do
|
||||
local def = all_items[row.Item] or {}
|
||||
add_row(row.Item,
|
||||
split(def.description, "\n")[1] or S("Unknown Item"),
|
||||
wear_string(row.Wear),
|
||||
add_row(#row.Item > 24 and string.sub(row.Item, 1, 24).."..." or row.Item,
|
||||
split(def.description, "\n")[1] or S("No description"),
|
||||
wear_string(row.Wear),
|
||||
row.Buy_Volume or 0,
|
||||
row.Buy_Max or "N/A",
|
||||
row.Sell_Volume or 0,
|
||||
@ -100,9 +101,12 @@ minetest.register_on_joinplayer(function(player)
|
||||
buy_wear = wear_levels[1].text,
|
||||
buy_price = "",
|
||||
buy_amount = "1",
|
||||
buy_filter = "",
|
||||
sell_price = "",
|
||||
buy_page = 1,
|
||||
buy_pagemax = 0,
|
||||
selected_index = 0,
|
||||
filtered_list = nil,
|
||||
}
|
||||
end)
|
||||
|
||||
@ -131,6 +135,34 @@ minetest.after(0, function()
|
||||
pagemax = math.max(math.ceil(#selectable_list / pageitems), 1)
|
||||
end)
|
||||
|
||||
local function filter_list(p_name, filter)
|
||||
local filtered_list = {}
|
||||
if not filter or filter == "" then return nil, pagemax end
|
||||
|
||||
-- search by translated language
|
||||
local player_info = minetest.get_player_information(p_name)
|
||||
local lang = player_info and player_info.lang_code or ""
|
||||
local can_translate = minetest.get_translated_string and lang ~= ""
|
||||
|
||||
for index, name in ipairs(selectable_list) do
|
||||
local match = string.find(name, filter) -- search in name
|
||||
if not match then -- si not found, search in description and translated description ie:(filter="pomme", description="pomme d'or" )
|
||||
local def = minetest.registered_items[name]
|
||||
if def and def.description and def.description ~= "" then
|
||||
if string.find(string.lower(def.description), filter) or
|
||||
can_translate and string.find(string.lower(minetest.get_translated_string(lang, def.description)), filter) then
|
||||
match = true
|
||||
end
|
||||
end
|
||||
end
|
||||
if match then
|
||||
filtered_list[#filtered_list+1] = name
|
||||
end
|
||||
end
|
||||
|
||||
return filtered_list, math.max(math.ceil(#filtered_list / pageitems), 1)
|
||||
end
|
||||
|
||||
local main_form = "global_exchange:exchange_main"
|
||||
|
||||
local function table_from_results(fs, results, name, x, y, w, h, selected)
|
||||
@ -186,16 +218,20 @@ local function mk_main_buy_fs(fs, p_name, state)
|
||||
|
||||
fs:container(0,4, function()
|
||||
fs:button( 0,0.25, 1,1, "buy_left", "<<")
|
||||
fs:button( 5,0.25, 2,1, "position", state.buy_page .. "/" .. pagemax)
|
||||
fs:button(11,0.25, 1,1, "buy_right", ">>")
|
||||
fs:button( 1,0.25, 2,1, "position", state.buy_page .. "/" .. state.buy_pagemax)
|
||||
fs:button(3,0.25, 1,1, "buy_right", ">>")
|
||||
|
||||
fs:field(5.28,0.55, 3,1, "buy_filter", S("Filter"), state.buy_filter, false)
|
||||
fs:button(8, 0.25, 2,1, "filter", S("Search"))
|
||||
fs:button(10, 0.25, 2,1, "reset_filter", S("Reset"))
|
||||
|
||||
local firstitem = ((state.buy_page - 1) * pageitems)
|
||||
local item_list = state.filtered_list or selectable_list
|
||||
for y=0,(pageheight-1) do
|
||||
for x=0,(pagewidth-1) do
|
||||
local index = firstitem + (pagewidth * y) + x + 1
|
||||
if selectable_list[index] then
|
||||
fs:item_image_button(x,1.25+y, 1,1, "select_" .. index,
|
||||
selectable_list[index])
|
||||
if item_list[index] then
|
||||
fs:item_image_button(x,1.25+y, 1,1, "select_" .. index, item_list[index])
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -385,6 +421,7 @@ local function handle_main(player, fields)
|
||||
"buy_wear",
|
||||
"buy_amount",
|
||||
"buy_price",
|
||||
"buy_filter",
|
||||
"sell_price"
|
||||
}
|
||||
for _,k in ipairs(copy_fields) do
|
||||
@ -393,25 +430,30 @@ local function handle_main(player, fields)
|
||||
end
|
||||
end
|
||||
|
||||
if state.buy_pagemax == 0 then
|
||||
state.buy_pagemax = pagemax
|
||||
end
|
||||
|
||||
if fields.tab then
|
||||
state.tab = tonumber(fields.tab) or 1
|
||||
show_main(p_name)
|
||||
end
|
||||
|
||||
if fields.buy_left then
|
||||
state.buy_page = (((state.buy_page or 1) + ((2*pagemax-1) - 1)) % pagemax) + 1
|
||||
state.buy_page = (((state.buy_page or 1) + ((2*state.buy_pagemax-1) - 1)) % state.buy_pagemax) + 1
|
||||
show_main(p_name)
|
||||
end
|
||||
|
||||
if fields.buy_right then
|
||||
state.buy_page = (((state.buy_page or 1) + ((2*pagemax-1) + 1)) % pagemax) + 1
|
||||
state.buy_page = (((state.buy_page or 1) + ((2*state.buy_pagemax-1) + 1)) % state.buy_pagemax) + 1
|
||||
show_main(p_name)
|
||||
end
|
||||
|
||||
local item_list = state.filtered_list or selectable_list
|
||||
for name in pairs(fields) do
|
||||
local index = tonumber(string.match(name, "select_([0-9]+)"))
|
||||
if index and index >= 1 and index < #selectable_list then
|
||||
state.buy_item = selectable_list[index]
|
||||
if index and index >= 1 and index <= #item_list then
|
||||
state.buy_item = item_list[index]
|
||||
show_main(p_name)
|
||||
end
|
||||
end
|
||||
@ -430,6 +472,19 @@ local function handle_main(player, fields)
|
||||
end
|
||||
end
|
||||
|
||||
if fields.filter then
|
||||
state.filtered_list, state.buy_pagemax = filter_list(p_name, string.lower(minetest.formspec_escape(state.buy_filter)))
|
||||
state.buy_page = 1
|
||||
show_main(p_name)
|
||||
end
|
||||
|
||||
if fields.reset_filter then
|
||||
state.buy_filter = ""
|
||||
state.filtered_list, state.buy_pagemax = filter_list(p_name, nil)
|
||||
state.buy_page = 1
|
||||
show_main(p_name)
|
||||
end
|
||||
|
||||
if fields.sell then
|
||||
local succ, err = post_sell(player, "", fields.sell_price)
|
||||
if succ then
|
||||
|
10
init.lua
10
init.lua
@ -3,6 +3,8 @@ assert(insecure_env, "global_exchange needs to be trusted to run under mod secur
|
||||
|
||||
local modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/"
|
||||
|
||||
local S = minetest.get_translator("global_exchange")
|
||||
|
||||
local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env).
|
||||
open_exchange(minetest.get_worldpath() .. "/global_exchange.db")
|
||||
|
||||
@ -17,13 +19,13 @@ local function handle_setbalance_command(caller, name, newbalance)
|
||||
end
|
||||
|
||||
minetest.register_privilege("balance", {
|
||||
description = "Can use /setbalance",
|
||||
description = S("Can use /setbalance"),
|
||||
give_to_singleplayer = false
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("setbalance", {
|
||||
params = "[<name>] <balance>",
|
||||
description = "set a player's trading balance",
|
||||
params = S("[<name>] <balance>"),
|
||||
description = S("set a player's trading balance"),
|
||||
privs = {balance=true},
|
||||
func = function(caller, param)
|
||||
local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)")
|
||||
@ -31,7 +33,7 @@ minetest.register_chatcommand("setbalance", {
|
||||
name = caller
|
||||
balancestr = string.match(param, "([0-9]+)")
|
||||
if not balancestr then
|
||||
return false, "Invalid parameters (see /help setbalance)"
|
||||
return false, S("Invalid parameters (see /help setbalance)")
|
||||
end
|
||||
end
|
||||
return handle_setbalance_command(caller, name, tonumber(balancestr))
|
||||
|
@ -21,6 +21,7 @@ No such order.=Pas un tel ordre.
|
||||
Order does not exist.=L'ordre n'existe pas.
|
||||
|
||||
### init.lua ###
|
||||
Can use /setbalance=Peut utiliser /setbalance
|
||||
set a player's trading balance=définir le solde commercial d'un joueur
|
||||
Invalid parameters (see /help setbalance)=Paramètres invalides (voir /help setbalance)
|
||||
|
||||
@ -46,13 +47,14 @@ Transaction Log=Journaux transactions
|
||||
ATM=Distributeur Automatique d'argent
|
||||
Cash deposit (+@1)=Dépot d'espèces (+@1)
|
||||
|
||||
### exchange_macine.lua ###
|
||||
### exchange_machine.lua ###
|
||||
Wear=Usure
|
||||
Buy Vol=Qté achat
|
||||
Buy Max=Achat Max
|
||||
Sell Vol=Qté vente
|
||||
Sell Min=Vente Min
|
||||
Unknown Item=Item inconnue
|
||||
No description=Pas de description
|
||||
New (-0%)=Neuf (-0%)
|
||||
Good (-10%)=Bon (-10%)
|
||||
Worn (-50%)=Usé (-50%)
|
||||
@ -74,4 +76,7 @@ Invalid wear.=Usure invalide.
|
||||
Invalid amount.=Montant invalide.
|
||||
Invalid rate.=Taux invalide.
|
||||
Cannot sell an item with metadata.=Ne peut vendre un item avec des métadonnées.
|
||||
Qty=Qté
|
||||
Qty=Qté
|
||||
Filter=Filtre
|
||||
Search=Chercher
|
||||
Reset=Reset
|
||||
|
Reference in New Issue
Block a user