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
- -- floorno - the REVERSE INDEXED floor number this computer serves (used for highlighting)
- -- floors - the floor listing (top to bottom), one floor/line
- -- ===============================================
- -- reads a config for floor names
- f = fs.open('floors','r')
- floorList = {}
- curLine = f.readLine()
- while curLine ~= nil do
- table.insert(floorList, curLine)
- curLine = f.readLine()
- end
- f.close()
- f = fs.open('floorno','r')
- curFloor = tonumber( f.readAll() )
- f.close()
- -- end floor config read
- -- ===============================================
- -- hw init
- f = fs.open('monside','r')
- curMon = peripheral.wrap(f.readAll())
- f.close()
- curMon.clear()
- 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 renderFloor(floorNum, mon)
- local floorText = floorList[floorNum]
- -- 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 = height-( (#floorList-floorNum) *2)
- -- text rendering :D
- -- set the color appropriately
- if floorNum == curFloor then
- mon.setTextColor(colors.lime)
- elseif preProcColor ~= nil and colors[preProcColor] ~= nil then
- mon.setTextColor(colors[preProcColor])
- else
- mon.setTextColor(colors.white)
- end
- floorCode = nil
- -- attempt to crudely center this
- if floorNum == curFloor then
- floorCode = '==> '
- else
- floorCode = 'L'..(#floorList-floorNum+1)..': '
- end
- if strlen + string.len(floorCode) > width then
- -- wider than screen. Left justify it.
- mon.setCursorPos(1, cursorPosY)
- mon.write(floorCode..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(1,cursorPosY)
- mon.write(floorCode)
- mon.setCursorPos(cursorPosX, cursorPosY)
- mon.write(floorText)
- end
- end
- -- print store header
- txt = 'Hastwell Industries'
- curMon.setCursorPos(computeCenteringPos(string.len(txt),0),1)
- curMon.write(txt)
- printHorizRule(curMon,2)
- for i = 1, #floorList do
- renderFloor(i,curMon)
- end
Advertisement
Add Comment
Please, Sign In to add comment