Advertisement
Redxone

[CC-CrossBow] - Zipped PreAlpha Crossbow

Jun 2nd, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 153.63 KB | None | 0 0
  1. {
  2.   [ "apis/novaio/" ] = {
  3.     content = "local str = \"\"\
  4. local active = true\
  5. local inputindex = #str\
  6. local function setStartStr(nstr)\
  7. \009str = nstr\
  8. end\
  9. function read(e,maxlen,mslen,x,y)\
  10. \009term.setCursorBlink(active)\
  11. \009local function drawstr()\
  12. \009\009term.setCursorPos(x,y)\
  13. \009\009write(string.rep(\" \",mslen+1))\
  14. \009\009term.setCursorPos(x,y)\
  15. \009\009if(#str > mslen)then\
  16. \009\009\009local dif = #str - mslen\
  17. \009\009\009if(inputindex <= dif)then\
  18. \009\009\009\009write(str:sub(inputindex,mslen+inputindex))\
  19. \009\009\009else\
  20. \009\009\009\009write(str:sub(dif,mslen+dif))\
  21. \009\009\009end\
  22. \009\009else\
  23. \009\009\009write(str)\
  24. \009\009end\
  25. \009\009if(inputindex > mslen)then\
  26. \009\009\009term.setCursorPos(x+inputindex-(#str-mslen),y)\
  27. \009\009else\
  28. \009\009\009term.setCursorPos(x+inputindex,y)\
  29. \009\009end\
  30. \009end\
  31. \009local function undrawstr()\
  32. \009\009term.setCursorPos(x,y)\
  33. \009\009write(string.rep(\" \",mslen))\
  34. \009end\
  35. \009local function updatestr()\
  36. \009\009inputindex = inputindex + 1\
  37. \009\009drawstr()\
  38. \009end\
  39. \009if(active)then\
  40. \009\009if(e[1] == \"char\" and #str < maxlen)then\
  41. \009        str = str:sub(1,inputindex) .. tostring(e[2]) .. str:sub(inputindex+1,#str)\
  42.        \009updatestr()\
  43. \009\009end\
  44. \009\009if(e[1] == \"key\")then\
  45. \009\009\009local key = e[2]\
  46. \009\009\009 if(key == keys.enter)then\
  47. \009\009\009 \009term.setCursorBlink(false)\
  48. \009\009\009 \009active = false\
  49. \009\009\009 \009return true\
  50. \009\009\009 end\
  51. \009\009\009 if(key == keys.backspace and inputindex > 0)then\
  52. \009\009\009 \009 undrawstr()\
  53. \009\009\009 \009 str =  string.sub( str, 1, inputindex - 1 ) .. string.sub( str, inputindex + 1 )\
  54. \009\009\009 \009 inputindex = inputindex - 1\
  55. \009\009\009 \009 drawstr()\
  56. \009\009\009 end\
  57. \009\009\009 if(key == keys.left and inputindex > 0)then\
  58. \009\009\009 \009 inputindex = inputindex - 1\
  59. \009\009\009 \009 drawstr()\
  60. \009\009\009 end\
  61. \009\009\009 if(key == keys.right and inputindex < #str)then\
  62. \009\009\009 \009 inputindex = inputindex + 1\
  63. \009\009\009 \009 drawstr()\
  64. \009\009\009 end\
  65. \009\009\009 if(key == keys.delete and inputindex < #str)then\
  66. \009\009\009 \009 undrawstr()\
  67. \009\009\009 \009 str = string.sub( str, 1, inputindex ) .. string.sub( str, inputindex + 2 )\
  68. \009\009\009 \009 drawstr()\
  69. \009\009\009 end\
  70. \009\009end\
  71. \009end\
  72. \009if(e[1] == \"mouse_click\" and (e[4] ~= y or e[3] < x or e[3] > x+maxlen) )then\
  73. \009\009active = false\
  74. \009\009term.setCursorBlink(active)\
  75. \009elseif(e[1] == \"mouse_click\" and e[4] == y)then\
  76. \009\009if(not active)then\
  77. \009\009\009active = true\
  78. \009\009\009term.setCursorPos(x+inputindex,y)\
  79. \009\009\009term.setCursorBlink(active)\
  80. \009\009end\
  81. \009\009if(e[3]-x >= 0 and e[3]-x <= #str)then\
  82. \009\009\009inputindex = e[3]-x\
  83. \009\009\009drawstr()\
  84. \009\009end\
  85. \009end\
  86. end\
  87. function getInput()\
  88. \009return str\
  89. end\
  90. function resetInput()\
  91. \009str = \"\"\
  92. \009inputindex = #str\
  93. end\
  94. function setInput(nstr)\
  95. \009str = nstr\
  96. \009inputindex = #str\
  97. end\
  98. function setActive(act)\
  99. \009active = act\
  100. end\
  101. function getActive()\
  102. \009return active\
  103. end",
  104.   },
  105.   [ "users/Test/JDJJD/" ] = {
  106.     content = "",
  107.   },
  108.   [ "programs/novaexplore/" ] = {
  109.     content = "--====================================================\
  110. --]] Nova Explore and all file apis created by\
  111. --]] Lewisk3 CEO of Nova, all rights reservered \
  112. --]] DO NOT REDISTRIBUTE without the permission \
  113. --]] of Nova, Editing and/or \"rebranding\" is prohibited.\
  114. --]] Any copys found outside the permission of Nova\
  115. --]] will be taken and money will be due to the rights\
  116. --]] of Nova Technologys\
  117. -------------------------------------------------------\
  118. --=]      We have the rights to all the above       [=-       \
  119. --=====================================================\
  120. --]] Determine OS and load apis accordingly \
  121. local w, h = term.getSize()\
  122. local sbc = term.setBackgroundColor\
  123. local stc = term.setTextColor\
  124. local scp = term.setCursorPos\
  125. local clr = term.clear\
  126. local clrln = term.clearLine\
  127. local actionkeydown = false\
  128. local actionkey = keys.leftCtrl\
  129. local multiselecting = false\
  130. local diskside = \"right\"\
  131. files_selected = {}\
  132. local archiver = \"\"\
  133. local pa = paintutils\
  134. local apis = {'ugapi','fpath','futils','novaio'}\
  135. local pinnednames = {}\
  136. local innova = true\
  137. local iscrossbow = false\
  138. --]] Load apis\
  139. \009if( fs.isDir(\"CrossBow/apis\") )then\
  140. \009\009os.loadAPI(\"CrossBow/apis/novautils\")\
  141. \009else\
  142. \009\009os.loadAPI(shell.resolveProgram(\"novautils\"))\
  143. \009end\
  144. \009novautils.init(shell)\
  145. \009iscrossbow = novautils.getApisFrom(\"CrossBow/apis\",apis)\
  146. \009if(iscrossbow)then\
  147. \009\009archiver = \"CrossBow/programs/novazip\"\
  148. \009else\
  149. \009\009if(not shell.resolveProgram(\"novazip\"))then\
  150. \009\009\009print(\"NovaZIP not found, novaexplore will run with no ZIP viewer. \")\
  151. \009\009else\
  152. \009\009\009archiver = shell.resolveProgram(\"novazip\")\
  153. \009\009end\
  154. \009end\
  155. --]] Define variables \
  156. local file_selected = 0\
  157. local files = {}\
  158. -- Path isnt locked\
  159. local path = fpath.newpath(\"/\")\
  160. novaio.setActive(false)\
  161. novaio.setInput(path:getraw())\
  162. local fileoffs = 0\
  163. local sideoffs = 0\
  164. local sidemax = h-1\
  165. local filemax = h\
  166. local searching = false\
  167. local selectedside = 0\
  168. local search = \"\"\
  169. local clipboard = {}\
  170. local inmenu = false\
  171. local inmenutype = {}\
  172. local drawingmenu = {}\
  173. local inmenux, inmenuy = 1, 4\
  174. local sideitems = {}\
  175. local pinslocation = \".novapins\"\
  176. local icons = {\
  177. \009folder = \"&e[=]\",\
  178. \009file = \"&7-~-\",\
  179. \009executable = \"&8:&7=&8:\",\
  180. \009game = \"&4-&7=&8]\",\
  181. \009zip = \"&5[&1=&2]\",\
  182. \009paint = \"&2~&4* \",\
  183. \009pin = \"&7<&8 \",\
  184. \009disk= \"&8:&4^&8:\"\
  185. }\
  186. --]] Menus \
  187. filemenu = {\
  188. \009 {n=\"Open    \",func=function(file) openHref(path:getraw() .. file.n) end},\
  189. \009 {n=\"Edit    \",func=function(file) \
  190. \009 \009editfile(path:getraw() .. file.n)\
  191. \009 end},\
  192. \009 {n=\"Open as \",func=function(file) \
  193. \009 \009local ans = novautils.openYesNo(\"Open File As. \",\"Select open option.*\",novaex_redraw,\"With\", \"Args\")\
  194. \009 \009if(ans == 1)then -- open with file\
  195. \009 \009\009local openfile = novautils.openReadDialog(\"Open with another file. \",novaex_redraw)\
  196. \009 \009\009if(file ~= \"\")then\
  197. \009 \009\009\009runFile(openfile,path:getraw() .. file.n,true)\
  198. \009 \009\009end\
  199. \009 \009elseif(ans == 2)then -- open with arguments\
  200. \009 \009\009local args = novautils.openReadDialog(\"Open with arguments. \",novaex_redraw)\
  201. \009 \009\009runFile(path:getraw() .. file.n,args,true)\
  202. \009 \009end\
  203. \009 end},\
  204. \009 {n=\"Rename  \",relies=function(file) \
  205. \009 \009return file.t ~= \"disk\"\
  206. \009 end,\
  207. \009 func=function(file)\
  208. \009 \009\009local sid = getSelectedFile()\
  209. \009 \009\009sbc(colors.lightGray)\
  210. \009 \009\009scp(23,(sid-fileoffs)+4)\
  211. \009 \009\009write(string.rep(\" \",17))\
  212. \009 \009\009scp(23,(sid-fileoffs)+4)\
  213. \009 \009\009local newname = novautils.readEx(17,false,file.n)\
  214. \009 \009\009renameFile(path:getraw(),file.n,newname)\
  215. \009 end},\
  216. \009 {n=\"Extract \",relies=function(file) return file.t == \"zip\" end,\
  217. \009 func=function(file) \
  218. \009 \009 local eto = novautils.openReadDialog(\"Extract to: \",novaex_redraw)\
  219. \009 \009 local ans = novautils.openYesNo(\"Extract \", \"Extract contents of * \" .. file.n .. \" to: \" .. eto .. \"? \",novaex_redraw)\
  220. \009 \009 if(ans == 1)then\
  221. \009 \009 \009 futils.extract(path:getraw() .. file.n,eto)\
  222. \009 \009 \009 ans = novautils.openYesNo(\"Extract \", \"Extracted to: \" .. eto .. \"* Open location?\",novaex_redraw)\
  223. \009 \009 \009 if(ans == 1)then\
  224. \009 \009 \009 \009 path:set(eto)\
  225. \009 \009 \009 \009 getfiles()\
  226. \009 \009 \009 \009 undrawFiles()\
  227. \009 \009 \009 \009 drawFiles()\
  228. \009 \009 \009 end\
  229. \009 \009 end\
  230. \009 end},\
  231. \009 {n=\"Archive \",relies=function(file) return file.t ~= \"zip\" end,\
  232. \009 func=function(file) \
  233. \009 \009 local eto = novautils.openReadDialog(\"Export archive to: \",novaex_redraw)\
  234. \009 \009 if(futils.archive(path:getraw() .. file.n,eto))then\
  235. \009 \009\009 novautils.notify(\"Archive\",\"Folder/file successfully * archived. \",novaex_redraw)\
  236. \009     else\
  237. \009     \009 novautils.notify(\"Archive\",\"Failed to archive folder/file. \",novaex_redraw)\
  238. \009 \009 end\
  239. \009 end},\
  240. \009 {n=\"Cut     \",relies=function(file) \
  241. \009\009return not fs.isReadOnly(path:getraw() .. file.n)\
  242. \009 end,func=function(file) \
  243. \009 \009setClipboard(path:getraw() .. file.n, file.n, \"cut\")\
  244. \009 end},\
  245. \009 {n=\"Copy    \",func=function(file) \
  246. \009 \009setClipboard(path:getraw() .. file.n, file.n, \"copy\")\
  247. \009 end},\
  248. \009 {n=\"Paste   \",relies=function(file) \
  249. \009 \009return clipboard.name ~= nil and \
  250. \009 \009\009not fs.isReadOnly(path:getraw() .. file.n)\
  251. \009 end,\
  252. \009 func=function(file) \
  253. \009 \009pasteFile(path:getraw()) \
  254. \009 end},\
  255. \009 {n=\"Pin item\",relies=function(file) \
  256. \009 \009return not isPinnedItem(path:getraw() .. file.n) end,\
  257. \009 func=function(file)\
  258. \009 \009 addPinnedFile(\
  259. \009 \009 \009icons[file.t] .. \" &r\" .. file.n,file.t,path:getraw() .. file.n\
  260. \009 \009 )\
  261. \009 end},\
  262. \009 {n=\"Unpin   \",relies=function(file) \
  263. \009 \009return isPinnedItem(path:getraw() .. file.n) end,\
  264. \009 func=function(file) \
  265. \009 \009 removePinnedFile(path:getraw() .. file.n)\
  266. \009 end},\
  267. \009 {n=\"Delete  \",relies=function(file) \
  268. \009 \009 return not fs.isReadOnly(path:getraw() .. file.n) and \
  269. \009 \009 \009not (file.t == \"disk\" and peripheral.find(\"drive\"))\
  270. \009 end,func=function(file) \
  271. \009 \009\009local ans = novautils.openYesNo(\"File deletion. \",\"Confirm &4deletion&r of *\" .. file.n,novaex_redraw)\
  272. \009 \009\009if(ans == 1)then\
  273. \009 \009\009\009deleteFile(path:getraw() .. file.n)\
  274. \009 \009\009end\
  275. \009 end},\
  276. }\
  277. sidemenu = {\
  278. \009 {n=\"Open   \",func=function() openHref(getSelectedSideItem().href) end},\
  279. \009 {n=\"Rename \",\
  280. \009 func=function(file)\
  281. \009 \009\009local sid = getSelectedSide()\
  282. \009 \009\009scp(5,(sid-sideoffs)+4)\
  283. \009 \009\009sbc(colors.lightGray)\
  284. \009 \009\009write(string.rep(\" \",11))\
  285. \009 \009\009scp(5,(sid-sideoffs)+4)\
  286. \009 \009\009local newname = novautils.readEx(9,false)\
  287. \009 \009\009renameSideItem(getSelectedSide(),newname)\
  288. \009 end},\
  289. \009 {n=\"Unpin  \",relies=function() return getSelectedSide() >= 8 end,\
  290. \009 func=function(file) \
  291. \009 \009removePinnedFile(getSelectedSideItem().href)\
  292. \009 end},\
  293. \009 {n=\"Up     \",relies=function() \
  294. \009 \009\009return getSideItem(getSelectedSide()-1).t ~= nil and  \
  295. \009 \009\009\009   getSideItem(getSelectedSide()-1).t ~= \"text\" \
  296. \009 \009\009end,\
  297. \009 func=function(file) \
  298. \009 \009\009moveSideItem(getSelectedSide(),-1)\
  299. \009 end},\
  300. \009 {n=\"Down   \",relies=function() \
  301. \009 \009return (getSelectedSide() < getSideAmmount()) and \
  302. \009 \009\009   (getSideItem(getSelectedSide()+1).n ~= nil) and\
  303. \009 \009\009   (getSideItem(getSelectedSide()+1).n ~= \"text\")\
  304. \009 end,\
  305. \009 func=function(file) \
  306. \009 \009moveSideItem(getSelectedSide(),1)\
  307. \009 end},\
  308. }\
  309. emptymenu = {\
  310. \009{n=\"New Folder \",func=function() \
  311. \009\009local file = novautils.openReadDialog(\"New Folder\",novaex_redraw)\
  312. \009\009newFileFolder(\"folder\",path:getraw(),file) \
  313. \009end},\
  314. \009{n=\"New File   \",func=function() \
  315. \009\009local file = novautils.openReadDialog(\"New File\",novaex_redraw)\
  316. \009\009newFileFolder(\"file\",path:getraw(),file) \
  317. \009end},\
  318. \009 {n=\"Paste      \",relies=function() \
  319. \009 \009return clipboard.name ~= nil and \
  320. \009 \009\009not fs.isReadOnly(path:getraw())\
  321. \009 end,\
  322. \009 func=function() \
  323. \009 \009pasteFile(path:getraw()) \
  324. \009 end},\
  325. \009 {n=\"Test Crash \",func=function() error(\"Lol get rekt!\") end},\
  326. }\
  327. foldermenu = {\
  328. \009 filemenu[1],\
  329. \009 filemenu[4],\
  330. \009 filemenu[6],\
  331. \009 filemenu[7],\
  332. \009 filemenu[8],\
  333. \009 filemenu[9],\
  334. \009 {n=\"Pin item\",relies=function(file) \
  335. \009 \009return not isPinnedItem(path:getraw() .. file.n) end,\
  336. \009 func=function(file) \
  337. \009 \009 addPinnedFile(\
  338. \009 \009 \009icons[file.t] .. \" &r\" .. file.n,file.t,path:getraw() .. file.n\
  339. \009 \009 )\
  340. \009 end},\
  341. \009 filemenu[11],\
  342. \009 {n=\"Eject   \",relies=function(file) \
  343. \009 \009 return (file.t == \"disk\" and peripheral.find(\"drive\"))\
  344. \009 end,func=function(file) \
  345. \009 \009\009disk.eject(getDiskside())\
  346. \009 end},\
  347. \009 filemenu[12],\
  348. }\
  349. if(iscrossbow)then\
  350. \009sideitems = {\
  351. \009\009{n='&5* &rQuick Access',t='text'},\
  352. \009\009{n=' ',t='text'},\
  353. \009\009{n=icons.folder..' &rPrograms',t='folder',href=\"CrossBow/programs\"},\
  354. \009\009{n=icons.folder..' &rGames',t='folder',href=\"CrossBow/games\"},\
  355. \009\009{n=' ',t='text'},\
  356. \009\009{n=' ',t='text'},\
  357. \009\009{n=icons.pin .. \"&rPinned Items\",t='text'},\
  358. \009\009{n=' ',t='text'},\
  359. \009\009{n=icons.game..' &rGameOfLife',t='game',href=\"CrossBow/games/GameOfLife\"},\
  360. \009\009{n=icons.game..' &r2048',t='game',href=\"CrossBow/games/2048\"},\
  361. \009\009{n=icons.folder..' &5Apis',t='folder',href=\"CrossBow/apis\"},\
  362. \009}\
  363. else\
  364. \009sideitems = {\
  365. \009\009{n='&5* &rQuick Access',t='text'},\
  366. \009\009{n=' ',t='text'},\
  367. \009\009{n=icons.folder..' &rPrograms',t='folder',href=\"rom/programs\"},\
  368. \009\009{n=icons.folder..' &rGames',t='folder',href=\"rom/programs/fun\"},\
  369. \009\009{n=' ',t='text'},\
  370. \009\009{n=' ',t='text'},\
  371. \009\009{n=icons.pin .. \"&rPinned Items\",t='text'},\
  372. \009\009{n=' ',t='text'},\
  373. \009\009{n=icons.game..' &2Worm',t='game',href=\"rom/programs/fun/worm\"},\
  374. \009\009{n=icons.game..' &8Redirection',t='game',href=\"rom/programs/fun/advanced/redirection\"},\
  375. \009}\
  376. end\
  377. --]] Get functions and file definitions\
  378. local pinnednames = {}\
  379. if(iscrossbow)then\
  380. \009pinslocation = \"configs/novapins\"\
  381. end\
  382. function getDiskside() return diskside end\
  383. function getWorkingDir()\
  384. \009return fs.getDir(shell.getRunningProgram()) .. \"/\"\
  385. end\
  386. function getConfigPinnedItems()\
  387. \009if(fs.exists(getWorkingDir() .. pinslocation))then\
  388. \009\009local pfile = (getWorkingDir() .. pinslocation)\
  389. \009\009local itemspinned = textutils.unserialize(futils.file_readAll(pfile))\
  390. \009\009for i = 1, #itemspinned do\
  391. \009\009\009sideitems[8+(i-1)] = itemspinned[i]\
  392. \009\009end\
  393. \009\009getPinnedNames()\
  394. \009else\
  395. \009\009local writeitems = {}\
  396. \009\009for i = 8, #sideitems do\
  397. \009\009\009writeitems[#writeitems+1] = sideitems[i]\
  398. \009\009end\
  399. \009\009futils.file_write(getWorkingDir() .. pinslocation,textutils.serialize(writeitems))\
  400. \009\009getConfigPinnedItems()\
  401. \009end\
  402. end\
  403. function saveConfigPinnedItems()\
  404. \009local writeitems = {}\
  405. \009for i = 8, #sideitems do\
  406. \009\009writeitems[#writeitems+1] = sideitems[i]\
  407. \009end\
  408. \009if(fs.exists(getWorkingDir() .. pinslocation))then\
  409. \009\009futils.file_write(getWorkingDir() .. pinslocation,textutils.serialize(writeitems))\
  410. \009end\
  411. end\
  412. \
  413. function isPinnedItem(path)\
  414. \009return pinnednames[formatPinPath(path)]\
  415. end\
  416. \
  417. -- Icon drawing\
  418. \
  419. \
  420. function formatPinPath(path)\
  421. \009local npath  = fpath.newpath(path)\
  422.    local pathtbl={}\
  423.    for str in string.gmatch(path, \"([^/]+)\") do\
  424.        pathtbl[#pathtbl+1] = str  \
  425.    end\
  426.    fname = pathtbl[#pathtbl]\
  427.    npath:goback(1)\
  428. \
  429. \009if(path:sub(1,1) == \"/\" and #npath:getraw() > 1)then path = path:sub(2,#path) end \
  430. \009if(#npath:getraw() <= 1)then path = \"/\" .. fname end\
  431. \009return path\
  432. end\
  433. \
  434. function novaex_redraw()\
  435. \009undrawFiles()\
  436. \009getfiles()\
  437. \009drawMain()\
  438. \009drawFiles()\
  439. end\
  440. \
  441. function moveSideItem(id,to)\
  442. \009local moveitem = sideitems[id]\
  443. \009local toitem = sideitems[id+to]\
  444. \
  445. \009sideitems[id+to] = moveitem\
  446. \009sideitems[id] = toitem\
  447. \009selectedside = selectedside + to\
  448. \009drawSideBar()\
  449. end\
  450. function deleteFile(file)\
  451. \009file_selected = 0\
  452. \009fs.delete(file)\
  453. \009undrawFiles()\
  454. \009getfiles()\
  455. \009drawFiles()\
  456. end\
  457. function newFileFolder(forf,path,file)\
  458. \009if(file == \"\" or file:find(\" \"))then return false end\
  459. \009if(not fs.exists(path .. file))then\
  460. \009\009if(forf == \"folder\")then\
  461. \009\009\009if(file:sub(1,4) == \"disk\")then\
  462. \009\009\009\009novautils.notify(\"Creation Error.\",\"Cannot create disk directory!\",novaex_redraw)\
  463. \009\009\009\009return false\
  464. \009\009\009end\
  465. \009\009\009fs.makeDir(path .. file)\
  466. \009\009elseif(forf == \"file\")then\
  467. \009\009\009local f = fs.open(path .. file,\"w\")\
  468. \009\009\009f.write(\"\")\
  469. \009\009\009f.close()\
  470. \009\009end\
  471. \009\009getfiles()\
  472. \009\009drawFiles()\
  473. \009else\
  474. \009\009novautils.notify(\"Creation Error.\",\"File or folder already exists.\",novaex_redraw)\
  475. \009end\
  476. end\
  477. function renameSideItem(id,nname)\
  478.     if(nname ~= \"\")then\
  479.     \009 nname = icons[sideitems[id].t] .. \"&r \" .. nname\
  480.     \009 sideitems[id].n = nname\
  481.     \009 saveConfigPinnedItems()\
  482.     end\
  483.       drawSideBar()\
  484. end\
  485. function getSideItemType(id)\
  486. \009return sideitems[id].t\
  487. end\
  488. function getSideItem(id)\
  489. \009return sideitems[id]\
  490. end\
  491. function addPinnedFile(name,type,link)\
  492. \009sideitems[#sideitems+1] = {n=name,t=type,href=formatPinPath(link)}\
  493. \009pinnednames[formatPinPath(link)] = true\
  494. \009saveConfigPinnedItems()\
  495. \009drawFiles()\
  496. \009drawSideBar()\
  497. end\
  498. function setClipboard(p,n,t)\
  499. \009clipboard = {path=p,name=n,type=t}\
  500. \009if(t == \"cut\")then\
  501. \009\009drawFiles()\
  502. \009end\
  503. end\
  504. function getSelectedSideItem()\
  505. \009return sideitems[selectedside]\
  506. end\
  507. function getSelectedSide()\
  508. \009return selectedside\
  509. end\
  510. function getSideAmmount()\
  511. \009return #sideitems\
  512. end\
  513. function getSelectedFile()\
  514. \009return file_selected\
  515. end\
  516. function getnamedpins()\
  517. \009return pinnednames\
  518. end\
  519. function getClipboard()\
  520. \009return clipboard\
  521. end\
  522. function removePinnedFile(link)\
  523. \009for i = 8, #sideitems do\
  524. \009\009if(sideitems[i].href == formatPinPath(link))then\
  525. \009\009\009table.remove(sideitems,i)\
  526. \009\009\009getPinnedNames()\
  527. \009\009\009saveConfigPinnedItems()\
  528. \009\009\009break\
  529. \009\009end\
  530. \009end\
  531. \009selectedside = 0\
  532. \009drawFiles()\
  533. \009drawSideBar()\
  534. end\
  535. function getPinnedNames()\
  536. \009pinnednames = {}\
  537. \009for i = 1, #sideitems do\
  538. \009\009if(sideitems[i].t ~= \"text\")then\
  539. \009\009\009pinnednames[sideitems[i].href] = true\
  540. \009\009end\
  541. \009end\
  542. end\
  543. \
  544. --]] Get files in directory\
  545. \
  546. function getfiles()\
  547. \009files = {}\
  548. \009local folders = {}\
  549. \009for k , v in pairs(fs.list(path:getraw())) do\
  550. \009\009if(fs.isDir(path:getraw() .. v))then\
  551. \009\009\009local spt = 'folder'\
  552. \009\009\009if(v:sub(1,4) == \"disk\")then \
  553. \009\009\009\009if(#v > 4)then\
  554. \009\009\009\009\009if(tonumber(v:sub(5,#v)) ~= nil)then\
  555. \009\009\009\009\009\009spt = \"disk\"\
  556. \009\009\009\009\009end\
  557. \009\009\009\009else\
  558. \009\009\009\009\009spt = \"disk\" \
  559. \009\009\009\009end\
  560. \009\009\009end\
  561. \009\009\009folders[#folders+1] = {n=v,t=spt}\
  562. \009\009else\
  563. \009\009\009local nt = 'file'\
  564. \009\009\009if(v:sub(#v-3,#v) == '.zip')then nt = 'zip' end\
  565. \009\009\009if(v:sub(#v-3,#v) == '.exe')then nt = 'exe' end\
  566. \009\009\009if(path:getraw():find(\"CrossBow/games\") or \
  567. \009\009\009\009path:getraw():find(\"rom/programs/fun\"))then nt = \"game\" end\
  568. \009\009\009if(path:getraw():find(\"CrossBow/programs\"))then nt = \"executable\" end\
  569. \009\009\009if(novautils.isFileImage(path:getraw() .. v))then nt = \"paint\" end\
  570. \009\009\009files[#files+1] = {n=v,t=nt}\
  571. \009\009end\
  572. \009end\
  573. \009-- Sort folders before files\
  574. \009for k,v in pairs(files) do \
  575. \009\009table.insert(folders, v) \
  576. \009end\
  577. \009files = folders\
  578. end\
  579. \
  580. --]] Draw program layout\
  581. function drawSideBar()\
  582. \009term.current().setVisible(false)\
  583. \009sbc(colors.white)\
  584. \009pa.drawFilledBox(0,4,17,h,colors.white)\
  585. \009sbc(1,1)\
  586. \009local loopam = #sideitems\
  587. \009if(#sideitems > h-5)then\
  588. \009\009loopam = (h-5)+sideoffs\
  589. \009end\
  590. \009for i = 1+sideoffs, loopam do\
  591. \009\009if(i-sideoffs < sidemax)then\
  592. \009\009\009if(sideitems[i] ~= nil)then\
  593. \009\009\009\009scp(1,(i-sideoffs)+4)\
  594. \009\009\009\009write(string.rep(\" \",16))\
  595. \009\009\009\009if(selectedside == i)then\
  596. \009\009\009\009\009sbc(colors.lightGray)\
  597. \009\009\009\009else\
  598. \009\009\009\009\009sbc(colors.white)\
  599. \009\009\009\009end\
  600. \009\009\009\009novautils.colorwrite(sideitems[i].n,12,1,(i-sideoffs)+4)\
  601. \009\009\009end\
  602. \009\009end\
  603. \009end\
  604. \009pa.drawBox(17,4,17,h,colors.gray)\
  605. \009pa.drawBox(1,h,17,h,colors.gray)\
  606. \009pa.drawBox(16,4,16,h-1,colors.lightGray)\
  607. \009stc(colors.gray)\
  608. \009ugapi.writexy(\"^\",16,4)\
  609. \009ugapi.writexy(\"v\",16,h-1)\
  610. \009term.current().setVisible(true)\
  611. end\
  612. -- Deprecidated\
  613. function drawFile(ind)\
  614. \009 -- Draw selected files\
  615. \009term.current().setVisible(false)\
  616. \009sbc(colors.white)\
  617. \009stc(colors.black)\
  618. \009drawFilePath()\
  619. \009  if(ind <= filemax)then\
  620. \009 \009    scp(19,ind+fileoffs)\
  621. \009\009\009write(string.rep(\" \",30))\
  622. \009\009\009novautils.colorwrite(icons[files[ind].t] .. \" &r\" .. files[ind].n ,12,19,ind,file_selected == ind)\
  623. \009\009\009scp(40,ind+fileoffs)\
  624. \009\009 if(not fs.isDir(path:getraw() .. files[ind].n))then\
  625. \009\009     \009write(tostring(fs.getSize(path:getraw() .. files[ind].n) / 1000):sub(1,4) .. \"KB\")\
  626. \009\009 end\
  627. \009  end\
  628. \009  term.current().setVisible(true)\
  629. end\
  630. function undrawFiles()\
  631. \009pa.drawFilledBox(18,4,w-1,h,colors.white)\
  632. end\
  633. function drawFilePath()\
  634. \009sbc(colors.white)\
  635. \009ugapi.writexy(string.rep(\" \",w-24),12,2)\
  636. \009sbc(colors.white)\
  637. \009stc(colors.black)\
  638. \009scp(13,2)\
  639. \009if(#path:getraw() > 25)then\
  640. \009\009local dif = #path:getraw() - 25\
  641. \009\009write(path:getraw():sub(dif,#path:getraw()))\
  642. \009else\
  643. \009\009write(path:getraw())\
  644. \009end\
  645. end\
  646. function drawFiles()\
  647. \009term.current().setVisible(false)\
  648. \009sbc(colors.white)\
  649. \009stc(colors.black)\
  650. \009drawFilePath()\
  651. \009 scp(23,4)\
  652. \009 stc(colors.lightGray)\
  653. \009 write(\"Name\")\
  654. \009 scp(40,4)\
  655. \009 write(\"Size\")\
  656. \009if(#files == 0)then\
  657. \009\009scp(25,5)\
  658. \009\009stc(colors.lightGray)\
  659. \009\009if(search ~= \"\")then\
  660. \009\009\009scp(20,5)\
  661. \009\009\009write(\"No items matched your search. \")\
  662. \009\009else\
  663. \009\009\009write(\"This folder is empty. \")\
  664. \009\009end\
  665. \009end\
  666. \009local loopam = #files\
  667. \009if(#files > h-4)then\
  668. \009\009loopam = (h-4)+fileoffs\
  669. \009end\
  670. \009 for i = 1+fileoffs, loopam do\
  671. \009 \009  if(i-fileoffs <= filemax)then\
  672. \009 \009  \009if(files[i].n ~= nil)then\
  673. \009 \009  \009 scp(19,(i-fileoffs)+4)\
  674. \009\009\009 write(string.rep(\" \",30))\
  675. \009\009\009 local namecolor = \" &r\"\
  676. \009\009\009 local drawname = files[i].n\
  677. \009\009\009 if(path:getraw() .. files[i].n == clipboard.path and clipboard.type == \"cut\")then\
  678. \009\009\009  \009namecolor = \" &7\"\
  679. \009\009\009end\
  680. \009\009\009 if(isPinnedItem(path:getraw() .. files[i].n))then \
  681. \009\009\009 \009 namecolor = \" &b\"\
  682. \009\009\009 \009if(path:getraw() .. files[i].n == clipboard.path and clipboard.type == \"cut\")then\
  683. \009\009\009 \009 \009namecolor = \" &e\"\
  684. \009\009\009 \009end\
  685. \009\009\009 end\
  686. \009\009\009 local selected = (file_selected == i)\
  687. \009\009\009 if(multiselecting)then\
  688. \009\009\009 \009for s = 1, #files_selected do\
  689. \009\009\009 \009\009if(files_selected[s].n == files[i].n and \
  690. \009\009\009 \009\009\009path:getraw() == files_selected[s].p)then\
  691. \009\009\009 \009\009\009if(clipboard.type == \"cut\")then\
  692. \009\009\009 \009\009\009\009namecolor = \" &7\"\
  693. \009\009\009 \009\009\009\009if(isPinnedItem(path:getraw() .. files[i].n))then \
  694. \009\009\009 \009\009\009\009\009namecolor = \" &e\"\
  695. \009\009\009 \009\009\009\009end\
  696. \009\009\009 \009\009\009end\
  697. \009\009\009 \009\009\009selected = true\
  698. \009\009\009 \009\009end\
  699. \009\009\009 \009end\
  700. \009\009\009 end\
  701. \009\009\009 local bcol = colors.white\
  702. \009\009\009 if(selected)then bcol = colors.lightBlue end\
  703. \009\009\009 novautils.colorwrite(icons[files[i].t] .. namecolor .. drawname ..\"&r\",12,19,(i-fileoffs)+4,bcol)\
  704. \009\009\009 scp(40,(i-fileoffs)+4)\
  705. \009\009\009 if(not fs.isDir(path:getraw() .. files[i].n))then\
  706. \009\009\009 \009write(tostring(fs.getSize(path:getraw() .. files[i].n) / 1000):sub(1,4) .. \"KB\")\
  707. \009\009\009 end\
  708. \009 \009  end\
  709. \009 \009 end\
  710. \009 end \
  711. \009 term.current().setVisible(true)\
  712. end\
  713. function renameFile(path,name,nname)\
  714. \009local odir = shell.dir()\
  715. \009shell.setDir(\"\")\
  716. \009if(not fs.exists(path .. nname) and nname ~= \"\" and not nname:find(\" \"))then\
  717. \009\009if(nname:sub(1,4) == \"disk\" and fs.isDir(path .. name))then\
  718. \009\009\009shell.setDir(odir)\
  719. \009\009\009novautils.notify(\"Rename Error.\",\"Cannot rename directory to * disk!\",novaex_redraw)\
  720. \009\009\009return false\
  721. \009\009end\
  722. \009\009fs.move(path .. name, path .. nname)\
  723. \009\009getfiles()\
  724. \009elseif(nname ~= \"\" and not nname:find(\" \"))then\
  725. \009\009novautils.notify(\"Couldn't rename file.\",\"File with name:  * \".. nname .. \", already exists.\",novaex_redraw)\
  726. \009end\
  727. \009drawFiles()\
  728. \009shell.setDir(odir)\
  729. end\
  730. function runFile(fpath,args,noclick)\
  731. \009local odir = shell.dir()\
  732. \009sbc(colors.black)\
  733. \009stc(colors.white)\
  734. \009clr()\
  735. \009scp(1,1)\
  736. \009shell.setDir(\"\")\
  737. \009if(novautils.isFileImage(fpath))then \
  738. \009\009args = fpath\
  739. \009\009fpath = \"paint\"\
  740. \009\009noclick = true\
  741. \009end\
  742. \009if(shell.resolveProgram(fpath))then\
  743. \009\009if(fs.exists(shell.resolveProgram(fpath)))then \
  744. \009\009\009shell.run(fpath,args)\
  745. \009\009\009if(not noclick)then\
  746. \009\009\009\009ugapi.writecy(\"Click any where to return to NovaBrowse. \",9)\
  747. \009\009\009\009os.pullEvent(\"mouse_click\")\
  748. \009\009\009end\
  749. \009\009else\
  750. \009\009\009novautils.notify(\"Open file.\", \"&4File not found. \",novaex_redraw)\
  751. \009\009end\
  752. \009end\
  753. \009shell.setDir(odir)\
  754. \009drawMain()\
  755. \009getfiles()\
  756. \009drawFiles()\
  757. end\
  758. function setDir(name)\
  759. \009if(fs.isDir(name))then\
  760. \009\009clearSearch()\
  761. \009\009file_selected = 0\
  762. \009\009if(name:sub(#name,#name) ~= \"/\")then name = name .. \"/\" end\
  763. \009\009fileoffs = 0\
  764. \009\009path:set(name)\
  765. \009\009getfiles()\
  766. \009\009undrawFiles()\
  767. \009\009drawFiles()\
  768. \009\009return true\
  769. \009else\
  770. \009\009drawFilePath()\
  771. \009\009return false\
  772. \009end\
  773. end\
  774. function addDir(name)\
  775. \009selectedside = 0\
  776. \009drawSideBar() \
  777. \009clearSearch()\
  778. \009file_selected = 0\
  779. \009fileoffs = 0\
  780. \009path:add(name)\
  781. \009getfiles()\
  782. \009undrawFiles()\
  783. \009drawFiles()\
  784. end\
  785. function clearSearch()\
  786. \009search = \"\"\
  787. \009scp(40,2)\
  788. \009sbc(colors.lightGray)\
  789. \009write(string.rep(\" \",11))\
  790. end\
  791. function searchDir(val)\
  792. \009file_selected = 0\
  793. \009fileoffs = 0\
  794. \009local nfiles = {}\
  795. \009undrawFiles()\
  796. \009if(val == \"\" or val == \" \")then\
  797. \009\009getfiles()\
  798. \009else\
  799. \009\009for i = 1, #files do\
  800. \009\009\009if(files[i].n:find(val))then\
  801. \009\009\009\009nfiles[#nfiles+1] = files[i]\
  802. \009\009\009end\
  803. \009\009end\
  804. \009\009files = nfiles\
  805. \009end\
  806. \009drawFiles()\
  807. end\
  808. function openHref(href)\
  809. if(fs.isDir(href))then\
  810. \009setDir(href)\
  811. elseif(fs.exists(href))then\
  812. \009return runFile(href)\
  813. end\
  814. end\
  815. function editfile(filepath)\
  816. \009runFile(\"edit\",filepath,true)\
  817. end\
  818. function pasteMultiFile(to)\
  819. \009if(multiselecting)then\
  820. \009\009for i = 1, #files_selected do\
  821. \009\009\009clipboard.path = files_selected[i].p .. files_selected[i].n\
  822. \009\009\009clipboard.name = files_selected[i].n\
  823. \009\009\009pasteFile(to)\
  824. \009\009end\
  825. \009end\
  826. end\
  827. function pasteFile(to)\
  828. \009local odir = shell.dir()\
  829. \009if(fs.isReadOnly(to))then\
  830. \009\009novautils.notify(\"Paste file \", \"Access Denied. \",novaex_redraw)\
  831. \009\009return\
  832. \009end\
  833. \009if(not fs.exists(to .. clipboard.name))then\
  834. \009\009fs.copy(clipboard.path,path:getraw() .. clipboard.name)\
  835. \009\009if(clipboard.type == \"cut\")then fs.delete(clipboard.path) clipboard = {} end\
  836. \009\009getfiles()\
  837. \009\009drawFiles()\
  838. \009else\
  839. \009\009if(to .. clipboard.name == clipboard.path)then\
  840. \009\009\009clipboard = {}\
  841. \009\009\009drawFiles()\
  842. \009\009\009return\
  843. \009\009end\
  844. \009\009local ans = novautils.openYesNo(\"File transfer\",\"File exists, Rename file? \",novaex_redraw)\
  845. \009\009if(ans == 1)then\
  846. \009\009\009local newname = novautils.openReadDialog(\"Rename paste file. \",novaex_redraw,clipboard.name)\
  847. \009\009\009if(newname:find(\" \"))then\
  848. \009\009\009\009novautils.notify(\"File rename \", \"Invalid file name. \",novaex_redraw)\
  849. \009\009\009else\
  850. \009\009\009\009clipboard.name = newname\
  851. \009\009\009end\
  852. \009\009\009return pasteFile(to)\
  853. \009\009end\
  854. \009end\
  855. \
  856. \009shell.setDir(odir)\
  857. end\
  858. function prevDir(ind) \
  859. \009selectedside = 0 \
  860. \009drawSideBar()\
  861. \009scp(2,2)\
  862. \009sbc(colors.gray)\
  863. \009stc(colors.black)\
  864. \009write(\"<-\")\
  865. \009sleep(0.1)\
  866. \009scp(2,2)\
  867. \009sbc(colors.lightGray)\
  868. \009stc(colors.gray)\
  869. \009write(\"<-\")\
  870. \009clearSearch()\
  871. \009file_selected = 0\
  872. \009fileoffs = 0\
  873. \009path:goback(ind)\
  874. \009getfiles()\
  875. \009undrawFiles()\
  876. \009drawFiles()\009\
  877. end\
  878. function refreshDir()\
  879. \009scp(6,2)\
  880. \009sbc(colors.gray)\
  881. \009stc(colors.black)\
  882. \009write(\"<>\")\
  883. \009sleep(0.1)\
  884. \009scp(6,2)\
  885. \009sbc(colors.lightGray)\
  886. \009stc(colors.gray)\
  887. \009write(\"<>\")\
  888. \009clearSearch()\
  889. \009file_selected = 0\
  890. \009fileoffs = 0\
  891. \009drawMain()\
  892. \009getConfigPinnedItems()\
  893. \009getPinnedNames()\
  894. \009drawSideBar()\
  895. \009getfiles()\
  896. \009drawFiles()\
  897. \009checkUpdate()\
  898. end\
  899. function drawfilemenu(menu,sx,sy)\
  900. \009local finalmenu = {}\
  901. \009for i = 1, #menu do\
  902. \009\009if(menu[i].relies == nil)then\
  903. \009\009\009finalmenu[#finalmenu+1] = menu[i]\
  904. \009\009elseif(menu[i].relies(files[file_selected],pinnednames))then\
  905. \009\009\009finalmenu[#finalmenu+1] = menu[i]\
  906. \009\009end\
  907. \009end\
  908. \009if(sy+#finalmenu > h)then\
  909. \009\009sy = sy - ((sy+#finalmenu)-h)\
  910. \009end\
  911. \009if(sx+#finalmenu[1].n >= w-1)then\
  912. \009\009sx = sx - ((sx+#finalmenu[1].n)-(w-1))\
  913. \009end\
  914. \009pa.drawBox(sx,sy+2,sx+#finalmenu[1].n,sy+#finalmenu+1,colors.black)\
  915. \009for i = 1, #finalmenu do\
  916. \009\009if(sy+i <= h)then\
  917. \009\009\009scp(sx-1,sy+i)\
  918. \009\009\009sbc(colors.lightGray)\
  919. \009\009\009stc(colors.white)\
  920. \009\009\009write(string.rep(\" \",#finalmenu[i].n+1))\
  921. \009\009\009scp(sx,sy+i)\
  922. \009\009\009write(finalmenu[i].n)\
  923. \009\009end\
  924. \009end\
  925. \009return finalmenu, sx, sy\
  926. end\
  927. function drawMenuClick(mop)\
  928. \009local _, dny = term.getCursorPos()\
  929. \009local dnx = inmenux+1\
  930. \009sbc(colors.gray)\
  931. \009stc(colors.black)\
  932. \009write(mop.n)\
  933. \009sleep(0.2)\
  934. \009scp(dnx,dny)\
  935. \009sbc(colors.lightGray)\
  936. \009stc(colors.white)\
  937. \009write(mop.n)\
  938. end\
  939. function updatemenu(e,menu,sx,sy,clrfunc)\
  940. \009if(e[1] == \"mouse_click\")then\
  941. \009\009local x, y = e[3], e[4]\
  942. \009\009local mlen = #menu[1].n-1\
  943. \009\009if(x >= sx and x <= sx+mlen and y >= sy+1 and y <= sy+#menu)then\
  944. \009\009\009 local clicked = menu[(y-sy)]\
  945. \009\009\009 scp(sx,y)\
  946. \009\009\009 drawMenuClick(clicked)\
  947. \009\009\009 clrfunc()\
  948. \009\009\009 e[1] = nil\
  949. \009\009\009 inmenu = false\
  950. \009\009\009 return clicked.func(files[file_selected])\
  951. \009\009else\
  952. \009\009\009clrfunc()\
  953. \009\009\009inmenu = false\
  954. \009\009end\
  955. \009end\
  956. end\
  957. function opencloseMenu(type,x,y,yind)\
  958. \009if(inmenu)then\
  959. \009\009undrawFiles()\
  960. \009\009drawFiles()\
  961. \009\009drawSideBar()\
  962. \009\009inmenu = false\
  963. \009elseif(type==\"reg\")then\
  964. \009\009local mtodraw = filemenu\
  965. \009\009if(fs.isDir(path:getraw() .. files[file_selected].n))then\
  966. \009\009\009mtodraw = foldermenu\
  967. \009\009end\
  968. \009\009drawingmenu = mtodraw\
  969. \009\009inmenutype, inmenux, inmenuy = drawfilemenu(mtodraw,x,y)\
  970. \009\009inmenu = true\
  971. \009elseif(type==\"sidebar\")then\
  972. \009\009drawingmenu = sidemenu\
  973. \009\009inmenutype, _, inmenuy = drawfilemenu(sidemenu,5,y)\
  974. \009\009inmenux = 5\
  975. \009\009inmenu = true\
  976. \009elseif(type==\"new\" and not fs.isReadOnly(path:getraw()) )then\
  977. \009\009drawingmenu = emptymenu\
  978. \009\009inmenutype,inmenux,inmenuy = drawfilemenu(emptymenu,x,y)\
  979. \009\009inmenu = true\
  980. \009end\
  981. end\
  982. local function update(e)\
  983. \009if(inmenu)then\
  984. \009\009updatemenu(e,inmenutype,inmenux,inmenuy,novaex_redraw)\
  985. \009end\
  986. \009if(e[1] == \"disk\")then\
  987. \009\009getfiles()\
  988. \009\009drawFiles()\
  989. \009\009diskside = e[2]\
  990. \009\009if(fs.exists(\"disk/autorun\"))then\
  991. \009\009\009local ans = novautils.openYesNo(\"Disk detected \",\"A software disk has been * detected. \",novaex_redraw,\"Run\",\"Cancel\")\
  992. \009\009\009if(ans == 1)then\
  993. \009\009\009\009runFile(\"disk/autorun\")\
  994. \009\009\009end\
  995. \009\009elseif(disk.hasAudio(e[2]))then\
  996. \009\009\009local ans = novautils.openYesNo(\"Music detected \",\"A music disk has been * inserted. \",novaex_redraw,\"Play\",\"Cancel\")\
  997. \009\009\009if(ans == 1)then\
  998. \009\009\009\009disk.playAudio(e[2])\
  999. \009\009\009end\
  1000. \009\009else\
  1001. \009\009\009local ans = novautils.openYesNo(\"Disk detected \",\"A floppy disk has been * inserted. \",novaex_redraw,\"Open\",\"Cancel\")\
  1002. \009\009\009if(ans == 1)then\
  1003. \009\009\009\009setDir(\"disk/\")\
  1004. \009\009\009end\
  1005. \009\009end\
  1006. \009elseif(e[1] == \"disk_eject\")then\
  1007. \009\009if(path:getraw():find(\"disk/\"))then\
  1008. \009\009\009path:set(\"/\")\
  1009. \009\009end\
  1010. \009\009undrawFiles()\
  1011. \009\009getfiles()\
  1012. \009\009drawFiles()\
  1013. \009end\
  1014. \009if(e[1] == \"paste\")then\
  1015. \009\009if(clipboard.name ~= nil)then\
  1016. \009\009\009if(multiselecting)then\
  1017. \009\009\009\009pasteMultiFile(path:getraw())\
  1018. \009\009\009else\
  1019. \009\009\009\009pasteFile(path:getraw())\
  1020. \009\009\009end\
  1021. \009\009end\
  1022. \009end\
  1023. \009if(e[1] == \"key\")then\
  1024. \009\009local key = e[2] \
  1025. \009\009if(key == actionkey and not actionkeydown)then\
  1026. \009\009\009actionkeydown = true\
  1027. \009\009elseif(actionkeydown)then\
  1028. \009\009\009local opper = \"copy\"\
  1029. \009\009\009if(key == keys.c or key == keys.x)then\
  1030. \009\009\009\009if(key == keys.x)then opper = \"cut\" end\
  1031. \009\009\009\009if(file_selected ~= 0)then\
  1032. \009\009\009\009\009setClipboard(path:getraw() .. files[file_selected].n, \
  1033. \009\009\009\009\009files[file_selected].n, opper)\
  1034. \009\009\009\009end\
  1035. \009\009\009end\
  1036. \009\009end\
  1037. \009\009if(file_selected > 0)then\
  1038. \009\009\009if(key == keys.delete)then\
  1039. \009\009 \009\009local ans = novautils.openYesNo(\"File deletion. \",\"Confirm &4deletion&r of *\" .. files[file_selected].n,novaex_redraw)\
  1040. \009\009 \009\009if(ans == 1)then\
  1041. \009\009 \009\009\009deleteFile(path:getraw() .. files[file_selected].n)\
  1042. \009\009 \009\009end\
  1043. \009\009\009end\
  1044. \009\009end\
  1045. \009\009if(selectedside > 0)then\
  1046. \009\009\009if(key == keys.up and sideitems[selectedside-1].t ~= nil and  \
  1047. \009 \009\009   sideitems[selectedside-1].t ~= \"text\" )then\
  1048. \009\009\009\009moveSideItem(selectedside,-1)\
  1049. \009\009\009elseif(key == keys.down and (selectedside < #sideitems) and \
  1050. \009 \009\009   (sideitems[selectedside+1].n ~= nil) and \
  1051. \009 \009\009    sideitems[selectedside+1].t ~= \"text\" )then\
  1052. \009\009\009\009moveSideItem(selectedside,1)\
  1053. \009\009\009end\
  1054. \009\009end\
  1055. \009elseif(e[1] == \"key_up\")then\
  1056. \009\009\009local key = e[2] \
  1057. \009\009if(key == actionkey and actionkeydown )then\
  1058. \009\009\009actionkeydown = false\
  1059. \009\009end\
  1060. \009end\
  1061. \009if(e[1] == \"mouse_click\")then\
  1062. \009\009 local x,y = e[3], e[4]    \
  1063. \009\009 -- Left clicked\
  1064. \009\009if(e[2] == 1)then\
  1065. \009\009\009if(x == w and y == 1)then\
  1066. \009\009\009\009clickExit()\
  1067. \009\009\009\009innova = false\
  1068. \009\009\009\009sbc(colors.white)\
  1069. \009\009\009\009clr()\
  1070. \009\009\009\009stc(colors.gray)\
  1071. \009\009\009\009ugapi.writecy(\"Thank you for using Nova Explore. \",9)\
  1072. \009\009\009\009ugapi.writecy(\"Click the screen to exit. \",10)\
  1073. \009\009\009\009os.pullEvent(\"mouse_click\")\
  1074. \009\009\009\009sbc(colors.black)\
  1075. \009\009\009\009clr()\
  1076. \009\009\009\009stc(colors.white)\
  1077. \009\009\009\009scp(1,1)\
  1078. \009\009\009\009return \
  1079. \009\009\009end\
  1080. \009\009 \009if(x >= 38 and x <= 51 and y == 2)then\
  1081. \009\009 \009\009novaio.setInput(search)\
  1082. \009\009 \009\009searching = true\
  1083. \009\009 \009elseif(searching)then\
  1084. \009\009 \009\009search = novaio.getInput()\
  1085. \009\009 \009\009searching = false\
  1086. \009\009 \009end\
  1087. \009\009 \009if(x >= 2 and x <= 4 and y == 2)then\
  1088. \009\009 \009\009if(inmenu)then inmenu = false end\
  1089. \009\009 \009\009prevDir(1)\
  1090. \009\009 \009end\
  1091. \009\009 \009if(x >= 6 and x <= 8 and y == 2)then\
  1092. \009\009 \009\009refreshDir()\
  1093. \009\009 \009end\
  1094. \009\009end \
  1095. \009\009-- Left or right clicked\
  1096. \009\009 \009local yind = (y+fileoffs)-4\
  1097. \009\009 \009local syind = (y+sideoffs)-4\
  1098. \009\009 \009if(x < 18 and syind <= #sideitems and syind > 0)then\
  1099. \009\009\009 \009 if(y > 4 and x >= 1 and x <= #(sideitems[syind].n:sub(1,14)) )then\
  1100. \009\009\009 \009   if(e[2] == 1 and not inmenu)then\
  1101. \009\009\009\009 \009 \009if(fs.isDir(sideitems[syind].href) and sideitems[syind].t ~= \"text\")then\
  1102. \009\009\009\009 \009 \009    selectedside = syind\
  1103. \009\009\009\009 \009 \009  \009openHref(sideitems[syind].href)\
  1104. \009\009\009\009 \009 \009  \009drawSideBar()\
  1105. \009\009\009\009 \009 \009elseif(sideitems[syind].t ~= \"text\")then\
  1106. \009\009\009\009 \009 \009  \009if(selectedside == syind)then\
  1107. \009\009\009\009 \009 \009  \009 \009openHref(sideitems[syind].href)\
  1108. \009\009\009\009 \009 \009  \009else\
  1109. \009\009\009\009 \009 \009  \009    selectedside = syind\
  1110. \009\009\009\009 \009 \009  \009 \009drawSideBar()\
  1111. \009\009\009\009 \009 \009  \009end\
  1112. \009\009\009\009 \009 \009end\
  1113. \009\009\009\009   elseif(e[2] == 2)then\
  1114. \009\009\009\009   \009\009if(selectedside ~= 0)then\
  1115. \009\009\009\009 \009 \009\009opencloseMenu(\"sidebar\",x,y)\009\
  1116. \009\009\009\009 \009 \009end\
  1117. \009\009\009 \009   end\
  1118. \009\009\009 \009 end\
  1119. \009\009\009 elseif(yind <= #files and yind > 0)then\
  1120. \009\009 \009 \009if(y > 4 and x >= 18 and x <= 22+#files[yind].n)then\
  1121. \009\009 \009 \009   if(e[2] == 1 and not inmenu)then\
  1122. \009\009\009 \009 \009  if(file_selected == yind)then\
  1123. \009\009\009\009 \009 \009  \009if(fs.isDir(path:getraw() .. files[file_selected].n))then\
  1124. \009\009\009\009 \009 \009  \009\009if(inmenu)then inmenu = false end\
  1125. \009\009\009\009 \009 \009  \009 \009addDir(files[yind].n)\
  1126. \009\009\009\009 \009 \009  \009 else\
  1127. \009\009\009\009 \009 \009  \009 \009runFile(path:getraw() .. files[file_selected].n)\
  1128. \009\009\009\009 \009 \009  \009end\
  1129. \009\009\009\009 \009 \009  else\
  1130. \009\009\009\009 \009 \009  \009 file_selected = yind\
  1131. \009\009\009\009 \009 \009  \009 drawFiles()\
  1132. \009\009\009\009 \009 \009  end\
  1133. \009\009\009 \009   elseif(e[2] == 2 )then\
  1134. \009\009\009 \009   \009   if(file_selected == yind)then\
  1135. \009\009\009 \009   \009   \009\009opencloseMenu(\"reg\",x,y,yind)\
  1136. \009\009\009 \009   \009   else\
  1137. \009\009\009 \009   \009   \009\009opencloseMenu(\"new\",x,y,yind)\
  1138. \009\009\009\009\009   end\
  1139. \009\009\009\009end\
  1140. \009\009 end\
  1141. \009\009end\
  1142. \009\009if(e[2] == 2 and not inmenu and x > 18)then\
  1143. \009\009 \009opencloseMenu(\"new\",x,y,1)\
  1144. \009\009end\
  1145. \009end\
  1146. \009if(e[1] == \"mouse_scroll\")then\
  1147. \009\009local dir = e[2]\
  1148. \009\009local x,y = e[3], e[4]\
  1149. \009\009if(dir == -1)then\
  1150. \009\009\009if(x > 16 and fileoffs > 0 )then\
  1151. \009\009\009\009fileoffs = fileoffs - 1\
  1152. \009\009\009\009drawFiles()\
  1153. \009\009\009elseif(x <= 16 and sideoffs > 0)then\
  1154. \009\009\009\009sideoffs = sideoffs - 1\
  1155. \009\009\009\009drawSideBar()\
  1156. \009\009\009end\
  1157. \009\009elseif(dir == 1)then\
  1158. \009\009\009if(x > 16 and fileoffs < #files-(filemax-4))then\
  1159. \009\009\009\009fileoffs = fileoffs + 1\
  1160. \009\009\009\009drawFiles()\
  1161. \009\009\009elseif(x <= 16 and sideoffs < #sideitems-(sidemax-4))then\
  1162. \009\009\009\009sideoffs = sideoffs + 1\
  1163. \009\009\009\009drawSideBar()\
  1164. \009\009\009end\
  1165. \009\009end\
  1166. \009end\
  1167. \009if(novaio.getActive() == false and not searching)then\
  1168. \009\009if(novaio.getInput() ~= path:getraw())then\
  1169. \009\009\009novaio.setInput(path:getraw())\
  1170. \009\009end\
  1171. \009end\
  1172. \
  1173. \009if(not searching)then\
  1174. \009\009stc(colors.black)\
  1175. \009\009sbc(colors.white)\
  1176. \009\009local doneinp = novaio.read(e,1000,25,13,2)\
  1177. \009\009if(doneinp)then\
  1178. \009    \009novaio.setActive(false)\
  1179. \009\009\009if( setDir(novaio.getInput()) )then\
  1180. \009\009\009\009selectedside = 0\
  1181. \009\009\009\009drawSideBar()\
  1182. \009\009\009end\
  1183. \009\009\009novaio.setInput(\"\")\
  1184. \009\009end\
  1185. \009else\
  1186. \009\009stc(colors.black)\
  1187. \009\009sbc(colors.lightGray)\
  1188. \009\009local doneinp = novaio.read(e,1000,10,40,2)\
  1189. \009\009if(doneinp)then\
  1190. \009\009\009searching = false\
  1191. \009    \009novaio.setActive(false)\
  1192. \009    \009search = novaio.getInput()\
  1193. \009\009\009searchDir(novaio.getInput()) \
  1194. \009\009\009novaio.setInput(\"\")\
  1195. \009\009end\
  1196. \009end\
  1197. end\
  1198. function displayError(err)\
  1199. \009sbc(colors.white)\
  1200. \009clr()\
  1201. \009stc(colors.gray)\
  1202. \009ugapi.writecy(\" Well, thats not supposed to happen. \",1)\
  1203. \009scp(2,3)\
  1204. \009stc(colors.lightGray)\
  1205. \009write(err)\
  1206. \009ugapi.writecy(\" Why you do dis to me :(. \",16)\
  1207. \009stc(colors.black)\
  1208. \009ugapi.writecy(\" Press any key to end NovaExplore. \",17)\
  1209. \009ugapi.writecy(\"  Click to restart NovaExplore. \",18)\
  1210. \009local e = {os.pullEvent()}\
  1211. \009if(e[1] == \"key\")then \
  1212. \009\009sbc(colors.black)\
  1213. \009\009clr()\
  1214. \009\009stc(colors.white)\
  1215. \009\009scp(1,1)\
  1216. \009elseif(e[1] == \"mouse_click\")then\
  1217. \009\009local odir = shell.dir()\
  1218. \009\009shell.setDir(\"\")\
  1219. \009\009shell.run(shell.getRunningProgram())\
  1220. \009\009shell.setDir(odir)\
  1221. \009end\
  1222. end\
  1223. function clickExit()\
  1224. \009scp(w,1)\
  1225. \009stc(colors.black)\
  1226. \009sbc(colors.pink)\
  1227. \009write(\"X\")\
  1228. \009sleep(0.2)\
  1229. \009scp(w,1)\
  1230. \009stc(colors.white)\
  1231. \009sbc(colors.red)\
  1232. \009write(\"X\")\
  1233. end\
  1234. function checkUpdate()\
  1235. \009if(http)then\
  1236. \009\009local upd = http.get(\"http://pastebin.com/raw/rpipr5pT\")\
  1237. \009\009if(upd ~= nil)then\
  1238. \009\009\009local cont = upd.readAll()\
  1239. \009\009\009local f = fs.open(shell.getRunningProgram(),\"r\")\
  1240. \009\009\009local pcont = f.readAll()\
  1241. \009\009\009f.close()\
  1242. \009\009\009if(cont ~= pcont)then\
  1243. \009\009\009\009local ans = novautils.openYesNo(\"Auto update\", \"Update detected, would you * like to update?.\",novaex_redraw)\
  1244. \009\009\009\009if(ans == 1)then\
  1245. \009\009\009\009\009local f = fs.open(shell.getRunningProgram(),\"w\")\
  1246. \009\009\009\009\009f.write(cont)\
  1247. \009\009\009\009\009f.close()\
  1248. \009\009\009\009\009novautils.notify(\"Auto update\", \"Updated, restart required.\",novaex_redraw)\
  1249. \009\009\009\009\009innova = false\
  1250. \009\009\009\009\009return shell.run(shell.resolveProgram(shell.getRunningProgram()))\
  1251. \009\009\009\009end\
  1252. \009\009\009end\
  1253. \009\009else\
  1254. \009\009\009novautils.notify(\"Auto update\", \"Failed to connect to pastebin.\",novaex_redraw)\
  1255. \009\009end\
  1256. \009else\
  1257. \009\009novautils.notify(\"Auto update\", \"Http is disabled, Failed to * check for updates.\",novaex_redraw)\
  1258. \009\009return\
  1259. \009end\
  1260. end\
  1261. function drawMain()\
  1262. \009sbc(colors.white)\
  1263. \009clr()\
  1264. \009scp(1,2)\
  1265. \009sbc(colors.lightGray)\
  1266. \009clrln()\
  1267. \009pa.drawBox(w-12,1,w,3,colors.gray)\
  1268. \009sbc(colors.white)\
  1269. \009ugapi.writexy(string.rep(\" \",w-12),1,2)\
  1270. \009pa.drawBox(10,1,w-12,3,colors.gray)\
  1271. \009drawSideBar()\
  1272. \009pa.drawFilledBox(1,1,9,3,colors.lightGray)\
  1273. \009scp(2,2)\
  1274. \009stc(colors.gray)\
  1275. \009write(\"<-  <>\")\
  1276. \009--pa.drawBox(15,h,w,h,colors.lightGray)\
  1277. \009pa.drawBox(w,4,w,h,colors.lightGray)\
  1278. \009stc(colors.gray)\
  1279. \009ugapi.writexy(\"^\",w,4)\
  1280. \009ugapi.writexy(\"v\",w,h)\
  1281. \009scp(w,1)\
  1282. \009stc(colors.white)\
  1283. \009sbc(colors.red)\
  1284. \009write(\"X\")\
  1285. \009sbc(colors.black)\
  1286. end\
  1287. drawMain()\
  1288. getConfigPinnedItems()\
  1289. getPinnedNames()\
  1290. drawSideBar()\
  1291. getfiles()\
  1292. drawFiles()\
  1293. checkUpdate()\
  1294. \
  1295. local function loop()\
  1296. \009while innova do \
  1297. \009\009local e = {os.pullEvent()}\
  1298. \009\009update(e)\
  1299. \009end\
  1300. end\
  1301. local ok, err = pcall(loop)\
  1302. if(not ok)then\
  1303. \009if(term.current().setVisible)then\
  1304. \009\009term.current().setVisible(true)\
  1305. \009end\
  1306. \009displayError(err)\
  1307. end",
  1308.   },
  1309.   [ "apis/fpath/" ] = {
  1310.     content = "local function path_goback(path,amm)\
  1311.    pathtbl={}\
  1312.    s=\"\"\
  1313.    pathsize=0\
  1314.    -- Divide string and count the number of \
  1315.    -- divisions.\
  1316.     for str in string.gmatch(path, \"([^/]+)\") do\
  1317.         pathtbl[#pathtbl+1] = str  \
  1318.     end\
  1319.     for k, v in pairs(pathtbl) do\
  1320.         pathsize=k\
  1321.     end\
  1322.     pathsize = pathsize - amm\
  1323.    -- Based on how large the user wants the string to be \
  1324.    -- add only the string bits that led up to the user defined\
  1325.    -- size.\
  1326.    for k, v in pairs(pathtbl) do\
  1327.        if(k <= pathsize)then s = s..pathtbl[k]..\"/\" end\
  1328.    end\
  1329.    return s\
  1330. end\
  1331. local function path_getsize(path)\
  1332.    pathtbl={}\
  1333.    pathsize=0\
  1334.    -- Divide string and count the number of \
  1335.    -- divisions.\
  1336.     for str in string.gmatch(path, \"([^/]+)\") do\
  1337.         pathtbl[#pathtbl+1] = str  \
  1338.     end\
  1339.     for k, v in pairs(pathtbl) do\
  1340.         pathsize=k\
  1341.     end\
  1342.     return pathsize\
  1343. end\
  1344. \
  1345. function newpath(name,stuckindex)\
  1346.    if(name == nil or type(name) ~= \"string\")then error(\"PathAPI: Name must be provided for new paths. \") end\
  1347.    if(string.sub(name,#name,#name) ~= \"/\")then\
  1348.        name = name .. \"/\"\
  1349.    end\
  1350.    if(type(stuckindex) ~= \"number\")then stuckindex = 0 end\
  1351.    local pathobj = {\
  1352.        path = name,\
  1353.        stuckind = stuckindex,\
  1354.        getsize = function(self)\
  1355.           return path_getsize(self.path)\
  1356.        end,\
  1357.        goback = function(self,amm)\
  1358.            if(self:getsize() - amm >= self.stuckind)then\
  1359.               self.path = path_goback(self.path,amm)\
  1360.               return self.path\
  1361.            else\
  1362.                return false\
  1363.            end\
  1364.        end,\
  1365.        getraw = function(self)\
  1366.            return self.path\
  1367.        end,\
  1368.        add = function(self,new)\
  1369.            self.path = self.path .. new .. \"/\"\
  1370.            return self.path\
  1371.        end,\
  1372.        set = function(self,npath)\
  1373.            self.path = npath\
  1374.            return self.path\
  1375.        end,\
  1376.        lockpath = function(self)\
  1377.            self.stuckind = self:getsize()\
  1378.        end,\
  1379.        unlockpath = function(self)\
  1380.            self.stuckind = 0\
  1381.        end,\
  1382.    }\
  1383.    return pathobj\
  1384. end",
  1385.   },
  1386.   [ "programs/novazip/" ] = {
  1387.     content = "--====================================================\
  1388. --]] Nova Zip and all file apis created by\
  1389. --]] Lewisk3 CEO of Nova, all rights reservered \
  1390. --]] DO NOT REDISTRIBUTE without the permission \
  1391. --]] of Nova, Editing and/or \"rebranding\" is prohibited.\
  1392. --]] Any copys found outside the permission of Nova\
  1393. --]] will be taken and money will be due to the rights\
  1394. --]] of Nova Technologys\
  1395. -------------------------------------------------------\
  1396. --=]      We have the rights to all the above       [=-       \
  1397. --=====================================================\
  1398. --]] Determine OS and load apis accordingly \
  1399. local args = { ... }\
  1400. if(#args < 1)then error(\"Ussage: novazip <zipfile>\") end\
  1401. local w, h = term.getSize()\
  1402. local sbc = term.setBackgroundColor\
  1403. local stc = term.setTextColor\
  1404. local scp = term.setCursorPos\
  1405. local clr = term.clear\
  1406. local clrln = term.clearLine\
  1407. local pa = paintutils\
  1408. local offs = 0\
  1409. local zip = args[1]\
  1410. local files = {}\
  1411. local selected = 0\
  1412. local inmenu = false\
  1413. local inmenutype = {}\
  1414. local drawingmenu = {}\
  1415. local inmenux, inmenuy = 1, 4\
  1416. local apis = {'ugapi','fpath','futils','novaio','ziputils','novautils'}\
  1417. local innovazip = true\
  1418. \
  1419. local function init()\
  1420. \009if(fs.isDir(\"CrossBow/apis\"))then\
  1421. \009\009iscrossbow = true\
  1422. \009\009for i = 1, #apis do\
  1423. \009\009\009\009if(fs.exists(\"CrossBow/apis/\"..apis[i]))then\
  1424. \009\009\009\009\009apis[i] = \"CrossBow/apis/\" ..apis[i]\
  1425. \
  1426. \009\009\009\009else\
  1427. \009\009\009\009\009error(\"Program had to Quit: CrossBow install outdated or malformed. \")\
  1428. \009\009\009\009end\
  1429. \009\009end \
  1430. \009end\
  1431. \009for i = 1, #apis do\
  1432. \009\009if(iscrossbow)then\
  1433. \009\009\009os.loadAPI((apis[i]))\
  1434. \009\009else\
  1435. \009\009\009os.loadAPI(shell.resolveProgram((apis[i])))\
  1436. \009\009end\
  1437. \009end\
  1438. end\
  1439. init()\
  1440. \
  1441. nz_menu = {\
  1442. \009{n=\"Open    \",func=function(file) end},\
  1443. \009{n=\"Edit    \",relies=function(file) return file.type ~= \"folder\" end,func=function(file) end},\
  1444. \009{n=\"Rename  \",func=function(file) end},\
  1445. \009{n=\"Delete  \",func=function(file) end},\
  1446. }\
  1447. \
  1448. nz_newmenu = {\
  1449. \009{n=\"New File \",func=function() end},\
  1450. \009{n=\"Add File \",func=function() end},\
  1451. \009{n=\"Extract  \",func=function() end},\
  1452. \009{n=\"Close    \",func=function() end},\009\
  1453. }\
  1454. \
  1455. function nz_opencloseMenu(type,x,y)\
  1456. \009if(inmenu)then\
  1457. \009\009nz_drawfiles(1)\
  1458. \009\009inmenu = false\
  1459. \009elseif(type==\"reg\")then\
  1460. \009\009local mtodraw = nz_menu\
  1461. \009\009drawingmenu = mtodraw\
  1462. \009\009inmenutype, inmenux, inmenuy = nz_drawmenu(drawingmenu,x,y)\
  1463. \009\009inmenu = true\
  1464. \009elseif(type==\"new\")then\
  1465. \009\009drawingmenu = nz_newmenu\
  1466. \009\009inmenutype,inmenux,inmenuy = nz_drawmenu(drawingmenu,x,y)\
  1467. \009\009inmenu = true\
  1468. \009end\
  1469. end\
  1470. function drawMenuClick(mop)\
  1471. \009local _, dny = term.getCursorPos()\
  1472. \009local dnx = inmenux+1\
  1473. \009sbc(colors.gray)\
  1474. \009stc(colors.black)\
  1475. \009write(mop.n)\
  1476. \009sleep(0.2)\
  1477. \009scp(dnx,dny)\
  1478. \009sbc(colors.lightGray)\
  1479. \009stc(colors.white)\
  1480. \009write(mop.n)\
  1481. end\
  1482. \
  1483. function nz_updatemenu(e,menu,sx,sy)\
  1484. \009if(e[1] == \"mouse_click\")then\
  1485. \009\009local x, y = e[3], e[4]\
  1486. \009\009local mlen = #menu[1].n-1\
  1487. \009\009if(x >= sx and x <= sx+mlen and y >= sy+1 and y <= sy+#menu and e[2] == 1)then\
  1488. \009\009\009 local clicked = menu[(y-sy)]\
  1489. \009\009\009 scp(sx,y)\
  1490. \009\009\009 novautils.drawMenuClick(clicked)\
  1491. \009\009\009 nz_drawfiles(1)\
  1492. \009\009\009 e[1] = nil\
  1493. \009\009\009 inmenu = false\
  1494. \009\009\009 return clicked.func(files[file_selected])\
  1495. \009\009else\
  1496. \009\009\009nz_drawfiles(1)\
  1497. \009\009\009inmenu = false\
  1498. \009\009end\
  1499. \009end\
  1500. end\
  1501. \
  1502. function nz_drawmenu(menu,sx,sy)\
  1503. \009local finalmenu = {}\
  1504. \009for i = 1, #menu do\
  1505. \009\009if(menu[i].relies == nil)then\
  1506. \009\009\009finalmenu[#finalmenu+1] = menu[i]\
  1507. \009\009elseif(menu[i].relies(files[selected],pinnednames))then\
  1508. \009\009\009finalmenu[#finalmenu+1] = menu[i]\
  1509. \009\009end\
  1510. \009end\
  1511. \009if(sy+#finalmenu > h-2)then\
  1512. \009\009sy = sy - ((sy+#finalmenu)-(h-2))\
  1513. \009end\
  1514. \009if(sx+#finalmenu[1].n >= w-1)then\
  1515. \009\009sx = sx - ((sx+#finalmenu[1].n)-(w-1))\
  1516. \009end\
  1517. \009pa.drawBox(sx,sy+2,sx+#finalmenu[1].n,sy+#finalmenu+1,colors.black)\
  1518. \009for i = 1, #finalmenu do\
  1519. \009\009if(sy+i <= h)then\
  1520. \009\009\009scp(sx-1,sy+i)\
  1521. \009\009\009sbc(colors.lightGray)\
  1522. \009\009\009stc(colors.white)\
  1523. \009\009\009write(string.rep(\" \",#finalmenu[i].n+1))\
  1524. \009\009\009scp(sx,sy+i)\
  1525. \009\009\009write(finalmenu[i].n)\
  1526. \009\009end\
  1527. \009end\
  1528. \009return finalmenu, sx, sy\
  1529. end\
  1530. \
  1531. function nz_openYesNo()\
  1532. \009local r = novautils.openYesNo()\
  1533. \009nz_getfiles()\
  1534. \009nz_drawmain()\
  1535. \009nz_drawfiles()\
  1536. \009return r\
  1537. end\
  1538. --- NovaZIP start --\
  1539. local path = fpath.newpath(\"\")\
  1540. function nz_formatzippath(path)\
  1541. \009if(path:sub(1,1) == \"/\")then\
  1542. \009\009return path:sub(2,#path)\
  1543. \009else\
  1544. \009\009return path\
  1545. \009end\
  1546. end\
  1547. function nz_getfiles()\
  1548. \009offs = 0\
  1549. \009files = {}\
  1550. \009files = ziputils.ziplist(shell.resolveProgram(zip),nz_formatzippath(path:getraw()))\
  1551. \009pa.drawFilledBox(2,8,w-1,h-1,colors.white)\
  1552. end\
  1553. function nz_addDir(dir)\
  1554. \009path:add(dir:sub(1,#dir-1))\
  1555. \009nz_getfiles()\
  1556. \009nz_drawfiles()\
  1557. end\
  1558. function nz_drawfiles(c)\
  1559. \009if(c)then pa.drawFilledBox(2,8,w-1,h-1,colors.white) end\
  1560. \009scp(7,6)\
  1561. \009stc(colors.white)\
  1562. \009sbc(colors.lightGray)\
  1563. \009write(string.rep(\" \",w-5))\
  1564. \009scp(7,6)\
  1565. \009write( nz_formatzippath(path:getraw()) )\
  1566. \009scp(2,8)\
  1567. \009sbc(colors.white)\
  1568. \009stc(colors.lightGray)\
  1569. \009write(\"     Name             Type              Size \")\
  1570. \009local lamm = #files-offs\
  1571. \009if(#files-offs > 10)then\
  1572. \009\009lamm = 10 \
  1573. \009end\
  1574. \009for i = 1+offs, lamm+offs do\
  1575. \009\009sbc(colors.white)\
  1576. \009\009scp(2,(i+8)-offs)\
  1577. \009\009write(string.rep(\" \",w-2))\
  1578. \009\009if(files[i].type == \"folder\")then\
  1579. \009\009\009sbc(colors.yellow)\
  1580. \009\009\009stc(colors.brown)\
  1581. \009\009\009scp(2,(i+8)-offs)\
  1582. \009\009\009write(\"[=]\")\
  1583. \009\009\009sbc(colors.white)\
  1584. \009\009\009if(selected == i)then sbc(colors.lightBlue) end\
  1585. \009\009\009stc(colors.black)\
  1586. \009\009\009scp(5,i+8-offs)\
  1587. \009\009\009write(' ' .. files[i].n:sub(1,#files[i].n-1))\
  1588. \009\009\009files[i].t = \"Folder\"\
  1589. \009\009else\
  1590. \009\009\009sbc(colors.gray)\
  1591. \009\009\009stc(colors.lightGray)\
  1592. \009\009\009scp(2,i+8-offs)\
  1593. \009\009\009write(\"-~-\")\
  1594. \009\009\009sbc(colors.white)\
  1595. \009\009\009if(selected == i)then sbc(colors.lightBlue) end\
  1596. \009\009\009stc(colors.black)\
  1597. \009\009\009scp(5,i+8-offs)\
  1598. \009\009\009write(' ' .. files[i].n)\
  1599. \009\009\009files[i].t = \"File\"\
  1600. \009\009end\
  1601. \009end\
  1602. end\
  1603. function nz_drawmain()\
  1604. \009sbc(colors.white)\
  1605. \009clr()\
  1606. \009pa.drawBox(1,7,w,h,colors.gray)\
  1607. \009pa.drawBox(1,1,w,7,colors.gray)\
  1608. \009pa.drawFilledBox(2,2,w-1,5,colors.lightGray)\
  1609. \009scp(2,5)\
  1610. \009sbc(colors.gray)\
  1611. \009stc(colors.white)\
  1612. \009write(string.rep(\"_\",w-2))\
  1613. \009scp(2,6)\
  1614. \009sbc(colors.black)\
  1615. \009stc(colors.lightGray)\
  1616. \009write(\"^-\")\
  1617. \009sbc(colors.lightGray)\
  1618. \009stc(colors.black)\
  1619. \009write(\":/\")\
  1620. \009write(string.rep(\" \",w-6))\
  1621. \009scp(2,7)\
  1622. \009sbc(colors.gray)\
  1623. \009stc(colors.white)\
  1624. \009write(string.rep(\"-\",w-2))\
  1625. end\
  1626. function nz_goback()\
  1627. \009scp(2,6)\
  1628. \009sbc(colors.gray)\
  1629. \009stc(colors.white)\
  1630. \009write(\"^-\")\
  1631. \009sleep(0.2)\
  1632. \009sbc(colors.black)\
  1633. \009stc(colors.lightGray)\
  1634. \009scp(2,6)\
  1635. \009write(\"^-\")\
  1636. \009path:goback(1)\
  1637. \009nz_getfiles()\
  1638. \009nz_drawfiles()\
  1639. end\
  1640. \
  1641. local function update()\
  1642. \009local e = {os.pullEvent()}\
  1643. \009if(inmenu)then\
  1644. \009\009nz_updatemenu(e,inmenutype,inmenux,inmenuy)\
  1645. \009end\
  1646. \009if(e[1] == \"mouse_scroll\" and #files > 1)then\
  1647. \009\009if(e[2] == -1 and offs > 0)then\
  1648. \009\009\009offs = offs - 1\
  1649. \009\009\009nz_drawfiles()\
  1650. \009\009end\
  1651. \009\009if(e[2] == 1 and offs < #files-(10))then\
  1652. \009\009\009offs = offs + 1\
  1653. \009\009\009nz_drawfiles()\
  1654. \009\009end\
  1655. \009end\
  1656. \009if(e[1] == \"mouse_click\")then\
  1657. \009\009local x, y = e[3], e[4]\
  1658. \009\009local yind = (y-8)+offs\
  1659. \009\009if(e[2] == 1)then\
  1660. \009\009\009if(x >= 2 and x <= 4 and y == 6)then\
  1661. \009\009\009\009nz_goback()\
  1662. \009\009\009end\
  1663. \
  1664. \009\009\009if(yind > 0 and yind <= #files and x >= 4 and x <= 5+#files[yind].n)then\
  1665. \009\009\009\009if(selected == yind)then\
  1666. \009\009\009\009\009if(files[yind].type == \"folder\")then\
  1667. \009\009\009\009\009\009nz_addDir(files[selected].n)\
  1668. \009\009\009\009\009\009selected = 0\
  1669. \009\009\009\009\009end\
  1670. \009\009\009\009else\
  1671. \009\009\009\009\009selected = yind\
  1672. \009\009\009\009end\
  1673. \009\009\009elseif(inmenu)then\
  1674. \009\009\009\009inmenu = false\
  1675. \009\009\009end\
  1676. \009\009\009\009nz_drawfiles()\
  1677. \009\009\009elseif(e[2] == 2)then\
  1678. \009\009\009\009if(not inmenu and x > 1 and y > 8)then\
  1679. \009\009\009\009\009if(yind == selected and x >= 4 and x <= 5+#files[yind].n)then\
  1680. \009\009\009\009\009\009nz_opencloseMenu(\"reg\",x,y)\
  1681. \009\009\009\009\009else\
  1682. \009\009\009\009\009\009nz_opencloseMenu(\"new\",x,y)\
  1683. \009\009\009\009\009end\
  1684. \009\009\009\009end\
  1685. \009\009\009end\
  1686. \009\009end\
  1687. end\
  1688. nz_getfiles()\
  1689. nz_drawmain()\
  1690. nz_drawfiles()\
  1691. \
  1692. local function loop()\
  1693. \009while innovazip do\
  1694. \009\009update()\
  1695. \009end\
  1696. end\
  1697. loop()",
  1698.   },
  1699.   [ "users/tes/" ] = {
  1700.     content = "",
  1701.   },
  1702.   [ "apis/grid/" ] = {
  1703.     content = "\
  1704. -- ] Created by: Redxone(Lewisk3) [ -- \
  1705. -- ] \009(c)Lewisk3 Corpz 2016\009  [ -- \
  1706. \
  1707. -- DOCUMENTATION (Sorta...) -- \
  1708. --] grid.create(width,height)\
  1709. --] grid:set(x,y,thing)\
  1710. --] grid:find(obj) - returns the found objects x and y location\
  1711. --] grid:findByAttrib(attrib,compare)\
  1712. --] grid:get(x,y) - returns the object in the x any y of the grid\
  1713. --] grid:getByAttrib(attrib,compare)\
  1714. --] grid:getWidth() - returns width of grid\
  1715. --] grid:getHeight() - returns grid height\
  1716. --] grid:unset(x,y) - set grid spot to {}\
  1717. --] grid:getRaw() - returns entire grid unserialized\
  1718. --] grid:getSerial() - returns entire grid serialized\
  1719. --] grid:replace(newgrid) - replaces grid with another grid\
  1720. --] grid:draw()\
  1721. --] grid:drawAttrib(attrib)\
  1722. --] grid:fill(with) - fills grid with something\
  1723. --] grid:setRegion(startx,starty,endx,endy,with) - fills grid from start x and start y to ends with something\
  1724. --] grid:drawRegion(startx,starty,endx,endy)\
  1725. \
  1726. function create(w, h)\
  1727. \009local gridtable = {\
  1728. \009\009maxw = w,\
  1729. \009\009maxh = h,\
  1730. \009\009grid = {},\
  1731. \
  1732. \009\009set = function(self,x,y,obj)\
  1733. \009\009\009if(x <= self.maxw and y <= self.maxh)then\
  1734. \009\009\009\009self.grid[y][x] = obj\
  1735. \009\009\009else\
  1736. \009\009\009\009error(\"grid:set -> Invaild X and/or Y param(s).\")\
  1737. \009\009\009end\
  1738. \009\009end,\
  1739. \
  1740. \009\009find = function(self,obj)\
  1741. \009\009\009for y = 0, self.maxh do\
  1742. \009\009\009 \009for x = 0, self.maxw do\
  1743. \009\009\009 \009\009if(textutils.serialize(self.grid[y][x]) == textutils.serialize(obj))then\
  1744. \009\009\009 \009\009\009return x, y\
  1745. \009\009\009 \009\009end\
  1746. \009\009\009 \009end\
  1747. \009\009\009 end\
  1748. \009\009end,\
  1749. \
  1750. \009\009get = function(self,x,y)\
  1751. \009\009\009local tbl = {}\
  1752. \009\009\009if(x <= self.maxw and y <= self.maxh )then\
  1753. \009\009\009\009return self.grid[y][x]\
  1754. \009\009\009else\
  1755. \009\009\009\009return tbl\
  1756. \009\009\009end\
  1757. \009\009end,\
  1758. \
  1759. \009\009getByAttribEqual = function(self,a,c)\
  1760. \009\009\009local gx, gy = 0, 0\
  1761. \009\009\009for y = 0, self.maxh do\
  1762. \009\009\009 \009for x = 0, self.maxw do\
  1763. \009\009\009 \009\009if(self.grid[y][x][a] == c)then\
  1764. \009\009\009 \009\009\009gx = x\
  1765. \009\009\009 \009\009\009gy = y\
  1766. \009\009\009 \009\009end\
  1767. \009\009\009 \009end\
  1768. \009\009\009 end\
  1769. \009\009\009return self:get(gx,gy)\
  1770. \009\009end,\
  1771. \
  1772. \009\009checkAttribEqual = function(self,x,y,a,e)\
  1773. \009\009\009 if(self.grid[y][x][a] == c)then\
  1774. \009\009\009 \009return true\
  1775. \009\009\009 else\
  1776. \009\009\009 \009return false\
  1777. \009\009\009 end\
  1778. \009\009end,\
  1779. \
  1780. \009\009getByAttrib = function(self,a)\
  1781. \009\009\009local xx, yy = 0, 0\
  1782. \009\009\009for y = 0, self.maxh do\
  1783. \009\009\009 \009for x = 0, self.maxw do\
  1784. \009\009\009 \009\009if(self.grid[y][x][a] ~= nil)then\
  1785. \009\009\009 \009\009\009 xx = x\
  1786. \009\009\009 \009\009\009 yy = y\
  1787. \009\009\009 \009\009end\
  1788. \009\009\009 \009end\
  1789. \009\009\009 end\
  1790. \
  1791. \009\009\009 if(xx ~= 0 and yy ~= 0)then\
  1792. \009\009\009\009return self:get(xx,yy)[a]\
  1793. \009\009\009 else\
  1794. \009\009\009\009return {}\
  1795. \009\009\009 end\
  1796. \009\009end,\
  1797. \
  1798. \009\009setByAttrib = function(self,a,n)\
  1799. \009\009\009for y = 0, self.maxh do\
  1800. \009\009\009 \009for x = 0, self.maxw do\
  1801. \009\009\009 \009\009if(self.grid[y][x][a] ~= nil)then\
  1802. \009\009\009 \009\009\009 local bset = self.grid[y][x]\
  1803. \009\009\009 \009\009\009 bset[a] = n\
  1804. \009\009\009 \009\009\009 self:set(x,y,bset)\
  1805. \009\009\009 \009\009end\
  1806. \009\009\009 \009end\
  1807. \009\009\009 end\
  1808. \009\009end,\
  1809. \
  1810. \009\009getWidth = function(self)\
  1811. \009\009\009return self.maxw\
  1812. \009\009end,\
  1813. \
  1814. \009\009getHeight = function(self)\
  1815. \009\009\009return self.maxh\
  1816. \009\009end,\
  1817. \
  1818. \009\009unset = function(self,x,y)\
  1819. \009\009\009if(x <= self.maxw and y <= self.maxh)then\
  1820. \009\009\009\009self.grid[y][x] = {}\
  1821. \009\009\009else\
  1822. \009\009\009\009error(\"grid:unset -> Invaild X and/or Y param(s).\")\
  1823. \009\009\009end\
  1824. \009\009end,\
  1825. \
  1826. \009\009getRaw = function(self)\
  1827. \009\009\009return self.grid\
  1828. \009\009end,\
  1829. \
  1830. \009\009getSerial = function(self)\
  1831. \009\009\009return textutils.serialize(self.grid):gsub(\"\\n%s*\",\"\")\
  1832. \009\009end,\
  1833. \
  1834. \009\009replace = function(self,grid)\
  1835. \009\009\009if(type(grid) ~= \"table\")then error(\"grid:replace -> Invalid grid type. \") end\
  1836. \009\009\009 -- calculating grid size... --\
  1837. \009\009\009 self.maxh = 0\
  1838. \009\009\009 self.maxw = 0\
  1839. \
  1840. \009\009\009 for iy = 1, #grid do\
  1841. \009\009\009 \009self.maxh = self.maxh + 1\
  1842. \009\009\009 end\
  1843. \
  1844. \009\009\009 for ix = 1, #grid[0] do\
  1845. \009\009\009\009self.maxw = self.maxw + 1\
  1846. \009\009     end\
  1847. \
  1848. \009\009     self.grid = grid\
  1849. \
  1850. \009\009\009 if(self.maxh <= 0 or self.maxw <= 0)then error(\"grid:replace -> Grid is malformed.\") end\
  1851. \
  1852. \009\009end,\
  1853. \
  1854. \009\009draw = function(self)\
  1855. \009\009\009for y = 0, self.maxh do\
  1856. \009\009\009 \009for x = 0, self.maxw do\
  1857. \009\009\009 \009\009term.setCursorPos(x,y)\
  1858. \009\009\009 \009\009if(self.grid[y][x] ~= {})then\
  1859. \009\009\009\009\009\009term.write(self.grid[y][x])\
  1860. \009\009\009\009\009end\
  1861. \009\009\009 \009end\
  1862. \009\009\009 end\
  1863. \009\009end,\
  1864. \
  1865. \009\009swap = function(self,fromx,fromy,tox,toy)\
  1866. \009\009\009local prevo = self.grid[fromy][fromx] \
  1867. \009\009\009local too = self.grid[toy][tox]\
  1868. \009\009\009self.grid[fromy][fromx] = too\
  1869. \009\009\009self.grid[toy][tox] = prevo\
  1870. \009\009end,\
  1871. \
  1872. \009\009moveInto = function(self,obj,x,y,uap,flags)\
  1873. \009\009\009local prloc = self:get(x,y)\
  1874. \009\009\009local ox, oy = self:find(obj)\
  1875. \009\009\009-- only take place if flags on other block are met --\
  1876. \009\009\009if(type(flags) == \"table\")then\
  1877. \009\009\009\009for k, v in pairs(flags) do\
  1878. \009\009\009\009\009if(not self:checkAttribEqual(x,y,k,v))then\
  1879. \009\009\009\009\009\009return false\
  1880. \009\009\009\009\009end\
  1881. \009\009\009\009end\
  1882. \009\009\009end\
  1883. \009\009\009-- if passes flags -- \
  1884. \009\009\009if(type(uap) == \"table\")then\
  1885. \009\009\009\009for k, v in pairs(uap) do\
  1886. \009\009\009\009\009obj[k] = v\
  1887. \009\009\009\009end\009\009\009\009\
  1888. \009\009\009end\
  1889. \009\009\009self:set(ox,oy,prloc)\
  1890. \009\009\009self:set(x,y,obj)\
  1891. \009\009end,\
  1892. \
  1893. \009\009renderSwap = function(self, charattrib, tcolattrib, bcolattrib, fromx,fromy,tox,toy)\
  1894. \009\009\009self:swap(fromx,fromy,tox,toy)\009\009\
  1895. \009\009\009self:renderRegion(charattrib, tcolattrib, bcolattrib,tox,toy,tox,toy)\
  1896. \009\009\009self:renderRegion(charattrib, tcolattrib, bcolattrib,fromx,fromy,fromx,fromy)\
  1897. \009\009end,\
  1898. \
  1899. \009\009render = function(self,charattrib,tcolattrib,bcolattrib)\
  1900. \009\009\009local ta = colors.white\
  1901. \009\009\009local ba = colors.black\
  1902. \009\009\009for y = 0, self.maxh do\
  1903. \009\009\009 \009for x = 0, self.maxw do\
  1904. \009\009\009 \009\009term.setCursorPos(x,y)\
  1905. \009\009\009 \009\009term.setTextColor(self.grid[y][x][tcolattrib])\
  1906. \009\009\009 \009\009term.setBackgroundColor(self.grid[y][x][bcolattrib])\
  1907. \009\009\009\009\009 \009ta = colors.white\
  1908. \009\009\009\009\009 \009ba = colors.black\
  1909. \009\009\009\009\009 \009if(type(tcolattrib) == \"number\")then ta = tcolattrib end\
  1910. \009\009\009\009\009 \009if(type(bcolattrib) == \"number\")then ba = bcolattrib end\
  1911. \009\009\009\009\009 \009if(self.grid[y][x][charattrib] ~= nil)then\
  1912. \009\009\009\009\009 \009\009if(self.grid[y][x][tcolattrib] ~= nil)then\
  1913. \009\009\009\009\009 \009\009\009ta = self.grid[y][x][tcolattrib]\
  1914. \009\009\009\009\009 \009\009end\
  1915. \009\009\009\009\009 \009\009if(self.grid[y][x][bcolattrib] ~= nil)then\
  1916. \009\009\009\009\009 \009\009\009ba = self.grid[y][x][bcolattrib]\
  1917. \009\009\009\009\009 \009\009end\
  1918. \009\009\009\009\009\009 \009term.setTextColor(ta)\
  1919. \009\009\009\009 \009\009\009term.setBackgroundColor(ba)\
  1920. \009\009\009\009\009 \009\009term.write(self.grid[y][x][charattrib])\
  1921. \009\009\009\009\009 \009end\
  1922. \009\009\009\009end\
  1923. \009\009\009 end\
  1924. \009\009end,\
  1925. \
  1926. \009\009drawAttrib = function(self,a)\
  1927. \009\009\009for y = 0, self.maxh do\
  1928. \009\009\009 \009for x = 0, self.maxw do\
  1929. \009\009\009 \009\009term.setCursorPos(x,y)\
  1930. \009\009\009 \009\009if(self.grid[y][x][a] ~= nil)then\
  1931. \009\009\009 \009\009\009term.write(self.grid[y][x][a])\
  1932. \009\009\009 \009\009end\
  1933. \009\009\009 \009end\
  1934. \009\009\009 end\
  1935. \009\009end,\
  1936. \
  1937. \009\009fill = function(self,obj)\
  1938. \009\009\009for y = 0, self.maxh do\
  1939. \009\009\009 \009for x = 0, self.maxw do\
  1940. \009\009\009 \009\009self.grid[y][x] = obj\
  1941. \009\009\009 \009end\
  1942. \009\009\009 end\
  1943. \009\009end,\
  1944. \
  1945. \009\009setCursorPos = function(self,x,y)\
  1946. \009\009\009term.setCursorPos(y,x)\
  1947. \009\009end,\
  1948. \
  1949. \009\009loop = function(self,f,startx,starty,endx,endy)\
  1950. \009\009\009if(startx == nil)then startx = 0 end\
  1951. \009\009\009if(starty == nil)then starty = 0 end\
  1952. \009\009\009if(endx == nil and startx ~= nil)then endx = startx end\
  1953. \009\009\009if(endy == nil and starty ~= nil)then endy = starty end\
  1954. \009\009\009if(endx == nil)then endx = self.maxw end\
  1955. \009\009\009if(endy == nil)then endy = self.maxh end\
  1956. \009\009\009for y = tonumber(starty), tonumber(endy) do\
  1957. \009\009\009\009for x = tonumber(startx), tonumber(endx) do\
  1958. \009\009\009\009\009f(x,y)\
  1959. \009\009\009\009end\
  1960. \009\009\009end\
  1961. \009\009end,\
  1962. \
  1963. \009\009setRegion = function(self, sx, sy, ex, ey, obj)\
  1964. \009\009\009if(sx <= self.maxw and sy <= self.maxh and ex <= self.maxw and ey <= self.maxh)then\
  1965. \009\009\009\009for y = tonumber(sy), tonumber(ey) do\
  1966. \009\009\009\009 \009for x = tonumber(sx), tonumber(ex) do\
  1967. \009\009\009\009 \009\009self.grid[y][x] = obj\
  1968. \009\009\009\009 \009end\
  1969. \009\009\009\009 end\
  1970. \009\009\009else\
  1971. \009\009\009\009error(\"grid:setRegion -> Invaild X and/or Y param(s).\")\
  1972. \009\009\009end\
  1973. \009\009end,\
  1974. \
  1975. \009\009drawRegion = function(self, sx, sy, ex, ey)\
  1976. \009\009\009if(sx <= self.maxw and sy <= self.maxh and ex <= self.maxw and ey <= self.maxh)then\
  1977. \009\009\009\009for y = tonumber(sy), tonumber(ey) do\
  1978. \009\009\009\009 \009for x = tonumber(sx), tonumber(ex) do\
  1979. \009\009\009\009\009 \009term.setCursorPos(x,y)\
  1980. \009\009\009\009 \009\009if(self.grid[y][x] ~= {})then\
  1981. \009\009\009\009\009\009\009term.write(self.grid[y][x])\
  1982. \009\009\009\009\009\009end\
  1983. \009\009\009\009 \009end\
  1984. \009\009\009\009 end\
  1985. \009\009\009else\
  1986. \009\009\009\009error(\"grid:drawRegion -> Invaild X and/or Y param(s).\")\
  1987. \009\009\009end\
  1988. \009\009end,\
  1989. \
  1990. \009\009renderRegion = function(self, charattrib, tcolattrib, bcolattrib, sx, sy, ex, ey)\
  1991. \009\009\009if(sx <= self.maxw and sy <= self.maxh and ex <= self.maxw and ey <= self.maxh)then\
  1992. \009\009\009\009local ta = colors.white\
  1993. \009\009\009 \009local ba = colors.black\
  1994. \009\009\009\009for y = tonumber(sy), tonumber(ey) do\
  1995. \009\009\009\009 \009for x = tonumber(sx), tonumber(ex) do\
  1996. \009\009\009\009\009 \009term.setCursorPos(x,y)\
  1997. \009\009\009\009\009 \009ta = colors.white\
  1998. \009\009\009\009\009 \009ba = colors.black\
  1999. \009\009\009\009\009 \009if(self.grid[y][x][charattrib] ~= nil)then\
  2000. \009\009\009\009\009 \009\009if(self.grid[y][x][tcolattrib] ~= nil)then\
  2001. \009\009\009\009\009 \009\009\009ta = self.grid[y][x][tcolattrib]\
  2002. \009\009\009\009\009 \009\009end\
  2003. \009\009\009\009\009 \009\009if(self.grid[y][x][bcolattrib] ~= nil)then\
  2004. \009\009\009\009\009 \009\009\009ba = self.grid[y][x][bcolattrib]\
  2005. \009\009\009\009\009 \009\009end\
  2006. \009\009\009\009\009\009 \009term.setTextColor(ta)\
  2007. \009\009\009\009 \009\009\009term.setBackgroundColor(ba)\
  2008. \009\009\009\009\009 \009\009term.write(self.grid[y][x][charattrib])\
  2009. \009\009\009\009\009 \009end\
  2010. \009\009\009\009 \009end\
  2011. \009\009\009\009 end\
  2012. \009\009\009else\
  2013. \009\009\009\009error(\"grid:renderRegion -> Invaild X and/or Y param(s).\")\
  2014. \009\009\009end\
  2015. \009\009end,\
  2016. \
  2017. \009}\
  2018. \
  2019. \
  2020. \009-- generate grid locally --\
  2021. \009for y = 0, h do\
  2022. \009\009gridtable.grid[y] = {}\
  2023. \009\009for x = 0, w do\
  2024. \009\009\009gridtable.grid[y][x] = {}\
  2025. \009\009end\
  2026. \009end\
  2027. \
  2028. \009-- return grid to user --\
  2029. \009return gridtable\
  2030. end",
  2031.   },
  2032.   [ "games/2048/" ] = {
  2033.     content = "local running = true\
  2034. local cx,cy = 0, 0\
  2035. local drawx = 11\
  2036. local drawy = -2\
  2037. local xscale = 5\
  2038. local yscale = 4\
  2039. local cubexsize = 6\
  2040. local cubeysize = 4\
  2041. local score = 2\
  2042. local function calcdragpos(sx,sy,ex,ey,dx,dy)\
  2043. \009if(ex < sx-dx)then return -1,0\
  2044. \009elseif(ex > sx+dx)then return 1,0\
  2045. \009elseif(ey < sy-dy)then return 0,-1\
  2046. \009elseif(ey > sy+dy)then return 0,1 end\
  2047. end\
  2048. \
  2049. local map = {\
  2050. \009{2,0,0,0},\
  2051. \009{0,0,0,0},\
  2052. \009{0,0,0,0},\
  2053. \009{0,0,0,0},\
  2054. }\
  2055. local numcols = {\
  2056. \009['2'] = \"white\",\
  2057. \009['4'] = \"lightGray\",\
  2058. \009['8'] = \"brown\",\
  2059. \009['16'] = \"orange\",\
  2060. \009['32'] = \"pink\",\
  2061. \009['64'] = \"red\",\
  2062. \009['128'] = \"yellow\",\
  2063. \009['256'] = \"yellow\",\
  2064. \009['512'] = \"yellow\",\
  2065. \009['1024'] = \"yellow\",\
  2066. \009['2048'] = \"yellow\",\
  2067. \009['4096'] = \"magenta\",\
  2068. \009['8192'] = \"purple\",\
  2069. }\
  2070. local function drawtile(x,y)\
  2071. \009   \009local sx = (drawx)+(x)*xscale\
  2072.   \009   \009local sy = (drawy)+(y)*yscale\
  2073.   \009   \009local ex = (drawx+x*xscale)+cubexsize\
  2074.   \009   \009local ey = (drawy+y*yscale)+cubeysize\
  2075.   \009   \009if(map[y][x] ~= 0)then\
  2076.   \009   \009\009-- drawing code form empty\
  2077.   \009   \009\009bcol = numcols[tostring(map[y][x])]\
  2078.   \009   \009\009if(bcol == nil)then col = colors.lightBlue end\
  2079.   \009   \009\009paintutils.drawFilledBox(sx+1,sy+1,ex-(cubexsize/2)+1,ey-(cubeysize/2)+1,colors[bcol])\
  2080.   \009   \009\009term.setTextColor(colors.black)\
  2081.   \009   \009\009term.setCursorPos((sx+3) - #tostring(map[y][x])/2 ,sy+2)\
  2082.   \009   \009\009write(map[y][x])\
  2083.   \009    else\
  2084.   \009   \009\009paintutils.drawFilledBox(sx+1,sy+1,ex-(cubexsize/2)+1,ey-(cubeysize/2)+1,colors.black)\
  2085.   \009   \009end\
  2086. end\
  2087. local function drawtiles()\
  2088. \009term.current().setVisible(false)\
  2089. \009--paintutils.drawBox(drawx,drawy,drawx+(#map[1]*xscale),drawy+(#map*yscale),colors.gray)\
  2090. \009for y = 1, #map do\
  2091.   \009   for x = 1, #map[y] do \
  2092.   \009   \009\009local tile = map[y][x]\
  2093.   \009   \009\009   \009local sx = (drawx)+(x)*xscale\
  2094.   \009   \009\009\009local sy = (drawy)+(y)*yscale\
  2095.   \009   \009\009\009local ex = (drawx+x*xscale)+cubexsize\
  2096.   \009   \009\009\009local ey = (drawy+y*yscale)+cubeysize\
  2097.   \009   \009\009\009paintutils.drawBox(sx,sy,ex-1,ey,colors.gray)\
  2098.   \009   \009\009\009drawtile(x,y)\
  2099.   \009   end\
  2100.   \009end\
  2101.   \009term.current().setVisible(true)\
  2102. end\
  2103. local function setTile(x,y,n)\
  2104. \009if(map[y][x] ~= 0 and n ~= 0)then \
  2105. \009\009score = score + (n-map[y][x]) \
  2106. \009elseif(map[y][x] ~= 0 and n == 0)then\
  2107. \009\009score = score - map[y][x]\
  2108. \009else\
  2109. \009\009score = score + n\
  2110. \009end\
  2111. \009map[y][x] = n\
  2112. \009drawtile(x,y)\
  2113. end\
  2114. \
  2115. local function getRandTile()\
  2116. \009local rx = math.ceil(math.random(1,#map[1]))\
  2117. \009local ry = math.ceil(math.random(1,#map))\
  2118. \009local rn = math.ceil(math.random(1,10))\
  2119. \009if(rn == 10)then\
  2120. \009\009rn = 4\
  2121. \009else \
  2122. \009\009rn = 2\
  2123. \009end\
  2124. \009return rx,ry,rn\
  2125. end\
  2126. \
  2127. local function slidetiles(xd,yd)\
  2128. \009-- 1, UP: 2, DOWN, 3: LEFT, 4: RIGHT\
  2129. \009local rna = math.ceil(math.random(1,2))\
  2130. \009local moved=false\
  2131. \009local cancombine = true\
  2132. \009for li = 1, #map[1] do\
  2133. \009   for y = 1, #map do\
  2134. \009   \009  for x = 1, #map[y] do\
  2135. \009   \009    \009local to = nil\
  2136. \009   \009    \009if(y+yd < 0 or x+xd < 0)then break end\
  2137. \009   \009\009    if(map[y+yd] ~= nil)then\
  2138. \009   \009\009    \009if(map[y+yd][x+xd] ~= nil)then\
  2139. \009   \009\009\009\009\009to = map[y+yd][x+xd]\
  2140. \009   \009\009\009\009end\
  2141. \009   \009\009\009end\
  2142. \
  2143. \009   \009\009    if(to == 0)then\
  2144. \009\009\009\009\009setTile(x+xd,y+yd,map[y][x])\
  2145. \009   \009\009\009\009setTile(x,y,0)\
  2146. \009   \009\009\009\009moved = true\
  2147. \009   \009\009\009elseif(to == map[y][x] and cancombine and to ~= 8192)then\
  2148. \009\009\009\009\009setTile(x+xd,y+yd,map[y+yd][x+xd]+map[y][x])\
  2149. \009   \009\009\009\009setTile(x,y,0)\
  2150. \009   \009\009\009\009cancombine = false\
  2151. \009   \009\009\009end\
  2152. \009   \009   end\
  2153. \009   end\
  2154. \009end\
  2155. \009local rx,ry,rn = getRandTile()\
  2156. \009if(map[ry][rx] == 0 and moved)then\
  2157. \009\009setTile(rx,ry,rn)\
  2158. \009end\
  2159. \009term.setCursorPos(1,1)\
  2160. \009term.setBackgroundColor(colors.white)\
  2161. \009term.setTextColor(colors.black)\
  2162. \009term.clearLine()\
  2163. \009print(score)\
  2164. end\
  2165. term.clear()\
  2166. drawtiles()\
  2167. while running do\
  2168. \
  2169. \009local e = {os.pullEvent()}\009\
  2170. \009if(e[1] == \"mouse_click\")then \
  2171. \009\009cx = e[3]\
  2172. \009\009cy = e[4]\
  2173. \009end\
  2174. \009if(e[1] == \"mouse_drag\" and cx ~= 0 and cy ~= 0)then\
  2175. \009\009local xdir,ydir = calcdragpos(cx,cy,e[3],e[4],2,1)\
  2176.       if(type(xdir) == \"number\" and type(ydir) == \"number\")then\
  2177.       \009  slidetiles(tonumber(xdir),tonumber(ydir))\
  2178.       \009  cx = 0\
  2179.       \009  cy = 0\
  2180.       end\
  2181. \009end\
  2182. end",
  2183.   },
  2184.   [ "apis/novautils/" ] = {
  2185.     content = "local w, h = term.getSize()\
  2186. local sbc = term.setBackgroundColor\
  2187. local stc = term.setTextColor\
  2188. local scp = term.setCursorPos\
  2189. local clr = term.clear\
  2190. local clrln = term.clearLine\
  2191. local shell = {}\
  2192. function init(nshell)\
  2193. \009shell = nshell\
  2194. end\
  2195. \
  2196. function openReadDialog(title,clrfunc,startread)\
  2197. \009local bw, bh = 30,0\
  2198. \009local sx, sy = w/2-math.ceil(bw/2), (h/2)-math.ceil(bh/2)-1\
  2199. \009local ex, ey = w/2+math.ceil(bw/2), (h/2)+math.floor(bh/2)-1\
  2200. \009paintutils.drawFilledBox(sx+1,sy,ex+2,ey+2,colors.black)\
  2201. \009paintutils.drawFilledBox(sx,sy,ex,ey,colors.lightGray)\
  2202. \009paintutils.drawBox(sx-1,sy-1,ex+1,ey+1,colors.gray)\
  2203. \009scp(sx,sy-1)\
  2204. \009stc(colors.white)\
  2205. \009write(title)\
  2206. \009scp(sx,sy)\
  2207. \009sbc(colors.lightGray)\
  2208. \009local inp = readEx(30,true,startread)\
  2209. \009clrfunc()\
  2210. \009return inp\
  2211. end\
  2212. \
  2213. function notify(title,txt,clrfunc)\
  2214. \009local bw, bh = 30,5\
  2215. \009local sx, sy = w/2-math.ceil(bw/2), (h/2)-math.ceil(bh/2)+2\
  2216. \009local ex, ey = w/2+math.ceil(bw/2), (h/2)+math.floor(bh/2)+1\
  2217. \009paintutils.drawLine(sx,sy-1,ex,sy-1,colors.gray)\
  2218. \009paintutils.drawFilledBox(sx+1,sy+1,ex+1,ey+1,colors.black)\
  2219. \009paintutils.drawFilledBox(sx,sy,ex,ey,colors.lightGray)\
  2220. \009scp(sx,sy-1)\
  2221. \009stc(colors.white)\
  2222. \009sbc(colors.gray)\
  2223. \009write(title)\
  2224. \009sbc(colors.lightGray)\
  2225. \009local msg = {}\
  2226.     for str in string.gmatch(txt, \"([^*]+)\") do\
  2227.         msg[#msg+1] = str  \
  2228.     end\
  2229.     for i = 1, #msg do\
  2230.     \009sbc(colors.lightGray)\
  2231.     \009fullwrite(\" \" .. msg[i],45,sx,sy+i)\
  2232.     end\
  2233.     fullwrite(\"&4Click&r to close. \",45,sx+8,sy+#msg+2)\
  2234. \009os.pullEvent(\"mouse_click\")\
  2235. \009clrfunc()\
  2236. end\
  2237. function openYesNo(title,txt,clrfunc,y,n)\
  2238. \009if(y == nil or n == nil)then \
  2239. \009\009 y = \"Yes\"\
  2240. \009\009 n = \"No\"\
  2241. \009end\
  2242. \009local ynm = {y, n}\
  2243. \009local inynm = true\
  2244. \009local bw, bh = 30,5\
  2245. \009local opinc = 9\
  2246. \009local sx, sy = w/2-math.ceil(bw/2), (h/2)-math.ceil(bh/2)+2\
  2247. \009local ex, ey = w/2+math.ceil(bw/2), (h/2)+math.floor(bh/2)+1\
  2248. \009paintutils.drawLine(sx,sy-1,ex,sy-1,colors.gray)\
  2249. \009paintutils.drawFilledBox(sx+1,sy+1,ex+1,ey+1,colors.black)\
  2250. \009paintutils.drawFilledBox(sx,sy,ex,ey,colors.lightGray)\
  2251. \009scp(sx,sy-1)\
  2252. \009stc(colors.white)\
  2253. \009sbc(colors.gray)\
  2254. \009write(title)\
  2255. \009sbc(colors.lightGray)\
  2256. \009 local msg = {}\
  2257.     for str in string.gmatch(txt, \"([^*]+)\") do\
  2258.         msg[#msg+1] = str  \
  2259.     end\
  2260.     for i = 1, #msg do\
  2261.     \009sbc(colors.lightGray)\
  2262.     \009colorwrite(\" \" .. msg[i],45,sx,sy+i)\
  2263.     end\
  2264. \009stc(colors.white)\
  2265. \009local function drawm()\
  2266. \009\009  for i = 1, #ynm do\
  2267. \009\009  \009\009sbc(colors.red)\
  2268. \009\009  \009\009if(i==1)then\
  2269. \009\009  \009\009\009sbc(colors.green)\
  2270. \009\009  \009\009end\
  2271. \009\009  \009\009scp(sx+(i*opinc),ey-1)\
  2272. \009\009  \009\009write(ynm[i])\
  2273. \009\009  end\
  2274. \009end\
  2275. \009local function drawmopt(id,clk)\
  2276. \009\009 sbc(colors.red)\
  2277. \009\009 if(i==1)then\
  2278. \009\009    sbc(colors.green)\
  2279. \009\009 end\
  2280. \009\009 if(clk)then sbc(colors.gray) end\
  2281. \009\009 scp(sx+(id*opinc),ey-1)\
  2282. \009\009 write(ynm[id])\
  2283. \009\009 sleep(0.2)\
  2284. \009end\
  2285. \009local function mupdate()\
  2286. \009\009while inynm do\
  2287. \009\009\009local ev = {os.pullEvent()}\
  2288. \009\009\009if(ev[1] == \"mouse_click\")then\
  2289. \009\009\009\009local x, y = ev[3], ev[4]\
  2290. \009\009\009\009for i = 1, #ynm do\
  2291. \009\009\009\009\009if( x >= sx+(i*opinc)-1 and x <= sx+(i*opinc)+#ynm[i] and y == math.floor(ey-1) )then\
  2292. \009\009\009\009\009\009inynm = false\
  2293. \009\009\009\009\009\009drawmopt(i,true)\
  2294. \009\009\009\009\009\009return i\
  2295. \009\009\009\009\009end\
  2296. \009\009\009\009end\
  2297. \009\009\009end\
  2298. \009\009end\
  2299. \009end\
  2300. \009drawm()\
  2301. \009local res = mupdate()\
  2302. \009clrfunc()\
  2303. \009return res\
  2304. end\
  2305. function readEx(mlen,scroll,startw)\
  2306. \009novaio.setActive(false)\
  2307. \009if(startw == nil)then startw = \"\" end\
  2308. \009novaio.setInput(startw)\
  2309. \009local x, y = term.getCursorPos()\
  2310. \009local readxoff = x\
  2311. \009if(startw ~= \"\")then\
  2312. \009\009scp(readxoff,y)\
  2313. \009\009write(novaio.getInput())\
  2314. \009end\
  2315. \009local oinp = novaio.getInput()\
  2316. \009local ininp = true\
  2317. \009if(scroll)then\
  2318. \009\009mslen = 1000\
  2319. \009else\
  2320. \009\009mslen = mlen+1\
  2321. \009end\
  2322. \009term.setCursorBlink(true)\
  2323. \009while ininp do\
  2324. \009\009local e = {os.pullEvent()}\
  2325. \009\009local inp = novaio.read(e,mslen,mlen-1,readxoff,y)\
  2326. \009\009novaio.setActive(true)\
  2327. \009\009if(inp)then \
  2328. \009\009\009ininp = false\
  2329. \009\009\009novaio.setActive(false)\
  2330. \009\009\009local inp = novaio.getInput()\
  2331. \009\009\009novaio.setInput(oinp)\
  2332. \009\009\009if(inp == startw)then\
  2333. \009\009\009\009inp = \"\"\
  2334. \009\009\009end\
  2335. \009\009\009return inp\
  2336. \009\009end\
  2337. \009\009-- Dont let the user out of the read!\
  2338. \009\009if(novaio.getActive() == \"false\")then novaio.setActive(true) end\
  2339. \009end\
  2340. end\
  2341. \
  2342. \
  2343. function isFileImage(file)\
  2344. \009local isImg = false\
  2345. \009local f = fs.open(file,\"r\")\
  2346. \009if(f)then\
  2347. \009\009if(tonumber(f.readAll():gsub(\"%s+\",\"\"),16) ~= nil) then\
  2348. \009\009\009 isImg = true\
  2349. \009\009end\
  2350. \009\009f.close()\
  2351. \009end\
  2352. \009return isImg\
  2353. end\
  2354. \
  2355. function getApisFrom(loc,apis)\
  2356. \009local inloc = false\
  2357. \009if(fs.isDir(loc))then\
  2358. \009\009inloc = true\
  2359. \009\009for i = 1, #apis do\
  2360. \009\009\009\009if(fs.exists(\"CrossBow/apis/\"..apis[i]))then\
  2361. \009\009\009\009\009apis[i] = \"CrossBow/apis/\" ..apis[i]\
  2362. \
  2363. \009\009\009\009else\
  2364. \009\009\009\009\009error(\"Program had to Quit: CrossBow install outdated or malformed. \")\
  2365. \009\009\009\009end\
  2366. \009\009end \
  2367. \009end\
  2368. \
  2369. \009for i = 1, #apis do\
  2370. \009\009if(inloc)then\
  2371. \009\009\009os.loadAPI((apis[i]))\
  2372. \009\009else\
  2373. \009\009\009os.loadAPI(shell.resolveProgram((apis[i])))\
  2374. \009\009end\
  2375. \009end\
  2376. \
  2377. \009return inloc\
  2378. end\
  2379. \
  2380. function colorwrite(str,smax,x,y,special)\
  2381. \009scp(x,y)\
  2382. \009\009local colorencode = {\
  2383. \009    ['&r'] = \"black\",\
  2384. \009    ['&1'] = \"blue\",\
  2385. \009    ['&2'] = \"green\",\
  2386. \009    ['&3'] = \"cyan\",\
  2387. \009    ['&4'] = \"red\",\
  2388. \009    ['&5'] = \"purple\",\
  2389. \009    ['&6'] = \"brown\",\
  2390. \009    ['&7'] = \"lightGray\",\
  2391. \009    ['&8'] = \"gray\",\
  2392. \009    ['&9'] = \"lightBlue\",\
  2393. \009    ['&a'] = \"lime\",\
  2394. \009    ['&b'] = \"orange\",\
  2395. \009    ['&c'] = \"pink\",\
  2396. \009    ['&d'] = \"magenta\",\
  2397. \009    ['&e'] = \"yellow\",\
  2398. \009    ['&f'] = \"white\",\
  2399. \009}\
  2400. \009if(special)then sbc(special) end\
  2401.    for a = 1, #str do\
  2402.        if(string.sub(str,a,a) == \"&\")then\
  2403.            if(colorencode[string.sub(str,a,a+1)] ~= nil)then\
  2404.                stc(colors[colorencode[string.sub(str,a,a+1)]])\
  2405.            end\
  2406.            str = string.sub(str,1,a-1) .. string.sub(str,a+1,#str)\
  2407.        else\
  2408.            write(string.sub(str,a,a))\
  2409.        end\
  2410.    end  \
  2411.    sbc(colors.white)\
  2412. end",
  2413.   },
  2414.   [ "apis/ugapi/" ] = {
  2415.     content = "--]] Language assigning [[--\
  2416. \
  2417. pos = term.setCursorPos\
  2418. bcolor = term.setBackgroundColor\
  2419. tcolor = term.setTextColor\
  2420. blink = term.setCursorBlink\
  2421. buffer = term.current().setVisible\
  2422. getpos = term.getCursorPos\
  2423. getbcolor = term.getBackgroundColor\
  2424. gettcolor = term.getTextColor\
  2425. printslow = textutils.slowPrint\
  2426. clr = term.clear\
  2427. clrln = term.clearLine\
  2428. clrlny = function(y)\
  2429.  local x,_ = getpos()\
  2430.  pos(x,y)\
  2431.  clrln()\
  2432. end\
  2433. clrlnycolor = function(col,y) bcolor(col) clrlny(y) end\
  2434. box = paintutils.drawFilledBox\
  2435. hbox = paintutils.drawBox\
  2436. drawimage = function(img,x,y) paintutils.drawImage(paintutils.loadImage(img),x,y) end\
  2437. \
  2438. \
  2439. -- ]] Write functions [[--\
  2440. function writexy(text,x,y)\
  2441.  term.setCursorPos(x,y)\
  2442.  term.write(text)\
  2443. end\
  2444. \
  2445. function writec(text)\
  2446.  local w, h = term.getSize()\
  2447.  term.setCursorPos(w/2 - #text/2, (h/2)- 1)\
  2448.  term.write(text)\
  2449. end\
  2450. \
  2451. function writecy(text,y)\
  2452.    local w,_ = term.getSize()\
  2453.    term.setCursorPos(w/2 - #text/2, y)\
  2454.    term.write(text)\
  2455. end\
  2456. \
  2457. \
  2458. \
  2459. -- ]] Print functions [[--\
  2460. function printc(text)\
  2461.  local w,h = term.getSize()\
  2462.  term.setCursorPos( (w/2) - #text/2,(h/2) - 1)\
  2463.  print(text)\
  2464. end\
  2465. \
  2466. function printcy(text,y)\
  2467.  local w,_ = term.getSize()\
  2468.  term.setCursorPos(w/2 - #text/2, y)\
  2469.  print(text)\
  2470. end\
  2471. \
  2472. function println(text)\
  2473.   local xx, yy = term.getCursorPos()\
  2474.   term.setCursorPos(xx,yy+1)\
  2475.   print(text)\
  2476. end\
  2477. \
  2478. function printxy(text,x,y)\
  2479.  term.setCursorPos(x,y)\
  2480.  print(text)\
  2481. end\
  2482. \
  2483. --]] Transitions [[--\
  2484. function fadeIn(time)\
  2485.   \
  2486.   local ctbl = {\
  2487.     'black',\
  2488.     'gray',\
  2489.     'lightGray',\
  2490.     'white',\
  2491.   }\
  2492. \
  2493.   for i = 1, #ctbl do\
  2494.      term.setBackgroundColor(colors[ ctbl[i] ])\
  2495.      term.clear()\
  2496.      sleep(time)  \
  2497.   end\
  2498. end\
  2499. \
  2500. function fadeOut(time)\
  2501.   \
  2502.   local ctbl = {\
  2503.     'white',\
  2504.     'lightGray',\
  2505.     'gray',\
  2506.     'black',\
  2507.   }\
  2508.   \
  2509.   for i = 1, #ctbl do\
  2510.      term.setBackgroundColor(colors[ ctbl[i] ])\
  2511.      term.clear()\
  2512.      sleep(time)  \
  2513.   end\
  2514. end\
  2515. \
  2516. \
  2517. function fadecolors(time,ctbl)\
  2518.  for i = 1, #ctbl do\
  2519.    term.setBackgroundColor(colors[ctbl[i]])\
  2520.    term.clear()\
  2521.    sleep(time)\
  2522.  end\
  2523. end\
  2524. \
  2525. function transitionIn(pixeltime, linetime,smoothness)\
  2526. \009local w, h = term.getSize()\
  2527. \009local left = true\
  2528. \009for hh = 1, h/2+1 do\
  2529. \009\009for ww = 1, w do\
  2530. \009\009\009bcolor(colors.white)\
  2531. \009\009\009if(left)then writexy(string.rep(\" \",smoothness),w-(ww-1),hh) else writexy(\" \",ww,hh) end\
  2532. \009\009\009bcolor(colors.white)\
  2533. \009\009\009if(left)then writexy(string.rep(\" \",smoothness),ww,h-(hh-1) ) else writexy(\" \",w-(ww-1),h-(hh-1)) end\
  2534. \009\009\009if(pixeltime > 0) then sleep(pixeltime) end\
  2535. \009\009end\
  2536. \009\009if(left)then left = false else left = true end\
  2537. \009\009if(linetime > 0)then sleep(linetime) end\
  2538. \009end\
  2539. \
  2540. end\
  2541. \
  2542. function transitionOut(pixeltime, linetime,smoothness)\
  2543. \009local w, h = term.getSize()\
  2544. \009local left = true\
  2545. \009for hh = 1, h/2+1 do\
  2546. \009\009for ww = 1, w do\
  2547. \009\009\009bcolor(colors.black)\
  2548. \009\009\009if(left)then writexy(string.rep(\" \",smoothness),w-(ww-1),hh) else writexy(\" \",ww,hh) end\
  2549. \009\009\009bcolor(colors.black)\
  2550. \009\009\009if(left)then writexy(string.rep(\" \",smoothness),ww,h-(hh-1) ) else writexy(\" \",w-(ww-1),h-(hh-1)) end\
  2551. \009\009\009if(pixeltime > 0) then sleep(pixeltime) end\
  2552. \009\009end\
  2553. \009\009if(left)then left = false else left = true end\
  2554. \009\009if(linetime > 0)then sleep(linetime) end\
  2555. \009end\
  2556. \
  2557. end\
  2558. \
  2559. --]] Button API [[ -- \
  2560. \
  2561. function newButton(name,x,y,width,height,namecolor,color,activecolor)\
  2562. \009local button = {\
  2563. \009\009name = name,\
  2564. \009\009x = x,\
  2565. \009\009y = y,\
  2566. \009\009w = width-1,\
  2567. \009\009h = height-1,\
  2568. \009\009tcol = namecolor,\
  2569. \009\009col = color,\
  2570. \009\009acol = activecolor,\
  2571. \009\009active = false,\
  2572. \009\009rfun = function() end,\
  2573. \009\009fun = function() end,\
  2574. \
  2575. \009\009draw = function(self)\
  2576. \009\009\009local dbcol\
  2577. \009\009\009if(self.active)then dbcol = self.acol \
  2578. \009\009\009else dbcol = self.col end\
  2579. \009\009\009box(self.x,self.y,self.x+self.w,self.y+self.h,dbcol)\
  2580. \009\009\009-- Center text on button --\
  2581. \009\009\009tcolor(self.tcol)\
  2582. \009\009\009writexy(self.name,\
  2583. \009\009\009\009( (self.x+self.w/2) - (#self.name/2) ),\
  2584. \009\009\009\009( (self.y+self.h) - (self.h/2) )\
  2585. \009\009\009)\
  2586. \009\009end,\
  2587. \
  2588. \009\009update = function(self,ev)\
  2589. \009\009\009if(ev[1] == \"mouse_click\")then\
  2590. \009\009\009\009-- Display active for a bit then switch off\
  2591. \009\009\009\009if(ev[3] >= self.x and ev[3] <= self.x + self.w and ev[4] >= self.y and ev[4] <= self.y + self.h)then\
  2592. \009\009\009\009\009self:setActive(true)\
  2593. \009\009\009\009\009sleep(0.2)\
  2594. \009\009\009\009\009self:setActive(false)\
  2595. \
  2596. \009\009\009\009\009if(ev[2] == 1)then self.fun() end\
  2597. \009\009\009\009\009if(ev[2] == 2)then self.rfun() end\
  2598. \
  2599. \009\009\009\009end\
  2600. \009\009\009end\
  2601. \009\009end,\
  2602. \
  2603. \009\009onPress = function(self,func)\
  2604. \009\009\009self.fun = func\
  2605. \009\009end,\
  2606. \
  2607. \009\009setName = function(self,nname)\
  2608. \009\009\009self.name = nname\
  2609. \009\009end,\
  2610. \
  2611. \009\009getName = function(self,nname)\
  2612. \009\009\009return self.name\
  2613. \009\009end,\
  2614. \
  2615. \009\009setPos = function(self,x,y)\
  2616. \009\009\009self.x = x\
  2617. \009\009\009self.y = y\
  2618. \009\009\009self:draw()\
  2619. \009\009end,\
  2620. \
  2621. \009\009getPos = function(self)\
  2622. \009\009\009return self.x, self.y\
  2623. \009\009end,\
  2624. \
  2625. \009\009onRightPress = function(self,func)\
  2626. \009\009\009self.rfun = func\
  2627. \009\009end,\
  2628. \
  2629. \009\009setActive = function(self,act)\
  2630. \009\009\009self.active = act\
  2631. \009\009\009self:draw()\
  2632. \009\009end,\
  2633. \
  2634. \009\009getActive = function(self)\
  2635. \009\009\009return self.active\
  2636. \009\009end,\
  2637. \
  2638. \009}\
  2639. \
  2640. \009return button\
  2641. end\
  2642. \
  2643. -- Menu API --\
  2644. function newMenu(x,y,width,height,bcolor)\
  2645. \
  2646. \009local menu = {\
  2647. \009\009x = x,\
  2648. \009\009y = y,\
  2649. \009\009w = width,\
  2650. \009\009h = height,\
  2651. \009\009bcol = bcolor,\
  2652. \009\009options={},\
  2653. \009\009presets={},\
  2654. \
  2655. \009\009draw = function(self)\
  2656. \009\009\009box(self.x,self.y,self.x+self.w-1,self.y+self.h-1,self.bcol)\
  2657. \009\009\009for i = 1, #self.options do\
  2658. \009\009\009\009if(self.options[i].name ~= nil)then\
  2659. \009\009\009\009\009local bcol = self.presets[self.options[i].pset].bc\
  2660. \009\009\009\009\009local tcol = self.presets[self.options[i].pset].tc\
  2661. \
  2662. \009\009\009\009\009if(self.options[i].active)then\
  2663. \009\009\009\009\009\009bcol = self.presets[self.options[i].pset].ab\
  2664. \009\009\009\009\009\009tcol = self.presets[self.options[i].pset].at\
  2665. \009\009\009\009\009end\
  2666. \
  2667. \009\009\009\009\009term.setBackgroundColor(bcol)\
  2668. \009\009\009\009\009term.setTextColor(tcol)\
  2669. \
  2670. \009\009\009\009\009pos( self.x, self.y+(i-1) )\
  2671. \
  2672. \009\009\009\009\009write(self.options[i].name)\
  2673. \009\009\009\009end\
  2674. \009\009\009end\
  2675. \009\009end,\
  2676. \
  2677. \009\009update = function(self, ev)\
  2678. \009\009\009if(ev[1] == \"mouse_click\")then\
  2679. \
  2680. \009\009\009\009for i = 1, #self.options do\
  2681. \009\009\009\009\009if(self.options[i].name ~= nil)then\
  2682. \009\009\009\009\009\009if(ev[3] >= self.x and ev[3] <= #self.options[i].name + self.x\
  2683. \009\009\009\009\009\009  and ev[4] == self.y + (i-1))then\
  2684. \009\009\009\009\009\009\009self:setActiveOption(self.options[i].name,true)\
  2685. \009\009\009\009\009\009\009sleep(0.2)\
  2686. \009\009\009\009\009\009\009self:setActiveOption(self.options[i].name,false)\
  2687. \
  2688. \009\009\009\009\009\009\009self.options[i].act()\
  2689. \009\009\009\009\009\009end\
  2690. \009\009\009\009\009end\
  2691. \009\009\009\009end\
  2692. \
  2693. \009\009\009end\
  2694. \009\009end,\
  2695. \
  2696. \009\009addOption = function(self,name,preset,action)\
  2697. \009\009\009if(self.presets[preset].tc ~= nil)then\
  2698. \009\009\009\009self.options[#self.options+1] = {name=name,pset=preset,act=action,active=false}\
  2699. \009\009\009else\
  2700. \009\009\009\009error(\"UGAPI: ->menu->addOption: No such preset.\")\
  2701. \009\009\009end\
  2702. \009\009end,\
  2703. \
  2704. \009\009setPreset = function(self,name,tcolor,bcolor,atcolor,abcolor,action)\
  2705. \009\009\009self.presets[name] = {tc=tcolor,bc=bcolor,at=atcolor,ab=abcolor}\
  2706. \009\009end,\
  2707. \
  2708. \009\009addWhiteSpace = function(self)\
  2709. \009\009\009self.options[#self.options+1] = {name=nil}\
  2710. \009\009end,\
  2711. \
  2712. \009\009setActiveOption = function(self,nname,isact)\
  2713. \009\009\009for i = 1, #self.options do\
  2714. \009\009\009\009if(self.options[i].name == nname and nname ~= nil)then\
  2715. \009\009\009\009\009self.options[i].active = isact\
  2716. \009\009\009\009end\
  2717. \009\009\009end\
  2718. \
  2719. \009\009\009self:draw()\
  2720. \009\009end,\
  2721. \
  2722. \009}\
  2723. \
  2724. \009return menu \
  2725. end",
  2726.   },
  2727.   [ "apis/futils/" ] = {
  2728.     content = "function file_readAll(file,s)\
  2729.    local f = fs.open(file,\"r\")\
  2730.    local cont = f.readAll()\
  2731.    f.close()\
  2732.    if(s)then return textutils.unserialize(s) end\
  2733.    return cont\
  2734. end\
  2735. function file_readLine(file,s)\
  2736.    local f = fs.open(file,\"r\")\
  2737.    local cont = f.readLine()\
  2738.    f.close()\
  2739.    if(s)then return textutils.unserialize(s) end\
  2740.    return cont\
  2741. end\
  2742. function file_write(file,data,s)\
  2743.    local f = fs.open(file,\"w\")\
  2744.    if(s)then f.write(textutils.serialize(data)) else\
  2745.    f.write(data) end\
  2746.    f.close()\
  2747. end\
  2748. function file_writeline(file,data,s)\
  2749.    local f = fs.open(file,\"w\")\
  2750.    if(s)then f.writeLine(textutils.serialize(data)) else\
  2751.    f.writeLine(data) end\
  2752.    f.close()\
  2753. end\
  2754. local function formatpath(path)\
  2755. \009local pathtbl={}\
  2756.    local s=\"\"\
  2757.    local pathsize=0\
  2758.    -- Divide string and count the number of \
  2759.    -- divisions.\
  2760.     for str in string.gmatch(path, \"([^/]+)\") do\
  2761.         pathtbl[#pathtbl+1] = str  \
  2762.     end\
  2763.     table.remove(pathtbl,1)\
  2764.     for i = 1, #pathtbl do\
  2765.     \009s = s .. pathtbl[i] .. \"/\"\
  2766.     end\
  2767.    return s\
  2768. end\
  2769. \
  2770. local function getcontent(data,wdata,ctbl)\
  2771.    -- Returns a table --\
  2772.    for k, v in pairs(fs.list(data)) do\
  2773.     \
  2774.      if(fs.isDir(data..\"/\"..v) )then\
  2775.        getcontent(data..v..\"/\",v..\"/\",ctbl)\
  2776.      else\
  2777.      --print(data..v)\
  2778.        local f = fs.open(data..v,\"r\")\
  2779.        ctbl[formatpath(data..v)] = {content=f.readAll()}\
  2780.        f.close()\
  2781.      end\
  2782.    end\
  2783.     return textutils.serialize(ctbl)\
  2784. end\
  2785. function archive(data,export)\
  2786.    local content = {}\
  2787.    content = getcontent('/' .. data .. \"/\",\"/\",content)\
  2788.    file_write(export,content)\
  2789.    return true\
  2790. end\
  2791. \
  2792. function extract(file,to)\
  2793.    local cont = textutils.unserialize(file_readAll(file))\
  2794.    for k,v in pairs(cont) do\
  2795.         file_write(to .. \"/\" .. k,v.content)\
  2796.    end\
  2797. end",
  2798.   },
  2799.   [ "apis/ziputils/" ] = {
  2800.     content = "local function formatpath(path)\
  2801. \009local pathtbl={}\
  2802.    local s=\"\"\
  2803.    local pathsize=0\
  2804.    -- Divide string and count the number of \
  2805.    -- divisions.\
  2806.     for str in string.gmatch(path, \"([^/]+)\") do\
  2807.         pathtbl[#pathtbl+1] = str  \
  2808.     end\
  2809.     for k, v in pairs(pathtbl) do\
  2810.         pathsize=k\
  2811.     end\
  2812.     pathsize = pathsize - 1\
  2813.    -- Based on how large the user wants the string to be \
  2814.    -- add only the string bits that led up to the user defined\
  2815.    -- size.\
  2816.    for k, v in pairs(pathtbl) do\
  2817.        if(k <= pathsize)then s = s..pathtbl[k]..\"/\" end\
  2818.    end\
  2819.    return s\
  2820. end\
  2821. local function pathlen(path)\
  2822. \009local pathtbl={}\
  2823.    local s=\"\"\
  2824.    local pathsize=0\
  2825.    -- Divide string and count the number of \
  2826.    -- divisions.\
  2827.     for str in string.gmatch(path, \"([^/]+)\") do\
  2828.         pathtbl[#pathtbl+1] = str  \
  2829.     end\
  2830.     return #pathtbl\
  2831. end\
  2832. local function filterdirpath(dir,path)\
  2833. \009local pathtbl={}\
  2834.    local s=\"\"\
  2835.    local pathsize=0\
  2836.    -- Divide string and count the number of \
  2837.    -- divisions.\
  2838.     local la = 0\
  2839.     for str in string.gmatch(path, \"([^/]+)\") do\
  2840.     \009if(la >= pathlen(dir))then\
  2841.         \009pathtbl[#pathtbl+1] = str  \
  2842.        end\
  2843.        la = la + 1\
  2844.     end\
  2845.     \009for i = 1, #pathtbl do\
  2846.     \009\009s  = s .. pathtbl[i] .. \"/\"\
  2847.     \009end \
  2848.    return s\
  2849. end\
  2850. local function comparesubpath(flpath,subpath)\
  2851. \009return (formatpath(subpath) == flpath) or (subpath:find(flpath) and pathlen(formatpath(subpath)) == pathlen(flpath)+1 )\
  2852. end\
  2853. local function comparefolderpath(flpath,subpath)\
  2854. \009return \
  2855. end\
  2856. local function getend(path)\
  2857. \009local pathtbl={}\
  2858.    local s=\"\"\
  2859.    local pathsize=0\
  2860.    -- Divide string and count the number of \
  2861.    -- divisions.\
  2862.     for str in string.gmatch(path, \"([^/]+)\") do\
  2863.         pathtbl[#pathtbl+1] = str  \
  2864.     end\
  2865.     return pathtbl[#pathtbl]\
  2866. end\
  2867. function iszip(file)\
  2868. \009local f = fs.open(file,\"r\")\
  2869. \009local c = f.readAll()\
  2870. \009f.close()\
  2871. \009return type(c) == \"table\"\
  2872. end\
  2873. local function intable(tbl,am)\
  2874. \009for i = 1, #tbl do\
  2875. \009\009if(tbl[i].n == am)then\
  2876. \009\009\009return true\
  2877. \009\009end\
  2878. \009end\
  2879. \009return false \
  2880. end\
  2881. function ziplist(zip,dir)\
  2882. \009local folders = {}\
  2883. \009local files = {}\
  2884. \009local list = {}\
  2885. \009local startls = false\
  2886. \009local f = fs.open(zip,\"r\")\
  2887. \009local c = (f.readAll())\
  2888. \009c = textutils.unserialize(c)\
  2889. \009f.close()\
  2890. \009for k, v in pairs(c) do\
  2891. \009\009if(comparesubpath(dir,k))then\
  2892. \009\009\009if(pathlen(formatpath(k)) == pathlen(dir))then\
  2893. \009\009\009\009files[getend(k)] = {t=\"file\",c=v.content}\
  2894. \009\009\009\009--print(\"File:\" .. getend(k))\
  2895. \009\009\009\009--print(\"------------------\")\
  2896. \009\009\009\009--os.pullEvent(\"key\")\
  2897. \009\009\009elseif(pathlen(formatpath(k)) < 2+pathlen(dir) and \
  2898. \009\009\009not intable(folders,filterdirpath(dir,formatpath(k))))then\
  2899. \009\009\009\009folders[#folders+1] = {n=filterdirpath(dir,formatpath(k)),t=\"folder\",c=v.content}\
  2900. \009\009\009\009--print(\"Folder: \" .. filterdirpath(dir,formatpath(k)))\
  2901. \009\009\009\009--os.pullEvent(\"key\")\
  2902. \009\009\009end\
  2903. \009\009end\
  2904. \009end\
  2905. \009for k, v in pairs(files) do\
  2906. \009\009folders[#folders+1] = {n=k,type=v.t,data=v.c}\
  2907. \009end\
  2908. \009for i = 1, #folders do\
  2909. \009\009list[i] = {n=folders[i].n,type=folders[i].t,data=folders[i].c}\
  2910. \009end\
  2911. \009return list\
  2912. end",
  2913.   },
  2914.   [ "programs/test/" ] = {
  2915.     content = "\
  2916. print(getPinnedNames())\
  2917. print(pinnednames)",
  2918.   },
  2919.   [ "programs/lightshot/" ] = {
  2920.     content = "\
  2921. --  \
  2922. --  Lighshot Screen Recorder\
  2923. --  Made by GravityScore\
  2924. --  \
  2925. \
  2926. \
  2927. --  -------- Variables\
  2928. \
  2929. --  Lower the loop rate to decrease recording lag but to decrease compression\
  2930. --  Do not set to below 50 else the file could become really big\
  2931. local loopRate = 300\
  2932. \
  2933. -- Version\
  2934. local version = \"1.5\"\
  2935. \
  2936. -- Terminal\
  2937. local oldTerm = {}\
  2938. local newTerm = {}\
  2939. local w, h = term.getSize()\
  2940. \
  2941. -- Events\
  2942. local event_exitRecording = \"lightshot_exitRecordingEvent\"\
  2943. \
  2944. -- Locations\
  2945. local lightshotURL = \"https://raw.github.com/GravityScore/Lightshot/master/lightshot.lua\"\
  2946. local lightshotLocation = \"/\" .. shell.getRunningProgram()\
  2947. local recordLocation = \"/.lightshot_recording\"\
  2948. \
  2949. -- Variables\
  2950. local clock = 0\
  2951. local nfaRecording = false\
  2952. local paused = false\
  2953. local handle = nil\
  2954. \
  2955. local recordHeader = [[\
  2956. --  \
  2957. --  Recorded by Lightshot\
  2958. --  \
  2959. \
  2960. local function sp(...) return sleep(...) end\
  2961. local function c(...) return term.write(...) end\
  2962. local function d(...) return term.setCursorPos(...) end\
  2963. local function e(...) return term.setBackgroundColor(...) end\
  2964. local function f(...) return term.setTextColor(...) end\
  2965. local function g(...) return term.clear(...) end\
  2966. local function h(...) return term.clearLine() end\
  2967. local function i(...) return term.setCursorBlink(...) end\
  2968. local function j(...) return term.scroll(...) end\
  2969. \
  2970. -- sD here...\
  2971. \
  2972. ]]\
  2973. \
  2974. \
  2975. --  -------- Utilities\
  2976. \
  2977. local function modRead(properties)\
  2978. \009local w, h = term.getSize()\
  2979. \009local defaults = {replaceChar = nil, history = nil, visibleLength = nil, textLength = nil, \
  2980. \009\009liveUpdates = nil, exitOnKey = nil}\
  2981. \009if not properties then properties = {} end\
  2982. \009for k, v in pairs(defaults) do if not properties[k] then properties[k] = v end end\
  2983. \009if properties.replaceChar then properties.replaceChar = properties.replaceChar:sub(1, 1) end\
  2984. \009if not properties.visibleLength then properties.visibleLength = w end\
  2985. \
  2986. \009local sx, sy = term.getCursorPos()\
  2987. \009local line = \"\"\
  2988. \009local pos = 0\
  2989. \009local historyPos = nil\
  2990. \
  2991. \009local function redraw(repl)\
  2992. \009\009local scroll = 0\
  2993. \009\009if properties.visibleLength and sx + pos > properties.visibleLength + 1 then \
  2994. \009\009\009scroll = (sx + pos) - (properties.visibleLength + 1)\
  2995. \009\009end\
  2996. \
  2997. \009\009term.setCursorPos(sx, sy)\
  2998. \009\009local a = repl or properties.replaceChar\
  2999. \009\009if a then term.write(string.rep(a, line:len() - scroll))\
  3000. \009\009else term.write(line:sub(scroll + 1, -1)) end\
  3001. \009\009term.setCursorPos(sx + pos - scroll, sy)\
  3002. \009end\
  3003. \
  3004. \009local function sendLiveUpdates(event, ...)\
  3005. \009\009if type(properties.liveUpdates) == \"function\" then\
  3006. \009\009\009local ox, oy = term.getCursorPos()\
  3007. \009\009\009properties.liveUpdates(line, event, ...)\
  3008. \009\009\009if a == true and data == nil then\
  3009. \009\009\009\009term.setCursorBlink(false)\
  3010. \009\009\009\009return line\
  3011. \009\009\009elseif a == true and data ~= nil then\
  3012. \009\009\009\009term.setCursorBlink(false)\
  3013. \009\009\009\009return data\
  3014. \009\009\009end\
  3015. \009\009\009term.setCursorPos(ox, oy)\
  3016. \009\009end\
  3017. \009end\
  3018. \
  3019. \009term.setCursorBlink(true)\
  3020. \009while true do\
  3021. \009\009local e, but, x, y, p4, p5 = os.pullEvent()\
  3022. \
  3023. \009\009if e == \"char\" then\
  3024. \009\009\009local s = false\
  3025. \009\009\009if properties.textLength and line:len() < properties.textLength then s = true\
  3026. \009\009\009elseif not properties.textLength then s = true end\
  3027. \
  3028. \009\009\009local canType = true\
  3029. \009\009\009if not properties.grantPrint and properties.refusePrint then\
  3030. \009\009\009\009local canTypeKeys = {}\
  3031. \009\009\009\009if type(properties.refusePrint) == \"table\" then\
  3032. \009\009\009\009\009for _, v in pairs(properties.refusePrint) do\
  3033. \009\009\009\009\009\009table.insert(canTypeKeys, tostring(v):sub(1, 1))\
  3034. \009\009\009\009\009end\
  3035. \009\009\009\009elseif type(properties.refusePrint) == \"string\" then\
  3036. \009\009\009\009\009for char in properties.refusePrint:gmatch(\".\") do\
  3037. \009\009\009\009\009\009table.insert(canTypeKeys, char)\
  3038. \009\009\009\009\009end\
  3039. \009\009\009\009end\
  3040. \009\009\009\009for _, v in pairs(canTypeKeys) do if but == v then canType = false end end\
  3041. \009\009\009elseif properties.grantPrint then\
  3042. \009\009\009\009canType = false\
  3043. \009\009\009\009local canTypeKeys = {}\
  3044. \009\009\009\009if type(properties.grantPrint) == \"table\" then\
  3045. \009\009\009\009\009for _, v in pairs(properties.grantPrint) do\
  3046. \009\009\009\009\009\009table.insert(canTypeKeys, tostring(v):sub(1, 1))\
  3047. \009\009\009\009\009end\
  3048. \009\009\009\009elseif type(properties.grantPrint) == \"string\" then\
  3049. \009\009\009\009\009for char in properties.grantPrint:gmatch(\".\") do\
  3050. \009\009\009\009\009\009table.insert(canTypeKeys, char)\
  3051. \009\009\009\009\009end\
  3052. \009\009\009\009end\
  3053. \009\009\009\009for _, v in pairs(canTypeKeys) do if but == v then canType = true end end\
  3054. \009\009\009end\
  3055. \
  3056. \009\009\009if s and canType then\
  3057. \009\009\009\009line = line:sub(1, pos) .. but .. line:sub(pos + 1, -1)\
  3058. \009\009\009\009pos = pos + 1\
  3059. \009\009\009\009redraw()\
  3060. \009\009\009end\
  3061. \009\009elseif e == \"key\" then\
  3062. \009\009\009if but == keys.enter then break\
  3063. \009\009\009elseif but == keys.left then if pos > 0 then pos = pos - 1 redraw() end\
  3064. \009\009\009elseif but == keys.right then if pos < line:len() then pos = pos + 1 redraw() end\
  3065. \009\009\009elseif (but == keys.up or but == keys.down) and properties.history then\
  3066. \009\009\009\009redraw(\" \")\
  3067. \009\009\009\009if but == keys.up then\
  3068. \009\009\009\009\009if historyPos == nil and #properties.history > 0 then \
  3069. \009\009\009\009\009\009historyPos = #properties.history\
  3070. \009\009\009\009\009elseif historyPos > 1 then \
  3071. \009\009\009\009\009\009historyPos = historyPos - 1\
  3072. \009\009\009\009\009end\
  3073. \009\009\009\009elseif but == keys.down then\
  3074. \009\009\009\009\009if historyPos == #properties.history then historyPos = nil\
  3075. \009\009\009\009\009elseif historyPos ~= nil then historyPos = historyPos + 1 end\
  3076. \009\009\009\009end\
  3077. \
  3078. \009\009\009\009if properties.history and historyPos then\
  3079. \009\009\009\009\009line = properties.history[historyPos]\
  3080. \009\009\009\009\009pos = line:len()\
  3081. \009\009\009\009else\
  3082. \009\009\009\009\009line = \"\"\
  3083. \009\009\009\009\009pos = 0\
  3084. \009\009\009\009end\
  3085. \
  3086. \009\009\009\009redraw()\
  3087. \009\009\009\009sendLiveUpdates(\"history\")\
  3088. \009\009\009elseif but == keys.backspace and pos > 0 then\
  3089. \009\009\009\009redraw(\" \")\
  3090. \009\009\009\009line = line:sub(1, pos - 1) .. line:sub(pos + 1, -1)\
  3091. \009\009\009\009pos = pos - 1\
  3092. \009\009\009\009redraw()\
  3093. \009\009\009\009sendLiveUpdates(\"delete\")\
  3094. \009\009\009elseif but == keys.home then\
  3095. \009\009\009\009pos = 0\
  3096. \009\009\009\009redraw()\
  3097. \009\009\009elseif but == keys.delete and pos < line:len() then\
  3098. \009\009\009\009redraw(\" \")\
  3099. \009\009\009\009line = line:sub(1, pos) .. line:sub(pos + 2, -1)\
  3100. \009\009\009\009redraw()\
  3101. \009\009\009\009sendLiveUpdates(\"delete\")\
  3102. \009\009\009elseif but == keys[\"end\"] then\
  3103. \009\009\009\009pos = line:len()\
  3104. \009\009\009\009redraw()\
  3105. \009\009\009elseif properties.exitOnKey then \
  3106. \009\009\009\009if but == properties.exitOnKey or (properties.exitOnKey == \"control\" and \
  3107. \009\009\009\009\009\009(but == 29 or but == 157)) then \
  3108. \009\009\009\009\009term.setCursorBlink(false)\
  3109. \009\009\009\009\009return nil\
  3110. \009\009\009\009end\
  3111. \009\009\009end\
  3112. \009\009end\
  3113. \
  3114. \009\009sendLiveUpdates(e, but, x, y, p4, p5)\
  3115. \009end\
  3116. \
  3117. \009term.setCursorBlink(false)\
  3118. \009if line ~= nil then line = line:gsub(\"^%s*(.-)%s*$\", \"%1\") end\
  3119. \009return line\
  3120. end\
  3121. \
  3122. local function centerPrint(text, ny)\
  3123. \009if type(text) == \"table\" then for _, v in pairs(text) do centerPrint(v) end\
  3124. \009else\
  3125. \009\009local x, y = term.getCursorPos()\
  3126. \009\009local w, h = term.getSize()\
  3127. \009\009term.setCursorPos(w/2 - text:len()/2 + (#text % 2 == 0 and 1 or 0), ny or y)\
  3128. \009\009print(text)\
  3129. \009end\
  3130. end\
  3131. \
  3132. \
  3133. --  -------- Updating\
  3134. \
  3135. local function download(url, path)\
  3136. \009for i = 1, 3 do\
  3137. \009\009local response = http.get(url)\
  3138. \009\009if response then\
  3139. \009\009\009local data = response.readAll()\
  3140. \009\009\009response.close()\
  3141. \009\009\009if path then\
  3142. \009\009\009\009local f = io.open(path, \"w\")\
  3143. \009\009\009\009f:write(data)\
  3144. \009\009\009\009f:close()\
  3145. \009\009\009end\
  3146. \009\009\009return true\
  3147. \009\009end\
  3148. \009end\
  3149. \
  3150. \009return false\
  3151. end\
  3152. \
  3153. local function updateClient()\
  3154. \009local updateLocation = \"/.lightshot-update\"\
  3155. \009fs.delete(updateLocation)\
  3156. \
  3157. \009download(lightshotURL, updateLocation)\
  3158. \009local a = io.open(updateLocation, \"r\")\
  3159. \009local b = io.open(lightshotLocation, \"r\")\
  3160. \009local new = a:read(\"*a\")\
  3161. \009local cur = b:read(\"*a\")\
  3162. \009a:close()\
  3163. \009b:close()\
  3164. \
  3165. \009if cur ~= new then\
  3166. \009\009fs.delete(lightshotLocation)\
  3167. \009\009fs.move(updateLocation, lightshotLocation)\
  3168. \009\009return true\
  3169. \009else\
  3170. \009\009fs.delete(updateLocation)\
  3171. \009\009return false\
  3172. \009end\
  3173. end\
  3174. \
  3175. \
  3176. --  -------- Compression\
  3177. \
  3178. local sD = {{}}\
  3179. local cD = {}\
  3180. \
  3181. local function proccessFunction(data)\
  3182. \009if data:len() < 8 then\
  3183. \009\009if data:sub(-1,-1) == \"]\" then return \"[[\" .. data .. \"] .. \\\"]\\\"\"\
  3184. \009\009else return \"[[\" .. data .. \"]]\" end\
  3185. \009end\
  3186. \009if cD[v] then return cD[v] end\
  3187. \009for k, v in pairs(sD[#sD]) do\
  3188. \009\009if v == data then\
  3189. \009\009\009cD[v] = (\"sD[\" .. #sD .. \"][\" .. k .. \"]\")\
  3190. \009\009\009return(\"sD[\" .. #sD .. \"][\" .. k .. \"]\")\
  3191. \009\009end\
  3192. \009end\
  3193. \009table.insert(sD[#sD], data)\
  3194. \009local returnData = (\"sD[\".. #sD .. \"][\" .. #sD[#sD] .. \"]\")\
  3195. \009if #sD[#sD] > loopRate then sD[#sD + 1] = {} end\
  3196. \009return returnData\
  3197. end\
  3198. \
  3199. \
  3200. --  -------- Terminal Override\
  3201. \
  3202. local function add(...)\
  3203. \009if not handle then\
  3204. \009\009if fs.exists(recordLocation) then\
  3205. \009\009\009handle = io.open(recordLocation, \"a\")\
  3206. \009\009else\
  3207. \009\009\009handle = io.open(recordLocation, \"w\")\
  3208. \009\009end\
  3209. \009end\
  3210. \
  3211. \009for _, v in pairs({...}) do\
  3212. \009\009handle:write(v)\
  3213. \009end\
  3214. end\
  3215. \
  3216. local bg, tc, blnk = -1, -1, nil\
  3217. for k, v in pairs(term.native()) do oldTerm[k] = v end\
  3218. \
  3219. newTerm.write = function(...)\
  3220. \009local text = \"\"\
  3221. \009for k, v in pairs({...}) do text = text .. tostring(v) end\
  3222. \
  3223. \009local a = \"\"\
  3224. \009if not paused and os.clock() - clock > 0 then\
  3225. \009\009a = \"sp(\" .. os.clock() - clock .. \") \"\
  3226. \009end\
  3227. \009text = proccessFunction(text)\
  3228. \009local b = \"c(\" .. text .. \")\\n\"\
  3229. \
  3230. \009add(a .. b)\
  3231. \009clock = os.clock()\
  3232. \
  3233. \009if not nfaRecording then return oldTerm.write(...) end\
  3234. end\
  3235. \
  3236. newTerm.setCursorPos = function(x, y)\
  3237. \009local a = \"\"\
  3238. \009if not paused and os.clock() - clock > 0 then\
  3239. \009\009a = \"sp(\" .. os.clock() - clock .. \") \"\
  3240. \009end\
  3241. \009add(a .. \"d(\" .. tostring(x) .. \", \" .. tostring(y) .. \")\\n\")\
  3242. \009clock = os.clock()\
  3243. \
  3244. \009return oldTerm.setCursorPos(x, y)\
  3245. end\
  3246. \
  3247. newTerm.getCursorPos = function(...) return oldTerm.getCursorPos(...) end\
  3248. \
  3249. newTerm.setBackgroundColor = function(col)\
  3250. \009if bg ~= col then\
  3251. \009\009local a = \"\"\
  3252. \009\009if not paused and not nfaRecording and os.clock() - clock > 0 then\
  3253. \009\009\009a = \"sp(\" .. os.clock() - clock .. \") \"\
  3254. \009\009end\
  3255. \
  3256. \009\009add(a .. \"e(\" .. tostring(col) .. \")\\n\")\
  3257. \009\009clock = os.clock()\
  3258. \009\009bg = col\
  3259. \009end\
  3260. \
  3261. \009return oldTerm.setBackgroundColor(col)\
  3262. end\
  3263. \
  3264. newTerm.setTextColor = function(col)\
  3265. \009if tc ~= col then\
  3266. \009\009local a = \"\"\
  3267. \009\009if not paused and not nfaRecording and os.clock() - clock > 0 then\
  3268. \009\009\009a = \"sp(\" .. os.clock() - clock .. \") \"\
  3269. \009\009end\
  3270. \
  3271. \009\009add(a .. \"f(\" .. tostring(col) .. \")\\n\")\
  3272. \009\009clock = os.clock()\
  3273. \009\009tc = col\
  3274. \009end\
  3275. \
  3276. \009return oldTerm.setTextColor(col)\
  3277. end\
  3278. \
  3279. newTerm.setBackgroundColour = function(col) return term.setBackgroundColor(col) end\
  3280. newTerm.setTextColour = function(col) return term.setTextColor(col) end\
  3281. \
  3282. newTerm.clear = function(...)\
  3283. \009local a = \"\"\
  3284. \009if not paused and os.clock() - clock > 0 then\
  3285. \009\009a = \"sp(\" .. os.clock() - clock .. \") \"\
  3286. \009end\
  3287. \009add(a .. \"g()\\n\")\
  3288. \009clock = os.clock()\
  3289. \
  3290. \009return oldTerm.clear(...)\
  3291. end\
  3292. \
  3293. newTerm.clearLine = function(...)\
  3294. \009local a = \"\"\
  3295. \009if not paused and os.clock() - clock > 0 then\
  3296. \009\009a = \"sp(\" .. os.clock() - clock .. \") \"\
  3297. \009end\
  3298. \009add(a .. \"h()\\n\")\
  3299. \009clock = os.clock()\
  3300. \
  3301. \009return oldTerm.clearLine(...)\
  3302. end\
  3303. \
  3304. newTerm.setCursorBlink = function(flag)\
  3305. \009if flag ~= blnk then\
  3306. \009\009local a = \"\"\
  3307. \009\009if not paused and os.clock() - clock > 0 then\
  3308. \009\009\009a = \"sp(\" .. os.clock() - clock .. \") \"\
  3309. \009\009end\
  3310. \009\009add(a .. \"i(\" .. tostring(flag) .. \")\\n\")\
  3311. \009\009clock = os.clock()\
  3312. \009\009blnk = flag\
  3313. \009end\
  3314. \
  3315. \009return oldTerm.setCursorBlink(flag)\
  3316. end\
  3317. \
  3318. newTerm.scroll = function(n)\
  3319. \009local a = \"\"\
  3320. \009if not paused and os.clock() - clock > 0 then\
  3321. \009\009a = \"sp(\" .. os.clock() - clock .. \") \"\
  3322. \009end\
  3323. \009add(a .. \"j(\" .. tostring(n) .. \")\\n\")\
  3324. \009clock = os.clock()\
  3325. \
  3326. \009return oldTerm.scroll(n)\
  3327. end\
  3328. \
  3329. newTerm.getSize = function(...) return oldTerm.getSize(...) end\
  3330. newTerm.redirect = function(...) return oldTerm.redirect(...) end\
  3331. newTerm.restore = function(...) return oldTerm.restore(...) end\
  3332. newTerm.isColor = function(...) return oldTerm.isColor and oldTerm.isColor(...) end\
  3333. newTerm.isColour = function(...) return term.isColor(...) end\
  3334. \
  3335. \
  3336. --  -------- Recording\
  3337. \
  3338. local function record(location)\
  3339. \009while true do\
  3340. \009\009local e, key = os.pullEventRaw()\
  3341. \009\009if (e == \"key\" and key == 59) or e == event_exitRecording or e == \"terminate\" then\
  3342. \009\009\009local a = \"\"\
  3343. \009\009\009if os.clock() - clock > 0 then a = \"sp(\" .. os.clock() - clock .. \") \" end\
  3344. \009\009\009add(a)\
  3345. \
  3346. \009\009\009add(\"\\n\\nterm.setCursorBlink(false)\\n\")\
  3347. \009\009\009add(\"if term.isColor() then term.setTextColor(colors.yellow)\\n\")\
  3348. \009\009\009add(\"else term.setTextColor(colors.white) end\\n\")\
  3349. \009\009\009add(\"term.setBackgroundColor(colors.black)\\n\")\
  3350. \009\009\009add(\"term.clear()\\n\")\
  3351. \009\009\009add(\"term.setCursorPos(1, 1)\\n\")\
  3352. \009\009\009add(\"print(\\\"End of Recording!\\\")\\n\")\
  3353. \
  3354. \009\009\009local sd = \"local sD = \" .. textutils.serialize(sD) .. \"\\n\"\
  3355. \
  3356. \009\009\009term.redirect(term.native())\
  3357. \009\009\009term.setCursorBlink(false)\
  3358. \
  3359. \009\009\009handle:close()\
  3360. \009\009\009handle = nil\
  3361. \009\009\009local f = io.open(recordLocation, \"r\")\
  3362. \009\009\009local ncont = f:read(\"*a\")\
  3363. \009\009\009f:close()\
  3364. \
  3365. \009\009\009ncont = ncont:gsub(\"%-%- sD here...\\n\", sd)\
  3366. \009\009\009local f = io.open(location, \"w\")\
  3367. \009\009\009f:write(ncont)\
  3368. \009\009\009f:close()\
  3369. \009\009\009fs.delete(recordLocation)\
  3370. \
  3371. \009\009\009break\
  3372. \009\009elseif e == \"key\" and key == 61 then\
  3373. \009\009\009paused = not paused\
  3374. \009\009\009if paused then\
  3375. \009\009\009\009add(\"sp(2)\\n\")\
  3376. \009\009\009end\
  3377. \009\009end\
  3378. \009end\
  3379. end\
  3380. \
  3381. \
  3382. --  -------- Movie\
  3383. \
  3384. local function loadNfa(path)\
  3385. \009local ret = {}\
  3386. \009if fs.exists(path) and not fs.isDir(path) then\
  3387. \009\009local f = io.open(path, \"r\")\
  3388. \009\009local l = f:read(\"*l\")\
  3389. \009\009local curFrame = \"\"\
  3390. \009\009while l do\
  3391. \009\009\009if l ~= \"\" and l ~= \"~\" then curFrame = curFrame .. l .. \"\\n\"\
  3392. \009\009\009elseif l == \"~\" then\
  3393. \009\009\009\009table.insert(ret, curFrame)\
  3394. \009\009\009\009curFrame = \"\"\
  3395. \009\009\009end\
  3396. \009\009\009l = f:read(\"*l\")\
  3397. \009\009end\
  3398. \009\009f:close()\
  3399. \009end\
  3400. \
  3401. \009return ret\
  3402. end\
  3403. \
  3404. local function movie(location, duration)\
  3405. \009nfaRecording = true\
  3406. \009local frames = loadNfa(location)\
  3407. \009if frames ~= {} then\
  3408. \009\009for i, v in ipairs(frames) do\
  3409. \009\009\009term.setTextColor(colors.white)\
  3410. \009\009\009term.setBackgroundColor(colors.black)\
  3411. \009\009\009term.clear()\
  3412. \
  3413. \009\009\009local tempImageLocation = \"/.lightshot-temp-image\"\
  3414. \009\009\009local f = io.open(tempImageLocation, \"w\")\
  3415. \009\009\009f:write(v)\
  3416. \009\009\009f:close()\
  3417. \009\009\009local a = paintutils.loadImage(tempImageLocation)\
  3418. \009\009\009paintutils.drawImage(a, 1, 1)\
  3419. \009\009\009fs.delete(tempImageLocation)\
  3420. \009\009\009add(\"sp(\" .. duration .. \")\\n\")\
  3421. \009\009end\
  3422. \
  3423. \009\009add(\"sp(\" .. duration .. \")\\n\")\
  3424. \009end\
  3425. \
  3426. \009add(\"\\n\\nterm.setCursorBlink(false)\\n\")\
  3427. \009add(\"if term.isColor() then term.setTextColor(colors.yellow)\\n\")\
  3428. \009add(\"else term.setTextColor(colors.white) end\\n\")\
  3429. \009add(\"term.setBackgroundColor(colors.black)\\n\")\
  3430. \009add(\"term.clear()\\n\")\
  3431. \009add(\"term.setCursorPos(1, 1)\\n\")\
  3432. \009add(\"print(\\\"The End! :D\\\")\\n\")\
  3433. \
  3434. \009nfaRecording = false\
  3435. \009term.restore()\
  3436. \009term.setCursorBlink(false)\
  3437. \009if term.isColor() then term.setTextColor(colors.yellow)\
  3438. \009else term.setTextColor(colors.white) end\
  3439. \009term.setBackgroundColor(colors.black)\
  3440. \009term.clear()\
  3441. \009term.setCursorPos(1, 1)\
  3442. \009print(\"Movie Recorded Successfully!\")\
  3443. \
  3444. \009handle:close()\
  3445. \009handle = nil\
  3446. \009local f = io.open(recordLocation, \"r\")\
  3447. \009local ncont = f:read(\"*a\")\
  3448. \009f:close()\
  3449. \
  3450. \009local sd = \"local sD = \" .. textutils.serialize(sD) .. \"\\n\"\
  3451. \009ncont = ncont:gsub(\"%-%- sD here...\\n\", sd)\
  3452. \009local f = io.open(location, \"w\")\
  3453. \009f:write(ncont)\
  3454. \009f:close()\
  3455. \009fs.delete(recordLocation)\
  3456. end\
  3457. \
  3458. \
  3459. --  -------- Main\
  3460. \
  3461. local theme = {}\
  3462. if term.isColor and term.isColor() then\
  3463. \009theme = {\
  3464. \009\009[\"prompt\"] = \"cyan\",\
  3465. \009\009[\"promptHighlight\"] = \"lightBlue\",\
  3466. \009\009[\"textColor\"] = \"white\",\
  3467. \009}\
  3468. else\
  3469. \009theme = {\
  3470. \009\009[\"prompt\"] = \"black\",\
  3471. \009\009[\"promptHighlight\"] = \"black\",\
  3472. \009\009[\"textColor\"] = \"white\",\
  3473. \009}\
  3474. end\
  3475. \
  3476. local function drawButton(v, sel)\
  3477. \009if sel then term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\
  3478. \009else term.setBackgroundColor(v.bg or colors[theme.prompt]) end\
  3479. \009term.setTextColor(v.tc or colors[theme.textColor])\
  3480. \009for i = -1, 1 do\
  3481. \009\009term.setCursorPos(v[2], v[3] + i)\
  3482. \009\009term.write(string.rep(\" \", v[1]:len() + 4))\
  3483. \009end\
  3484. \
  3485. \009term.setCursorPos(v[2], v[3])\
  3486. \009if sel then\
  3487. \009\009term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\
  3488. \009\009term.write(\" > \")\
  3489. \009else term.write(\" - \") end\
  3490. \009term.write(v[1] .. \" \")\
  3491. end\
  3492. \
  3493. local function prompt(list, dir)\
  3494. \009local function draw(sel)\
  3495. \009\009for i, v in ipairs(list) do\
  3496. \009\009\009if i == sel then term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\
  3497. \009\009\009else term.setBackgroundColor(v.bg or colors[theme.prompt]) end\
  3498. \009\009\009term.setTextColor(v.tc or colors[theme.textColor])\
  3499. \009\009\009for i = -1, 1 do\
  3500. \009\009\009\009term.setCursorPos(v[2], v[3] + i)\
  3501. \009\009\009\009term.write(string.rep(\" \", v[1]:len() + 4))\
  3502. \009\009\009end\
  3503. \
  3504. \009\009\009term.setCursorPos(v[2], v[3])\
  3505. \009\009\009if i == sel then\
  3506. \009\009\009\009term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\
  3507. \009\009\009\009term.write(\" > \")\
  3508. \009\009\009else term.write(\" - \") end\
  3509. \009\009\009term.write(v[1] .. \" \")\
  3510. \009\009end\
  3511. \009end\
  3512. \
  3513. \009local sel = 1\
  3514. \009draw(sel)\
  3515. \
  3516. \009while true do\
  3517. \009\009local e, but, x, y = os.pullEvent()\
  3518. \009\009if e == \"key\" and but == 28 then return list[sel][1]\
  3519. \009\009elseif e == \"key\" and but == 200 and sel > 1 then\
  3520. \009\009\009sel = sel - 1\
  3521. \009\009\009draw(sel)\
  3522. \009\009elseif e == \"key\" and but == 208 and ((err == true and sel < #list - 1) or (sel < #list)) then\
  3523. \009\009\009sel = sel + 1\
  3524. \009\009\009draw(sel)\
  3525. \009\009elseif e == \"key\" and but == 203 and sel > 2 then\
  3526. \009\009\009sel = sel - 2\
  3527. \009\009\009draw(sel)\
  3528. \009\009elseif e == \"key\" and but == 205 and sel < 3 then\
  3529. \009\009\009sel = sel + 2\
  3530. \009\009\009draw(sel)\
  3531. \009\009elseif e == \"mouse_click\" then\
  3532. \009\009\009for i, v in ipairs(list) do\
  3533. \009\009\009\009if x >= v[2] - 1 and x <= v[2] + v[1]:len() + 3 and y >= v[3] - 1 and y <= v[3] + 1 then\
  3534. \009\009\009\009\009return list[i][1]\
  3535. \009\009\009\009end\
  3536. \009\009\009end\
  3537. \009\009end\
  3538. \009end\
  3539. end\
  3540. \
  3541. local function menu()\
  3542. \009term.setBackgroundColor(colors.gray)\
  3543. \009term.setTextColor(colors.white)\
  3544. \009term.clear()\
  3545. \009term.setCursorPos(1, 1)\
  3546. \
  3547. \009term.setBackgroundColor(colors.lightGray)\
  3548. \009for i = 2, 4 do term.setCursorPos(1, i) term.clearLine() end\
  3549. \009term.setCursorPos(3, 3)\
  3550. \009term.write(\"Lightshot \" .. version)\
  3551. \
  3552. \009local opt = prompt({{\"Record a Video\", w/2 - 16, 9}, {\"Record an Animation\", w/2 - 21, 13},\
  3553. \009\009{\"Update Lightshot\", w/2 + 4, 9}, {\"Exit\", w/2 + 4, 13, bg = (term.isColor and term.isColor())\
  3554. \009\009and colors.red or colors.black, highlight = (term.isColor and term.isColor()) and colors.pink\
  3555. \009\009or colors.black}}, \"vertical\")\
  3556. \009if opt == \"Record a Video\" or opt == \"Record an Animation\" then\
  3557. \009\009term.setBackgroundColor(colors.gray)\
  3558. \009\009for i = 7, 14 do term.setCursorPos(1, i) term.clearLine() end\
  3559. \009\009term.setBackgroundColor(colors.cyan)\
  3560. \009\009for i = 8, 11 do term.setCursorPos(7, i) term.write(string.rep(\" \", w - 14)) end\
  3561. \009\009drawButton({\"Control to Return to Menu\", 7, 14}, true)\
  3562. \009\009term.setBackgroundColor(colors.cyan)\
  3563. \009\009term.setCursorPos(8, 9)\
  3564. \009\009term.write(\"Where to save the recording?\")\
  3565. \009\009term.setCursorPos(9, 10)\
  3566. \009\009term.write(\"/\")\
  3567. \009\009local loc = modRead({visibleLength = w - 14, exitOnKey = \"control\"})\
  3568. \009\009if not loc or loc == \"\" then return \"menu\" end\
  3569. \
  3570. \009\009term.setCursorPos(8, 9)\
  3571. \009\009term.write(string.rep(\" \", 28))\
  3572. \009\009term.setCursorPos(8, 9)\
  3573. \009\009loc = \"/\" .. loc\
  3574. \009\009if fs.isReadOnly(loc) then term.write(\"File is Read Only!\") sleep(1.6) return \"menu\"\
  3575. \009\009elseif fs.isDir(loc) then term.write(\"Location is a directory!\") sleep(1.6) return \"menu\"\
  3576. \009\009elseif opt == \"Record a Video\" then\
  3577. \009\009\009if fs.exists(loc) then fs.delete(loc) end\
  3578. \009\009\009term.setTextColor(colors.white)\
  3579. \009\009\009term.setBackgroundColor(colors.black)\
  3580. \009\009\009term.clear()\
  3581. \009\009\009term.setCursorPos(2, 5)\
  3582. \009\009\009term.write(\"Press F1 to end the recording\")\
  3583. \009\009\009term.setCursorPos(2, 6)\
  3584. \009\009\009term.write(\"Press F3 to pause or unpause the recording\")\
  3585. \
  3586. \009\009\009if term.isColor and term.isColor() then term.setTextColor(colors.yellow) end\
  3587. \009\009\009for i = 1, 3 do\
  3588. \009\009\009\009term.setCursorPos(2, 3)\
  3589. \009\009\009\009term.clearLine()\
  3590. \009\009\009\009term.write(\"Recording in \" .. 4 - i .. \"...\")\
  3591. \009\009\009\009sleep(1)\
  3592. \009\009\009end\
  3593. \
  3594. \009\009\009return \"record\", loc\
  3595. \009\009elseif opt == \"Record an Animation\" then\
  3596. \009\009\009if loc:sub(-4, -1) ~= \".nfa\" then\
  3597. \009\009\009\009term.write(\"File Not An nPaintPro Animation!\")\
  3598. \009\009\009\009sleep(1.6)\
  3599. \009\009\009\009return \"menu\"\
  3600. \009\009\009end\
  3601. \
  3602. \009\009\009term.setCursorPos(8, 9)\
  3603. \009\009\009term.write(\"Duration between frames (seconds):\")\
  3604. \009\009\009term.setCursorPos(9, 10)\
  3605. \009\009\009term.write(string.rep(\" \", w - 16))\
  3606. \009\009\009term.setCursorPos(9, 10)\
  3607. \009\009\009local dur = modRead({visibleLength = w - 14, exitOnKey = \"control\"})\
  3608. \009\009\009if not dur or dur == \"\" then return \"menu\" end\
  3609. \
  3610. \009\009\009term.setCursorPos(8, 9)\
  3611. \009\009\009term.write(string.rep(\" \", 38))\
  3612. \009\009\009term.setCursorPos(8, 9)\
  3613. \009\009\009dur = tonumber(dur)\
  3614. \009\009\009if not dur then term.write(\"Duration must be an integer!\") sleep(1.6) return \"menu\"\
  3615. \009\009\009else return \"tomovie\", loc, dur end\
  3616. \009\009end\
  3617. \009elseif opt == \"Update Lightshot\" then\
  3618. \009\009term.setTextColor(colors.white)\
  3619. \009\009term.setBackgroundColor(colors.lightGray)\
  3620. \009\009term.setCursorPos(3, 3)\
  3621. \009\009term.clearLine()\
  3622. \009\009term.write(\"Checking for Updates...\")\
  3623. \009\009term.setCursorPos(3, 3)\
  3624. \009\009if updateClient() then\
  3625. \009\009\009term.clearLine()\
  3626. \009\009\009term.write(\"Updated!\")\
  3627. \009\009\009sleep(1.6)\
  3628. \009\009\009opt = \"Exit\"\
  3629. \009\009else\
  3630. \009\009\009term.clearLine()\
  3631. \009\009\009term.write(\"No Updates Found!\")\
  3632. \009\009\009sleep(1.6)\
  3633. \009\009\009return \"menu\"\
  3634. \009\009end\
  3635. \009end if opt == \"Exit\" then return nil end\
  3636. end\
  3637. \
  3638. local function main()\
  3639. \009local action, location, duration = \"menu\", nil, nil\
  3640. \009while action == \"menu\" do action, location, duration = menu() end\
  3641. \
  3642. \009if action and location then\
  3643. \009\009clock = os.clock()\
  3644. \009\009add(recordHeader)\
  3645. \009\009term.redirect(newTerm)\
  3646. \
  3647. \009\009term.setTextColor(colors.white)\
  3648. \009\009term.setBackgroundColor(colors.black)\
  3649. \009\009term.clear()\
  3650. \009\009term.setCursorPos(1, 1)\
  3651. \009\009if action == \"record\" then\
  3652. \009\009\009parallel.waitForAny(function()\
  3653. \009\009\009\009record(location)\
  3654. \009\009\009end, function()\
  3655. \009\009\009\009term.setBackgroundColor(colors.black)\
  3656. \009\009\009\009term.setTextColor(colors.white)\
  3657. \009\009\009\009term.clear()\
  3658. \009\009\009\009term.setCursorPos(1, 1)\
  3659. \
  3660. --[[\
  3661. \009\009\009\009-- Run startup\
  3662. \009\009\009\009if fs.exists(\"/startup\") and not fs.isDir(\"/startup\") then shell.run(\"/startup\") end\
  3663. \009\009\009\009term.setBackgroundColor(colors.black)\
  3664. \009\009\009\009term.setTextColor(colors.white)\
  3665. \009\009\009\009term.clear()\
  3666. \009\009\009\009term.setCursorPos(1, 1)\
  3667. ]]--\
  3668. \
  3669. \009\009\009\009-- Run shell\
  3670. \009\009\009\009shell.run(\"/rom/programs/shell\")\
  3671. \009\009\009\009os.queueEvent(event_exitRecording)\
  3672. \009\009\009end)\
  3673. \
  3674. \009\009\009if term.isColor() then term.setTextColor(colors.yellow)\
  3675. \009\009\009else term.setTextColor(colors.white) end\
  3676. \009\009\009term.setBackgroundColor(colors.black)\
  3677. \009\009\009term.clear()\
  3678. \009\009\009term.setCursorPos(2, 3)\
  3679. \009\009\009print(\"Recording Saved!\")\
  3680. \009\009\009sleep(1.1)\
  3681. \009\009elseif action == \"tomovie\" then\
  3682. \009\009\009movie(location, duration)\
  3683. \009\009end\
  3684. \009else\
  3685. \009\009return \"exit\"\
  3686. \009end\
  3687. end\
  3688. \
  3689. -- Run\
  3690. local oldDir = shell.dir()\
  3691. while main() ~= \"exit\" do end\
  3692. shell.setDir(oldDir)\
  3693. \
  3694. -- Exit Message\
  3695. term.setBackgroundColor(colors.black)\
  3696. term.setTextColor(colors.white)\
  3697. term.clear()\
  3698. term.setCursorPos(1, 1)\
  3699. centerPrint(\"Thanks for Using Lightshot \" .. version .. \"!\")\
  3700. centerPrint(\"Made by GravityScore and 1lann\")",
  3701.   },
  3702.   [ "programs/RedLevel/" ] = {
  3703.     content = "--]] Block Table [--\
  3704. term.redirect(term.native())\
  3705. local w, h = term.getSize()\
  3706. local sMenuIndex = 1\
  3707. local inSave = false\
  3708. local inGame = true\
  3709. local sPlay = false\
  3710. local bOff = 2\
  3711. local selBlock = bOff\
  3712. \
  3713. local map = {}\
  3714. local blocks = {\
  3715.    [0]={name=\"Air\",color=\"black\",bcolor=\"black\",graphic=\" \",solid=false},\
  3716.    {name=\"Player\",color=\"blue\",bcolor=\"black\",graphic=\"@\",solid=true},\
  3717.    {name=\"Dirt\",color=\"yellow\",bcolor=\"brown\",graphic=\" \",solid=true}, -- 1\
  3718.    {name=\"Stone\",color=\"lightGray\",bcolor=\"gray\",graphic=\"@\",solid=true}, -- 2\
  3719.    {name=\"Sand\",color=\"white\",bcolor=\"yellow\",graphic=\"+\",solid=true}, -- 3\
  3720.    {name=\"Scifi\",color=\"purple\",bcolor=\"blue\",graphic=\"0\",solid=true}, -- 4\
  3721.    {name=\"Grass\",color=\"green\",bcolor=\"brown\",graphic=\"*\",solid=true}, -- 5\
  3722.    {name=\"Iron\",color=\"white\",bcolor=\"lightGray\",graphic=\"/\",solid=true}, -- 6\
  3723.    {name=\"Gravel\",color=\"white\",bcolor=\"brown\",graphic=\"G\",solid=true}, -- 7\
  3724.    {name=\"Quartz\",color=\"lightGray\",bcolor=\"white\",graphic=\"X\",solid=true}, -- 8\
  3725. }\
  3726. \
  3727. \
  3728. \
  3729. local sMenu = {\
  3730.  {name=\"Save\",run=function()\
  3731. \
  3732.       term.setCursorPos(1,h)\
  3733.      term.clearLine()\
  3734.      write(\"Export BlockMap To File : \")\
  3735.      tf = read()\
  3736.      f = fs.open(tf,\"w\")\
  3737.      f.write(textutils.serialize(blocks))\
  3738.      f.close()\
  3739.      term.setCursorPos(1,h)\
  3740.      term.clearLine()\
  3741.      write(\"Exported To File  - \"..tf)  \
  3742.      os.pullEvent(\"key\") \
  3743. \
  3744.    term.setCursorPos(1,h)\
  3745.    term.clearLine() \
  3746.    write(\"Save Map As: \")\
  3747.    sa=read()\
  3748.    f = fs.open(sa,\"w\")\
  3749.    --for i = 1, #map do\
  3750.    --   f.writeLine(table.concat(map[i]))\
  3751.    -- end\
  3752.    f.write(textutils.serialize(map):gsub(\"\\n%s*\",\"\"))\
  3753.    f.close()\
  3754.    term.setCursorPos(1,h)\
  3755.    term.clearLine() write(\"Saved As  \"..sa)\
  3756.    drawMap()\
  3757.    inSave=false\
  3758.  end};\
  3759.  {name=\"Load\",run=function()\
  3760.        term.setCursorPos(1,h)\
  3761.      term.clearLine()\
  3762.      write(\"Blocks Map File : \")\
  3763.      tf = read()\
  3764.      f = fs.open(tf,\"r\")\
  3765.      blocks = textutils.unserialize(f.readAll())\
  3766.      f.close()\
  3767.      term.setCursorPos(1,h)\
  3768.      term.clearLine()\
  3769.      write(\"Imported From File  - \"..tf)  \
  3770.      os.pullEvent(\"key\")\
  3771.      term.setCursorPos(1,h)\
  3772.      term.clearLine()\
  3773.      write(\"Load Map: \")\
  3774.      sa=read()\
  3775. \
  3776.    if(fs.exists(sa) and sa ~= \"\" and  sa ~= \" \")then\
  3777.      f = fs.open(sa,\"r\")\
  3778.      smap = textutils.unserialize(f.readAll())\
  3779.      f.close()\
  3780.      if(type(smap) ~= \"table\")then\
  3781.        term.setCursorPos(1,h)\
  3782.        term.clearLine()\
  3783.        write(\"Not a valid save file!\")\
  3784.        os.pullEvent(\"key\")\
  3785.      else\
  3786.        term.setCursorPos(1,h)\
  3787.        term.clearLine()\
  3788.        map=smap\
  3789.        write(\"Save loaded \"..sa)\
  3790.        os.pullEvent(\"key\")  \
  3791.      end\
  3792.      -- for line in f.readLine do\
  3793.      --    map[#map+1] = {}\
  3794.      --  for i = 1, #line do\
  3795.      --    local l = line:sub(i,i)\
  3796.      --    map[#map][i] = tonumber(l) or tostring(l)\
  3797.      --    end\
  3798.      -- end\
  3799.    else\
  3800.      term.setCursorPos(1,h)\
  3801.      term.clearLine()\
  3802.      write(\"File Not Found - \"..sa)  \
  3803.      os.pullEvent(\"key\")    \
  3804.    end\
  3805.    inSave=false\
  3806.    drawMap()\
  3807.    end};\
  3808.    -- {name=\"Play\",run=function()\
  3809.    --        sPlay=true\
  3810.    --        inSave=false\
  3811.    -- end};\
  3812. \
  3813.      {name=\"AddBlock\",run=function()\
  3814.        term.setCursorPos(1,h)\
  3815.        term.clearLine()\
  3816.        local nb = {}\
  3817.        write(\"Name: \")\
  3818.        nbName = read()\
  3819.        write(\"TextColor: \")\
  3820.        nbTCol= read()\
  3821.        write(\"BackColor: \")\
  3822.        nbBCol = read()\
  3823.        write(\"Graphic: \")\
  3824.        nbGraph = read()\
  3825.        write(\"Solid?: \")\
  3826.        sol = read()\
  3827. \009  \
  3828. \009if(sol == \"true\")then\
  3829. \009  issol = true;\
  3830. \009else\
  3831. \009  issol = false;\
  3832. \009end\
  3833. \
  3834.        nb = {name=nbName,color=nbTCol,bcolor=nbBCol,graphic=nbGraph,solid=issol}\
  3835. \
  3836.        table.insert(blocks,nb)\
  3837.        term.setCursorPos(1,h)\
  3838.        term.clearLine()\
  3839.        write(\"Block Created - \"..nbName)  \
  3840.        os.pullEvent(\"key\") \
  3841.         inSave=false\
  3842.         drawMap()\
  3843.     end};\
  3844. \
  3845. \
  3846.      {name=\"RemoveBlock\",run=function()\
  3847.        term.setCursorPos(1,h)\
  3848.        term.clearLine()\
  3849.        write(\"Name: \")\
  3850.        nbName = read()\
  3851.       for i = 1, #blocks do\
  3852.            if(blocks[i].name == nbName)then\
  3853.              table.remove(blocks,i)\
  3854.            end\
  3855.       end\
  3856. \
  3857.        term.setCursorPos(1,h)\
  3858.        term.clearLine()\
  3859.        write(\"Block(s) Removed - \"..nbName)  \
  3860.        os.pullEvent(\"key\") \
  3861.        drawMenu()\
  3862.         inSave=false\
  3863.         drawMap()\
  3864.     end};\
  3865. \
  3866.     {name=\"Exit\",run=function() inGame = false\
  3867.         term.setBackgroundColor(colors.black)\
  3868.          term.setTextColor(colors.white)\
  3869.          term.clear()\
  3870.          term.setCursorPos(1,1)\
  3871.      end};\
  3872. }\
  3873. \
  3874. function drawMenu()\
  3875.    term.setCursorPos(1,h)\
  3876.   term.setTextColor(colors.white)\
  3877.   term.setBackgroundColor(colors.gray)\
  3878.   if(not inSave)then\
  3879.    if(selBlock < 8)then mCalc = bOff else mCalc = (selBlock-(8+(bOff-1)))+bOff end\
  3880.    for i = mCalc, (mCalc-1)+8 do\
  3881.      if(blocks[i]==nil)then \
  3882.          selBlock = 1\
  3883.      else\
  3884.        if(i ~= selBlock)then\
  3885.            write(\"[\")\
  3886.            term.setTextColor(colors[blocks[i].color])\
  3887.            term.setBackgroundColor(colors[blocks[i].bcolor])\
  3888.            write(blocks[i].graphic)\
  3889.            term.setTextColor(colors.white)\
  3890.            term.setBackgroundColor(colors.gray)\
  3891.            write(\"] \")\
  3892.       else\
  3893.            write(\">\")\
  3894.            term.setTextColor(colors[blocks[i].color])\
  3895.            term.setBackgroundColor(colors[blocks[i].bcolor])\
  3896.            write(blocks[i].graphic)\
  3897.            term.setTextColor(colors.white)\
  3898.            term.setBackgroundColor(colors.gray)\
  3899.            write(\"< \")\
  3900.       end    \
  3901.      end\
  3902.    end\
  3903.     term.setTextColor(colors.yellow)\
  3904.    write(\"Press Ctrl For Menu\")\
  3905. end\
  3906. \
  3907.     if(inSave)then\
  3908.         term.setCursorPos(1,h)\
  3909.             term.clearLine()\
  3910.             term.setTextColor(colors.white)\
  3911.         for i = 1, #sMenu do\
  3912.              if(i == sMenuIndex)then\
  3913.                    term.setTextColor(colors.yellow)\
  3914.                    write(\"[\")\
  3915.                    term.setTextColor(colors.white)\
  3916.                    write(sMenu[i].name)\
  3917.                    term.setTextColor(colors.yellow)\
  3918.                    write(\"]\")\
  3919.              else\
  3920.                    term.setTextColor(colors.yellow)\
  3921.                    write(\" \")\
  3922.                    term.setTextColor(colors.white)\
  3923.                    write(sMenu[i].name)\
  3924.                    term.setTextColor(colors.yellow)\
  3925.                    write(\" \")    \
  3926.              end    \
  3927.              term.setTextColor(colors.white)\
  3928.         end\
  3929.     end\
  3930. end\
  3931. \
  3932. function buildMap(w,h)\
  3933.         for i = 1, h do\
  3934.        map[i] = {}\
  3935.       for c = 1, w do\
  3936.            map[i][c] = 0\
  3937.       end    \
  3938.    end\
  3939. end\
  3940. \
  3941. function drawMap()\
  3942.    term.setBackgroundColor(colors.black)\
  3943.    term.clear()\
  3944.    term.setCursorPos(1,1)\
  3945.    for i = 1, #map do\
  3946.        for c = 1, #map[i] do\
  3947.            if(blocks[map[i][c]] == nil)then map[i][c] = 0 end\
  3948.            term.setTextColor(colors[blocks[map[i][c]].color])\
  3949.            term.setBackgroundColor(colors[blocks[map[i][c]].bcolor])\
  3950.            write(blocks[map[i][c]].graphic)    \
  3951.        end\
  3952.        write(\"\\n\")\
  3953.    end    \
  3954. end\
  3955. \
  3956. function isPlayer()\
  3957.    local is = false\
  3958.    for i = 1, #map do\
  3959.        for c = 1, #map[i] do\
  3960.            if(map[i][c] == tonumber(4))then\
  3961.                 is=true\
  3962.            end\
  3963.        end\
  3964.    end\
  3965.        return is\
  3966. end\
  3967. \
  3968. function getPlayerX()\
  3969.    local fx = 1\
  3970.    for i = 1, #map do\
  3971.        for c = 1, #map[i] do\
  3972.            if(map[i][c] == tonumber(4))then\
  3973.                fx=i\
  3974.            end\
  3975.        end\
  3976.    end\
  3977.            return fx\
  3978. end\
  3979. \
  3980. function getPlayerY()\
  3981.    local fy = 1\
  3982.    for i = 1, #map do\
  3983.        for c = 1, #map[i] do\
  3984.            if(map[i][c] == tonumber(4))then\
  3985.                fy=c\
  3986.            end\
  3987.        end\
  3988.    end\
  3989.            return fy\
  3990. end\
  3991. \
  3992. function drawMapBlock(x,y)\
  3993.  if(blocks[map[x][y]] == nil)then map[x][y] = 0 end\
  3994.    term.setCursorPos(tonumber(y),tonumber(x))\
  3995.     term.setTextColor(colors[blocks[map[x][y]].color])\
  3996.     term.setBackgroundColor(colors[blocks[map[x][y]].bcolor])\
  3997.    print(blocks[map[x][y]].graphic)    \
  3998. end\
  3999. \
  4000. function placeBlock(id,x,y)\
  4001.    for i = 1, #blocks do\
  4002. \
  4003.        if(i == id)then\
  4004.            map[x][y] = id  \
  4005.        end\
  4006.    end\
  4007. end\
  4008. \
  4009. function breakBlock(x,y)\
  4010.            map[x][y] = 0\
  4011. end\
  4012. \
  4013. buildMap(w,h-1)\
  4014. drawMap()\
  4015. \
  4016. \
  4017. \
  4018. \
  4019. function update()\
  4020.    drawMenu()\
  4021.   \
  4022.    a = {os.pullEvent()}\
  4023.    term.setCursorPos(1,1)\
  4024.    --if(a[1]==\"timer\" and not sPlay)then gTimer=os.startTimer(fps) end\
  4025. \
  4026.    if( (a[1] == \"mouse_click\" and a[4] < h) or (a[1] == \"mouse_drag\" and a[4] < h) and not inSave)then\
  4027.        if(a[2] == 1)then\
  4028.            placeBlock(selBlock,a[4],a[3])  \
  4029.            drawMapBlock(a[4],a[3])  \
  4030.        elseif(a[2] == 2)then\
  4031.                    breakBlock(a[4],a[3])  \
  4032.                    drawMapBlock(a[4],a[3])  \
  4033.        end\
  4034.     elseif(a[1] == \"mouse_scroll\" and not inSave )then  \
  4035.        if(a[2] == 1 and selBlock < #blocks)then\
  4036.            selBlock = selBlock + 1\
  4037.        elseif(a[2] == -1 and selBlock > bOff) then\
  4038.            selBlock = selBlock - 1\
  4039.        end\
  4040.    elseif(a[1] == \"key\")then\
  4041.                if(a[2] == keys.enter and inSave)then sMenu[sMenuIndex].run() end\
  4042.              if(a[2] == 29)then inSave = not inSave end\
  4043.                if(a[2] == keys.left and sMenuIndex > 1  and inSave)then\
  4044.                     sMenuIndex = sMenuIndex - 1\
  4045.               elseif(a[2] == keys.right and sMenuIndex < #sMenu  and inSave)then\
  4046.                     sMenuIndex = sMenuIndex + 1    \
  4047.                end\
  4048.    end\
  4049. end\
  4050. \
  4051. while inGame do\
  4052.    update()    \
  4053. end",
  4054.   },
  4055.   [ "apis/Redgame/" ] = {
  4056.     content = "--]] RedGame API By: Redxone[[--\
  4057. \
  4058. function init()\
  4059. \009w,h = term.getSize()\
  4060. \009pmap = {}\
  4061. \009 for i = 1, h do\
  4062.        pmap[i] = {}\
  4063.       for c = 1, w do\
  4064.            pmap[i][c] = 0\
  4065.       end    \
  4066.    end\
  4067. \
  4068.    gmap = {}\
  4069. \009emp={}\
  4070. \009gplayer={}\
  4071. \009gblocks={}\
  4072. \009doors={}\
  4073. \009maps={}\
  4074. \009mapName = \"\"\
  4075. \
  4076. end\
  4077. \
  4078. function getGMAP()\
  4079. \009return gmap\
  4080. end\
  4081. \
  4082. function getPMAP()\
  4083. \009return pmap\
  4084. end\
  4085. \
  4086. function getGBLOCKS()\
  4087. \009return gblocks\
  4088. end\
  4089. \
  4090. function setPMAP(x,y,id)\
  4091. \009pmap[y][x] = id\
  4092. end\
  4093. \
  4094. function setGMAP(x,y,id)\
  4095. \009gmap[y][x] = id\
  4096. end\
  4097. \
  4098. function openTextbox()\
  4099. \009paintutils.drawBox(1,h-5,w,h,colors.gray)\
  4100. \009paintutils.drawFilledBox(2,h-4,w-1,h-1,colors.blue)\
  4101. end\
  4102. \
  4103. clearTextbox = openTextbox\
  4104. \
  4105. function drawTextbox(text,ln,speed)\
  4106. \009term.setCursorPos(6,h- ( 4 - ( ln-1 ) ) )\
  4107. \009term.setTextColor(colors.white)\
  4108. \009textutils.slowPrint(text,speed)\
  4109. end\
  4110. \
  4111. function createYesNo(YText,NText,ln)\
  4112. \009local sel = 1\
  4113. \009local waiting = true\
  4114. \009local opt = {\
  4115. \009\009{name=YText};\
  4116. \009\009{name=NText};\
  4117. \009}\
  4118. \
  4119. \009function waitResult()\
  4120. \009\009while waiting do\
  4121. \009\009\009for i = 1, #opt do\
  4122. \009\009\009\009term.setCursorPos((w/2) - #opt[i].name/2,h- ( 4 - ( (ln+i)-1 ) ) )\
  4123. \009\009\009\009if(sel == i )then\
  4124. \009\009\009\009\009write(\"[\"..opt[i].name..\"]\")\
  4125. \009\009\009\009else\
  4126. \009\009\009\009\009write(\" \"..opt[i].name..\" \")\
  4127. \009\009\009\009end\
  4128. \009\009\009end\
  4129. \
  4130. \009\009\009a = {os.pullEvent(\"key\")}\
  4131. \
  4132. \009\009\009if(a[2] == keys.w and sel > 1)then\
  4133. \009\009\009\009sel = sel - 1\
  4134. \009\009\009end\
  4135. \009\009\009if(a[2] == keys.s and sel < #opt)then\
  4136. \009\009\009\009sel = sel + 1\
  4137. \009\009\009end\
  4138. \009\009\009if(a[2] == keys.space)then\
  4139. \009\009\009\009if(sel == 1)then waiting = false  return \"ok\" end\
  4140. \009\009\009\009if(sel == 2)then  waiting = false return \"no\" end\
  4141. \009\009\009end\
  4142. \009\009end\
  4143. \009end\
  4144. \009return waitResult()\
  4145. end\
  4146. \
  4147. \
  4148. function addDoor(fromx,fromy,tox,toy,fromMap,toMap)\
  4149. \009doors[#doors+1] = {fx=fromx,fy=fromy,tx=tox,ty=toy,fMap=fromMap,tMap=toMap}\
  4150. end\
  4151. \
  4152. function draw()\
  4153. \
  4154. \009for i = 1, #gmap do\
  4155. \009\009for c = 1, #gmap[i] do\
  4156. \009\009\009term.setCursorPos(c,i)\
  4157. \009\009\009term.setTextColor(colors[ gblocks[ gmap[i][c] ].color ])\
  4158. \009\009\009term.setBackgroundColor(colors[ gblocks[ gmap[i][c] ].bcolor ])\
  4159. \009\009\009write(gblocks[ gmap[i][c] ].graphic)\
  4160. \009\009end\
  4161. \009end\
  4162. \
  4163. \009for i = 1, #pmap do\
  4164. \009\009for c = 1, #pmap[i] do\
  4165. \009\009\009if(pmap[i][c] ~= 0)then\
  4166. \009\009\009\009term.setCursorPos(c,i)\
  4167. \009\009\009\009term.setTextColor(colors[ gblocks[ pmap[i][c] ].color ])\
  4168. \009\009\009\009term.setBackgroundColor(colors[ gblocks[ pmap[i][c] ].bcolor ])\
  4169. \009\009\009\009write(gblocks[ pmap[i][c] ].graphic)\
  4170. \009\009\009end\
  4171. \009\009end\
  4172. \009end\
  4173. \
  4174. end\
  4175. \
  4176. \
  4177. function closeTextbox()\
  4178. \009os.pullEvent(\"key\")\
  4179. \009draw()\
  4180. \009term.setCursorPos(1,h)\
  4181. \009term.setBackgroundColor(colors[gblocks[0].bcolor])\
  4182. \009term.clearLine()\
  4183. end\
  4184. \
  4185. function closeTextboxRaw()\
  4186. \009draw()\
  4187. \009term.setCursorPos(1,h)\
  4188. \009term.setBackgroundColor(colors[gblocks[0].bcolor])\
  4189. \009term.clearLine()\
  4190. end\
  4191. \
  4192. \
  4193. function drawMapPixel(x,y)\
  4194. \009term.setCursorPos(y,x)\
  4195. \009term.setTextColor(colors[ gblocks[ gmap[x][y] ].color ])\
  4196. \009term.setBackgroundColor(colors[ gblocks[ gmap[x][y] ].bcolor ])\
  4197. \009write(gblocks[ gmap[x][y] ].graphic)\
  4198. \009if(pmap[x][y] ~= 0)then\
  4199. \009\009term.setCursorPos(y,x)\
  4200. \009\009term.setTextColor(colors[ gblocks[ pmap[x][y] ].color ])\
  4201. \009\009term.setBackgroundColor(colors[ gblocks[ pmap[x][y] ].bcolor ])\
  4202. \009\009write(gblocks[ pmap[x][y] ].graphic)\
  4203. \009end\
  4204. end\
  4205. \
  4206. function lookupBlock(id)\
  4207. \009for i = 1, #gmap do\
  4208. \009\009for c = 1, #gmap[i] do\
  4209. \009\009\009if(gmap[i][c] == id)then return true end\
  4210. \009\009end\
  4211. \009end\
  4212. \009return false\
  4213. end\
  4214. \
  4215. function findBlockAt(id)\
  4216. \009inf = {}\
  4217. \009for i = 1, #gmap do\
  4218. \009\009for c = 1, #gmap[i] do\
  4219. \009\009\009if(gmap[i][c] == tonumber(id))then \
  4220. \009\009\009\009 return i,c \
  4221. \009\009\009end\
  4222. \009\009end\
  4223. \009end\
  4224. \009return nil\
  4225. end\
  4226. \
  4227. function getBlockAt(x,y)\
  4228. \009return gmap[y][x]\
  4229. end\
  4230. \
  4231. function setBlockAt(id,x,y)\
  4232. \009gmap[y][x] = id\
  4233. \009drawMapPixel(y,x)\
  4234. end\
  4235. \
  4236. function breakBlockAt(x,y)\
  4237. \009gmap[y][x] = 0\
  4238. \009drawMapPixel(y,x)\
  4239. end\
  4240. \
  4241. function editBlock(id,color,bcolor,graphic,solid)\
  4242. \009gblocks[id].color = color\
  4243. \009gblocks[id].bcolor = bcolor\
  4244. \009gblocks[id].graphic = graphic\
  4245. \009gblocks[id].solid = solid\
  4246. \009draw()\
  4247. end\
  4248. function getCurrentMap()\
  4249. \009return mapName\
  4250. end\
  4251. \
  4252. \
  4253. function addMap(name,levmap,blocks)\
  4254. \009if(maps[name] ~= nil)then error(\"[Redgame] - > AddMap - > Map already added!\") end\
  4255. \009maps[name] = {level=levmap,blockmap=blocks}\
  4256. end\
  4257. \
  4258. function setSolid(id,solid)\
  4259. \009gblocks[id].solid = solid\
  4260. end\
  4261. \
  4262. function getResource(file)\
  4263. \009f = fs.open(file,\"r\")\
  4264. \009res = textutils.unserialize(f.readAll())\
  4265. \009f.close()\
  4266. \009if(type(res) ~= \"table\")then error(\"[RedGame]: getResource -> file [\"..file..\"] must contain only a table!\") end\
  4267. \009return res\
  4268. end\
  4269. \
  4270. function setMap(map)\
  4271. \009if(maps[map] == nil)then\
  4272. \009\009error(\"[RedGame] -> setMap -> No such map.\")\
  4273. \009end\
  4274. \009gmap=maps[map].level\
  4275. \009mapName = map\
  4276. \009gblocks = maps[map].blockmap\
  4277. \009draw()\
  4278. end\
  4279. \
  4280. function getMap()\
  4281. \009return gmap\
  4282. end\
  4283. \
  4284. \
  4285. \
  4286. \
  4287. function createPlayer(block,startX,startY)\
  4288. \
  4289. \009local player = {\
  4290. \
  4291. \009\009x=startX,\
  4292. \009\009y=startY,\
  4293. \009\009tickrate=tonumber(0.1),\
  4294. \009\009physicsTick = os.startTimer(0.1),\
  4295. \009\009jump_height=2,\
  4296. \009\009hspd = 0,\
  4297. \009\009vspd = 0,\
  4298. \009\009blockid = block,\
  4299. \009\009multidir = false,\
  4300. \009\009physic_control= {\
  4301. \009\009\009[\"direction_up\"] = keys.w,\
  4302. \009\009\009[\"direction_down\"] = keys.s,\
  4303. \009\009\009[\"direction_left\"] = keys.a,\
  4304. \009\009\009[\"direction_right\"] = keys.d,\
  4305. \009\009},\
  4306. \009\009lastMove = \"player_up\",\
  4307. \009\009events = {},\
  4308. \009\009interactions ={},\
  4309. \
  4310. \009\009addInteraction = function(self,mydmap,x,y,func)\
  4311. \009\009\009self.interactions[#self.interactions+1] = {onmap=mydmap,x=x,y=y,active=true,event=func}\
  4312. \009\009end,\
  4313. \
  4314. \009\009removeInteraction = function(self,mydmap,x,y)\
  4315. \009\009\009for i = 1, #self.interactions do\
  4316. \009\009\009\009if(self.interactions[i].x == x and self.interactions[i].y == y and self.interactions[i].onmap == mydmap)then\
  4317. \009\009\009\009\009self.interactions[i].active=false;\
  4318. \009\009\009\009end\
  4319. \009\009\009end \
  4320. \009\009end,\
  4321. \
  4322. \009\009setPhysicsTick = function(self,time)\
  4323. \009\009\009self.tickrate = tonumber(time)\
  4324. \009\009\009self.physicsTick = os.startTimer(time)\
  4325. \009\009end,\
  4326. \
  4327. \009\009addEvent = function(self,check,evfunc)\
  4328. \009\009\009table.insert(self.events,{type=check,run=evfunc})\
  4329. \009\009end,\
  4330. \
  4331. \009\009getBlockUnder = function(self)\
  4332. \009\009\009\009if(gmap[self.y][self.x] ~= 0)then\
  4333. \009\009\009\009\009return gmap[self.y][self.x]\
  4334. \009\009\009\009end\
  4335. \009\009\009\009return 0\
  4336. \009\009end,\
  4337. \
  4338. \
  4339. \009\009checkCollision = function(self,x,y)\
  4340. \009\009\009hasColl = false\
  4341. \009\009\009if( gblocks[gmap[y][x]].solid or pmap[y][x] ~= 0)then hasColl = true end\
  4342. \009\009\009if( gmap[y][x] == 0 and pmap[y][x] == 0)then hasColl = false end\
  4343. \009\009\009return hasColl\
  4344. \009\009end,\
  4345. \
  4346. \009\009jump = function(self,ammount)\
  4347. \009\009\009if(self:checkCollision(self.x,self.y+1))then\
  4348. \009\009\009\009for i = 1, ammount do\
  4349. \009\009\009\009\009if(not self:checkCollision(self.x,self.y-1))then\
  4350. \009\009\009\009\009\009pmap[self.y][self.x] = 0\
  4351. \009\009\009\009\009\009drawMapPixel(self.y,self.x)\
  4352. \009\009\009\009\009\009self.y = self.y - 1\
  4353. \009\009\009\009\009\009pmap[self.y][self.x] = self.blockid\
  4354. \009\009\009\009\009\009drawMapPixel(self.y,self.x)\
  4355. \009\009\009\009\009end\
  4356. \009\009\009\009end\
  4357. \009\009\009end\
  4358. \009\009end,\
  4359. \
  4360. \009\009moveUp=function(self,ammount)\
  4361. \009\009\009if(not self:checkCollision(self.x,self.y-1) and not self:checkPhysics(\"gravity\"))then\
  4362. \009\009\009\009pmap[self.y][self.x] = 0\
  4363. \009\009\009\009drawMapPixel(self.y,self.x)\
  4364. \009\009\009\009self.y = self.y - ammount\
  4365. \009\009\009\009pmap[self.y][self.x] = self.blockid\
  4366. \009\009\009\009drawMapPixel(self.y,self.x)\
  4367. \009\009\009end\
  4368. \
  4369. \009\009\009if(not self:checkCollision(self.x,self.y-1) and self:checkPhysics(\"gravity\"))then\
  4370. \009\009\009\009self:jump(self.jump_height)\
  4371. \009\009\009end\
  4372. \009\009end,\
  4373. \
  4374. \009\009moveDown=function(self,ammount)\
  4375. \009\009\009if(not self:checkCollision(self.x,self.y+1))then\
  4376. \009\009\009\009pmap[self.y][self.x] = 0\
  4377. \009\009\009\009drawMapPixel(self.y,self.x)\
  4378. \009\009\009\009self.y = self.y + ammount\
  4379. \009\009\009\009pmap[self.y][self.x] = self.blockid\
  4380. \009\009\009\009drawMapPixel(self.y,self.x)\
  4381. \009\009\009end\009\
  4382. \009\009\
  4383. \009\009end,\
  4384. \
  4385. \009\009moveLeft=function(self,ammount)\
  4386. \009\009\009--pmap[self.y][self.x-1] == 0\
  4387. \009\009\009if(not self:checkCollision(self.x-1,self.y))then\
  4388. \009\009\009\009pmap[self.y][self.x] = 0\
  4389. \009\009\009\009drawMapPixel(self.y,self.x)\
  4390. \009\009\009\009self.x = self.x - ammount\
  4391. \009\009\009\009pmap[self.y][self.x] = self.blockid\
  4392. \009\009\009\009drawMapPixel(self.y,self.x)\
  4393. \009\009\009end\009\009\
  4394. \
  4395. \
  4396. \009\009end,\
  4397. \
  4398. \009\009moveRight=function(self,ammount)\
  4399. \009\009\009if(not self:checkCollision(self.x+1,self.y))then\
  4400. \009\009\009\009pmap[self.y][self.x] = 0\
  4401. \009\009\009\009drawMapPixel(self.y,self.x)\
  4402. \009\009\009\009self.x = self.x + ammount\
  4403. \009\009\009\009pmap[self.y][self.x] = self.blockid\
  4404. \009\009\009\009drawMapPixel(self.y,self.x)\
  4405. \009\009\009end\009\009\
  4406. \009\009end,\
  4407. \
  4408. \
  4409. \009\009physics = {\
  4410. \
  4411. \009\009\009[\"gravity\"] = {has=false,func=function(self) \
  4412. \009\009\009\009if(not self:checkCollision(self.x,self.y+1))then\
  4413. \009\009\009\009\009\009self:moveDown(1)\
  4414. \009\009\009\009\009\009sleep(0.01)\
  4415. \009\009\009\009end\
  4416. \009\009\009end};\
  4417. \
  4418. \009\009\009[\"smooth_experimental\"] = {has=false,func=function(self) \
  4419. \009\009\009\009\009self.multidir = true\
  4420. \009\009\009\009\009self.physics[\"smooth_experimental\"].has = false\
  4421. \009\009\009end};\
  4422. \
  4423. \009\009},\
  4424. \
  4425. \
  4426. \009\009checkPhysics = function(self,element)\
  4427. \009\009\009for k, v in pairs(self.physics) do\
  4428. \009\009\009\009if(k == element and v.has)then\
  4429. \009\009\009\009\009return true\
  4430. \009\009\009\009end\
  4431. \009\009\009end\
  4432. \
  4433. \009\009\009return false\
  4434. \009\009end,\
  4435. \
  4436. \009\009checkInteract = function(self)\
  4437. \009\009\009for i = 1, #self.interactions do\
  4438. \009\009\009\009if(    ((self.y == self.interactions[i].y-1) \
  4439. \009\009\009\009\009and (self.x == self.interactions[i].x)) \
  4440. \009\009\009\009\009or ((self.y == self.interactions[i].y+1)\
  4441. \009\009\009\009    and (self.x == self.interactions[i].x))\
  4442. \009\009\009\009\009or ((self.y == self.interactions[i].y)\
  4443. \009\009\009\009    and (self.x == self.interactions[i].x+1))\
  4444. \009\009\009\009\009or ((self.y == self.interactions[i].y)\
  4445. \009\009\009\009    and (self.x == self.interactions[i].x-1))\
  4446. \009\009\009\009    )then\
  4447. \009\009\009\009\009if(self.interactions[i].onmap == getCurrentMap() and self.interactions[i].active)then\
  4448. \009\009\009\009\009\009self.interactions[i].event()\
  4449. \009\009\009\009\009end\
  4450. \009\009\009\009end\
  4451. \009\009\009end\
  4452. \009\009end,\
  4453. \
  4454. \009\009controls = {\
  4455. \009\009\009{name = \"player_interact\",event=\"key\",key=keys.space,func=function(self) self:checkInteract() end};\
  4456. \009\009\009{name=\"player_up\",event=\"key\",key=keys.w,func=function(self) self.lastMove = \"player_up\" self:moveUp(1)  end};\
  4457. \009\009\009{name=\"player_down\",event=\"key\",key=keys.s,func=function(self) self.lastMove = \"player_down\" self:moveDown(1) end};\
  4458. \009\009\009{name=\"player_left\",event=\"key\",key=keys.a,func=function(self) self.lastMove = \"player_left\" self:moveLeft(1) end};\
  4459. \009\009\009{name=\"player_right\",event=\"key\",key=keys.d,func=function(self)self.lastMove = \"player_right\" self:moveRight(1) end};\
  4460. \009\009},\
  4461. \
  4462. \009\009--]] movement functions\
  4463. \
  4464. \009\009put = function(self)\
  4465. \009\009\009pmap[self.y][self.x] = self.blockid \
  4466. \009\009end,\
  4467. \
  4468. \009\009unput = function(self)\
  4469. \009\009\009pmap[self.y][self.x] = 0; \
  4470. \009\009\009drawMapPixel(self.y,self.x)\
  4471. \009\009end,\
  4472. \
  4473. \009\009applyPhysics = function(self,element)\
  4474. \009\009\009if(self.physics[element] ~= nil)then\
  4475. \009\009\009\009if(self.physics[element].has == false)then\
  4476. \009\009\009\009\009self.physics[element].has = true\
  4477. \009\009\009\009end\
  4478. \009\009\009else\
  4479. \009\009\009\009error(\"[RedGame]: player -> addPhysicsElement -> no such element!\")\
  4480. \009\009\009end\
  4481. \009\009end,\
  4482. \
  4483. \009\009setJumpHeight = function(self,h)\
  4484. \009\009\009self.jump_height = h\
  4485. \009\009end,\
  4486. \
  4487. \009\009createPhysics = function(self,element,physic)\
  4488. \009\009\009\009if(self.physics[element] ~= nil)then error(\"[RedGame]: player - > createPhysicsElement -> element already exists!\") end\
  4489. \009\009\009\009if(type(physic) ~= \"table\")then error(\"[RedGame]: player -> createPhysicsElement -> must be in table format eg {func=function(self) physics stuff end};\") end\
  4490. \009\009\009\009 metaindex = {has=false,func=function(self) end};\
  4491. \009\009\009\009physic = setmetatable(physic, {__index = metaindex})\
  4492. \009\009\009\009self.physics[element] = physic\
  4493. \009\009end,\
  4494. \
  4495. \009\009remapPhysicsControl = function(self,name,to)\
  4496. \009\009\009\009if(self.physic_control[name])then\
  4497. \009\009\009\009\009self.physic_control[name] = to\
  4498. \009\009\009\009else\
  4499. \009\009\009\009\009error(\"[RedGame]: player -> remapPhysicsControl invalid control!\")\
  4500. \009\009\009\009end\
  4501. \009\009end,\
  4502. \
  4503. \009\009remapControl = function(self,name,to)\
  4504. \009\009\009for i = 1, #self.controls do\
  4505. \009\009\009\009if(self.controls[i].name == name)then\
  4506. \009\009\009\009\009self.controls[i].key = to\
  4507. \009\009\009\009end\
  4508. \009\009\009end\
  4509. \009\009end,\
  4510. \
  4511. \009\009addControl=function(self,controltable)\
  4512. \009\009\009if(type(controltable) ~= \"table\")then\
  4513. \009\009\009\009error(\"[RedGame]:addControl -> control must be a table in this format: {name=<control name>,event=<event>,key=<key in string format>,func=function() <actions> end}\")\
  4514. \009\009\009else\
  4515. \009\009\009\009table.insert(self.controls,controltable)\
  4516. \009\009\009end\
  4517. \009\009end,\
  4518. \
  4519. \009\009importControls=function(self,controltable)\
  4520. \009\009\009if(type(controltable) ~= \"table\")then\
  4521. \009\009\009\009error(\"[RedGame]:importControls -> control must be a table in this format: controls = { {name=<control name>,event=<event>,key=<key in string format>,func=function() <actions> end}, ect... }\")\
  4522. \009\009\009else\
  4523. \009\009\009\009self.controls = controltable\
  4524. \009\009\009end\
  4525. \009\009end,\
  4526. \
  4527. \
  4528. \009\009setPos = function(self,x,y)\
  4529. \009\009\009pmap[self.y][self.x] = 0\
  4530. \009\009\009drawMapPixel(self.y,self.x)\
  4531. \009\009\009self.x = x\
  4532. \009\009\009self.y = y\
  4533. \009\009\009self:checkCollision(self.x,self.y)\
  4534. \009\009\009pmap[self.y][self.x] = self.blockid\
  4535. \009\009\009drawMapPixel(self.y,self.x)\
  4536. \009\009end,\
  4537. \
  4538. \009\009update=function(self)\
  4539. \
  4540. \009\009\009for i = 1, #doors do\
  4541. \009\009\009\009if(getCurrentMap() == doors[i].fMap and self.x == doors[i].fx and self.y == doors[i].fy)then\
  4542. \009\009\009\009\009setMap(doors[i].tMap)\
  4543. \009\009\009\009\009self:setPos(doors[i].tx,doors[i].ty)\
  4544. \009\009\009\009end\
  4545. \009\009\009end\
  4546. \
  4547. \009\009\009if(self.multidir)then\
  4548. \009\009\009\009pmap[self.y][self.x] = 0\
  4549. \009\009\009\009drawMapPixel(self.y,self.x)\
  4550. \009\009\009\009if(not self:checkCollision(self.x+self.hspd,self.y))then\
  4551. \009\009\009\009\009self.x = self.x + self.hspd\
  4552. \009\009\009\009end\
  4553. \009\009\009\009if(not self:checkCollision(self.x,self.y+self.vspd))then\
  4554. \009\009\009\009\009self.y = self.y + self.vspd\
  4555. \009\009\009\009end\
  4556. \009\009\009\009pmap[self.y][self.x] = self.blockid\
  4557. \009\009\009\009drawMapPixel(self.y,self.x)\
  4558. \009\009\009end\
  4559. \
  4560. \009\009\009a = {os.pullEvent()}\
  4561. \
  4562. \009\009\009for k, v in pairs(self.events) do\
  4563. \009\009\009\009if(v.type == a[1])then\
  4564. \009\009\009\009\009v.run(a)\
  4565. \009\009\009\009end\
  4566. \009\009\009end\
  4567. \
  4568. \009\009\009if(a[1]==\"timer\")then\
  4569. \009\009\009\009self.physicsTick=os.startTimer(self.tickrate)\
  4570. \009\009\009\009for k, v in pairs(self.physics) do\
  4571. \009\009\009\009\009if(v.has)then v.func(self) end\
  4572. \009\009\009\009end\
  4573. \009\009\009end\
  4574. \
  4575. \009\009\009if(not self.multidir)then\
  4576. \009\009\009\009for i = 1, #self.controls do\
  4577. \009\009\009\009\009if(a[1] == self.controls[i].event and a[2] == self.controls[i].key)then\
  4578. \009\009\009\009\009\009self.controls[i].func(self)\
  4579. \009\009\009\009\009end\
  4580. \009\009\009\009end \
  4581. \009\009\009end\
  4582. \
  4583. \009\009\009if(self.multidir)then\
  4584. \009\009\009\009\009\009if(a[2] ~= self.physic_control[\"direction_up\"] and a[2] ~= self.physic_control[\"direction_down\"])then\
  4585. \009\009\009\009\009\009\009self.vspd = 0\
  4586. \009\009\009\009\009\009end\
  4587. \009\009\009\009\009\009if(a[2] ~= self.physic_control[\"direction_left\"] and a[2] ~= self.physic_control[\"direction_right\"])then\
  4588. \009\009\009\009\009\009\009self.hspd = 0\
  4589. \009\009\009\009\009\009end\
  4590. \009\009\009\009\009\009if(a[2] == self.physic_control[\"direction_up\"])then\
  4591. \009\009\009\009\009\009\009if(self:checkPhysics(\"gravity\"))then\
  4592. \009\009\009\009\009\009\009\009if(self:checkCollision(self.x,self.y+1))then\
  4593. \009\009\009\009\009\009\009\009\009self.vspd = -self.jump_height\
  4594. \009\009\009\009\009\009\009\009end\
  4595. \009\009\009\009\009\009\009else\
  4596. \009\009\009\009\009\009\009\009self.vspd = -self.jump_height\
  4597. \009\009\009\009\009\009\009end\
  4598. \009\009\009\009\009\009end\
  4599. \009\009\009\009\009\009if(a[2] == self.physic_control[\"direction_down\"])then\
  4600. \009\009\009\009\009\009\009self.vspd = 1\
  4601. \009\009\009\009\009\009end\
  4602. \009\009\009\009\009\009if(a[2] == self.physic_control[\"direction_left\"])then\
  4603. \009\009\009\009\009\009\009self.hspd = -1\
  4604. \009\009\009\009\009\009end\
  4605. \009\009\009\009\009\009if(a[2] == self.physic_control[\"direction_right\"])then\
  4606. \009\009\009\009\009\009\009self.hspd = 1\
  4607. \009\009\009\009\009\009end\
  4608. \009\009\009end\
  4609. \009\009end,\
  4610. \
  4611. \009}\
  4612. \
  4613. \009return player\
  4614. end",
  4615.   },
  4616.   [ "games/GameOfLife/" ] = {
  4617.     content = "--]] Game of life, by Redxone(Lewisk3), Special thanks to: MultMine [[--\
  4618. -- Rules:\
  4619. -- if less than 2, die\
  4620. -- if more then 3, die\
  4621. -- if has 2 or 3, live\
  4622. -- if more then 3, die\
  4623. -- if has exactly 3 and is dead, live\
  4624. os.loadAPI(\"CrossBow/apis/grid\")\
  4625. ------------------------------------\
  4626. term.setBackgroundColor(colors.black)\
  4627. term.clear()\
  4628. term.setCursorPos(1,1)\
  4629. term.setBackgroundColor(colors.gray)\
  4630. term.setTextColor(colors.white)\
  4631. term.clearLine()\
  4632. local w, h = term.getSize()\
  4633. -- check for updates -- \
  4634. term.setBackgroundColor(colors.gray)\
  4635. term.setTextColor(colors.white)\
  4636. term.clear()\
  4637. term.setCursorPos((w/2) - 11, 4)\
  4638. write(\"Checking for updates...\")\
  4639. if(http)then\
  4640. \009\009term.setCursorPos((w/2) - 1, (h/2) - 1)\
  4641. \009\009for i = 1, 5 do\
  4642. \009\009\009term.setCursorPos((w/2) - 1, (h/2) - 1)\
  4643. \009\009\009write(\":\")\
  4644. \009\009\009sleep(0.2)\
  4645. \009\009\009term.setCursorPos((w/2) - 1, (h/2) - 1)\
  4646. \009\009\009write(\"/\")\
  4647. \009\009\009sleep(0.2)\
  4648. \009\009\009term.setCursorPos((w/2) - 1, (h/2) - 1)\
  4649. \009\009\009write(\"-\")\
  4650. \009\009\009sleep(0.2)\
  4651. \009\009\009term.setCursorPos((w/2) - 1, (h/2) - 1)\
  4652. \009\009\009write(\"\\\\\")\009\
  4653. \009\009end\
  4654. \009local gameupdate = http.get(\"http://pastebin.com/raw/R3HfhA4x\")\
  4655. \009sleep(0.2)\
  4656. \009if(gameupdate == nil)then\
  4657.        gameupdate = gameupdate.readAll()\
  4658. \009\009f = fs.open(shell.getRunningProgram() ,\"r\")\
  4659. \009\009_contents = f.readAll()\
  4660. \009\009f.close()\
  4661. \009\009if(_contents ~= gameupdate)then\
  4662. \009\009\009term.setCursorPos((w/2) - 11, 4)\
  4663. \009\009\009write(\"Update found, updating...\")\
  4664. \009\009\009f = fs.open(shell.resolve(shell.getRunningProgram()),\"w\")\
  4665. \009\009\009f.write(gameupdate)\
  4666. \009\009\009f.close()\
  4667. \009\009\009sleep(0.5)\
  4668. \009\009\009term.setCursorPos((w/2) - 11, 4)\
  4669. \009\009\009term.clearLine()\
  4670. \009\009\009write(\" Restarting game...\")\
  4671. \009\009\009sleep(0.5)\
  4672. \009\009\009return shell.run(shell.getRunningProgram())\
  4673. \009\009end\
  4674. \009else\
  4675. \009\009term.setCursorPos((w/2) - 11, 4)\
  4676. \009\009write(\"Updating disable for CrossBow. launching game...\")\
  4677. \009\009sleep(0.2)\
  4678. \009end\
  4679. end\
  4680. term.clear()\
  4681. term.setCursorPos((w/2) - 12, (h/2) - 1)\
  4682. print(\"Creating cell universe...\")\
  4683. local verse = grid.create(82,50)\
  4684. local ngen = grid.create(82,50)\
  4685. sleep(0.2)\
  4686. local isPaused = false\
  4687. local running = true\
  4688. local generation = 0\
  4689. local speed = 0.01\
  4690. local xoff, yoff = 0, 0\
  4691. local genTimer = os.startTimer(speed)\
  4692. function newCell(alive)\
  4693.    local cell = {isAlive=true}\
  4694.    if(not alive)then cell.isAlive = false end\
  4695.    return cell\
  4696. end\
  4697. --- Fill universe with dead cells ---\
  4698. --verse:fill(newCell(false))\
  4699. --ngen:fill(newCell(false))\
  4700. --------------------------------------\
  4701. function drawCell(x,y)\
  4702.    if(x <= w and y <= 50 and y >= 2)then\
  4703.        term.setCursorPos(x,y)\
  4704.        if(verse:get(x+xoff,y+yoff).isAlive==true)then\
  4705.            if(isPaused)then term.setBackgroundColor(colors.yellow) else term.setBackgroundColor(colors.green) end\
  4706.            term.setTextColor(colors.black)\
  4707.            write(' ')\
  4708.        else\
  4709.             if(isPaused)then term.setBackgroundColor(colors.gray) else term.setBackgroundColor(colors.black) end\
  4710.             term.setTextColor(colors.lightGray)\
  4711.             if(isPaused)then write('L') else write (' ') end\
  4712.        end\
  4713.    end\
  4714. end\
  4715. function updateview()\
  4716.    for x = 1, verse:getHeight() do\
  4717.        for y = 1, verse:getWidth() do\
  4718.            drawCell(y,x)\
  4719.        end\
  4720.    end\
  4721. end\
  4722. function life()\
  4723.    for x = 1, verse:getHeight() do\
  4724.        for y = 1, verse:getWidth() do\
  4725.            local friends = 0\
  4726.            drawCell(y,x)\
  4727. \009\009    for _y = -1, 1 do\
  4728. \009\009     for _x = -1, 1 do\
  4729. \009\009      if _y ~= 0 or _x ~= 0 then\
  4730. \009\009       if(verse:get(y+_y,x+_x).isAlive == true) then friends = friends + 1 end\
  4731. \009\009      end\
  4732. \009\009     end\
  4733. \009\009    end\
  4734.             -- Die conditions\
  4735.            if(verse:get(y,x).isAlive and friends < 2)then\
  4736.                ngen:set(y,x,newCell(false))\
  4737.            elseif(friends > 3 and verse:get(y,x).isAlive)then\
  4738.                ngen:set(y,x,newCell(false))\
  4739.            end\
  4740.                -- Live conditions\
  4741.            if(verse:get(y,x).isAlive and (friends == 2 or friends == 3))then\
  4742.                ngen:set(y,x,newCell(true))\
  4743.            end\
  4744.            if(verse:get(y,x).isAlive ~= true and (friends == 3))then\
  4745.                ngen:set(y,x,newCell(true))\
  4746.            end\
  4747.        end\
  4748.    end\
  4749.  verse:replace(ngen:getRaw())\
  4750.  ngen = grid.create(82,50)\
  4751. end\
  4752. function infoBar()\
  4753.    term.setCursorPos(1,1)\
  4754.    term.setBackgroundColor(colors.gray)\
  4755.    term.setTextColor(colors.white)\
  4756.    term.clearLine()\
  4757.    local printgeneration = generation\
  4758.    if generation > 999 then printgeneration = 999 end\
  4759.    write(\" Editing:\" .. tostring(isPaused) .. \" Generation: \" .. printgeneration .. \",\" .. speed .. \" X:\" .. xoff .. \",Y:\" .. yoff)\
  4760.    term.setCursorPos(w,1)\
  4761.    term.setBackgroundColor(colors.red)\
  4762.    write('X')\
  4763.    term.setCursorPos(w-1,1)\
  4764.    term.setBackgroundColor(colors.lightGray)\
  4765.    write('C')\
  4766. end\
  4767. function endscr()\
  4768. \009term.setBackgroundColor(colors.black)\
  4769.    term.clear()\
  4770.    term.setCursorPos(1,1)\
  4771.    term.setBackgroundColor(colors.gray)\
  4772.    term.setTextColor(colors.white)\
  4773.    term.clearLine()\
  4774.    write(\"Thank you for playing Lewisk3's Game Of Life! Credits: John Conway, Multmine\")\
  4775.    term.setCursorPos(w,1)\
  4776.    term.setBackgroundColor(colors.brown)\
  4777.    write('X')\
  4778. \009term.setBackgroundColor(colors.black)\
  4779.    term.setCursorPos(1,3)\
  4780. \
  4781. end\
  4782. \
  4783. verse:loop(drawCell)\
  4784. while running do\
  4785.    term.current().setVisible(false)\
  4786.    infoBar()\
  4787.    ev = {os.pullEvent()}\
  4788.    if(ev[1] == 'key')then\
  4789.        if(ev[2] == keys.space)then isPaused = not isPaused end\
  4790.        if(ev[2] == keys.w and yoff > 0)then yoff = yoff - 1 end\
  4791.        if(ev[2] == keys.a and xoff > 0)then xoff = xoff - 1 end\
  4792.        if(ev[2] == keys.s and yoff < verse:getHeight()-h)then yoff = yoff + 1 end\
  4793.        if(ev[2] == keys.d and xoff < verse:getWidth()-w)then xoff = xoff + 1 end\
  4794.        if(ev[2] == keys.up and speed > 0.01)then speed = speed - 0.01 end  \
  4795.        if(ev[2] == keys.down)then speed = speed + 0.01 end\
  4796.        updateview()\
  4797.    end\
  4798.    if(ev[1] == 'timer' and ev[2] == genTimer)then\
  4799.        if(not isPaused)then life() generation = generation + 1 end\
  4800.        genTimer = os.startTimer(speed)\
  4801.    elseif(ev[1] == \"mouse_click\" or ev[1] == \"mouse_drag\")then\
  4802.        \009if(ev[3] == w and ev[4] == 1)then running = false endscr() end\
  4803.        \009if(ev[3] == w-1 and ev[4] == 1)then verse = grid.create(verse:getWidth(),verse:getHeight()) verse:fill({}) ngen = grid.create(ngen:getWidth(),ngen:getHeight()) updateview() end\
  4804.        if(isPaused)then   \
  4805.            if(ev[2] == 1)then verse:set(ev[3]+xoff,ev[4]+yoff,newCell(true)) end\
  4806.            if(ev[2] == 2)then verse:set(ev[3]+xoff,ev[4]+yoff,{}) end\
  4807.            drawCell(ev[3],ev[4])\
  4808.        end\
  4809.    end\
  4810.    term.current().setVisible(true)\
  4811. end",
  4812.   },
  4813.   [ "programs/configs/novapins/" ] = {
  4814.     content = "{\
  4815.  {\
  4816.    t = \"text\",\
  4817.    n = \" \",\
  4818.  },\
  4819.  {\
  4820.    n = \"&4-&7=&8] &rGameOfLife\",\
  4821.    href = \"CrossBow/games/GameOfLife\",\
  4822.    t = \"game\",\
  4823.  },\
  4824.  {\
  4825.    n = \"&4-&7=&8] &r2048\",\
  4826.    href = \"CrossBow/games/2048\",\
  4827.    t = \"game\",\
  4828.  },\
  4829.  {\
  4830.    n = \"&e[=] &5Apis\",\
  4831.    href = \"CrossBow/apis\",\
  4832.    t = \"folder\",\
  4833.  },\
  4834. }",
  4835.   },
  4836. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement