From ccd7438702f15d94edf091aea178b83785a44e08 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Sat, 7 Jan 2023 05:24:25 +0000 Subject: shop2 --- shop2.dat | 2 +- shop2/disp.lua | 9 +++++++-- shop2/items.lua | 9 +++++++++ shop2/main.lua | 14 ++------------ 4 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 shop2/items.lua diff --git a/shop2.dat b/shop2.dat index e2961f4..9a47450 100644 --- a/shop2.dat +++ b/shop2.dat @@ -1 +1 @@ -file shop2/disp.lua shop2/main.lua shop2/stock.lua +file shop2/disp.lua shop2/main.lua shop2/stock.lua shop2/items.lua diff --git a/shop2/disp.lua b/shop2/disp.lua index 55df99f..65aebc5 100644 --- a/shop2/disp.lua +++ b/shop2/disp.lua @@ -79,9 +79,14 @@ local function disp_shopscreen(items) {1,h-1}, colors.blue, centre("/pay @"..ourname.." ",w) } - +end - +local items = require"shop2.items" +local function run() + while true do + disp_shopscreen(items) + os.sleep(2) + end end disp_shopscreen() diff --git a/shop2/items.lua b/shop2/items.lua new file mode 100644 index 0000000..20e8a93 --- /dev/null +++ b/shop2/items.lua @@ -0,0 +1,9 @@ +local items = {} +local function i(adr,itname,hname,price) + items[adr]={itname=itname,hname=hname,price=price,adr=adr} +end +i("dmn","minecraft:diamond","Diamond",5) +i("blz","minecraft:blaze_rod","Blaze Rod",10) +i("ely","minecraft:elytra","Elytra",200) + +return items diff --git a/shop2/main.lua b/shop2/main.lua index 322d76c..67d3dba 100644 --- a/shop2/main.lua +++ b/shop2/main.lua @@ -3,18 +3,10 @@ package.path = "/?;/?.lua;"..package.path local key=assert(settings.get"krist.pkey","please set private key") local stock=require"shop2.stock" - +local items = require"shop2.items" -- ac.kst local OURNAME = "ac" -local ITEMS = {} -local function i(adr,itname,hname,price) - ITEMS[adr]={itname=itname,hname=hname,price=price,adr=adr} -end -i("dmn","minecraft:diamond","Diamond",5) -i("blz","minecraft:blaze_rod","Blaze Rod",10) -i("ely","minecraft:elytra","Elytra",200) - local sres =textutils.unserializeJSON( http.post("https://krist.dev/ws/start","privatekey="..key).readAll()) assert(sres.ok,"not ok") @@ -53,7 +45,7 @@ local function proctrans(tr) local function refund() if meta['return'] then sendws { type="make_transaction", to=meta['return'], amount=tr.value } end end local mtn = tr.sent_metaname - local idesc = ITEMS[mtn] + local idesc = items[mtn] if not idesc then -- some other metaname that has nothing to do with us -- presumably some other service @ac.kst. so just ignore it @@ -85,10 +77,8 @@ local function proctrans(tr) end local function run_shop() - print("RUNSHOP") while true do local msgtxt = assert(ws.receive(),"ws error") - print(msgtxt) local msg = textutils.unserializeJSON(msgtxt) if msg.type == "response" and msg.responding_to_type == "me" then our_addr = msg.address.address -- cgit v1.2.3