Update startup.lua
This commit is contained in:
16
startup.lua
16
startup.lua
@@ -2,6 +2,8 @@ local db = require("remotedb")
|
|||||||
local completion = require("cc.completion")
|
local completion = require("cc.completion")
|
||||||
local total_items = {}
|
local total_items = {}
|
||||||
local monitor = peripheral.find("monitor")
|
local monitor = peripheral.find("monitor")
|
||||||
|
local price_map = {}
|
||||||
|
local unit_name = nil
|
||||||
term.clear()
|
term.clear()
|
||||||
local x,y = term.getSize()
|
local x,y = term.getSize()
|
||||||
term.setCursorPos(1,y)
|
term.setCursorPos(1,y)
|
||||||
@@ -42,6 +44,7 @@ local function input()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
total_items[added_item_name] = (total_items[added_item_name] or 0 ) + added_item_count
|
total_items[added_item_name] = (total_items[added_item_name] or 0 ) + added_item_count
|
||||||
|
price_map[added_item_name] = db.getPrice(added_item_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif event[2] == keys.l then
|
elseif event[2] == keys.l then
|
||||||
@@ -88,9 +91,10 @@ local function input()
|
|||||||
sleep(0)
|
sleep(0)
|
||||||
term.setCursorPos(1,y)
|
term.setCursorPos(1,y)
|
||||||
term.write("unit name > ")
|
term.write("unit name > ")
|
||||||
local unit_name = read()
|
local unit_namel = read()
|
||||||
if unit_name ~= "" then
|
if unit_namel ~= "" then
|
||||||
db.setCurrencyUnit(unit_name)
|
db.setCurrencyUnit(unit_namel)
|
||||||
|
unit_name = unit_namel
|
||||||
print("set currency unit")
|
print("set currency unit")
|
||||||
end
|
end
|
||||||
elseif event[2] == keys.c then
|
elseif event[2] == keys.c then
|
||||||
@@ -125,6 +129,9 @@ local function render_monitor()
|
|||||||
while true do
|
while true do
|
||||||
sleep(0)
|
sleep(0)
|
||||||
if monitor then
|
if monitor then
|
||||||
|
if not unit_name then
|
||||||
|
unit_name = db.getCurrencyUnit()
|
||||||
|
end
|
||||||
monitor.clear()
|
monitor.clear()
|
||||||
local x,y = monitor.getSize()
|
local x,y = monitor.getSize()
|
||||||
monitor.setCursorPos(1,1)
|
monitor.setCursorPos(1,1)
|
||||||
@@ -133,7 +140,7 @@ local function render_monitor()
|
|||||||
monitor.setCursorPos(1,y)
|
monitor.setCursorPos(1,y)
|
||||||
monitor.write(tostring(k).." x"..tostring(v).."")
|
monitor.write(tostring(k).." x"..tostring(v).."")
|
||||||
monitor.scroll(1)
|
monitor.scroll(1)
|
||||||
total = total + (( db.getPrice(k) or 0)*v)
|
total = total + (( price_map[k] or 0)*v)
|
||||||
end
|
end
|
||||||
monitor.setCursorPos(1,y)
|
monitor.setCursorPos(1,y)
|
||||||
monitor.write("total: "..tostring(total).." "..tostring(db.getCurrencyUnit()))
|
monitor.write("total: "..tostring(total).." "..tostring(db.getCurrencyUnit()))
|
||||||
@@ -142,7 +149,6 @@ local function render_monitor()
|
|||||||
end
|
end
|
||||||
local loops = {input,render_monitor}
|
local loops = {input,render_monitor}
|
||||||
if db.loop then loops[#loops+1] = db.loop end
|
if db.loop then loops[#loops+1] = db.loop end
|
||||||
if db.loops then loops = {table.unpack(loops),table.unpack(db.loops)} end
|
|
||||||
for k,v in ipairs(loops) do
|
for k,v in ipairs(loops) do
|
||||||
---@cast loops thread[]
|
---@cast loops thread[]
|
||||||
loops[k] = coroutine.create(v)
|
loops[k] = coroutine.create(v)
|
||||||
|
|||||||
Reference in New Issue
Block a user