Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- market display sign
- -- files used:
- -- monside (top/bottom/left/etc) - side monitor is on. Can also use this to specify modem-connected stuff
- -- lines - the lines this sign should display
- -- scale - the text scaling to use
- -- ===============================================
- -- reads a config for lines
- os.sleep(4)
- shell.run("delete", "lines")
- shell.run("pastebin","get","hBkj3XcW","lines")
- f = fs.open('lines','r')
- linesList = {}
- curLine = f.readLine()
- while curLine ~= nil do
- table.insert(linesList, curLine)
- curLine = f.readLine()
- end
- f.close()
- -- end floor config read
- -- ===============================================
- -- hw init
- f = fs.open('monside','r')
- curMon = peripheral.wrap(f.readAll())
- f.close()
- curMon.clear()
- f = fs.open('scale','r')
- curMon.setTextScale(f.readAll() + 0.0)
- f.close()
- curMon.setTextColor(colors.white)
- local width, height = curMon.getSize()
- -- end hw init
- -- ===============================================
- local function computeCenteringPos(strlen, padding)
- return (width-strlen)/2 + 1 + padding
- end
- local function printHorizRule(mon, y)
- mon.setTextColor(colors.white)
- mon.setCursorPos(1,y)
- mon.write(string.rep('-', width))
- end
- local function renderLine(lineNo, mon)
- local floorText = linesList[lineNo]
- -- half of this stuff deals with text based on the size of it.
- -- strip and extract the color preprocessors
- preProcStart, preProcEnd = string.find(floorText, '~')
- preProcColor = nil
- if preProcStart == 1 then
- -- found the preproc!
- preProcStart, preProcEnd = string.find(floorText, '~',2)
- preProcColor = string.sub(floorText, 2,preProcEnd-1)
- print("preprocessor: "..preProcColor)
- floorText = floorText.sub(floorText, preProcEnd+1)
- end
- local width, height = mon.getSize()
- local strlen = string.len(floorText)
- local cursorPosX = 0
- local cursorPosY = lineNo
- -- text rendering :D
- -- set the color appropriately
- if preProcColor ~= nil and colors[preProcColor] ~= nil then
- mon.setTextColor(colors[preProcColor])
- else
- mon.setTextColor(colors.white)
- end
- if strlen > width then
- -- wider than screen. Left justify it.
- mon.setCursorPos(1, cursorPosY)
- mon.write(floorText)
- else
- -- ( (width-len(txt)) /2)*' ' + txt
- -- "+1" because LUA has 1-based indexes. This piece is designed for 0-based indices -_-
- -- "+2" to make it look centered against the offset that the floor numbers take up
- --cursorPosX = (width-strlen)/2 + 1 + 2
- cursorPosX = computeCenteringPos(strlen,2)
- mon.setCursorPos(cursorPosX, cursorPosY)
- mon.write(floorText)
- end
- end
- -- print store header
- printHorizRule(curMon,2)
- for i = 1, #linesList do
- renderLine(i,curMon)
- end
- while true do
- os.sleep(4)
- end
Advertisement
Add Comment
Please, Sign In to add comment