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
|
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({
|
red_stmt:bind_names({
|
||||||
id = row.Id,
|
id = row.Id,
|
||||||
delta = row_sold,
|
delta = row_sold,
|
||||||
})
|
})
|
||||||
red_del_stmt = red_stmt
|
red_del_stmt = red_stmt
|
||||||
else -- row_sold == row_amount or out_of_funds
|
else
|
||||||
del_stmt:bind_values(row.Id)
|
del_stmt:bind_values(row.Id)
|
||||||
red_del_stmt = del_stmt
|
red_del_stmt = del_stmt
|
||||||
end
|
end
|
||||||
|
@ -9,14 +9,15 @@ local S = minetest.get_translator("global_exchange")
|
|||||||
|
|
||||||
-- NALC split() function
|
-- NALC split() function
|
||||||
local function split(str, sep)
|
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 result = {}
|
||||||
local regex = ("([^%s]+)"):format(sep)
|
local regex = ("([^%s]+)"):format(sep)
|
||||||
for each in str:gmatch(regex) do
|
for each in str:gmatch(regex) do
|
||||||
if #each > 30 then
|
local sub = nil
|
||||||
each = string.sub(each, 1, 30).."..."
|
if #each > 34 then
|
||||||
|
sub = string.sub(each, 1, 34).."..."
|
||||||
end
|
end
|
||||||
table.insert(result, each)
|
table.insert(result, sub or each)
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
@ -50,9 +51,9 @@ local function mk_summary_fs()
|
|||||||
local all_items = minetest.registered_items
|
local all_items = minetest.registered_items
|
||||||
for i, row in ipairs(exchange:market_summary()) do
|
for i, row in ipairs(exchange:market_summary()) do
|
||||||
local def = all_items[row.Item] or {}
|
local def = all_items[row.Item] or {}
|
||||||
add_row(row.Item,
|
add_row(#row.Item > 24 and string.sub(row.Item, 1, 24).."..." or row.Item,
|
||||||
split(def.description, "\n")[1] or S("Unknown Item"),
|
split(def.description, "\n")[1] or S("No description"),
|
||||||
wear_string(row.Wear),
|
wear_string(row.Wear),
|
||||||
row.Buy_Volume or 0,
|
row.Buy_Volume or 0,
|
||||||
row.Buy_Max or "N/A",
|
row.Buy_Max or "N/A",
|
||||||
row.Sell_Volume or 0,
|
row.Sell_Volume or 0,
|
||||||
@ -100,9 +101,12 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
buy_wear = wear_levels[1].text,
|
buy_wear = wear_levels[1].text,
|
||||||
buy_price = "",
|
buy_price = "",
|
||||||
buy_amount = "1",
|
buy_amount = "1",
|
||||||
|
buy_filter = "",
|
||||||
sell_price = "",
|
sell_price = "",
|
||||||
buy_page = 1,
|
buy_page = 1,
|
||||||
|
buy_pagemax = 0,
|
||||||
selected_index = 0,
|
selected_index = 0,
|
||||||
|
filtered_list = nil,
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -131,6 +135,34 @@ minetest.after(0, function()
|
|||||||
pagemax = math.max(math.ceil(#selectable_list / pageitems), 1)
|
pagemax = math.max(math.ceil(#selectable_list / pageitems), 1)
|
||||||
end)
|
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 main_form = "global_exchange:exchange_main"
|
||||||
|
|
||||||
local function table_from_results(fs, results, name, x, y, w, h, selected)
|
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:container(0,4, function()
|
||||||
fs:button( 0,0.25, 1,1, "buy_left", "<<")
|
fs:button( 0,0.25, 1,1, "buy_left", "<<")
|
||||||
fs:button( 5,0.25, 2,1, "position", state.buy_page .. "/" .. pagemax)
|
fs:button( 1,0.25, 2,1, "position", state.buy_page .. "/" .. state.buy_pagemax)
|
||||||
fs:button(11,0.25, 1,1, "buy_right", ">>")
|
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 firstitem = ((state.buy_page - 1) * pageitems)
|
||||||
|
local item_list = state.filtered_list or selectable_list
|
||||||
for y=0,(pageheight-1) do
|
for y=0,(pageheight-1) do
|
||||||
for x=0,(pagewidth-1) do
|
for x=0,(pagewidth-1) do
|
||||||
local index = firstitem + (pagewidth * y) + x + 1
|
local index = firstitem + (pagewidth * y) + x + 1
|
||||||
if selectable_list[index] then
|
if item_list[index] then
|
||||||
fs:item_image_button(x,1.25+y, 1,1, "select_" .. index,
|
fs:item_image_button(x,1.25+y, 1,1, "select_" .. index, item_list[index])
|
||||||
selectable_list[index])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -385,6 +421,7 @@ local function handle_main(player, fields)
|
|||||||
"buy_wear",
|
"buy_wear",
|
||||||
"buy_amount",
|
"buy_amount",
|
||||||
"buy_price",
|
"buy_price",
|
||||||
|
"buy_filter",
|
||||||
"sell_price"
|
"sell_price"
|
||||||
}
|
}
|
||||||
for _,k in ipairs(copy_fields) do
|
for _,k in ipairs(copy_fields) do
|
||||||
@ -393,25 +430,30 @@ local function handle_main(player, fields)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if state.buy_pagemax == 0 then
|
||||||
|
state.buy_pagemax = pagemax
|
||||||
|
end
|
||||||
|
|
||||||
if fields.tab then
|
if fields.tab then
|
||||||
state.tab = tonumber(fields.tab) or 1
|
state.tab = tonumber(fields.tab) or 1
|
||||||
show_main(p_name)
|
show_main(p_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.buy_left then
|
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)
|
show_main(p_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.buy_right then
|
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)
|
show_main(p_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local item_list = state.filtered_list or selectable_list
|
||||||
for name in pairs(fields) do
|
for name in pairs(fields) do
|
||||||
local index = tonumber(string.match(name, "select_([0-9]+)"))
|
local index = tonumber(string.match(name, "select_([0-9]+)"))
|
||||||
if index and index >= 1 and index < #selectable_list then
|
if index and index >= 1 and index <= #item_list then
|
||||||
state.buy_item = selectable_list[index]
|
state.buy_item = item_list[index]
|
||||||
show_main(p_name)
|
show_main(p_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -430,6 +472,19 @@ local function handle_main(player, fields)
|
|||||||
end
|
end
|
||||||
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
|
if fields.sell then
|
||||||
local succ, err = post_sell(player, "", fields.sell_price)
|
local succ, err = post_sell(player, "", fields.sell_price)
|
||||||
if succ then
|
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 modpath = minetest.get_modpath(minetest.get_current_modname()) .. "/"
|
||||||
|
|
||||||
|
local S = minetest.get_translator("global_exchange")
|
||||||
|
|
||||||
local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env).
|
local exchange = assert(loadfile(modpath .. "exchange.lua"))(insecure_env).
|
||||||
open_exchange(minetest.get_worldpath() .. "/global_exchange.db")
|
open_exchange(minetest.get_worldpath() .. "/global_exchange.db")
|
||||||
|
|
||||||
@ -17,13 +19,13 @@ local function handle_setbalance_command(caller, name, newbalance)
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_privilege("balance", {
|
minetest.register_privilege("balance", {
|
||||||
description = "Can use /setbalance",
|
description = S("Can use /setbalance"),
|
||||||
give_to_singleplayer = false
|
give_to_singleplayer = false
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_chatcommand("setbalance", {
|
minetest.register_chatcommand("setbalance", {
|
||||||
params = "[<name>] <balance>",
|
params = S("[<name>] <balance>"),
|
||||||
description = "set a player's trading balance",
|
description = S("set a player's trading balance"),
|
||||||
privs = {balance=true},
|
privs = {balance=true},
|
||||||
func = function(caller, param)
|
func = function(caller, param)
|
||||||
local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)")
|
local name, balancestr = string.match(param, "([^ ]+) ([0-9]+)")
|
||||||
@ -31,7 +33,7 @@ minetest.register_chatcommand("setbalance", {
|
|||||||
name = caller
|
name = caller
|
||||||
balancestr = string.match(param, "([0-9]+)")
|
balancestr = string.match(param, "([0-9]+)")
|
||||||
if not balancestr then
|
if not balancestr then
|
||||||
return false, "Invalid parameters (see /help setbalance)"
|
return false, S("Invalid parameters (see /help setbalance)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return handle_setbalance_command(caller, name, tonumber(balancestr))
|
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.
|
Order does not exist.=L'ordre n'existe pas.
|
||||||
|
|
||||||
### init.lua ###
|
### init.lua ###
|
||||||
|
Can use /setbalance=Peut utiliser /setbalance
|
||||||
set a player's trading balance=définir le solde commercial d'un joueur
|
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)
|
Invalid parameters (see /help setbalance)=Paramètres invalides (voir /help setbalance)
|
||||||
|
|
||||||
@ -46,13 +47,14 @@ Transaction Log=Journaux transactions
|
|||||||
ATM=Distributeur Automatique d'argent
|
ATM=Distributeur Automatique d'argent
|
||||||
Cash deposit (+@1)=Dépot d'espèces (+@1)
|
Cash deposit (+@1)=Dépot d'espèces (+@1)
|
||||||
|
|
||||||
### exchange_macine.lua ###
|
### exchange_machine.lua ###
|
||||||
Wear=Usure
|
Wear=Usure
|
||||||
Buy Vol=Qté achat
|
Buy Vol=Qté achat
|
||||||
Buy Max=Achat Max
|
Buy Max=Achat Max
|
||||||
Sell Vol=Qté vente
|
Sell Vol=Qté vente
|
||||||
Sell Min=Vente Min
|
Sell Min=Vente Min
|
||||||
Unknown Item=Item inconnue
|
Unknown Item=Item inconnue
|
||||||
|
No description=Pas de description
|
||||||
New (-0%)=Neuf (-0%)
|
New (-0%)=Neuf (-0%)
|
||||||
Good (-10%)=Bon (-10%)
|
Good (-10%)=Bon (-10%)
|
||||||
Worn (-50%)=Usé (-50%)
|
Worn (-50%)=Usé (-50%)
|
||||||
@ -75,3 +77,6 @@ Invalid amount.=Montant invalide.
|
|||||||
Invalid rate.=Taux invalide.
|
Invalid rate.=Taux invalide.
|
||||||
Cannot sell an item with metadata.=Ne peut vendre un item avec des métadonnées.
|
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