· 6 years ago · Jan 01, 2020, 09:20 PM
1
2--[[
3
4OS Freeware v2
5
6Revisions from OS Freeware v1:
7 - more stable window api
8 - better app management
9 - less code with more stable engine
10 - more user friendly
11 - code more clear for developers to monkey with
12 - more avaliable settings for desktop
13
14Just Does Games
15
16]]
17
18version = "Freeware v2.1.0" -- os version
19dir = "/freewarev2/" -- os directory
20
21
22-- pre-functions
23
24function clr() return term.clear() end
25function cp(x,y) return term.setCursorPos(x,y) end
26function setText(col) return term.setTextColor(colors[col]) end
27function setBack(col) return term.setBackgroundColor(colors[col]) end
28function notnil(vari) if vari == nil then return false else return true end end
29
30-- pre-functions
31
32
33
34
35-- pre-values
36
37w,h = term.getSize() -- gets size of computer (entire computer, not the window api)
38
39if not http or not term.isColor() or w ~= 51 or h ~= 19 then -- strict requirements
40 if not http then
41 return print("Http is not present")
42 elseif not term.isColor() then
43 return print("Advanced Computer Required")
44 elseif w ~= 51 or h ~= 19 then
45 return print("51x19 Device Only")
46 end
47end
48
49--== Global Values ==--
50
51running = true -- loop for the os (if false, ends entire os)
52update = true -- update apps on the screen (used for after running a program or to update desktop)
53apps = {} -- used for loading all apps (format: name [string], type [number], location [string], texture [table])
54loaded_apps = {} -- used to load the currently displaying apps easier
55page = 1 -- current page
56maxPage = 1 -- max amount of pages
57app_locations = {8,22,36} -- app x-axis
58
59title_color = "white" -- app title color (default: "white")
60desktop_color = "black" -- desktop background color (default: "black")
61scroll_color = "gray" -- desktop scroll left to right background color (default: "gray")
62scroll_text_color = "white" -- desktop scroll left to right text color (default: "white")
63bar_color = "lightBlue" -- desktop bar color (default: "lightBlue")
64bar_text_color = "blue" -- desktop bar text color (default: "blue")
65
66--== Global Values ==--
67
68-- pre-values
69
70
71-- load icons
72
73_t = { -- default app textures
74
75{
76"noTexture",
77"eeeeeeee",
78"eeeeeeee",
79"55555555",
80"55555555",
81"bbbbbbbb",
82"bbbbbbbb"
83},
84
85{
86"ShellOS",
87"11111111",
88"10fffff1",
89"1f0ffff1",
90"10ff00f1",
91"1ffffff1",
92"11111111"
93},
94
95{
96"Homebrew",
97"90999909",
98"90999909",
99"90000009",
100"90000009",
101"90999909",
102"90999909"
103},
104
105{
106"Reboot",
107" 77777",
108" 71117",
109" 71717",
110" 71117",
111" 71777",
112" 777"
113},
114
115{
116"Shutdown",
117" 77777",
118" 7eee7",
119" 7e7e7",
120" 7eee7",
121" 7e777",
122" 777"
123},
124
125{
126"Worm",
127" 777777",
128"7777ddd7",
129"7e77d777",
130"7777d777",
131"7dddd7e7",
132" 777777"
133},
134
135{
136"Adventure",
137" 777777",
138"77000077",
139"77077077",
140"77000077",
141"77077077",
142" 777777"
143},
144
145{
146"Landslide",
147" cccccc ",
148"cc0ccccc",
149"cc0ccccc",
150"cc0ccccc",
151"cc0000cc",
152" cccccc "
153},
154
155{
156"Pastebin",
157" 000000",
158"08887000",
159"08087770",
160"08887070",
161"08007770",
162" 000000"
163},
164
165{
166"Lua",
167" bbbb",
168" b0bbbb",
169"bb0bbbbb",
170"bb0bbbbb",
171" b0000b",
172" bbbb"
173},
174
175{
176"Crash",
177" bbbb",
178" b0000b",
179"bb0bbbbb",
180"bb0bbbbb",
181" b0000b",
182" bbbb"
183},
184
185{
186"Desktop",
187"ffffffff",
188"fef1f4ff",
189"ffffffff",
190"fdfbfaff",
191"fdfbfaff",
192"ffffffff",
193},
194
195{
196"Files",
197"48884444",
198"48884444",
199"44444444",
200"44444444",
201"43333334",
202"43444434"
203},
204
205}
206for i=1, #_t do -- verifies that the files exists. If the file does not exists, creates the file again.
207 if not fs.exists(dir.."icons/".._t[i][1]..".nfp") then
208 local file = fs.open(dir.."icons/".._t[i][1]..".nfp", "w")
209 for ii=1, #_t[i]-1 do
210 file.writeLine(_t[i][ii+1])
211 end
212 file.close()
213 end
214end
215t_noTexture = paintutils.loadImage(dir.."icons/noTexture.nfp")
216t_ShellOS = paintutils.loadImage(dir.."icons/ShellOS.nfp")
217t_Homebrew = paintutils.loadImage(dir.."icons/Homebrew.nfp")
218t_Reboot = paintutils.loadImage(dir.."icons/Reboot.nfp")
219t_Shutdown = paintutils.loadImage(dir.."icons/Shutdown.nfp")
220t_Worm = paintutils.loadImage(dir.."icons/Worm.nfp")
221t_Adventure = paintutils.loadImage(dir.."icons/Adventure.nfp")
222t_Landslide = paintutils.loadImage(dir.."icons/Landslide.nfp")
223t_Pastebin = paintutils.loadImage(dir.."icons/Pastebin.nfp")
224t_Lua = paintutils.loadImage(dir.."icons/Lua.nfp")
225t_Crash = paintutils.loadImage(dir.."icons/Crash.nfp")
226t_Desktop = paintutils.loadImage(dir.."icons/Desktop.nfp")
227t_Files = paintutils.loadImage(dir.."icons/Files.nfp")
228
229
230
231
232
233-- load icons
234
235
236
237
238-- os games
239
240function playLandslide()
241 -- Landslide --
242 -- Just Does Games --
243
244 term.clear()
245
246 local x,y = term.getSize()
247 local px = math.ceil(x/2)
248 local rocks = {} -- Rock Data: {rock x, rock y, id}
249 local maxRocks = 100
250 local run = true
251 local difficulty = {.1,.4}
252 local gamespeed = 0.3
253 local score = 0
254 local maxGamespeed = 0.01
255 local maxScore = 999999999
256 local alt = true
257
258 local function drawRedBar()
259 term.setCursorPos(1,y-3)
260 term.setBackgroundColor(colors["red"])
261 term.clearLine() print("")
262 term.clearLine()
263 end
264
265 local function drawRocks()
266 if score > 500 then
267 -- Do nothing
268 elseif score > 400 then
269 if alt then
270 term.setCursorPos(1,y-3)
271 for i=1, math.floor(x/2) do
272 write(" !")
273 end
274 term.setCursorPos(1,y-2)
275 for i=1, math.floor(x/2) do
276 write("! ")
277 end
278 else
279 term.setCursorPos(1,y-3)
280 for i=1, math.floor(x/2) do
281 write(" ")
282 end
283 term.setCursorPos(1,y-2)
284 for i=1, math.floor(x/2) do
285 write(" ")
286 end
287 end
288 alt = not alt
289 end
290 for i=1, #rocks do
291 term.setCursorPos(rocks[i][1],rocks[i][2]) term.setBackgroundColor(colors["lightGray"]) write(" ")
292 if rocks[i][2] ~= y+1 then
293 term.setCursorPos(rocks[i][1],rocks[i][2]-1) term.setBackgroundColor(colors["black"]) write(" ")
294 end
295 if notnil(rocks[i]) then
296 if px == rocks[i][1] and rocks[i][2] == y then run = false end
297 end
298 end
299 if score > 500 then
300 drawRedBar()
301 end
302 end
303
304 local function drawPlayer()
305 term.setCursorPos(px,y) term.setBackgroundColor(colors["white"]) write(" ")
306 if px ~= x then
307 term.setCursorPos(px+1,y) term.setBackgroundColor(colors["black"]) write(" ")
308 end
309 if px ~= 1 then
310 term.setCursorPos(px-1,y) term.setBackgroundColor(colors["black"]) write(" ")
311 end
312 end
313 drawPlayer()
314
315 local function spawnRock()
316 if maxRocks ~= #rocks then
317 table.insert(rocks, {math.random(1,x),0})
318 end
319 end
320
321 local function destroyRock(rock)
322 term.setCursorPos(rock[1],rock[2]) term.setBackgroundColor(colors["black"]) write(" ")
323 table.remove(rocks, 1)
324 if score ~= maxScore then score = score + 1 end
325 if gamespeed < maxGamespeed then
326 if score > 200 then
327 gamespeed = gamespeed - 0.01
328 elseif score > 400 then
329 gamespeed = gamespeed - 0.02
330 else
331 gamespeed = gamespeed - 0.03
332 end
333 elseif gamespeed < 0 then
334 gamespeed = maxGamespeed
335 end
336 end
337
338 local function engine1() -- player location
339 while run do
340 sleep(.0001)
341 local a,i = os.pullEvent("key")
342 if a == "key" then
343 if i == keys.a or i == keys.left then
344 if px ~= 1 then
345 px = px - 1
346 end
347 elseif i == keys.d or i == keys.right then
348 if px ~= x then
349 px = px + 1
350 end
351 end
352 end
353
354 for i=1, #rocks do
355 if notnil(rocks[i]) then
356 if px == rocks[i][1] and rocks[i][2] == y then run = false end
357 end
358 end
359 drawPlayer()
360 end
361 end
362
363 local function engine2() -- rock spawner
364 while true do
365 sleep(math.random(difficulty[1],difficulty[2]))
366 spawnRock()
367 end
368 end
369
370 local function engine3() -- rock manager
371 while run do
372 local rocksToDestroy = {}
373 for i=1, #rocks do
374 if notnil(rocks[i]) then
375 if rocks[i][2] ~= y+1 then
376 rocks[i][2] = rocks[i][2] + 1
377 else
378 table.insert(rocksToDestroy, rocks[i])
379 end
380 end
381 end
382 drawRocks()
383
384 for i=1, #rocksToDestroy do
385 destroyRock(rocksToDestroy[i])
386 end
387 for i=1, #rocks do
388 if notnil(rocks[i]) then
389 if px == rocks[i][1] and rocks[i][2] == y then run = false end
390 end
391 end
392 sleep(gamespeed)
393 end
394 end
395
396 local function gameover()
397 sleep(.5)
398 term.setTextColor(colors["white"])
399 term.setBackgroundColor(colors["black"])
400 term.clear()
401 term.setCursorPos(x/2-(string.len("Game Over")/2), y/2-1)
402 write("Game Over")
403 term.setCursorPos(x/2-(string.len("Score - "..score)/2), y/2)
404 write("Score - "..score)
405 sleep(1)
406 term.setCursorPos(x/2-(string.len("Press any key to exit...")/2), y/2+3)
407 write("Press any key to exit...")
408 os.pullEvent()
409 end
410
411 local function loop()
412 parallel.waitForAny(engine1,engine2,engine3)
413 gameover()
414 end
415
416 loop()
417end
418
419-- os games
420
421
422-- os programs
423
424
425function runFileProgram(browse)
426 --
427end
428
429
430function pbrun(code, action, name)
431 if code == nil then
432 return "Invalid Code"
433 elseif string.len(code) < 8 then
434 return "Invalid Code Length."
435 elseif action == "get" and name == nil or name == "" then
436 return "File Name Missing."
437 elseif notnil(name) then
438 if fs.exists(name) then
439 return "File Already Exists"
440 end
441 end
442 term.setCursorBlink(false)
443 cp(1,h-3) setBack("white") setText("white")
444 if action == "run" then
445 cp(1,1) setText("white") setBack("black") clr()
446 return shell.run("pastebin "..action.." "..code)
447 elseif action == "get" then
448 return shell.run("pastebin "..action.." "..code.." "..name)
449 end
450end
451
452function runPastebin()
453 term.setCursorBlink(true)
454 local buttonToggle = true
455 local updat = true
456 local chars = ""
457 local charSelected = true
458 local fsSelected = false
459 local fsPath = ""
460 local runPB = false
461 local stattoggle = true
462 local statm = ""
463
464 local run = true
465
466 while run do
467 if runPB then
468 runPB = false
469 local res
470 setBack("white")
471 cp(6,14+string.len("GO Status: ")) setText("orange") write("Running...")
472 if buttonToggle then
473 res = pbrun(chars, "get", fsPath)
474 else
475 res = pbrun(chars, "run")
476 end
477 term.setCursorBlink(true)
478 if res ~= true then
479 statm = res
480 else
481 statm = "Success!"
482 end
483 setText("black")
484 end
485 if updat then
486 updat = not updat
487 cp(1,1)
488 setText("black")
489 setBack("white")
490 clr()
491 paintutils.drawLine(1,1,w,1,colors["lightGray"])
492 cp(1,3)
493
494 setBack("white")
495 write("Pastebin Code: ")
496 setBack("lightGray")
497 for i=1, 9 do write(" ") end
498
499 if buttonToggle then
500 paintutils.drawFilledBox(5,5,10,8,colors["green"])
501 cp(6,6) write("Get")
502 paintutils.drawFilledBox(12,5,17,8,colors["gray"])
503 cp(13,6) write("Run")
504 else
505 paintutils.drawFilledBox(5,5,10,8,colors["gray"])
506 cp(6,6) write("Get")
507 paintutils.drawFilledBox(12,5,17,8,colors["green"])
508 cp(13,6) write("Run")
509 end
510 paintutils.drawFilledBox(5,12,10,15,colors["lime"])
511 cp(6,13) write("GO ")
512 setBack("white") write(" Status: ")
513 if stattoggle then setText("green") else setText("red") end
514 write(statm) setText("black")
515
516 if buttonToggle then
517 cp(1,10)
518 setBack("white")
519 write("File Name: ")
520 setBack("lightGray")
521 for i=1, w-string.len("File Name: ") do
522 write(" ")
523 end
524 end
525
526 end
527
528 setBack("lightGray")
529 cp(string.len("Pastebin Code: ")+1,3)
530 write(chars.." ")
531 cp(string.len("Pastebin Code: ")+1+string.len(chars),3)
532
533 if buttonToggle then
534 cp(string.len("File Name: ")+1,10)
535 write(fsPath.." ")
536
537 if charSelected then
538 cp(string.len("Pastebin Code: ")+1+#chars, 3)
539 else
540 cp(string.len("File Name: ")+1+string.len(fsPath), 10)
541 end
542 end
543
544 a,i,x,y = os.pullEvent()
545 if a == "mouse_click" then
546 if i == 1 then
547 if x >= string.len("Pastebin Code: ")+1 and x <= string.len("Pastebin Code: ")+9 and y == 3 then
548 term.setCursorBlink(true)
549 fsSelected = false
550 charSelected = true
551 elseif x >= string.len("File Name: ")+1 and y == 10 and buttonToggle then
552 term.setCursorBlink(true)
553 fsSelected = true
554 charSelected = false
555 else
556 term.setCursorBlink(false)
557 charSelected = false
558 if x >= 5 and x <= 10 and y >= 5 and y <= 8 then
559 buttonToggle = true updat = true
560 elseif x >= 12 and x <= 17 and y >= 5 and y <= 8 then
561 buttonToggle = false updat = true
562 end
563 end
564 end
565 elseif a == "paste" then
566 if charSelected then
567 if string.len(chars..i) <= 8 then chars = chars..i end
568 elseif fsSelected then
569 if string.len(fsPath..i) < w-string.len("File Name: ")-1 then fsPath = fsPath..i end
570 end
571 elseif a == "char" then
572 if i ~= " " then
573 if charSelected then
574 if string.len(chars) ~= 8 then chars = chars..i end
575 else
576 if string.len(fsPath) < w-string.len("File Name: ")-1 then fsPath = fsPath..i end
577 end
578 end
579 elseif a == "key" then
580 if i == keys.backspace and charSelected then
581 chars = string.sub(chars,1,-2)
582 elseif i == keys.backspace and fsSelected then
583 fsPath = string.sub(fsPath,1,-2)
584 elseif i == keys.enter or i == keys.tab then
585 if charSelected then
586 charSelected = false
587 if buttonToggle then
588 fsSelected = true
589 else
590 runPB = true updat = true
591 end
592 elseif fsSelected then
593 runPB = true updat = true
594 end
595 end
596 end
597
598 end
599 term.setCursorBlink(false)
600end
601
602function runDesktop(browse)
603 -- Desktop
604 --[[
605 if notnil(browse) then browse = true else browse = false end
606 local w,h = term.getSize()
607 local run = true
608 local selected = 1
609 local scroll = 0
610 local updat = true
611 local display
612 local l_apps = apps
613 for i=1, 10 do
614 table.insert(l_apps, {"Debug "..i, 2, "", t_noTexture, false})
615 end
616 while run do
617 if updat then
618 updat = false cp(1,1) setText("white") setBack("black") clr()
619 end
620 display = {}
621 if #l_apps > h-math.ceil(#l_apps/6) then
622 for i=1, h do
623 table.insert(display, l_apps[i+scroll])
624 end
625 else
626 display = l_apps
627 end
628 cp(1,1)
629 for i=1, #display do
630 if i == selected then
631 setText("lime")
632 write("> ")
633 else
634 write(" ")
635 end
636 if display[i][1] == "ShellOS" or display[i][1] == "Desktop" then
637 setText("orange")
638 else
639 if display[i][5] == true then
640 setText("white")
641 else
642 setText("gray")
643 end
644 end
645 if i == #display then
646 write(display[i][1].." ")
647 else
648 print(display[i][1].." ")
649 end
650 end
651 a,i = os.pullEvent("key")
652 if i == keys.w or i == keys.up then
653 if selected == 3 and scroll ~= 0 then
654 scroll = scroll - 1
655 elseif selected ~= 1 then
656 selected = selected - 1
657 end
658 elseif i == keys.s or i == keys.down then
659 if selected == #display-3 and display[#display] ~= l_apps[#l_apps] then
660 scroll = scroll + 1
661 elseif selected ~= #display then
662 selected = selected + 1
663 end
664 elseif i == keys.enter or i == keys.e then
665 _playAnimation("drag",1,selected,1,1,display[selected][1],.005)
666 clr()
667 local menu = {}
668 local sel = 1
669 if browse then
670 table.insert(menu, "Select App")
671 else
672 if display[selected][1] ~= "ShellOS" and display[selected][1] ~= "Desktop" then
673 table.insert(menu, "Toggle App")
674 end
675 if display[selected][2] ~= 1 then
676 table.insert(menu, "Remove App")
677 end
678 table.insert(menu, "Move App")
679 end
680
681 table.insert(menu, "Exit")
682 repeat
683 cp(1,1)
684 if display[selected][1] == "ShellOS" or display[selected][1] == "Desktop" then
685 setText("orange")
686 else
687 if display[selected][5] == true then
688 setText("white")
689 else
690 setText("gray")
691 end
692 end
693 print(display[selected][1])
694 print("")
695 for i=1, #menu do
696 if i == sel then
697 setText("white")
698 print("> "..menu[i].." ")
699 else
700 setText("gray")
701 print(" "..menu[i].." ")
702 end
703 end
704 a,i = os.pullEvent("key")
705 if i == keys.w or i == keys.up then
706 if sel > 1 then sel = sel - 1 end
707 elseif i == keys.s or i == keys.down then
708 if sel < #menu then sel = sel + 1 end
709 elseif i == keys.enter or i == keys.e then
710 if menu[sel] == "Exit" then
711 sel = true
712 elseif menu[sel] == "Toggle App" then
713 display[selected][5] = not display[selected][5]
714 l_apps[selected+scroll][5] = display[selected][5]
715 elseif menu[sel] == "Remove App" then
716 table.remove(display, selected)
717 table.remove(l_apps, selected+scroll)
718 sel = false
719 elseif menu[sel] == "Select App" then
720 return display[selected]
721 elseif menu[sel] == "Move App" then
722 local animate_display = true
723 local function main()
724 local loop = true
725 clr()
726 while loop do
727 display = {}
728 if #l_apps > h-math.ceil(#l_apps/6) then
729 for i=1, h do
730 table.insert(display, l_apps[i+scroll])
731 end
732 else
733 display = l_apps
734 end
735 cp(1,1)
736 for i=1, #display do
737 if i == selected then
738 setText("yellow")
739 write("> ")
740 else
741 write(" ")
742 end
743 if display[i][1] == "ShellOS" or display[i][1] == "Desktop" and selected ~= i then
744 setText("orange")
745 elseif i == selected and animate_display then
746 setText("purple")
747 else
748 if display[i][5] == true then
749 setText("white")
750 else
751 setText("gray")
752 end
753 end
754 if not animate_display and i == selected then
755 if i == #display then
756 write(" ")
757 else
758 print(" ")
759 end
760 else
761 if i == #display then
762 write(display[i][1].." ")
763 else
764 print(display[i][1].." ")
765 end
766 end
767 end
768 a,i = os.pullEvent("key")
769 if i == keys.w or i == keys.up then
770 if selected == 3 and scroll ~= 0 then
771 scroll = scroll - 1
772 local tmp1 = l_apps[selected+1+scroll]
773 local tmp2 = l_apps[selected+scroll]
774 l_apps[selected+1+scroll] = tmp2
775 l_apps[selected+scroll] = tmp1
776 elseif selected ~= 1 then
777 selected = selected - 1
778 local tmp1 = l_apps[selected+1+scroll]
779 local tmp2 = l_apps[selected+scroll]
780 l_apps[selected+1+scroll] = tmp2
781 l_apps[selected+scroll] = tmp1
782 end
783 elseif i == keys.s or i == keys.down then
784 if selected == #display-3 and display[#display] ~= l_apps[#l_apps] then
785 scroll = scroll + 1
786 local tmp1 = l_apps[selected-1+scroll]
787 local tmp2 = l_apps[selected+scroll]
788 l_apps[selected-1+scroll] = tmp2
789 l_apps[selected+scroll] = tmp1
790 elseif selected ~= #display then
791 selected = selected + 1
792 local tmp1 = l_apps[selected-1+scroll]
793 local tmp2 = l_apps[selected+scroll]
794 l_apps[selected-1+scroll] = tmp2
795 l_apps[selected+scroll] = tmp1
796 end
797 elseif i == keys.enter or i == keys.e then
798 loop = false
799 end
800 end
801 end
802 local function animate()
803 while true do
804 cp(1,selected) setText("yellow") write("> ") setText("purple") if selected == #display then write(l_apps[selected+scroll][1]) else print(l_apps[selected+scroll][1]) end animate_display = true sleep(.5) cp(1,selected) term.clearLine() setText("yellow") write("> ") animate_display = false sleep(.5)
805 end
806 end
807 parallel.waitForAny(main, animate)
808 clr()
809 end
810 end
811 until type(sel) ~= "number"
812 if sel == true then
813 _playAnimation("drag",1,1,1,selected,display[selected][1],.005)
814 else
815 selected = 1
816 scroll = 0
817 end
818 apps = l_apps
819 _save()
820 end
821 end
822 ]]
823end
824
825-- os programs
826
827
828
829
830
831-- base os-functions
832
833function _save() -- save all apps
834 local file = fs.open(dir.."apps/list.lua", "w")
835 file.write(textutils.serialize(apps))
836 file.close()
837 local cnt = 0
838 for i=1, #apps do
839 if apps[i][5] == false then
840 cnt = cnt + 1
841 end
842 end
843 page = 1
844 maxPage = math.ceil((#apps-cnt)/6)
845end
846
847function _load() -- load all apps
848 local default_apps = {{"ShellOS", 1, "", t_ShellOS, true},{"Homebrew", 1, "", t_Homebrew, true}, {"Shutdown", 1, "", t_Shutdown, true}, {"Files", 1, "", t_Files, true}, {"Reboot", 1, "", t_Reboot, true}, {"Worm", 1, "", t_Worm, true}, {"Adventure", 1, "", t_Adventure, true}, {"Landslide", 1, "", t_Landslide, true}, {"Pastebin", 1, "", t_Pastebin, true}, {"Lua", 1, "", t_Lua, true}, {"Crash", 1, "", t_Crash, true}, {"Desktop", 1, "", t_Desktop, true}, --[[{"Test", 1, "", t_noTexture, true}]]}
849 if fs.exists(dir.."apps/list.lua") then
850 local file = fs.open(dir.."apps/list.lua","r")
851 local data = file.readAll()
852 file.close()
853 apps = textutils.unserialize(data)
854 else
855 apps = default_apps
856 end
857 if apps ~= nil then if #apps < 1 then
858 apps = default_apps
859 end end
860 if apps == nil then
861 apps = default_apps
862 end
863 page = 1
864 maxPage = math.ceil(#apps/6)
865end
866
867function _display_desktop()
868 loaded_apps = {}
869 paintutils.drawLine(1,h,w,h,colors[bar_color]) cp(1,h) setText(bar_text_color) write("Page: "..page.."/"..maxPage)
870
871 local _appsLoaded = apps
872 local _rm = {}
873 for i=1, #_appsLoaded do
874 if _appsLoaded[i][5] == false then
875 table.insert(_rm, i)
876 end
877 end
878 for i=1, #_rm do
879 table.remove(_appsLoaded, _rm[i])
880 end
881 for i=1, 6 do
882 loaded_apps[i] = _appsLoaded[i+(6*(page-1))]
883 end
884
885 if page ~= 1 then
886 setBack(scroll_color)
887 setText(scroll_text_color)
888 else
889 setBack("black")
890 setText("gray")
891 end
892 for i=1, 6 do
893 cp(1,h/2-i+4)
894 write(" ")
895 end
896 cp(1,h/2-3) write("<")
897 cp(1,h/2+3) write("<")
898 if page ~= maxPage then
899 setBack(scroll_color)
900 setText(scroll_text_color)
901 else
902 setBack("black")
903 setText("gray")
904 end
905 for i=1, 6 do
906 cp(w, h/2-i+4)
907 write(" ")
908 end
909 cp(w,h/2-3) write(">")
910 cp(w,h/2+3) write(">")
911
912 setText(title_color)
913 for i=1, #loaded_apps do
914 if loaded_apps[i][5] ~= false then
915 if i <= 3 then -- top
916 setBack(desktop_color)
917 cp(app_locations[i], 1) write(loaded_apps[i][1])
918 if loaded_apps[i][4] == nil then loaded_apps[i][4] = t_noTexture end
919 paintutils.drawImage(loaded_apps[i][4], app_locations[i], 2)
920 else -- bottom
921 setBack(desktop_color)
922 cp(app_locations[i-3], h-8) write(loaded_apps[i][1])
923 if loaded_apps[i][4] == nil then loaded_apps[i][4] = t_noTexture end
924 paintutils.drawImage(loaded_apps[i][4], app_locations[i-3], h-7)
925 end
926 sleep(.05)
927 end
928 end
929end
930
931function _playAnimation(animation, arg1, arg2, arg3, arg4, arg5, arg6)
932 if animation == "drag" then
933 if notnil(arg1) == true and notnil(arg2) and notnil(arg3) and notnil(arg4) and notnil(arg5) and notnil(arg6) then
934 -- est. variables: arg1 = current_x_pos, arg2 = current_y_pos, arg3 = target_x_pos, arg4 = target_y_pos, text, speed
935 setText("purple")
936 local total
937 local rn = (arg1-arg3)+(arg2-arg4)
938 if rn < 0 then rn = rn*-1 end
939 for i=1, rn do
940 clr()
941 cp(arg1, arg2)
942 write(arg5)
943 sleep(arg6)
944 if arg1 ~= arg3 then
945 if arg1 > arg3 then
946 arg1 = arg1 - 1
947 else
948 arg1 = arg1 + 1
949 end
950 end
951 if arg2 ~= arg4 then
952 if arg2 > arg4 then
953 arg2 = arg2 - 1
954 else
955 arg2 = arg2 + 1
956 end
957 end
958 end
959 else
960 return error("One or more of the values provided are nil")
961 end
962 end
963end
964
965function _update()
966 update = false setBack(desktop_color) clr()
967 _display_desktop()
968end
969
970-- base os-functions
971
972
973-- os-program index
974
975function runProgram(location, wd)
976 local old = term.current() local mainw
977 if notnil(wd) then
978 mainw = window.create(term.current(),3,3,w-4,h-5)
979 paintutils.drawBox(2,2,w-1,h-2,colors["gray"])
980 setText("lightGray")
981 cp(3,2)
982 for i=1, w-4 do
983 write("-")
984 end
985 for i=1, h-5 do
986 cp(2,2+i)
987 write("|")
988 cp(w-1,2+i)
989 write("|")
990 end
991 cp(3,h-2)
992 for i=1, w-4 do
993 write("-")
994 end
995 paintutils.drawPixel(w-1,2,colors["red"])
996 else
997 mainw = window.create(term.current(),1,1,w,h-1)
998 setBack("black")
999 setText("white")
1000 clr()
1001 paintutils.drawLine(1,h,w,h,colors["lightGray"])
1002 paintutils.drawPixel(w,h,colors["red"])
1003 end
1004 local run = true
1005 local function window()
1006 while run do
1007 a,i,x,y = os.pullEvent()
1008 if a == "mouse_click" then
1009 if x == w and y == h and not notnil(wd) then
1010 run = false
1011 elseif x == w-1 and y == 2 and notnil(wd) then
1012 run = false
1013 end
1014 end
1015 end
1016 end
1017 local _program_return = ""
1018 local function program()
1019 if type(location) == "string" then
1020 cp(1,1) setText("white") setBack("black") clr() print("Loading App...") sleep(.7)
1021 _program_return = shell.run(location)
1022 sleep(1)
1023 print("Press any key to exit...")
1024 os.pullEvent()
1025 elseif type(location) == "function" then
1026 _program_return = location()
1027 end
1028 end
1029
1030 local oldTerm = term.redirect(mainw)
1031 local r,e = pcall(function() parallel.waitForAny(window, program) end)
1032 local newTerm = term.redirect(old)
1033
1034 term.setCursorBlink(false)
1035 update = true
1036 if not r then
1037 return error(e)
1038 end
1039 if run == true then
1040 return _program_return
1041 else
1042 return false
1043 end
1044end
1045
1046function _test()
1047 local w,h = term.getSize()
1048 for i=1, h+5 do
1049 print("Debug "..i)
1050 sleep(.1)
1051 end
1052 local res = runProgram(function() return runFileProgram(true) end, true)
1053 local w,h = term.getSize()
1054 for i=1, h+5 do
1055 print("Debug "..i.."res: "..type(res))
1056 sleep(.1)
1057 end
1058 sleep(1)
1059end
1060
1061_index = {
1062
1063ShellOS = function()
1064 runProgram(function() shell.run("shell") end)
1065end,
1066
1067Homebrew = function()
1068 running = false
1069end,
1070
1071Shutdown = function()
1072 os.shutdown()
1073end,
1074
1075Reboot = function()
1076 os.reboot()
1077end,
1078
1079Worm = function()
1080 runProgram(function() shell.run("worm") end)
1081end,
1082
1083Adventure = function()
1084 runProgram(function() shell.run("adventure") end)
1085end,
1086
1087Landslide = function()
1088 runProgram(function() playLandslide() end)
1089end,
1090
1091Pastebin = function()
1092 runProgram(function() runPastebin() end)
1093end,
1094
1095Lua = function()
1096 runProgram(function() shell.run("lua") end)
1097end,
1098
1099Crash = function()
1100 error("Crash App")
1101end,
1102
1103Desktop = function()
1104 runProgram(function() runDesktop() end)
1105end,
1106
1107Test = function() -- use this to test anything
1108 runProgram(function() _test() end)
1109end,
1110
1111Files = function()
1112 runProgram(function() runFileProgram() end)
1113end
1114
1115}
1116
1117-- os-program index
1118
1119
1120-- os
1121
1122function runtime() -- Main Loop
1123 -- main script
1124 _load()
1125 _save()
1126 while running do
1127 -- main loop
1128 if update then
1129 _update()
1130 end
1131 local a,i,x,y = os.pullEvent("mouse_click")
1132 if i == 1 then -- left-click
1133 if x == 1 and y >= 6 and y <= 12 then
1134 if page > 1 then page = page - 1 update = true end
1135 elseif x == w and y >= 6 and y <= 12 then
1136 if page < maxPage then page = page + 1 update = true end
1137 elseif x >= app_locations[1] and x <= app_locations[1]+7 then -- row 1 (left)
1138 if y >= 1 and y <= 7 then
1139 -- top-left
1140 if notnil(loaded_apps[1]) then
1141 if loaded_apps[1][2] == 1 then
1142 _index[string.gsub(loaded_apps[1][1], " ","")]()
1143 else
1144 runProgram(loaded_apps[1][3])
1145 end
1146 end
1147 elseif y >= 11 and y <= 17 then
1148 -- bottom-left
1149 if notnil(loaded_apps[4]) then
1150 if loaded_apps[4][2] == 1 then
1151 _index[string.gsub(loaded_apps[4][1], " ","")]()
1152 else
1153 runProgram(loaded_apps[4][3])
1154 end
1155 end
1156 end
1157 elseif x >= app_locations[2] and x <= app_locations[2]+7 then -- row 2 (middle)
1158 if y >= 1 and y <= 7 then
1159 -- top-mid
1160 if notnil(loaded_apps[2]) then
1161 if loaded_apps[2][2] == 1 then
1162 _index[string.gsub(loaded_apps[2][1], " ","")]()
1163 else
1164 runProgram(loaded_apps[2][3])
1165 end
1166 end
1167 elseif y >= 11 and y <= 17 then
1168 -- bottom-mid
1169 if notnil(loaded_apps[5]) then
1170 if loaded_apps[5][2] == 1 then
1171 _index[string.gsub(loaded_apps[5][1], " ","")]()
1172 else
1173 runProgram(loaded_apps[5][3])
1174 end
1175 end
1176 end
1177 elseif x >= app_locations[3] and x <= app_locations[3]+7 then -- row 3 (right)
1178 if y >= 1 and y <= 7 then
1179 -- top-right
1180 if notnil(loaded_apps[3]) then
1181 if loaded_apps[3][2] == 1 then
1182 _index[string.gsub(loaded_apps[3][1], " ","")]()
1183 else
1184 runProgram(loaded_apps[3][3])
1185 end
1186 end
1187 elseif y >= 11 and y <= 17 then
1188 -- bottom-right
1189 if notnil(loaded_apps[6]) then
1190 if loaded_apps[6][2] == 1 then
1191 _index[string.gsub(loaded_apps[6][1], " ","")]()
1192 else
1193 runProgram(loaded_apps[6][3])
1194 end
1195 end
1196 end
1197 end
1198 elseif i == 2 then -- right-click
1199
1200 end
1201 end
1202end
1203
1204function os_background_task_a()
1205 local _os_root_dir = shell.getRunningProgram()
1206 local _os_display_fps = false
1207 while true do
1208 local _os_tmp1 = fs.getSize(_os_root_dir)
1209 local _os_root_fps = 1
1210 parallel.waitForAny(function() while true do _os_root_fps = _os_root_fps + 1 sleep(.0000001) end end, function() sleep(1) end, function() while true do _os_a, _os_i = os.pullEvent("key") if _os_i == keys.leftAlt then _os_display_fps = not _os_display_fps end end end)
1211 if _os_display_fps then local _os_x,_os_y = term.getCursorPos() cp(1,1) setBack("black") setText("white") write("FPS: ".._os_root_fps.." ") cp(_os_x, _os_y) end
1212 if _os_tmp1 ~= fs.getSize(_os_root_dir) then
1213 os.reboot()
1214 end
1215 end
1216end
1217
1218local res, er
1219parallel.waitForAny(function() res, er = pcall(runtime) end, function() res, er = pcall(os_background_task_a) end)
1220-- os
1221
1222
1223-- end-of-code results
1224
1225if not res then -- Crashed
1226 setText("white")
1227 setBack("cyan")
1228 cp(1,1) clr()
1229 print("A problem has been detected and Freeware has been shut down to prevent damage to your computer.")
1230 print("")
1231 print("If this is the first time you've seen this Stop error screen, restart your computer. If this appears again, feel free to contact me.") print("")
1232 write("Discord Server: ") setText("blue") print("https://discord.gg/SA5tBQ2") setText("white")
1233 write("Email: ") setText("yellow") print("edwardelric32578@gmail.com") setText("white") print("")
1234 if er == nil then er = "error code was not found! (api?)" end
1235 write("Error: ")
1236 printError(er)
1237 print("")
1238 sleep(2)
1239 print("Press any key to reboot...")
1240 os.pullEvent() os.reboot()
1241end
1242
1243-- Only runs if it didn't crash
1244setText("white")
1245setBack("black")
1246cp(1,1) clr()
1247print("Freeware v2")
1248sleep(1)
1249
1250-- end-of-code results