From 7937536cf6e4458604422850832bd153540cbb5f Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 2 Jan 2023 02:43:09 +0000 Subject: shop --- shop2.lua | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/shop2.lua b/shop2.lua index 6c9e264..40e0e59 100644 --- a/shop2.lua +++ b/shop2.lua @@ -1,9 +1,9 @@ local ourname = "ac.kst" local ITEMS = { - {"dmn", 5, "minecraft:diamond"}, - {"blz", 10, "minecraft:blaze_rod"}, - {"ely", 40, "minecraft:elytra"}, + {"dmn", 5, "minecraft:diamond", "Diamond", 321}, + {"blz", 10, "minecraft:blaze_rod", "Blaze Rod", 27}, + {"ely", 40, "minecraft:elytra", "Elytra", 8}, } local function printseq(m) return function(q) @@ -24,6 +24,12 @@ local function printseq(m) return function(q) end end end +local function pad(s,n) + s=tostring(s) + local l = #s + local p = string.rep(" ",math.max(0,n-l)) + return p..s +end local function disp_shopscreen() local m = peripheral.wrap"left" @@ -33,14 +39,25 @@ local function disp_shopscreen() -- xxxxx xxxxxkst dmn Diamond -- 123456789012345678901234567890123456789012345678901234567 -- 0 1 2 3 4 5 + + local function fmt_row(m,y, stock,price,adr,name) + printseq(m) { + {1,y}, colors.white, pad(stock,5), + {8,y}, colors.yellow, pad(price,5), colors.lightGray, "kst", + {18,y}, colors.cyan, adr, + {25,y}, colors.white, name, + } + end + + printseq(m) { {1,1}, colors.orange, "Apionics Consortium Store", {1,2}, colors.lightGray, "Stock Price Adr. Name", - {1,3}, colors.white, " 321", - {8,3}, colors.yellow, " 5", colors.lightGray, "kst", - {18,3}, colors.cyan, "dmn", - {25,3}, colors.white, "Diamond", } + + for ix,i in ipairs(ITEMS) do + fmt_row(m,ix+2,i[5],i[2],i[1],i[4]) + end end -- cgit v1.2.3