summaryrefslogtreecommitdiff
path: root/shop2/disp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'shop2/disp.lua')
-rw-r--r--shop2/disp.lua43
1 files changed, 25 insertions, 18 deletions
diff --git a/shop2/disp.lua b/shop2/disp.lua
index 5260cdc..0283742 100644
--- a/shop2/disp.lua
+++ b/shop2/disp.lua
@@ -1,4 +1,5 @@
local ourname = "ac.kst"
+local stock=require"shop2.stock"
local function printseq(m) return function(q)
for _,v in ipairs(q) do
@@ -34,42 +35,48 @@ end
local function disp_shopscreen(items)
-- i don't like how hardcoded all the spacing is in this
-- but i also don't feel like rewriting it yet.
- local m = peripheral.wrap"left"
- m.clear()
- m.setTextScale(0.5)
+ local mon = peripheral.wrap"left"
+ mon.clear()
+ mon.setTextScale(0.5)
+
+ local si = stock.take_stock()
+
-- Stock Price Adr. Name
-- xxxx xxxkst dmn Diamond
-- 123456789012345678901234567890123456789012345678901234567
-- 0 1 2 3 4 5
-- local function fmt_row(m,y, stock,price,adr,name, colour)
- local function fmt_row(m,y, idesc,
+ local function fmt_row(y, idesc, colour)
+ local amt = stock.amt_of(si,idesc)
colour = colour or colors.cyan
- printseq(m) {
- {1,y}, colors.white, pad(stock,5),
- {8,y}, colors.yellow, pad(price,3), colors.lightGray, "kst",
- {16,y}, colour, adr,
- {22,y}, colour, name,
+ printseq(mon) {
+ {1,y}, colors.white, pad(amt,5),
+ {8,y}, colors.yellow, pad(idesc.price,3), colors.lightGray, "kst",
+ {16,y}, colour, idesc.adr,
+ {22,y}, colour, idesc.hname,
}
end
-
- printseq(m) {
+ printseq(mon) {
{1,1}, colors.orange, "Apiaristics Consortium Store",
{1,2}, colors.lightGray, "Stock Price Adr. Name",
}
- -- sort alphabetically
+ -- sort alphabetically by address
-- todo: more intuitive sort, once more things are for sale
- --
- for ix,i in ipairs() do
- fmt_row(m,ix+2,i[6],i[2],i[1],i[4],i[5])
+ local adrs = {}
+ for adr in pairs(items) do table.insert(adrs,adr) end
+ table.sort(adrs)
+ for ix,adr in ipairs(adrs) do
+ local idesc = items[adr]
+ fmt_row(ix+2, idesc)
end
- local w,h = m.getSize()
+ local w,h = mon.getSize()
- printseq(m) {
- {1,h-1}, colors.blue, centre("/pay <adr>@ac.kst <amount>",w)
+ printseq(mon) {
+ {1,h-1}, colors.blue, centre("/pay <adr>@"..ourname.." <amount>",w)
}