Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------
- --Init:
- -------
- --Local Functions
- local catchInvalidPeripheral
- --Local Vars
- local screen = "term"
- local peripheral_sides = {"left", "right", "top", "bottom", "front", "back"}
- ----------
- --Methods:
- ----------
- setDefaultScreen = function(...)
- --Input
- local input = {...}
- local default = {"term"}
- --Parameters
- local side = input[1] or default[1]
- --Method
- if (side == "term") then
- screen = side
- else
- catchInvalidPeripheral(side, "monitor")
- screen = side
- end
- return getMonitor(side)
- end
- getScreen = function(...)
- return screen
- end
- clear = function(...)
- --Input
- local input = {...}
- local default = {getScreen()}
- --Parameters
- local side = input[1] or default[1]
- --Peripheral
- local monitor = getMonitor(side)
- --Method
- monitor.setTextColor(colors.white)
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- if not(qbutton == nil) then
- qbutton.disableAllButtons()
- end
- end
- convertColor = function(...)
- --Input
- local input = {...}
- local default = {"a"}
- --Parameters
- local color = input[1] or default[1]
- --Method
- local color_mapping = {
- ["a"] = 1, --white
- ["b"] = 256, --lightGray
- ["c"] = 128, --gray
- ["d"] = 32768, --black
- ["e"] = 4096, --brown
- ["f"] = 16384, --red
- ["g"] = 2, --orange
- ["h"] = 16, --yellow
- ["i"] = 32, --lime
- ["j"] = 8192, --green
- ["k"] = 2048, --blue
- ["l"] = 512, --cyan
- ["m"] = 8, --lightBlue
- ["n"] = 1024, --purple
- ["o"] = 4, --magenta
- ["p"] = 64, --pink
- }
- if (color_mapping[color] == nil) then
- error("Invalid Color Code:"..color.." Use letters a-p.", 0)
- else
- return color_mapping[color]
- end
- end
- isIn = function(...)
- --Input
- local input = {...}
- local default = {1, {1, 2}}
- --Parameters
- local var = input[1] or default[1]
- local array = input[2] or default[2]
- --Method
- for i, v in pairs(array) do
- if (v == var) then
- return true
- end
- end
- return false
- end
- getMonitor = function(...)
- --Input
- local input = {...}
- local default = {"term"}
- --Parameters
- local side = input[1] or default[1]
- --Method
- if (side == "term") then
- return term
- else
- catchInvalidPeripheral(side, "monitor")
- return peripheral.wrap(side)
- end
- end
- ----------
- --Private:
- ----------
- catchInvalidPeripheral = function(side, target_peripheral)
- if not( isIn(side, peripheral_sides) ) then
- error(side.." is not a valid side.", 0)
- else
- if not( peripheral.getType(side) == target_peripheral ) then
- error("No "..target_peripheral.." on "..side.." side.", 0)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement