Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ENGINE V1 *** MAIN ENGINE *** *** MAIN ENGINE *** *** MAIN ENGINE *** ENGINE V1 --
- -- FUNCTIONS --
- local engineVersion = 2 -- Specify to only run on this version or another version if you want. this number is only going up by 1 every update
- local w,h = term.getSize()
- function gs() return term.getSize() end
- function valid(value,expected) if type(value) == expected then return true else return false end end
- function verify(value, expected) return valid(value,expected) end
- function include(api) return os.loadAPI(api) end
- function clr() term.clear() end
- function cp(x,y) if not valid(x,"number") then return error("Expected x to be a number, got "..type(x)) end if not valid(y,"number") then return error("Expected y to be a number, got "..type(y)) end term.setCursorPos(x,y) end
- function setText(col) if not valid(col,"string") then return error("Expected col to be a string, got "..type(x)) else return term.setTextColor(colors[col]) end end
- function setBack(col) if not valid(col,"string") then return error("Expected col to be a string, got "..type(x)) else return term.setBackgroundColor(colors[col]) end end
- function notnil(vari) if vari == nil then return false else return true end end
- function lt(tab) if not valid(tab,"table") then return error("Expected tab to be a table, got "..type(tab)) end local lt = 0 for i=1, #tab do if string.len(tab[i]) > lt then lt = string.len(tab[i]) end end return lt end
- function pullEvents(...) -- for pulling multiple events at a time, first event get priority
- local args = {...}
- --if #args == 0 then return os.pullEvent() end
- while true do
- print("Im gay and Retarded!")
- os.pullEvent("key")
- sleep(.000000001)
- event, arg1, arg2, arg3, arg4 = os.pullEvent()
- for i=1, #args do
- if args[i] == event then
- return event, arg1, arg2, arg3, arg4
- end
- end
- end
- end
- function getTableSize(image) -- Returns width and length of a table. used for images.
- if not valid(image,"table") then return error("Expected table for image, got "..type(image)) end
- local lng = 0
- for i=1, #image do
- if string.len(image[i]) > lng then
- lng = string.len(image[i])
- end
- end
- return lng, #image
- end
- function find(tble, thing)
- if not valid(tble,"table") then return error("Expected table for table, got "..type(image)) end
- if not valid(image,"string") then return error("Expected string for arg 2, got "..type(image)) end
- for i=1, #tble do
- if tble[i] == thing then
- return true
- end
- end return false
- end
- -- FUNCTIONS --
- -- COLLISION --
- col = {}
- function createCol(name,x,y,x2,y2,status)
- name = name or "name_"..#col table.insert(col,{}) status = status or true
- col[#col].x, col[#col].y, col[#col].x2, col[#col].y2, col[#col].name, col[#col].status = x, y, x2, y2, name, status
- end
- function deleteCol(name)
- if getCol(name) then table.remove(col, select(1, select( 2,getCol(name) ))) end
- end
- function getCol(x,y,name)
- if not valid(x,"number") or not valid(y,"number") then return error("need numbers, got: x- "..type(x).." y- "..type(y)) end
- if valid(name,"string") then
- for i=1, #col do
- if col[i].name == name then return true, i, col[i].name, col[i].x, col[i].y end
- end
- else
- for i=1, #col do
- if x >= col[i].x and x <= col[i].x2 and y >= col[i].y and y <= col[i].y2 then
- return true, i, col[i].name, col[i].x, col[i].y
- end
- end
- end
- return false
- end
- function moveCol(name,newx,newy)
- if select( 1,getCol(0,0,name) ) then
- id = select( 2, getCol(0,0,id) )
- col[id].x2,col[id].y2 = col[id].x2+newx-col[id].x, col[id].y2+newy-col[id].y
- col[id].x,col[id].y = newx,newy
- end
- end
- function drawCol(name, color)
- color = color or colors.red
- color2 = colors.orange
- for i=1, #col do
- if name == col[i].name then
- paintutils.drawFilledBox(col[i].x,col[i].y,col[i].x2,col[i].y2,color)
- paintutils.drawBox(col[i].x,col[i].y,col[i].x2,col[i].y2,color2)
- return true
- end
- end
- return false
- end
- -- COLLISION --
- -- COLOR RELATED --
- function renderImage(image,x,y) -- used to display custom images fast and easy
- if not valid(image,"table") then return error("Expected table for image, got "..type(image)) end
- if not valid(x,"number") then return error("Expected number for x, got "..type(x)) end
- if not valid(y,"number") then return error("Expected number for y, got "..type(y)) end
- cp(x,y)
- for i=1, #image do
- term.blit(string.rep(" ", #image[i]),string.rep("0", #image[i]),image[i])
- cp(x,y+i)
- end
- end
- function loadImage(image)
- if not valid(image,"string") then return error("Expected string for image, got "..type(image)) end
- if not fs.exists(image) then return false end
- local img = {}
- local file = fs.open(image, "r")
- local tmp = ""
- repeat
- tmp = file.readLine()
- if notnil(tmp) then
- img[#img+1] = tmp
- end
- until not notnil(tmp)
- file.close()
- return img
- end
- -- COLOR RELATED --
- -- RCM --
- local rcm_data = {}
- rcm_data.menu = {"Test 1", "Test 2", "Test 3"}
- rcm_data.active = false
- rcm_data.x, rcm_data.y = 1,1
- function rcm_click(x,y)
- if x >= rcm_data.x and x <= rcm_data.x+lt(rcm_data.menu) and y >= rcm_data.y and y <= rcm_data.y+#rcm_data.menu then
- return true
- end
- return false
- end
- function setRcmMenu(tab)
- if not valid(tab,"table") then return error("Expected tab to be a table, got "..type(tab)) end
- rcm_data.menu = tab
- end
- function rcm(x,y,options,wid,hei)
- if not valid(x,"number") then return error("Expected number for x, got "..type(x)) end
- if not valid(y,"number") then return error("Expected number for y, got "..type(y)) end
- if not valid(options,"table") then return error("Expected table for image, got "..type(options)) end
- local lnt = lt(options) -- short for longest term (used to set width of menu)
- local w,h if not notnil(wid) or not notnil(hei) then w,h = term.getSize() else w,h = wid,hei end
- if x >= w-lnt then
- if y > h-#options-1 then
- paintutils.drawBox(x-1,y-1,x-lnt-1,y-#options-1,colors.lightGray)
- paintutils.drawFilledBox(x,y,x-lnt,y-#options,colors.white)
- --cp(x,y) write("1")
- setText("black")
- for i=1, #options do
- cp(x-lnt,y-#options+i-1) write(options[i])
- end
- else
- paintutils.drawBox(x-lnt-1,y+1,x-1,y+#options+1,colors.lightGray)
- paintutils.drawFilledBox(x-lnt,y,x,y+#options,colors.white)
- --cp(x,y) write("2")
- setText("black")
- for i=1, #options do
- cp(x-lnt,y+i-1) write(options[i])
- end
- end
- elseif x < w-lnt then
- if y > h-#options-1 then
- paintutils.drawBox(x+1,y-#options-1,x+lnt+1,y-1,colors.lightGray)
- paintutils.drawFilledBox(x,y-#options,x+lnt,y,colors.white)
- --cp(x,y) write("3")
- setText("black")
- for i=1, #options do
- cp(x,y-#options+i-1) write(options[i])
- end
- else
- paintutils.drawBox(x+1,y+1,x+lnt+1,y+#options+1,colors.lightGray)
- paintutils.drawFilledBox(x,y,x+lnt,y+#options,colors.white)
- --cp(x,y) write("4")
- setText("black")
- for i=1, #options do
- cp(x,y+i-1) write(options[i])
- end
- end
- end
- sleep(.0001)
- end
- -- RCM --
- -- SHELL SECURITY --
- --[[
- shell = {
- run = function(program)
- if not notnil(program) or not fs.exists(program) then return error("No such program.") end
- local file = fs.open(program,"r")
- local file_info = file.readAll() file.close()
- local syntax = {"fs","error","shell.run","return"}
- local trustLevel = {}
- for i=1, #syntax do trustLevel[i] = false end
- local run = true
- for i=1, #syntax do
- if notnil(string.find(file_info,syntax[i])) then trustLevel[i] = true run = false end
- end
- if run then
- os.run({}, program)
- else
- sleep(.5)
- for i=1, #syntax do
- print(syntax[i].." - "..tostring(trustLevel[i]))
- end
- print("Press 'enter' to run. otherwise continue...")
- a,i = pullEvents("key") if i == keys.enter then os.run({}, program) end
- end
- end
- }
- ]]
- -- SHELL SECURITY --
- -- ENGINE V1 *** MAIN ENGINE *** *** MAIN ENGINE *** *** MAIN ENGINE *** ENGINE V1 --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement