Update startup.lua

This commit is contained in:
Rivulet
2026-04-05 01:16:21 +00:00
parent b95b2e8002
commit d8f8709c2e

View File

@@ -2,6 +2,8 @@ local db = require("remotedb")
local completion = require("cc.completion")
local total_items = {}
local monitor = peripheral.find("monitor")
local price_map = {}
local unit_name = nil
term.clear()
local x,y = term.getSize()
term.setCursorPos(1,y)
@@ -42,6 +44,7 @@ local function input()
end
end
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
elseif event[2] == keys.l then
@@ -88,9 +91,10 @@ local function input()
sleep(0)
term.setCursorPos(1,y)
term.write("unit name > ")
local unit_name = read()
if unit_name ~= "" then
db.setCurrencyUnit(unit_name)
local unit_namel = read()
if unit_namel ~= "" then
db.setCurrencyUnit(unit_namel)
unit_name = unit_namel
print("set currency unit")
end
elseif event[2] == keys.c then
@@ -125,6 +129,9 @@ local function render_monitor()
while true do
sleep(0)
if monitor then
if not unit_name then
unit_name = db.getCurrencyUnit()
end
monitor.clear()
local x,y = monitor.getSize()
monitor.setCursorPos(1,1)
@@ -133,7 +140,7 @@ local function render_monitor()
monitor.setCursorPos(1,y)
monitor.write(tostring(k).." x"..tostring(v).."")
monitor.scroll(1)
total = total + (( db.getPrice(k) or 0)*v)
total = total + (( price_map[k] or 0)*v)
end
monitor.setCursorPos(1,y)
monitor.write("total: "..tostring(total).." "..tostring(db.getCurrencyUnit()))
@@ -142,7 +149,6 @@ local function render_monitor()
end
local loops = {input,render_monitor}
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
---@cast loops thread[]
loops[k] = coroutine.create(v)