From 8be94cdcbf6d72732509a6fb32b64fa4d62cc0ce Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 2 Jan 2023 03:21:31 +0000 Subject: shop2m --- shop2.lua | 80 -------------------------------------------------------------- shop2m.lua | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 80 deletions(-) delete mode 100644 shop2.lua create mode 100644 shop2m.lua diff --git a/shop2.lua b/shop2.lua deleted file mode 100644 index c8e2716..0000000 --- a/shop2.lua +++ /dev/null @@ -1,80 +0,0 @@ -local ourname = "ac.kst" - -local ITEMS = { - {"dmn", 5, "minecraft:diamond", "Diamond", colors.cyan, 321}, - {"blz", 10, "minecraft:blaze_rod", "Blaze Rod", colors.orange, 27}, - {"ely", 40, "minecraft:elytra", "Elytra", colors.purple, 8}, -} - -local function printseq(m) return function(q) - for _,v in ipairs(q) do - print(type(v),v) - if type(v) == "number" then - m.setTextColor(v) - elseif type(v) == "string" then - m.write(v) - elseif type(v) == "table" then - if #v == 2 then - -- position - m.setCursorPos(v[1],v[2]) - else - error("unknown format") - end - end - 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 centre(s,w) - s=tostring(s) - local l = #s - local p = math.floor(math.max(0,w-l)/2) - return string.rep(" ",p)..s -end - -local function disp_shopscreen() - local m = peripheral.wrap"left" - m.clear() - m.setTextScale(0.5) - -- 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) - 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, - } - end - - - printseq(m) { - {1,1}, colors.orange, "Apiaristics Consortium Store", - {1,2}, colors.lightGray, "Stock Price Adr. Name", - } - - for ix,i in ipairs(ITEMS) do - fmt_row(m,ix+2,i[6],i[2],i[1],i[4],i[5]) - end - - local w,h = m.getSize() - - printseq(m) { - {1,h-1}, colors.blue, centre("/pay @ac.kst ",w) - } - - - - -end - -disp_shopscreen() diff --git a/shop2m.lua b/shop2m.lua new file mode 100644 index 0000000..c8e2716 --- /dev/null +++ b/shop2m.lua @@ -0,0 +1,80 @@ +local ourname = "ac.kst" + +local ITEMS = { + {"dmn", 5, "minecraft:diamond", "Diamond", colors.cyan, 321}, + {"blz", 10, "minecraft:blaze_rod", "Blaze Rod", colors.orange, 27}, + {"ely", 40, "minecraft:elytra", "Elytra", colors.purple, 8}, +} + +local function printseq(m) return function(q) + for _,v in ipairs(q) do + print(type(v),v) + if type(v) == "number" then + m.setTextColor(v) + elseif type(v) == "string" then + m.write(v) + elseif type(v) == "table" then + if #v == 2 then + -- position + m.setCursorPos(v[1],v[2]) + else + error("unknown format") + end + end + 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 centre(s,w) + s=tostring(s) + local l = #s + local p = math.floor(math.max(0,w-l)/2) + return string.rep(" ",p)..s +end + +local function disp_shopscreen() + local m = peripheral.wrap"left" + m.clear() + m.setTextScale(0.5) + -- 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) + 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, + } + end + + + printseq(m) { + {1,1}, colors.orange, "Apiaristics Consortium Store", + {1,2}, colors.lightGray, "Stock Price Adr. Name", + } + + for ix,i in ipairs(ITEMS) do + fmt_row(m,ix+2,i[6],i[2],i[1],i[4],i[5]) + end + + local w,h = m.getSize() + + printseq(m) { + {1,h-1}, colors.blue, centre("/pay @ac.kst ",w) + } + + + + +end + +disp_shopscreen() -- cgit v1.2.3