Spaces to tabs

This commit is contained in:
Vitalie Ciubotaru 2016-05-15 23:00:00 +09:00
parent 338d91aff5
commit 3804a61c74
No known key found for this signature in database
GPG Key ID: 6B60758D4DF9A7EE
2 changed files with 84 additions and 84 deletions

48
atm.lua
View File

@ -41,33 +41,33 @@ local function unique()
end end
function cash_fs(p_name) function cash_fs(p_name)
local balance = exchange:get_balance(p_name) local balance = exchange:get_balance(p_name)
local formspec = local formspec =
'size[8,9]'.. 'size[8,9]'..
'label[0,0;' .. p_name .. '\'s account]' .. 'label[0,0;' .. p_name .. '\'s account]' ..
'label[0,1;Balance: ' .. balance .. ']' .. 'label[0,1;Balance: ' .. balance .. ']' ..
--money --money
'list[detached:global_exchange;money;0,2;3,1;]'.. 'list[detached:global_exchange;money;0,2;3,1;]'..
--player inventory --player inventory
'list[current_player;main;0,4;8,4;]'.. 'list[current_player;main;0,4;8,4;]'..
--back button --back button
back(0,8) back(0,8)
--print(formspec) --print(formspec)
return formspec return formspec
end end
function bills2balance(stack, p_name) function bills2balance(stack, p_name)
local bal = exchange:get_balance(p_name) local bal = exchange:get_balance(p_name)
local name = stack:get_name() local name = stack:get_name()
local count = stack:get_count() local count = stack:get_count()
if name == 'currency:minegeld' then if name == 'currency:minegeld' then
bal = bal + count bal = bal + count
elseif name == 'currency:minegeld_5' then elseif name == 'currency:minegeld_5' then
bal = bal + count * 5 bal = bal + count * 5
elseif name == 'currency:minegeld_10' then elseif name == 'currency:minegeld_10' then
bal = bal + count * 10 bal = bal + count * 10
end end
return bal return bal
end end
local function wire_fs(p_name) local function wire_fs(p_name)

View File

@ -198,66 +198,66 @@ minetest.after(0, function()
inv:add_item("main", item_name) inv:add_item("main", item_name)
show_main(p_name, item_name) show_main(p_name, item_name)
end, end,
on_put = function(inv, listname, index, stack, player) on_put = function(inv, listname, index, stack, player)
local p_name = player:get_player_name() local p_name = player:get_player_name()
if listname == 'money' and minetest.get_item_group(stack:get_name(), 'minegeld') then if listname == 'money' and minetest.get_item_group(stack:get_name(), 'minegeld') then
local old_balance = exchange:get_balance(p_name) local old_balance = exchange:get_balance(p_name)
local balance = bills2balance(stack, p_name) local balance = bills2balance(stack, p_name)
exchange:change_balance(p_name, balance - old_balance) exchange:change_balance(p_name, balance - old_balance)
minetest.sound_play("atm_cash", {to_player = p_name}) minetest.sound_play("atm_cash", {to_player = p_name})
local stacks = inv:get_list('money') local stacks = inv:get_list('money')
local tens = math.floor(balance/10) local tens = math.floor(balance/10)
if tens > 0 then if tens > 0 then
inv:set_stack('money', 1, 'currency:minegeld_10 ' .. tens) inv:set_stack('money', 1, 'currency:minegeld_10 ' .. tens)
balance = balance - tens * 10 balance = balance - tens * 10
else else
inv:set_stack('money', 1, '') inv:set_stack('money', 1, '')
end end
local fives = math.floor(balance/5) local fives = math.floor(balance/5)
if fives > 0 then if fives > 0 then
inv:set_stack('money', 2, 'currency:minegeld_5 ' .. fives) inv:set_stack('money', 2, 'currency:minegeld_5 ' .. fives)
balance = balance - fives * 5 balance = balance - fives * 5
else else
inv:set_stack('money', 2, '') inv:set_stack('money', 2, '')
end end
local ones = math.floor(balance) local ones = math.floor(balance)
if ones > 0 then if ones > 0 then
inv:set_stack('money', 3, 'currency:minegeld ' .. ones) inv:set_stack('money', 3, 'currency:minegeld ' .. ones)
balance = balance - ones balance = balance - ones
else else
inv:set_stack('money', 3, '') inv:set_stack('money', 3, '')
end end
end end
minetest.show_formspec(p_name, "global_exchange:atm_form", cash_fs(p_name)) --redraw with new balance minetest.show_formspec(p_name, "global_exchange:atm_form", cash_fs(p_name)) --redraw with new balance
end, end,
allow_put = function(inv, listname, index, stack, player) allow_put = function(inv, listname, index, stack, player)
local name = stack:get_name() local name = stack:get_name()
if listname == 'money' and minetest.get_item_group(name, 'minegeld') > 0 then if listname == 'money' and minetest.get_item_group(name, 'minegeld') > 0 then
return stack:get_count() return stack:get_count()
end end
return 0 return 0
end, end,
on_take = function(inv, listname, index, stack, player) on_take = function(inv, listname, index, stack, player)
local p_name = player:get_player_name() local p_name = player:get_player_name()
if listname == 'money' and minetest.get_item_group(stack:get_name(), 'minegeld') then if listname == 'money' and minetest.get_item_group(stack:get_name(), 'minegeld') then
local name = stack:get_name() local name = stack:get_name()
local count = stack:get_count() local count = stack:get_count()
local delta local delta
if name == 'currency:minegeld' then if name == 'currency:minegeld' then
delta = count delta = count
elseif name == 'currency:minegeld_5' then elseif name == 'currency:minegeld_5' then
delta = count * 5 delta = count * 5
elseif name == 'currency:minegeld_10' then elseif name == 'currency:minegeld_10' then
delta = count * 10 delta = count * 10
end end
exchange:change_balance(p_name, -delta) --let's hope it always returns success exchange:change_balance(p_name, -delta) --let's hope it always returns success
minetest.sound_play("atm_cash", {to_player = p_name}) minetest.sound_play("atm_cash", {to_player = p_name})
end end
minetest.show_formspec(p_name, "global_exchange:atm_form", cash_fs(p_name)) --redraw with new balance minetest.show_formspec(p_name, "global_exchange:atm_form", cash_fs(p_name)) --redraw with new balance
end, end,
allow_take = function(inv, listname, index, stack, player) allow_take = function(inv, listname, index, stack, player)
return stack:get_count() return stack:get_count()
end, end,
}) })
local selectable_list,n = {},1 local selectable_list,n = {},1