Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local com = require("component")
- local unicode = require("unicode")
- local color = require("colors")
- local term = require("term")
- local gpu = com.gpu
- local seri = require("serialization")
- local W,H = gpu.getResolution()
- local GPAPI =
- {
- colors =
- {
- white = 0xFFFFFF,
- orange = 0xFEA500,
- magenta = 0xFF00FF,
- lightblue = 0xABDAE4,
- yellow = 0xFFFF00,
- lime = 0x06FC05,
- pink = 0xFBC2CB,
- gray = 0x808080,
- silver = 0xC0C0C0,
- cyan = 0x01FFFD,
- purple = 0x880087,
- blue = 0x0000FE,
- brown = 0xA52B2A,
- green = 0x008001,
- red = 0xFD0200,
- black = 0x000000,
- }
- }
- function cnsColor(colorB,colorF,hex)
- if hex == nil then
- if colorB ~= nil then
- gpu.setBackground(colorB)
- end
- if colorF ~= nil then
- gpu.setForeground(colorF)
- end
- else
- if colorB ~= nil then
- gpu.setBackground(colorB,true)
- end
- if colorF ~= nil then
- gpu.setForeground(colorF,true)
- end
- end
- end
- function GPAPI.textbox(x,y,text,typeT,colorBT,colorFT,hexT)
- local OldB = gpu.getBackground()
- local OldF = gpu.getForeground()
- cnsColor(colorBT,colorFT,hexT)
- if typeT ~= nil then
- if typeT == "center" then
- x = W/2 - unicode.len(text)/2
- elseif typeT == "left" then
- x = 5
- elseif typeT == "right" then
- x = W - 5 - unicode.len(text)/2
- end
- end
- if type(text) ~= "table" or type(text) ~= "function" then
- gpu.set(x,y,tostring(text))
- else
- error("function or table expected")
- gpu.setBackground(OldB)
- gpu.setForeground(OldF)
- end
- function GPAPI.draw(x,y,weight,height,colorBD,colorFD,hexD,typeD)
- local OldB = gpu.getBackground()
- local OldF = gpu.getForeground()
- cnsColor(colorBD,colorFD,hexD)
- if typeD ~= nil then
- gpu.fill(x,y,weight,height," ")
- gpu.fill(x,y,weight/160*typeD,height," ")
- if weight/160*typeD > weight then
- gpu.fill(x+weight,y,weight,height," ")
- end
- end
- gpu.fill(x,y,weight,height," ")
- gpu.setBackground(OldB)
- gpu.setForeground(OldF)
- end
- function GPAPI.button(sX,sY,x,y,weight,height,func,...)
- if sX >= x and sX < x + weight then
- if sY >= y and sY < y + height then
- DO = coroutine.create(func)
- coroutine.resume(DO,...)
- end
- end
- end
- function GPAPI.code(text)
- local byted = {}
- for i = 1,#text do
- byted[i] = string.reverse(string.byte(text,i,i))
- end
- sbyted = string.reverse(seri.serialize(byted))
- return sbyted
- end
- function GPAPI.uncode(sbyted)
- local sbyted = seri.unserialize(string.reverse(sbyted))
- local text = ""
- for i = 1,#sbyted do
- sbyted[i] = string.char(string.reverse(sbyted[i]))
- end
- for i = 1,#sbyted do
- text = text..sbyted[i]
- end
- return text
- end
- function GPAPI.split(str, separator)
- local separator, fields, start, i = separator or ",", {}, 1, 1
- while true do
- i = str:find(separator, start, true)
- if i then
- fields[#fields + 1] = str:sub(start, i - 1)
- start = i + #separator
- elseif start < #str then
- fields[#fields + 1] = str:sub(start)
- break
- else
- break
- end
- end
- return fields
- end
- function GPAPI.exit(OldB,OldF,W,H)
- gpu.setBackground(OldB,true)
- gpu.setForeground(OldF,true)
- gpu.setResolution(W,H)
- term.clear()
- os.exit()
- end
- function GPAPI.write(path,value,mode)
- local file
- if mode == nil then
- file = io.open(path,"a")
- else
- file = io.open(path,mode)
- end
- file:write(value)
- file:close()
- end
- function GPAPI.read(path)
- local file = io.open(path,"r")
- local value = file:read("*a")
- file:close()
- return value
- end
- function GPAPI.time()
- Time = os.date("*t")
- TimeF = "["..Time["hour"]..":"..Time["min"]..":"..Time["sec"].."_"..Time["day"].."."..Time["month"].."."..Time["year"].."]"
- return TimeF
- end
- --[[GPAPI.signals =
- {
- "component_added" = {address,componentType},
- "component_removed" = {address,componentType},
- "component_available" = componentType,
- "component_unavailable" = componentType,
- "term_available",
- "term_unavailable",
- "screen_resize" = {address,width,height},
- "touch" = {address,x,y,button,nick},
- "drag" = signals["touch"],
- "drop" = signals["touch"],
- "scroll" = {address,x,y,direction,nick},
- "walk" = {address,x,y,nick},
- "key_down" = {address,char,code,nick},
- "key_up" = {address,char,code,nick},
- "clipboard" = {address,value,nick},
- "redstone_changed" = {address,side},
- "modem_message" = {recieverAddress,senderAddress,port,distance,message},
- "inventory_changed" = slot,
- "motion" = {address,x,y,z,nick},
- }]]
- return GPAPI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement