Advertisement
JustDoesGames

engine

Feb 16th, 2020
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.79 KB | None | 0 0
  1. -- ENGINE V1 *** MAIN ENGINE *** *** MAIN ENGINE *** *** MAIN ENGINE *** ENGINE V1 --
  2. -- FUNCTIONS --
  3. 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
  4.  
  5. local w,h = term.getSize()
  6. function gs() return term.getSize() end
  7. function valid(value,expected) if type(value) == expected then return true else return false end end
  8. function verify(value, expected) return valid(value,expected) end
  9. function include(api) return os.loadAPI(api) end
  10. function clr() term.clear() end
  11. 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
  12. 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
  13. 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
  14. function notnil(vari) if vari == nil then return false else return true end end
  15. 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
  16. function pullEvents(...) -- for pulling multiple events at a time, first event get priority
  17.     local args = {...}
  18.     --if #args == 0 then return os.pullEvent() end
  19.     while true do
  20. print("Im gay and Retarded!")
  21. os.pullEvent("key")
  22.         sleep(.000000001)
  23.         event, arg1, arg2, arg3, arg4 = os.pullEvent()
  24.         for i=1, #args do
  25.             if args[i] == event then
  26.                 return event, arg1, arg2, arg3, arg4
  27.             end
  28.         end
  29.     end
  30. end
  31. function getTableSize(image) -- Returns width and length of a table. used for images.
  32.     if not valid(image,"table") then return error("Expected table for image, got "..type(image)) end
  33.     local lng = 0
  34.     for i=1, #image do
  35.         if string.len(image[i]) > lng then
  36.             lng = string.len(image[i])
  37.         end
  38.     end
  39.     return lng, #image
  40. end
  41. function find(tble, thing)
  42.     if not valid(tble,"table") then return error("Expected table for table, got "..type(image)) end
  43.     if not valid(image,"string") then return error("Expected string for arg 2, got "..type(image)) end
  44.     for i=1, #tble do
  45.         if tble[i] == thing then
  46.             return true
  47.         end
  48.     end return false
  49. end
  50. -- FUNCTIONS --
  51. -- COLLISION --
  52. col = {}
  53. function createCol(name,x,y,x2,y2,status)
  54.     name = name or "name_"..#col table.insert(col,{}) status = status or true
  55.     col[#col].x, col[#col].y, col[#col].x2, col[#col].y2, col[#col].name, col[#col].status = x, y, x2, y2, name, status
  56. end
  57. function deleteCol(name)
  58.     if getCol(name) then table.remove(col, select(1, select( 2,getCol(name) ))) end
  59. end
  60. function getCol(x,y,name)
  61.     if not valid(x,"number") or not valid(y,"number") then return error("need numbers, got: x- "..type(x).." y- "..type(y)) end
  62.     if valid(name,"string") then
  63.         for i=1, #col do
  64.             if col[i].name == name then return true, i, col[i].name, col[i].x, col[i].y end
  65.         end
  66.     else
  67.         for i=1, #col do
  68.             if x >= col[i].x and x <= col[i].x2 and y >= col[i].y and y <= col[i].y2 then
  69.                 return true, i, col[i].name, col[i].x, col[i].y
  70.             end
  71.         end
  72.     end
  73.     return false
  74. end
  75. function moveCol(name,newx,newy)
  76.     if select( 1,getCol(0,0,name) ) then
  77.         id = select( 2, getCol(0,0,id) )
  78.         col[id].x2,col[id].y2 = col[id].x2+newx-col[id].x, col[id].y2+newy-col[id].y
  79.         col[id].x,col[id].y = newx,newy
  80.     end
  81. end
  82. function drawCol(name, color)
  83.     color = color or colors.red
  84.     color2 = colors.orange
  85.     for i=1, #col do
  86.         if name == col[i].name then
  87.             paintutils.drawFilledBox(col[i].x,col[i].y,col[i].x2,col[i].y2,color)
  88.             paintutils.drawBox(col[i].x,col[i].y,col[i].x2,col[i].y2,color2)
  89.             return true
  90.         end
  91.     end
  92.     return false
  93. end
  94. -- COLLISION --
  95. -- COLOR RELATED --
  96. function renderImage(image,x,y) -- used to display custom images fast and easy
  97.     if not valid(image,"table") then return error("Expected table for image, got "..type(image)) end
  98.     if not valid(x,"number") then return error("Expected number for x, got "..type(x)) end
  99.     if not valid(y,"number") then return error("Expected number for y, got "..type(y)) end
  100.    
  101.     cp(x,y)
  102.     for i=1, #image do
  103.         term.blit(string.rep(" ", #image[i]),string.rep("0", #image[i]),image[i])
  104.         cp(x,y+i)
  105.     end
  106. end
  107. function loadImage(image)
  108.     if not valid(image,"string") then return error("Expected string for image, got "..type(image)) end
  109.     if not fs.exists(image) then return false end
  110.     local img = {}
  111.     local file = fs.open(image, "r")
  112.     local tmp = ""
  113.     repeat
  114.         tmp = file.readLine()
  115.         if notnil(tmp) then
  116.             img[#img+1] = tmp
  117.         end
  118.     until not notnil(tmp)
  119.     file.close()
  120.     return img
  121. end
  122. -- COLOR RELATED --
  123. -- RCM --
  124. local rcm_data = {}
  125. rcm_data.menu = {"Test 1", "Test 2", "Test 3"}
  126. rcm_data.active = false
  127. rcm_data.x, rcm_data.y = 1,1
  128. function rcm_click(x,y)
  129.     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
  130.         return true
  131.     end
  132.     return false
  133. end
  134. function setRcmMenu(tab)
  135.     if not valid(tab,"table") then return error("Expected tab to be a table, got "..type(tab)) end
  136.     rcm_data.menu = tab
  137. end
  138. function rcm(x,y,options,wid,hei)
  139.     if not valid(x,"number") then return error("Expected number for x, got "..type(x)) end
  140.     if not valid(y,"number") then return error("Expected number for y, got "..type(y)) end
  141.     if not valid(options,"table") then return error("Expected table for image, got "..type(options)) end
  142.     local lnt = lt(options) -- short for longest term (used to set width of menu)
  143.     local w,h if not notnil(wid) or not notnil(hei) then w,h = term.getSize() else w,h = wid,hei end
  144.     if x >= w-lnt then
  145.         if y > h-#options-1 then
  146.             paintutils.drawBox(x-1,y-1,x-lnt-1,y-#options-1,colors.lightGray)
  147.             paintutils.drawFilledBox(x,y,x-lnt,y-#options,colors.white)
  148.             --cp(x,y) write("1")
  149.             setText("black")
  150.             for i=1, #options do
  151.                 cp(x-lnt,y-#options+i-1) write(options[i])
  152.             end
  153.         else
  154.             paintutils.drawBox(x-lnt-1,y+1,x-1,y+#options+1,colors.lightGray)
  155.             paintutils.drawFilledBox(x-lnt,y,x,y+#options,colors.white)
  156.             --cp(x,y) write("2")
  157.             setText("black")
  158.             for i=1, #options do
  159.                 cp(x-lnt,y+i-1) write(options[i])
  160.             end
  161.         end
  162.     elseif x < w-lnt then
  163.         if y > h-#options-1 then
  164.             paintutils.drawBox(x+1,y-#options-1,x+lnt+1,y-1,colors.lightGray)
  165.             paintutils.drawFilledBox(x,y-#options,x+lnt,y,colors.white)
  166.             --cp(x,y) write("3")
  167.             setText("black")
  168.             for i=1, #options do
  169.                 cp(x,y-#options+i-1) write(options[i])
  170.             end
  171.         else
  172.             paintutils.drawBox(x+1,y+1,x+lnt+1,y+#options+1,colors.lightGray)
  173.             paintutils.drawFilledBox(x,y,x+lnt,y+#options,colors.white)
  174.             --cp(x,y) write("4")
  175.             setText("black")
  176.             for i=1, #options do
  177.                 cp(x,y+i-1) write(options[i])
  178.             end
  179.         end
  180.     end
  181.     sleep(.0001)
  182. end
  183. -- RCM --
  184. -- SHELL SECURITY --
  185. --[[
  186. shell = {
  187.     run = function(program)
  188.         if not notnil(program) or not fs.exists(program) then return error("No such program.") end
  189.         local file = fs.open(program,"r")
  190.         local file_info = file.readAll() file.close()
  191.         local syntax = {"fs","error","shell.run","return"}
  192.         local trustLevel = {}
  193.         for i=1, #syntax do trustLevel[i] = false end
  194.         local run = true
  195.         for i=1, #syntax do
  196.             if notnil(string.find(file_info,syntax[i])) then trustLevel[i] = true run = false end
  197.         end
  198.         if run then
  199.             os.run({}, program)
  200.         else
  201.             sleep(.5)
  202.             for i=1, #syntax do
  203.                 print(syntax[i].." - "..tostring(trustLevel[i]))
  204.             end
  205.             print("Press 'enter' to run. otherwise continue...")
  206.             a,i = pullEvents("key") if i == keys.enter then os.run({}, program) end
  207.         end
  208.     end
  209. }
  210. ]]
  211. -- SHELL SECURITY --
  212. -- ENGINE V1 *** MAIN ENGINE *** *** MAIN ENGINE *** *** MAIN ENGINE *** ENGINE V1 --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement