Merge remote-tracking branch 'upstream/master' into nalc-1.2-dev

This commit is contained in:
Sys Quatre 2020-06-16 21:34:14 +02:00
commit 0495aa6e33
8 changed files with 137 additions and 48 deletions

View File

@ -6,6 +6,8 @@
This mod adds an improved ("currency" compatible) shop to your world.
Requires 5.0.0-dev or newer
Features:
* 4 buyer and 4 seller slots
* Much storage capacity
@ -20,7 +22,10 @@ Optional dependencies:
## License
CC0 for everything unless specified otherwise below.
Textures: CC0 - or see notes below
Code: MIT
Following textures were imported from [currency](https://github.com/minetest-mods/currency)
* shop_front.png

View File

@ -1,6 +0,0 @@
default
currency?
bitchange?
wrench?
pipeworks?
tubelib?

View File

@ -1,3 +1,7 @@
if not minetest.get_translator then
error("exchange_shop requires at least Minetest 5.0.0-dev.")
end
exchange_shop = {}
exchange_shop.storage_size = 5 * 4
exchange_shop.shopname = "exchange_shop:shop"
@ -6,6 +10,12 @@ local modpath = minetest.get_modpath("exchange_shop")
local has_currency = minetest.get_modpath("currency")
local has_bitchange = minetest.get_modpath("bitchange")
-- Internationalisaton
exchange_shop.S = minetest.get_translator("exchange_shop")
exchange_shop.FS = function(...)
return minetest.formspec_escape(exchange_shop.S(...))
end
-- Currency migrate options
exchange_shop.migrate = {
use_lbm = false,

View File

@ -0,0 +1,35 @@
# textdomain: exchange_shop
# shop.lua
Title:=Titre :
Set=Définir
You give:=Vous donnez :
You get:=Vous recevez :
Exchange=Échanger
You need=Vous avez besoin de
You give=Vous donnez
:= :
Current stock:=Stock affiché :
Income=Entrée
Outgoing=Sortie
Use (E) + (Right click) for customer interface=Utilisez (E) + (Clic droit) pour afficher l'interface du client
owned by @1=propriété de @1
Exchange shop (owned by @1=Boutique d'échange (propriété de @1
Exchange shop:=Boutique d'échange :
Exchange Shop=Boutique d'échange
Exchange shop (constructing)=Boutique d'échange (en construction)
Cannot dig exchange shop: one or multiple stocks are in use.=Un ou plusieurs stocks sont en cours d'utilisation, impossible d'enlever la boutique d'échange.
Exchange shop: Insert your trade goods into 'Outgoing'.=Boutique d'échange : Insérez ce que vous souhaitez échanger dans 'Sortie'
# shop_functions.lua
One or multiple ejection fields are filled.=Un ou plusieurs champs déjection sont remplis.
Please empty them or contact the shop owner.=Veuillez les vider ou contactez le propriétaire de la boutique.
The field '@1' can not contain multiple times the same items.=Le champ '@1' ne peux contenir plusieurs fois les mêmes éléments.
The field '@1' can not contain multiple times the same items.=Le champ '@1' ne peux contenir plusieurs fois les mêmes éléments.
Please contact the shop owner.=Veuillez contacter le propriétaire de la boutique.
The stock in this shop is full. =Le stockage de cette boutique est saturé.
Please contact the shop owner.=Veuillez contacter le propriétaire de la boutique.
This shop is sold out.=Cette boutique est en rupture de stock.
You do not have enough space in your inventory.=Vous manquez de place dans votre inventaire.
You do not have the required items.=Vous ne disposez pas des éléments demandés.
Warning! Stacks are overflowing somewhere!=Attention ! Les piles débordent quelque part !

35
locale/template.txt Normal file
View File

@ -0,0 +1,35 @@
# textdomain: exchange_shop
# shop.lua
Title:=
Set=
You give:=
You get:=
Exchange=
You need=
You give=
:=
Current stock:=
Income=
Outgoing=
Use (E) + (Right click) for customer interface=
owned by @1=
Exchange shop (owned by @1=
Exchange shop:=
Exchange Shop=
Exchange shop (constructing)=
Cannot dig exchange shop: one or multiple stocks are in use.=
Exchange shop: Insert your trade goods into 'Outgoing'.=
# shop_functions.lua
One or multiple ejection fields are filled.=
Please empty them or contact the shop owner.=
The field '@1' can not contain multiple times the same items.=
The field '@1' can not contain multiple times the same items.=
Please contact the shop owner.=
The stock in this shop is full.=
Please contact the shop owner.=
This shop is sold out.=
You do not have enough space in your inventory.=
You do not have the required items.=
Warning! Stacks are overflowing somewhere!=

64
shop.lua Executable file → Normal file
View File

@ -5,7 +5,8 @@ This code is based on the idea of Dan Duncombe's exchange shop
https://web.archive.org/web/20160403113102/https://forum.minetest.net/viewtopic.php?id=7002
]]
local S = exchange_shop.S
local FS = exchange_shop.FS
local shop_positions = {}
local function get_exchange_shop_formspec(mode, pos, meta)
@ -16,17 +17,27 @@ local function get_exchange_shop_formspec(mode, pos, meta)
return "listring[".. name ..";" .. src .. "]" ..
"listring[current_player;main]"
end
local function make_slots(x, y, list, label)
local arrow = "exchange_shop_arrow.png"
if list == "cust_ow" then
arrow = arrow .. "\\^\\[transformFY"
end
return table.concat({
("label[%f,%f;%s]"):format(x, y - 0.6, label),
("image[%f,%f;0.6,0.6;shop_front.png]"):format(x + 0.15, y + 0.3),
("image[%f,%f;0.6,0.6;%s]"):format(x + 0.15, y + 0.0, arrow),
("list["..name..";%s;%f,%f;2,2;]"):format(list, x, y)
})
end
if mode == "customer" then
local overflow = not meta:get_inventory():is_empty("cust_ej")
-- customer
local formspec = (
(overflow and "size[8,9]" or "size[8,8]")..
"label[1,0.4;You give:]"..
"list["..name..";cust_ow;1,1;2,2;]"..
"button[3,2.4;2,1;exchange;Exchange]"..
"label[5,0.4;You get:]"..
"list["..name..";cust_og;5,1;2,2;]"
make_slots(1, 1, "cust_ow", FS("You give:")) ..
"button[3,2.5;2,1;exchange;" .. FS("Exchange") .. "]"..
make_slots(5, 1, "cust_og", FS("You get:"))
)
-- Insert fallback slots
local inv_pos = 4
@ -51,17 +62,13 @@ local function get_exchange_shop_formspec(mode, pos, meta)
-- owner
local formspec = (
"size[10,10]"..
"label[0,0.1;Title:]"..
"label[0,0.1;" .. FS("Title:") .. "]"..
"field[1.2,0.5;3,0.5;title;;"..title.."]"..
"field_close_on_enter[title;false]"..
"button[3.9,0.2;1,0.5;set_title;Set]"..
"container[0,2]"..
"label[0,-0.6;You need:]"..
"list["..name..";cust_ow;0,0;2,2;]"..
"label[2.5,-0.6;You give:]"..
"list["..name..";cust_og;2.5,0;2,2;]"..
"container_end[]"..
"label[5,0.1;Current stock:]"
"button[3.9,0.2;1,0.5;set_title;" .. FS("Set") .. "]"..
make_slots( 0, 2, "cust_ow", FS("You need") .. FS(":")) ..
make_slots(2.5, 2, "cust_og", FS("You give") .. FS(":")) ..
"label[5,0.1;" .. FS("Current stock:") .. "]"
)
if overflow then
@ -72,19 +79,22 @@ local function get_exchange_shop_formspec(mode, pos, meta)
)
end
local arrow = "exchange_shop_arrow.png"
if mode == "owner_custm" then
formspec = (formspec..
"button[7.5,0.2;2.5,0.5;view_stock;Income]"..
"button[7.5,0.2;2.5,0.5;view_stock;" .. FS("Income") .. "]"..
"list["..name..";custm;5,1;5,4;]"..
listring("custm"))
arrow = arrow .. "\\^\\[transformFY"
else
formspec = (formspec..
"button[7.5,0.2;2.5,0.5;view_custm;Outgoing]"..
"button[7.5,0.2;2.5,0.5;view_custm;" .. FS("Outgoing") .. "]"..
"list["..name..";stock;5,1;5,4;]"..
listring("stock"))
end
return (formspec..
"label[1,5.4;Use (E) + (Right click) for customer interface]"..
"label[1,5.4;" .. FS("Use (E) + (Right click) for customer interface") .. "]"..
"image[8.2,5.2;0.6,0.6;" .. arrow .. "]" ..
"list[current_player;main;1,6;8,4;]")
end
return ""
@ -118,10 +128,9 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
if title ~= fields.title then
if fields.title ~= "" then
meta:set_string("infotext", "'" .. fields.title
.. "' (owned by " .. shop_owner .. ")")
.. "' (" .. S("owned by @1", shop_owner) .. ")")
else
meta:set_string("infotext", "Exchange shop (owned by "
.. shop_owner ..")")
meta:set_string("infotext", S("Exchange shop (owned by @1", shop_owner) .. ")" )
end
meta:set_string("title", minetest.formspec_escape(fields.title))
end
@ -139,7 +148,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
-- Throw error message
if err_msg then
minetest.chat_send_player(player_name, minetest.colorize("#F33",
"Exchange shop: " .. err_msg))
S("Exchange shop:") .. " " .. err_msg))
end
if resend then
minetest.show_formspec(player_name, "exchange_shop:shop_formspec",
@ -158,7 +167,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
end)
minetest.register_node(exchange_shop.shopname, {
description = "Exchange Shop",
description = S"Exchange Shop",
tiles = {
"shop_top.png", "shop_top.png",
"shop_side.png","shop_side.png",
@ -171,12 +180,11 @@ minetest.register_node(exchange_shop.shopname, {
local meta = minetest.get_meta(pos)
local owner = placer:get_player_name()
meta:set_string("owner", owner)
meta:set_string("infotext", "Exchange shop (owned by "
.. owner .. ")")
meta:set_string("infotext", S("Exchange shop (owned by @1", owner) .. ")")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Exchange shop (constructing)")
meta:set_string("infotext", S("Exchange shop (constructing)"))
meta:set_string("owner", "")
local inv = meta:get_inventory()
inv:set_size("stock", exchange_shop.storage_size) -- needed stock for exchanges
@ -195,7 +203,7 @@ minetest.register_node(exchange_shop.shopname, {
return true
end
minetest.chat_send_player(player:get_player_name(),
"Cannot dig exchange shop: one or multiple stocks are in use.")
S("Cannot dig exchange shop: one or multiple stocks are in use."))
return false
end,
on_rightclick = function(pos, node, clicker, itemstack)
@ -221,7 +229,7 @@ minetest.register_node(exchange_shop.shopname, {
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == "custm" then
minetest.chat_send_player(player:get_player_name(),
"Exchange shop: Insert your trade goods into 'Outgoing'.")
S("Exchange shop: Insert your trade goods into 'Outgoing'."))
return 0
end
local meta = minetest.get_meta(pos)

View File

@ -1,3 +1,5 @@
local S = exchange_shop.S
function exchange_shop.has_access(meta, player_name)
local owner = meta:get_string("owner")
if player_name == owner or owner == "" then
@ -67,8 +69,8 @@ end
function exchange_shop.exchange_action(player_inv, shop_inv)
if not shop_inv:is_empty("cust_ej")
or not shop_inv:is_empty("custm_ej") then
return "One or multiple ejection fields are filled. "..
"Please empty them or contact the shop owner."
return S("One or multiple ejection fields are filled.") .. " " ..
S("Please empty them or contact the shop owner.")
end
local owner_wants = shop_inv:get_list("cust_ow")
local owner_gives = shop_inv:get_list("cust_og")
@ -81,8 +83,8 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
break
end
if i1 ~= i2 and name1 == item2:get_name() then
return "The field 'Owner needs' can not contain multiple "..
"times the same items. Please contact the shop owner."
return S("The field '@1' can not contain multiple times the same items.", S("You need")) .. " " ..
S("Please contact the shop owner.")
end
end
end
@ -95,8 +97,8 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
break
end
if i1 ~= i2 and name1 == item2:get_name() then
return "The field 'Owner gives' can not contain multiple "..
"times the same items. Please contact the shop owner."
return S("The field '@1' can not contain multiple times the same items.", S("You give")) .. " " ..
S("Please contact the shop owner.")
end
end
end
@ -104,8 +106,8 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
-- Check for space in the shop
for i, item in pairs(owner_wants) do
if not shop_inv:room_for_item("custm", item) then
return "The stock in this shop is full. "..
"Please contact the shop owner."
return S("The stock in this shop is full.") .. " " ..
S("Please contact the shop owner.")
end
end
@ -114,21 +116,21 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
-- Check availability of the shop's items
for i, item in pairs(owner_gives) do
if not list_contains_item(shop_inv, "stock", item) then
return "This shop is sold out."
return S("This shop is sold out.")
end
end
-- Check for space in the player's inventory
for i, item in pairs(owner_gives) do
if not player_inv:room_for_item("main", item) then
return "You do not have enough space in your inventory."
return S("You do not have enough space in your inventory.")
end
end
-- Check availability of the player's items
for i, item in pairs(owner_wants) do
if not list_contains_item(player_inv, "main", item) then
return "You do not have the required items."
return S("You do not have the required items.")
end
end
@ -157,6 +159,6 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
end
end
if not fully_exchanged then
return "Warning! Stacks are overflowing somewhere!", true
return S("Warning! Stacks are overflowing somewhere!"), true
end
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B