From a3b5cb26465107f2cd6cb9c53ea1b6e375abcdb1 Mon Sep 17 00:00:00 2001 From: Giov4 Date: Sat, 6 Mar 2021 18:06:56 +0100 Subject: [PATCH] Simplified add and sub functions --- api.lua | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/api.lua b/api.lua index cc36d54..27a1d3c 100644 --- a/api.lua +++ b/api.lua @@ -7,7 +7,6 @@ local storage = minetest.get_mod_storage() local registered_currencies = {} - --[[ def = { min_value : number = @@ -40,25 +39,13 @@ end function currencies.add(currency, pl_name, amount) - validate_currency(currency) - - local balances = get_database().balances - balances[pl_name] = balances[pl_name] or {} - balances[pl_name][currency] = balances[pl_name][currency] or 0 - - currencies.set(currency, pl_name, balances[pl_name][currency] + amount) + currencies.set(currency, pl_name, currencies.get(currency, pl_name) + amount) end function currencies.sub(currency, pl_name, amount) - validate_currency(currency) - - local balances = get_database().balances - balances[pl_name] = balances[pl_name] or {} - balances[pl_name][currency] = balances[pl_name][currency] or 0 - - currencies.set(currency, pl_name, balances[pl_name][currency] - amount) + currencies.set(currency, pl_name, currencies.get(currency, pl_name) - amount) end @@ -181,4 +168,4 @@ function get_valid_value(currency, value) end return value -end +end \ No newline at end of file