forked from minetest-mods/global_exchange
Compare commits
8 Commits
b22b72f5c2
...
master
Author | SHA1 | Date | |
---|---|---|---|
868213081f | |||
969571f559 | |||
15bba05412 | |||
10b438c2b7 | |||
3517409a1a | |||
8430e9fab5 | |||
6989f6a00e | |||
9c8f62320e |
@ -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,8 +51,8 @@ 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"),
|
||||
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",
|
||||
@ -134,12 +135,26 @@ minetest.after(0, function()
|
||||
pagemax = math.max(math.ceil(#selectable_list / pageitems), 1)
|
||||
end)
|
||||
|
||||
local function filter_list(filter)
|
||||
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.match(name, filter) or nil
|
||||
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
|
||||
@ -458,14 +473,14 @@ local function handle_main(player, fields)
|
||||
end
|
||||
|
||||
if fields.filter then
|
||||
state.filtered_list, state.buy_pagemax = filter_list(state.buy_filter)
|
||||
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(nil)
|
||||
state.filtered_list, state.buy_pagemax = filter_list(p_name, nil)
|
||||
state.buy_page = 1
|
||||
show_main(p_name)
|
||||
end
|
||||
|
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)
|
||||
|
||||
@ -53,6 +54,7 @@ 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%)
|
||||
|
Reference in New Issue
Block a user