1
0
mirror of https://github.com/SmallJoker/exchange_shop.git synced 2025-07-20 00:50:23 +02:00

1 Commits

Author SHA1 Message Date
9b9d3b7a5b Ajoute message de chargement du mod dans le journal "action" 2018-12-31 15:35:26 +01:00
8 changed files with 60 additions and 152 deletions

View File

@ -6,8 +6,6 @@
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
@ -22,10 +20,7 @@ Optional dependencies:
## License
Textures: CC0 - or see notes below
Code: MIT
CC0 for everything unless specified otherwise below.
Following textures were imported from [currency](https://github.com/minetest-mods/currency)
* shop_front.png

6
depends.txt Normal file
View File

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

View File

@ -1,7 +1,3 @@
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"
@ -10,12 +6,6 @@ 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,
@ -47,3 +37,5 @@ if has_currency then
dofile(modpath .. "/currency_override.lua")
end
end
minetest.log("action", "[exchange_shop] loaded.")

View File

@ -1,35 +0,0 @@
# 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 !

View File

@ -1,35 +0,0 @@
# 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 Normal file → Executable file
View File

@ -5,8 +5,7 @@ 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)
@ -17,27 +16,17 @@ 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]")..
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:"))
"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;]"
)
-- Insert fallback slots
local inv_pos = 4
@ -62,13 +51,17 @@ local function get_exchange_shop_formspec(mode, pos, meta)
-- owner
local formspec = (
"size[10,10]"..
"label[0,0.1;" .. FS("Title:") .. "]"..
"label[0,0.1;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;" .. 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:") .. "]"
"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:]"
)
if overflow then
@ -79,22 +72,19 @@ 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;" .. FS("Income") .. "]"..
"button[7.5,0.2;2.5,0.5;view_stock;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;" .. FS("Outgoing") .. "]"..
"button[7.5,0.2;2.5,0.5;view_custm;Outgoing]"..
"list["..name..";stock;5,1;5,4;]"..
listring("stock"))
end
return (formspec..
"label[1,5.4;" .. FS("Use (E) + (Right click) for customer interface") .. "]"..
"image[8.2,5.2;0.6,0.6;" .. arrow .. "]" ..
"label[1,5.4;Use (E) + (Right click) for customer interface]"..
"list[current_player;main;1,6;8,4;]")
end
return ""
@ -128,9 +118,10 @@ 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
.. "' (" .. S("owned by @1", shop_owner) .. ")")
.. "' (owned by " .. shop_owner .. ")")
else
meta:set_string("infotext", S("Exchange shop (owned by @1", shop_owner) .. ")" )
meta:set_string("infotext", "Exchange shop (owned by "
.. shop_owner ..")")
end
meta:set_string("title", minetest.formspec_escape(fields.title))
end
@ -148,7 +139,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",
S("Exchange shop:") .. " " .. err_msg))
"Exchange shop: " .. err_msg))
end
if resend then
minetest.show_formspec(player_name, "exchange_shop:shop_formspec",
@ -167,7 +158,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
end)
minetest.register_node(exchange_shop.shopname, {
description = S"Exchange Shop",
description = "Exchange Shop",
tiles = {
"shop_top.png", "shop_top.png",
"shop_side.png","shop_side.png",
@ -180,11 +171,12 @@ 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", S("Exchange shop (owned by @1", owner) .. ")")
meta:set_string("infotext", "Exchange shop (owned by "
.. owner .. ")")
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("Exchange shop (constructing)"))
meta:set_string("infotext", "Exchange shop (constructing)")
meta:set_string("owner", "")
local inv = meta:get_inventory()
inv:set_size("stock", exchange_shop.storage_size) -- needed stock for exchanges
@ -203,7 +195,7 @@ minetest.register_node(exchange_shop.shopname, {
return true
end
minetest.chat_send_player(player:get_player_name(),
S("Cannot dig exchange shop: one or multiple stocks are in use."))
"Cannot dig exchange shop: one or multiple stocks are in use.")
return false
end,
on_rightclick = function(pos, node, clicker, itemstack)
@ -229,7 +221,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(),
S("Exchange shop: Insert your trade goods into 'Outgoing'."))
"Exchange shop: Insert your trade goods into 'Outgoing'.")
return 0
end
local meta = minetest.get_meta(pos)

View File

@ -1,5 +1,3 @@
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
@ -34,26 +32,21 @@ end
-- Tool wear aware replacement for remove_item.
function exchange_shop.list_remove_item(inv, listname, stack)
local wanted_count = stack:get_count()
if wanted_count == 0 then
local wanted = stack:get_count()
if wanted == 0 then
return stack
end
local list = inv:get_list(listname)
local name = stack:get_name()
local wear = stack:get_wear()
-- Information about the removed stack
-- this includes the metadata of the last taken stack
local taken_stack = ItemStack()
local remaining = wanted_count
local remaining = wanted
local removed_wear = 0
for index, list_stack in pairs(list) do
if list_stack:get_name() == name and
list_stack:get_wear() <= wear then
-- Only sell better tools (less worn out)
taken_stack = list_stack:take_item(remaining)
list_stack:get_wear() <= wear then
local taken_stack = list_stack:take_item(remaining)
inv:set_stack(listname, index, list_stack)
removed_wear = math.max(removed_wear, taken_stack:get_wear())
@ -64,18 +57,18 @@ function exchange_shop.list_remove_item(inv, listname, stack)
end
end
-- For oversized stacks, ItemStack:add_item returns a leftover
-- handle the stack count manually to avoid this issue
taken_stack:set_count(wanted_count - remaining)
taken_stack:set_wear(removed_wear)
return taken_stack
-- Todo: Also remove kebab
local removed_stack = ItemStack(name)
removed_stack:set_count(wanted - remaining)
removed_stack:set_wear(removed_wear)
return removed_stack
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 S("One or multiple ejection fields are filled.") .. " " ..
S("Please empty them or contact the shop owner.")
return "One or multiple ejection fields are filled. "..
"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")
@ -88,8 +81,8 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
break
end
if i1 ~= i2 and name1 == item2:get_name() then
return S("The field '@1' can not contain multiple times the same items.", S("You need")) .. " " ..
S("Please contact the shop owner.")
return "The field 'Owner needs' can not contain multiple "..
"times the same items. Please contact the shop owner."
end
end
end
@ -102,8 +95,8 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
break
end
if i1 ~= i2 and name1 == item2:get_name() then
return S("The field '@1' can not contain multiple times the same items.", S("You give")) .. " " ..
S("Please contact the shop owner.")
return "The field 'Owner gives' can not contain multiple "..
"times the same items. Please contact the shop owner."
end
end
end
@ -111,8 +104,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 S("The stock in this shop is full.") .. " " ..
S("Please contact the shop owner.")
return "The stock in this shop is full. "..
"Please contact the shop owner."
end
end
@ -121,21 +114,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 S("This shop is sold out.")
return "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 S("You do not have enough space in your inventory.")
return "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 S("You do not have the required items.")
return "You do not have the required items."
end
end
@ -164,6 +157,6 @@ function exchange_shop.exchange_action(player_inv, shop_inv)
end
end
if not fully_exchanged then
return S("Warning! Stacks are overflowing somewhere!"), true
return "Warning! Stacks are overflowing somewhere!", true
end
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 438 B