diff --git a/startup.lua b/startup.lua index f88a083..de100c4 100644 --- a/startup.lua +++ b/startup.lua @@ -7,6 +7,7 @@ local price_map = {} local unit_name = nil local full_item_qoute local dirtied = false +local currencies_override = nil term.clear() if monitor then monitor.clear() end local function tallyUpItems(price) @@ -16,9 +17,11 @@ local function tallyUpItems(price) local worths = {} local minimum = 999 for k,v in ipairs(currencies) do - worthmap[db.getCurrencyWorth(v)] = v - worths[#worths+1] = db.getCurrencyWorth(v) - minimum = math.min(db.getCurrencyWorth(v),minimum) + if currencies_override == nil or currencies_override[v] then + worthmap[db.getCurrencyWorth(v)] = v + worths[#worths+1] = db.getCurrencyWorth(v) + minimum = math.min(db.getCurrencyWorth(v),minimum) + end end table.sort(worths, function (a, b) return a > b @@ -44,14 +47,14 @@ local function printTotal() printer.setCursorPos(1,y+2) local total = 0 for k,v in pairs(total_items) do - printer.write("- "..tostring(k).." x"..tostring(v)) + printer.write("- "..tostring(k).." x"..tostring(v).." - "..tostring((price_map[k] or 0)*v).." "..tostring(unit_name)) local x,y = printer.getCursorPos() printer.setCursorPos(1,y+1) - total = total + (( db.getPrice(k) or 0)*v) + total = total + (price_map[k] or 0)*v end local x,y = printer.getCursorPos() printer.setCursorPos(1,y+1) - printer.write("Total cost: "..tostring(math.floor(total*100+0.5)/100).." "..tostring(db.getCurrencyUnit())) + printer.write("Total cost: "..tostring(math.floor(total*100+0.5)/100).." "..tostring(unit_name)) local x,y = printer.getCursorPos() printer.setCursorPos(1,y+2) printer.write("Price in items:") @@ -62,7 +65,7 @@ local function printTotal() printer.write("- "..tostring(k).." x"..tostring(v)) local x,y = printer.getCursorPos() printer.setCursorPos(1,y+1) - total = total + (( db.getPrice(k) or 0)*v) + total = total + (( price_map[k] or 0)*v) end printer.endPage() print("printed the total!") @@ -98,7 +101,10 @@ local function input() local new_price = nil repeat term.write("item price > ") - new_price = 1/tonumber(read()) + local price = tonumber(read()) + if price then + new_price = 1/price + end until new_price ~= nil ---@cast new_price number if new_price > 0 then @@ -190,7 +196,8 @@ local function input() local x,y = term.getSize() term.setCursorPos(1,y) term.write("currency name > ") - added_currency_name = read() + local currencies = db.getCurrencies() + added_currency_name = read(nil,nil, function(text) return completion.choice(text, currencies) end) if added_currency_name == "" then added_currency_name = nil else @@ -235,6 +242,29 @@ local function input() end dirtied = true end + elseif event[2] == keys.b then + local currencies = db.getCurrencies() + currencies_override = nil + local running = true + while running do + term.write("add currency option> ") + local currency_name = read(nil,nil, function(text) return completion.choice(text, currencies) end) + if currency_name ~= "" then + if not currencies_override then currencies_override = {} end + currencies_override[currency_name] = true + else + running = false + end + end + if not currencies_override then + print("cleared override") + else + print("created override with currencies:") + for k,_ in pairs(currencies_override) do + write(k.." ") + end + print() + end end end end @@ -299,6 +329,7 @@ t to get the total in the terminal. (not listing items) f to finalize the transaction. (and optionally print the receipt) +b to override available currencies i to add or set the price of an item to the database. c to add or set the worth of a currency to the database. n to set the displayed currency unit.