first ui version working; api created
parent
a4f0810e1f
commit
4403b9bafd
|
@ -0,0 +1,60 @@
|
|||
|
||||
kiosk.inventar={}
|
||||
|
||||
kiosk.add_inventar=function(name,buy_value,sell_value,stock)
|
||||
if name == nil then
|
||||
return
|
||||
end
|
||||
if buy_value == nil then
|
||||
buy_value=1
|
||||
end
|
||||
if buy_value == 0 then
|
||||
buy_value=1
|
||||
end
|
||||
if sell_value == nil then
|
||||
sell_value=kiosk.sell_factor * buy_value
|
||||
end
|
||||
if sell_value > buy_factor then
|
||||
sell_value=kiosk.sell_factor * buy_value
|
||||
end
|
||||
if stock == nil then
|
||||
stock = 0
|
||||
end
|
||||
|
||||
if kiok.inventar[name] == nil then
|
||||
kiosk.inventar[name] = {name = name,
|
||||
sell = sell_value,
|
||||
buy = sell_value,
|
||||
stock=stock,
|
||||
}
|
||||
else
|
||||
local kiosk_inv=kiosk.inventar[name]
|
||||
kiosk_inv.sell=sell_value
|
||||
kiosk_inv.buy=buy_value
|
||||
end
|
||||
end
|
||||
|
||||
kiosk.get_value=function(name,value)
|
||||
if name == nil then return end
|
||||
if kiosk.inventar[name] == nil then
|
||||
kiosk.add_inventar(name,1,0.9,0)
|
||||
end
|
||||
local kinv=kiosk.inventar[name]
|
||||
local output = 0
|
||||
if kinv[value] ~= nil then
|
||||
output = kinv[value]
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
kiosk.get_buy=function(name)
|
||||
return kiosk.get_value(name,"buy")
|
||||
end
|
||||
|
||||
kiosk.get_sell=function(name)
|
||||
return kiosk.get_value(name,"sell")
|
||||
end
|
||||
|
||||
kiosk.get_stock=function(name)
|
||||
return kiosk.get_value(name,"stock")
|
||||
end
|
|
@ -0,0 +1 @@
|
|||
kiosk.sell_factor=tonumber(minetest.settings:get("kiosk.sell_factor")) or 0.95
|
41
init.lua
41
init.lua
|
@ -1,36 +1,29 @@
|
|||
-- base copied from 3d_armor_ui
|
||||
-- support for i18n
|
||||
local S = armor_i18n.gettext
|
||||
kiosk = {}
|
||||
kiosk.path = minetest.get_modpath("kiosk")
|
||||
kiosk.config = minetest.get_mod_storage()
|
||||
kiosk.modname=minetest.get_current_modname()
|
||||
local S = dofile(kiosk.path .. "/intllib.lua")
|
||||
kiosk.intllib = S
|
||||
local F = minetest.formspec_escape
|
||||
|
||||
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- start loading from "..minetest.get_modpath(minetest.get_current_modname()))
|
||||
|
||||
-- import settingtypes.txt
|
||||
basic_functions.import_settingtype(kiosk.path .. "/settingtypes.txt")
|
||||
|
||||
if not minetest.global_exists("unified_inventory") then
|
||||
minetest.log("warning", S("Kiosk: Mod loaded but unused."))
|
||||
return
|
||||
end
|
||||
|
||||
if unified_inventory.sfinv_compat_layer then
|
||||
return
|
||||
dofile(kiosk.path .. "/config.lua")
|
||||
dofile(kiosk.path .. "/api.lua")
|
||||
|
||||
if rawget(_G,"unified_inventory") then
|
||||
dofile(kiosk.path .. "/register.lua")
|
||||
end
|
||||
|
||||
unified_inventory.register_button("kiosk", {
|
||||
type = "image",
|
||||
image = "kiosk_button_128.png",
|
||||
tooltip = S("Kiosk")
|
||||
})
|
||||
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded ")
|
||||
|
||||
unified_inventory.register_page("kiosk", {
|
||||
get_formspec = function(player, perplayer_formspec)
|
||||
local fy = perplayer_formspec.formspec_y
|
||||
local name = player:get_player_name()
|
||||
if armor.def[name].init_time == 0 then
|
||||
return {formspec="label[0,0;"..F(S("Armor not initialized!")).."]"}
|
||||
end
|
||||
local formspec = "label[0,0;"..F(S("Kiosk")).."]"..
|
||||
"list[detached:"..name.."_kiosk;kiosk;0,"..fy..";1,2;]"..
|
||||
"label[5.0,"..(fy + 0.0)..";"..F(S("Buy at")).."]"..
|
||||
"label[5.0,"..(fy + 0.5)..";"..F(S("Sell at")).."]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[detached:"..name.."_kiosk;kiosk]"
|
||||
return {formspec=formspec}
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
-- Fallback functions for when `intllib` is not installed.
|
||||
-- Code released under Unlicense <http://unlicense.org>.
|
||||
|
||||
-- Get the latest version of this file at:
|
||||
-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
|
||||
|
||||
local function format(str, ...)
|
||||
local args = { ... }
|
||||
local function repl(escape, open, num, close)
|
||||
if escape == "" then
|
||||
local replacement = tostring(args[tonumber(num)])
|
||||
if open == "" then
|
||||
replacement = replacement..close
|
||||
end
|
||||
return replacement
|
||||
else
|
||||
return "@"..open..num..close
|
||||
end
|
||||
end
|
||||
return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
|
||||
end
|
||||
|
||||
local gettext, ngettext
|
||||
if minetest.get_modpath("intllib") then
|
||||
if intllib.make_gettext_pair then
|
||||
-- New method using gettext.
|
||||
gettext, ngettext = intllib.make_gettext_pair()
|
||||
else
|
||||
-- Old method using text files.
|
||||
gettext = intllib.Getter()
|
||||
end
|
||||
end
|
||||
|
||||
-- Fill in missing functions.
|
||||
|
||||
gettext = gettext or function(msgid, ...)
|
||||
return format(msgid, ...)
|
||||
end
|
||||
|
||||
ngettext = ngettext or function(msgid, msgid_plural, n, ...)
|
||||
return format(n==1 and msgid or msgid_plural, ...)
|
||||
end
|
||||
|
||||
return gettext, ngettext
|
2
mod.conf
2
mod.conf
|
@ -2,6 +2,6 @@ name = kiosk
|
|||
title = kiosk
|
||||
author = ademant
|
||||
description = Global trading via unified_inventories
|
||||
depends = default,basic_functions,unified_inventory
|
||||
depends = default,basic_functions,unified_inventory,xpfw
|
||||
license = MIT
|
||||
version = 1.0.0
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
local S = kiosk.intllib
|
||||
local F = minetest.formspec_escape
|
||||
|
||||
xpfw.register_attribute("kiosk_account",{min=0,max=math.huge,default=0,
|
||||
hud=1,})
|
||||
|
||||
unified_inventory.register_button("kiosk", {
|
||||
type = "image",
|
||||
image = "kiosk_button_128.png",
|
||||
tooltip = S("Kiosk")
|
||||
})
|
||||
|
||||
local sell = minetest.create_detached_inventory("sell", {
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
-- inv:set_stack(listname, index, nil)
|
||||
local item_stack=inv:get_stack(listname,index)
|
||||
if item_stack == nil then return end
|
||||
local item_name=item_stack:get_name()
|
||||
if item_name == nil then return end
|
||||
local item_count=item_stack:get_count()
|
||||
if item_count <1 then return end
|
||||
local player_name = player:get_player_name()
|
||||
-- minetest.sound_play("trash", {to_player=player_name, gain = 1.0})
|
||||
end,
|
||||
})
|
||||
sell:set_size("main", 1)
|
||||
local buy = minetest.create_detached_inventory("buy", {
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
-- inv:set_stack(listname, index, nil)
|
||||
local player_name = player:get_player_name()
|
||||
-- minetest.sound_play("trash", {to_player=player_name, gain = 1.0})
|
||||
end,
|
||||
})
|
||||
buy:set_size("main", 1)
|
||||
|
||||
|
||||
unified_inventory.register_page("kiosk", {
|
||||
get_formspec = function(player, perplayer_formspec)
|
||||
local fy = perplayer_formspec.formspec_y
|
||||
local name = player:get_player_name()
|
||||
local formspec = "label[0,0;"..F(S("Kiosk")).."]"..
|
||||
"list[detached:sell;main;1,1;1,1;]"..
|
||||
"list[detached:buy;main;1,2;1,1;]"..
|
||||
"button[3,1;2,1;button_sell;"..S("Sell").."]"..
|
||||
"button[3,2;2,1;button_buy;"..S("Buy").."]"..
|
||||
"label[5.0,"..(fy + 0.0)..";"..F(S("Buy at")).."]"..
|
||||
"label[5.0,"..(fy + 0.5)..";"..F(S("Sell at")).."]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring[detached:"..name.."_kiosk;kiosk]"
|
||||
return {formspec=formspec}
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.after(0.01,function()
|
||||
print("size")
|
||||
print(dump2(VoxelArea:getExtent()))
|
||||
for i,def in pairs(minetest.registered_nodes) do
|
||||
local nodeinfo=minetest.find_nodes_in_area({x=(-10),y=(-10),z=(-10)},{x=(10),y=(10),z=(10)},i)
|
||||
if #nodeinfo>0 then
|
||||
print(i..": "..#nodeinfo)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
@ -0,0 +1 @@
|
|||
kiosk.sell_factor (Difference between Sell and buy value) float 0.95
|
Before Width: | Height: | Size: 385 KiB After Width: | Height: | Size: 385 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Loading…
Reference in New Issue