Advertisement
Andy73

planet-garden

Mar 22nd, 2023
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 286.23 KB | Gaming | 0 0
  1. local t={}local n={}local o=require
  2. local function a(e,...)if n[e]then
  3. return n[e].value
  4. end
  5. if t[e]then
  6. local t=t[e]n[e]={value=(select("#",...)>0)and t(...)or t(e)}return n[e].value
  7. else
  8. if o then
  9. return o(e)else
  10. error("module '"..e.."' not found")end
  11. end
  12. end
  13. t={["lualib_bundle"]=function(...)local function y(e)return type(e)=="table"and(e[1]~=nil or next(e)==nil)end
  14. local function be(o,...)local n={...}local t={}local e=0
  15. for n=1,#o do
  16. e=e+1
  17. t[e]=o[n]end
  18. for o=1,#n do
  19. local n=n[o]if y(n)then
  20. for o=1,#n do
  21. e=e+1
  22. t[e]=n[o]end
  23. else
  24. e=e+1
  25. t[e]=n
  26. end
  27. end
  28. return t
  29. end
  30. local u,n
  31. do
  32. local e={__tostring=function(e)return("Symbol("..(e.description or""))..")"end}function u(t)return setmetatable({description=t},e)end
  33. n={iterator=u("Symbol.iterator"),hasInstance=u("Symbol.hasInstance"),species=u("Symbol.species"),toStringTag=u("Symbol.toStringTag")}end
  34. local function ye(t)local e=0
  35. return{[n.iterator]=function(e)return e
  36. end,next=function(n)local n={done=t[e+1]==nil,value={e,t[e+1]}}e=e+1
  37. return n
  38. end}end
  39. local function me(e,t,o)for n=1,#e do
  40. if not t(o,e[n],n-1,e)then
  41. return false
  42. end
  43. end
  44. return true
  45. end
  46. local function ge(e,r,l)local o={}local n=0
  47. for t=1,#e do
  48. if r(l,e[t],t-1,e)then
  49. n=n+1
  50. o[n]=e[t]end
  51. end
  52. return o
  53. end
  54. local function pe(e,t,o)for n=1,#e do
  55. t(o,e[n],n-1,e)end
  56. end
  57. local function _e(e,l,o)for n=1,#e do
  58. local t=e[n]if l(o,t,n-1,e)then
  59. return t
  60. end
  61. end
  62. return nil
  63. end
  64. local function Be(n,o,t)for e=1,#n do
  65. if o(t,n[e],e-1,n)then
  66. return e-1
  67. end
  68. end
  69. return-1
  70. end
  71. local r
  72. do
  73. local function o(e)local n=e.____coroutine
  74. local t,e=coroutine.resume(n)if not t then
  75. error(e,0)end
  76. if coroutine.status(n)=="dead"then
  77. return
  78. end
  79. return true,e
  80. end
  81. local function t(e)local e=e:next()if e.done then
  82. return
  83. end
  84. return true,e.value
  85. end
  86. local function l(n,e)e=e+1
  87. if e>#n then
  88. return
  89. end
  90. return e,string.sub(n,e,e)end
  91. function r(e)if type(e)=="string"then
  92. return l,e,0
  93. elseif e.____coroutine~=nil then
  94. return o,e
  95. elseif e[n.iterator]then
  96. local e=e[n.iterator](e)return t,e
  97. else
  98. return ipairs(e)end
  99. end
  100. end
  101. local j
  102. do
  103. local function t(n,e)e=e+1
  104. if e>n.length then
  105. return
  106. end
  107. return e,n[e]end
  108. local function n(e)if type(e.length)=="number"then
  109. return t,e,0
  110. end
  111. return r(e)end
  112. function j(t,o,l)local e={}if o==nil then
  113. for t,n in n(t)do
  114. e[#e+1]=n
  115. end
  116. else
  117. for n,t in n(t)do
  118. e[#e+1]=o(l,t,n-1)end
  119. end
  120. return e
  121. end
  122. end
  123. local function Fe(o,l,e)if e==nil then
  124. e=0
  125. end
  126. local t=#o
  127. local n=e
  128. if e<0 then
  129. n=t+e
  130. end
  131. if n<0 then
  132. n=0
  133. end
  134. for e=n+1,t do
  135. if o[e]==l then
  136. return true
  137. end
  138. end
  139. return false
  140. end
  141. local function ze(t,o,e)if e==nil then
  142. e=0
  143. end
  144. local n=#t
  145. if n==0 then
  146. return-1
  147. end
  148. if e>=n then
  149. return-1
  150. end
  151. if e<0 then
  152. e=n+e
  153. if e<0 then
  154. e=0
  155. end
  156. end
  157. for e=e+1,n do
  158. if t[e]==o then
  159. return e-1
  160. end
  161. end
  162. return-1
  163. end
  164. local function xe(t,e)if e==nil then
  165. e=","end
  166. local n={}for e=1,#t do
  167. n[e]=tostring(t[e])end
  168. return table.concat(n,e)end
  169. local function we(e,o,l)local t={}for n=1,#e do
  170. t[n]=o(l,e[n],n-1,e)end
  171. return t
  172. end
  173. local function ve(n,...)local t={...}local e=#n
  174. for o=1,#t do
  175. e=e+1
  176. n[e]=t[o]end
  177. return e
  178. end
  179. local function Te(n,t)local e=#n
  180. for o=1,#t do
  181. e=e+1
  182. n[e]=t[o]end
  183. return e
  184. end
  185. local function s(...)return select("#",...)end
  186. local function Se(n,l,...)local t=#n
  187. local o=0
  188. local e=nil
  189. if s(...)~=0 then
  190. e=...elseif t>0 then
  191. e=n[1]o=1
  192. else
  193. error("Reduce of empty array with no initial value",0)end
  194. for t=o+1,t do
  195. e=l(nil,e,n[t],t-1,n)end
  196. return e
  197. end
  198. local function ke(n,l,...)local o=#n
  199. local t=o-1
  200. local e=nil
  201. if s(...)~=0 then
  202. e=...elseif o>0 then
  203. e=n[t+1]t=t-1
  204. else
  205. error("Reduce of empty array with no initial value",0)end
  206. for t=t+1,1,-1 do
  207. e=l(nil,e,n[t],t-1,n)end
  208. return e
  209. end
  210. local function Ce(e)local n=1
  211. local t=#e
  212. while n<t do
  213. local o=e[t]e[t]=e[n]e[n]=o
  214. n=n+1
  215. t=t-1
  216. end
  217. return e
  218. end
  219. local function I(e,...)local t={...}local n=#t
  220. if n==0 then
  221. return#e
  222. end
  223. for t=#e,1,-1 do
  224. e[t+n]=e[t]end
  225. for n=1,n do
  226. e[n]=t[n]end
  227. return#e
  228. end
  229. local function se(e,n)if n~=nil then
  230. table.sort(e,function(t,e)return n(nil,t,e)<0 end)else
  231. table.sort(e)end
  232. return e
  233. end
  234. local function ue(l,e,n)local t=#l
  235. e=e or 0
  236. if e<0 then
  237. e=t+e
  238. if e<0 then
  239. e=0
  240. end
  241. else
  242. if e>t then
  243. e=t
  244. end
  245. end
  246. n=n or t
  247. if n<0 then
  248. n=t+n
  249. if n<0 then
  250. n=0
  251. end
  252. else
  253. if n>t then
  254. n=t
  255. end
  256. end
  257. local o={}e=e+1
  258. n=n+1
  259. local t=1
  260. while e<n do
  261. o[t]=l[e]e=e+1
  262. t=t+1
  263. end
  264. return o
  265. end
  266. local function fe(e,o,t)for n=1,#e do
  267. if o(t,e[n],n-1,e)then
  268. return true
  269. end
  270. end
  271. return false
  272. end
  273. local function ie(n,...)local a={...}local o=#n
  274. local r=s(...)local t=a[1]local i=a[2]if t<0 then
  275. t=o+t
  276. if t<0 then
  277. t=0
  278. end
  279. elseif t>o then
  280. t=o
  281. end
  282. local l=r-2
  283. if l<0 then
  284. l=0
  285. end
  286. local e
  287. if r==0 then
  288. e=0
  289. elseif r==1 then
  290. e=o-t
  291. else
  292. e=i or 0
  293. if e<0 then
  294. e=0
  295. end
  296. if e>o-t then
  297. e=o-t
  298. end
  299. end
  300. local i={}for e=1,e do
  301. local t=t+e
  302. if n[t]~=nil then
  303. i[e]=n[t]end
  304. end
  305. if l<e then
  306. for t=t+1,o-e do
  307. local e=t+e
  308. local t=t+l
  309. if n[e]then
  310. n[t]=n[e]else
  311. n[t]=nil
  312. end
  313. end
  314. for e=o-e+l+1,o do
  315. n[e]=nil
  316. end
  317. elseif l>e then
  318. for t=o-e,t+1,-1 do
  319. local e=t+e
  320. local t=t+l
  321. if n[e]then
  322. n[t]=n[e]else
  323. n[t]=nil
  324. end
  325. end
  326. end
  327. local t=t+1
  328. for e=3,r do
  329. n[t]=a[e]t=t+1
  330. end
  331. for e=#n,o-e+l+1,-1 do
  332. n[e]=nil
  333. end
  334. return i
  335. end
  336. local function ce(t)local n={}for e=1,#t do
  337. n[e-1]=t[e]end
  338. return n
  339. end
  340. local function X(t,n)if n==nil then
  341. n=1
  342. end
  343. local l={}local e=0
  344. for o=1,#t do
  345. local t=t[o]if n>0 and y(t)then
  346. local o
  347. if n==1 then
  348. o=t
  349. else
  350. o=X(t,n-1)end
  351. for n=1,#o do
  352. local n=o[n]e=e+1
  353. l[e]=n
  354. end
  355. else
  356. e=e+1
  357. l[e]=t
  358. end
  359. end
  360. return l
  361. end
  362. local function de(n,r,l)local t={}local e=0
  363. for o=1,#n do
  364. local n=r(l,n[o],o-1,n)if y(n)then
  365. for o=1,#n do
  366. e=e+1
  367. t[e]=n[o]end
  368. else
  369. e=e+1
  370. t[e]=n
  371. end
  372. end
  373. return t
  374. end
  375. local function he(n,e)if e<0 or e~=e or e==math.huge or math.floor(e)~=e then
  376. error("invalid array length: "..tostring(e),0)end
  377. for e=e+1,#n do
  378. n[e]=nil
  379. end
  380. return e
  381. end
  382. local function c(t,e)if type(e)~="table"then
  383. error("Right-hand side of 'instanceof' is not an object",0)end
  384. if e[n.hasInstance]~=nil then
  385. return not not e[n.hasInstance](e,t)end
  386. if type(t)=="table"then
  387. local n=t.constructor
  388. while n~=nil do
  389. if n==e then
  390. return true
  391. end
  392. n=n.____super
  393. end
  394. end
  395. return false
  396. end
  397. local function l(e,...)local e=setmetatable({},e.prototype)e:____constructor(...)return e
  398. end
  399. local function d(e)local e={prototype={}}e.prototype.__index=e.prototype
  400. e.prototype.constructor=e
  401. return e
  402. end
  403. local h=table.unpack or unpack
  404. local function v(t,...)local n={...}return function(e,...)local e={...}I(e,h(n))return t(h(e))end
  405. end
  406. local e
  407. do
  408. local function a(n)local n
  409. local t
  410. local e=l(e,function(l,o,e)n=o
  411. t=e
  412. end)return{promise=e,resolve=n,reject=t}end
  413. local function s(t,n)return c(n,e)end
  414. e=d()e.name="__TS__Promise"function e.prototype.____constructor(e,t)e.state=0
  415. e.fulfilledCallbacks={}e.rejectedCallbacks={}e.finallyCallbacks={}do
  416. local function o(n)e:reject(n)end
  417. local e,n=pcall(function()t(nil,v(e.resolve,e),v(e.reject,e))end)if not e then
  418. o(n)end
  419. end
  420. end
  421. function e.resolve(n)local e=l(e,function()end)e.state=1
  422. e.value=n
  423. return e
  424. end
  425. function e.reject(t)local n=l(e,function()end)n.state=2
  426. n.rejectionReason=t
  427. return n
  428. end
  429. e.prototype["then"]=function(e,l,r)local t=a(nil)local i=t.promise
  430. local n=t.resolve
  431. local t=t.reject
  432. local o=e.state==1
  433. local a=e.state==2
  434. if l then
  435. local n=e:createPromiseResolvingCallback(l,n,t)local t=e.fulfilledCallbacks
  436. t[#t+1]=n
  437. if o then
  438. n(nil,e.value)end
  439. else
  440. local e=e.fulfilledCallbacks
  441. e[#e+1]=function(t,e)return n(nil,e)end
  442. end
  443. if r then
  444. local t=e:createPromiseResolvingCallback(r,n,t)local n=e.rejectedCallbacks
  445. n[#n+1]=t
  446. if a then
  447. t(nil,e.rejectionReason)end
  448. else
  449. local e=e.rejectedCallbacks
  450. e[#e+1]=function(n,e)return t(nil,e)end
  451. end
  452. if o then
  453. n(nil,e.value)end
  454. if a then
  455. t(nil,e.rejectionReason)end
  456. return i
  457. end
  458. function e.prototype.catch(e,n)return e["then"](e,nil,n)end
  459. function e.prototype.finally(e,n)if n then
  460. local t=e.finallyCallbacks
  461. t[#t+1]=n
  462. if e.state~=0 then
  463. n(nil)end
  464. end
  465. return e
  466. end
  467. function e.prototype.resolve(n,t)if c(t,e)then
  468. t["then"](t,function(t,e)return n:resolve(e)end,function(t,e)return n:reject(e)end)return
  469. end
  470. if n.state==0 then
  471. n.state=1
  472. n.value=t
  473. for n,e in ipairs(n.fulfilledCallbacks)do
  474. e(nil,t)end
  475. for n,e in ipairs(n.finallyCallbacks)do
  476. e(nil)end
  477. end
  478. end
  479. function e.prototype.reject(e,n)if e.state==0 then
  480. e.state=2
  481. e.rejectionReason=n
  482. for t,e in ipairs(e.rejectedCallbacks)do
  483. e(nil,n)end
  484. for n,e in ipairs(e.finallyCallbacks)do
  485. e(nil)end
  486. end
  487. end
  488. function e.prototype.createPromiseResolvingCallback(n,r,l,e)return function(t,o)do
  489. local function t(n)e(nil,n)end
  490. local n,e=pcall(function()n:handleCallbackData(r(nil,o),l,e)end)if not n then
  491. t(e)end
  492. end
  493. end
  494. end
  495. function e.prototype.handleCallbackData(n,e,t,o)if s(nil,e)then
  496. local n=e
  497. if n.state==1 then
  498. t(nil,n.value)elseif n.state==2 then
  499. o(nil,n.rejectionReason)else
  500. e["then"](e,t,o)end
  501. else
  502. t(nil,e)end
  503. end
  504. end
  505. local function Ze(d)return l(e,function(t,a,n)local r,i,o,l,t
  506. function r(t,n)return c(n,e)and n or e.resolve(n)end
  507. function i(l,e)local t,e=coroutine.resume(t,e)if t then
  508. o(nil,e)else
  509. n(nil,e)end
  510. end
  511. function o(o,e)if l then
  512. return
  513. end
  514. if coroutine.status(t)=="dead"then
  515. a(nil,e)else
  516. local e=r(nil,e)e["then"](e,i,n)end
  517. end
  518. l=false
  519. t=coroutine.create(d)local t,e=coroutine.resume(t,function(t,e)l=true
  520. local e=r(nil,e)e["then"](e,a,n)end)if t then
  521. o(nil,e)else
  522. n(nil,e)end
  523. end)end
  524. local function Ne(e)return coroutine.yield(e)end
  525. local function z(n,e)n.____super=e
  526. local o=setmetatable({__index=e},e)setmetatable(n,o)local t=getmetatable(e)if t then
  527. if type(t.__index)=="function"then
  528. o.__index=t.__index
  529. end
  530. if type(t.__newindex)=="function"then
  531. o.__newindex=t.__newindex
  532. end
  533. end
  534. setmetatable(n.prototype,e.prototype)if type(e.prototype.__index)=="function"then
  535. n.prototype.__index=e.prototype.__index
  536. end
  537. if type(e.prototype.__newindex)=="function"then
  538. n.prototype.__newindex=e.prototype.__newindex
  539. end
  540. if type(e.prototype.__tostring)=="function"then
  541. n.prototype.__tostring=e.prototype.__tostring
  542. end
  543. end
  544. local function F(e)local o
  545. local l
  546. local n
  547. local t
  548. local r
  549. local a
  550. a=e.enumerable
  551. r=e.configurable
  552. t=e.get
  553. n=e.set
  554. l=e.writable
  555. o=e.value
  556. local e={enumerable=a==true,configurable=r==true}local a=t~=nil or n~=nil
  557. local r=l~=nil or o~=nil
  558. if a and r then
  559. error("Invalid property descriptor. Cannot both specify accessors and a value or writable attribute.",0)end
  560. if t or n then
  561. e.get=t
  562. e.set=n
  563. else
  564. e.value=o
  565. e.writable=l==true
  566. end
  567. return e
  568. end
  569. local function E(n,...)local e={...}for t=1,#e do
  570. local e=e[t]for t in pairs(e)do
  571. n[t]=e[t]end
  572. end
  573. return n
  574. end
  575. local function D(e,n)local e=getmetatable(e)if not e then
  576. return
  577. end
  578. if not rawget(e,"_descriptors")then
  579. return
  580. end
  581. return rawget(e,"_descriptors")[n]end
  582. local b
  583. do
  584. local function a(n,t)local e=rawget(n,t)if e~=nil then
  585. return e
  586. end
  587. local e=getmetatable(n)while e do
  588. local o=rawget(e,t)if o~=nil then
  589. return o
  590. end
  591. local o=rawget(e,"_descriptors")if o then
  592. local e=o[t]if e~=nil then
  593. if e.get then
  594. return e.get(n)end
  595. return e.value
  596. end
  597. end
  598. e=getmetatable(e)end
  599. end
  600. local function r(n,l,o)local t=getmetatable(n)while t do
  601. local e=rawget(t,"_descriptors")if e then
  602. local e=e[l]if e~=nil then
  603. if e.set then
  604. e.set(n,o)else
  605. if e.writable==false then
  606. error(((("Cannot assign to read only property '"..l).."' of object '")..tostring(n)).."'",0)end
  607. e.value=o
  608. end
  609. return
  610. end
  611. end
  612. t=getmetatable(t)end
  613. rawset(n,l,o)end
  614. function b(n,t,l,e)if e==nil then
  615. e=false
  616. end
  617. local o
  618. if e then
  619. o=n
  620. else
  621. o=getmetatable(n)end
  622. local e=o
  623. if not e then
  624. e={}setmetatable(n,e)end
  625. local o=rawget(n,t)if o~=nil then
  626. rawset(n,t,nil)end
  627. if not rawget(e,"_descriptors")then
  628. e._descriptors={}end
  629. e._descriptors[t]=F(l)e.__index=a
  630. e.__newindex=r
  631. end
  632. end
  633. local function Ue(o,e,n,r)local t=e
  634. do
  635. local l=#o
  636. while l>=0 do
  637. local o=o[l+1]if o~=nil then
  638. local a=t
  639. if n==nil then
  640. t=o(nil,t)elseif r==true then
  641. local t=rawget(e,n)local l=D(e,n)or({configurable=true,writable=true,value=t})local t=o(nil,e,n,l)or l
  642. local o=t.configurable==true and t.writable==true and not t.get and not t.set
  643. if o then
  644. rawset(e,n,t.value)else
  645. b(e,n,E({},l,t))end
  646. elseif r==false then
  647. t=o(nil,e,n,r)else
  648. t=o(nil,e,n)end
  649. t=t or a
  650. end
  651. l=l-1
  652. end
  653. end
  654. return t
  655. end
  656. local function nn(e,n)return function(l,t,o)return n(nil,t,o,e)end
  657. end
  658. local function g(n,t,e)if not e then
  659. e=1
  660. else
  661. e=e+1
  662. end
  663. local e=string.find(n,t,e,true)return e~=nil
  664. end
  665. local w,S,k,T,x,B
  666. do
  667. local function a(e,t)local e=1
  668. while true do
  669. local n=debug.getinfo(e,"f")e=e+1
  670. if not n then
  671. e=1
  672. break
  673. elseif n.func==t then
  674. break
  675. end
  676. end
  677. if g(_VERSION,"Lua 5.0")then
  678. return debug.traceback(("[Level "..tostring(e)).."]")else
  679. return debug.traceback(nil,e)end
  680. end
  681. local function r(e,n)return function(e)local n=n(e)local t=debug.getinfo(3,"f")local o=g(_VERSION,"Lua 5.0")or _VERSION=="Lua 5.1"if o or t and t.func~=error then
  682. return n
  683. else
  684. return(n.."\n")..tostring(e.stack)end
  685. end
  686. end
  687. local function t(t,e,n)e.name=n
  688. return setmetatable(e,{__call=function(t,t,n)return l(e,n)end})end
  689. local o=t
  690. local n=d()n.name=""function n.prototype.____constructor(e,n)if n==nil then
  691. n=""end
  692. e.message=n
  693. e.name="Error"e.stack=a(nil,e.constructor.new)local e=getmetatable(e)if e and not e.__errorToStringPatched then
  694. e.__errorToStringPatched=true
  695. e.__tostring=r(nil,e.__tostring)end
  696. end
  697. function n.prototype.__tostring(e)return e.message~=""and(e.name..": ")..e.message or e.name
  698. end
  699. w=o(nil,n,"Error")local function n(e,o)local t=t
  700. local e=d()e.name=e.name
  701. z(e,w)function e.prototype.____constructor(n,...)e.____super.prototype.____constructor(n,...)n.name=o
  702. end
  703. return t(nil,e,o)end
  704. S=n(nil,"RangeError")k=n(nil,"ReferenceError")T=n(nil,"SyntaxError")x=n(nil,"TypeError")B=n(nil,"URIError")end
  705. local function C(e)local e=getmetatable(e)if not e then
  706. return{}end
  707. return rawget(e,"_descriptors")or({})end
  708. local function Qe(n,e)local t=C(n)local o=t[e]if o then
  709. if not o.configurable then
  710. error(l(x,((("Cannot delete property "..tostring(e)).." of ")..tostring(n)).."."),0)end
  711. t[e]=nil
  712. return true
  713. end
  714. n[e]=nil
  715. return true
  716. end
  717. local function m(n,e)if e>=0 and e<#n then
  718. return string.sub(n,e+1,e+1)end
  719. end
  720. local function Ye(e)if type(e)=="string"then
  721. for n=0,#e-1 do
  722. coroutine.yield(m(e,n))end
  723. elseif e.____coroutine~=nil then
  724. local n=e.____coroutine
  725. while true do
  726. local t,e=coroutine.resume(n)if not t then
  727. error(e,0)end
  728. if coroutine.status(n)=="dead"then
  729. return e
  730. else
  731. coroutine.yield(e)end
  732. end
  733. elseif e[n.iterator]then
  734. local e=e[n.iterator](e)while true do
  735. local e=e:next()if e.done then
  736. return e.value
  737. else
  738. coroutine.yield(e.value)end
  739. end
  740. else
  741. for n,e in ipairs(e)do
  742. coroutine.yield(e)end
  743. end
  744. end
  745. local A
  746. do
  747. local function t(e)return e
  748. end
  749. local function o(e,...)local e=e.____coroutine
  750. if coroutine.status(e)=="dead"then
  751. return{done=true}end
  752. local t,n=coroutine.resume(e,...)if not t then
  753. error(n,0)end
  754. return{value=n,done=coroutine.status(e)=="dead"}end
  755. function A(l)return function(...)local e={...}local r=s(...)return{____coroutine=coroutine.create(function()return l(h(e,1,r))end),[n.iterator]=t,next=o}end
  756. end
  757. end
  758. local function en(e)local e=type(e)return e=="table"or e=="function"end
  759. local function Je(o,l,e)local n={}local e,t=o(l,e)while e do
  760. n[#n+1]={e,t}e,t=o(l,e)end
  761. return h(n)end
  762. local t
  763. do
  764. t=d()t.name="Map"function t.prototype.____constructor(e,t)e[n.toStringTag]="Map"e.items={}e.size=0
  765. e.nextKey={}e.previousKey={}if t==nil then
  766. return
  767. end
  768. local o=t
  769. if o[n.iterator]then
  770. local n=o[n.iterator](o)while true do
  771. local n=n:next()if n.done then
  772. break
  773. end
  774. local n=n.value
  775. e:set(n[1],n[2])end
  776. else
  777. local n=t
  778. for t,n in ipairs(n)do
  779. e:set(n[1],n[2])end
  780. end
  781. end
  782. function t.prototype.clear(e)e.items={}e.nextKey={}e.previousKey={}e.firstKey=nil
  783. e.lastKey=nil
  784. e.size=0
  785. end
  786. function t.prototype.delete(e,n)local l=e:has(n)if l then
  787. e.size=e.size-1
  788. local o=e.nextKey[n]local t=e.previousKey[n]if o~=nil and t~=nil then
  789. e.nextKey[t]=o
  790. e.previousKey[o]=t
  791. elseif o~=nil then
  792. e.firstKey=o
  793. e.previousKey[o]=nil
  794. elseif t~=nil then
  795. e.lastKey=t
  796. e.nextKey[t]=nil
  797. else
  798. e.firstKey=nil
  799. e.lastKey=nil
  800. end
  801. e.nextKey[n]=nil
  802. e.previousKey[n]=nil
  803. end
  804. e.items[n]=nil
  805. return l
  806. end
  807. function t.prototype.forEach(e,t)for o,n in r(e:keys())do
  808. t(nil,e.items[n],n,e)end
  809. end
  810. function t.prototype.get(e,n)return e.items[n]end
  811. function t.prototype.has(e,n)return e.nextKey[n]~=nil or e.lastKey==n
  812. end
  813. function t.prototype.set(e,n,l)local o=not e:has(n)if o then
  814. e.size=e.size+1
  815. end
  816. e.items[n]=l
  817. if e.firstKey==nil then
  818. e.firstKey=n
  819. e.lastKey=n
  820. elseif o then
  821. e.nextKey[e.lastKey]=n
  822. e.previousKey[n]=e.lastKey
  823. e.lastKey=n
  824. end
  825. return e
  826. end
  827. t.prototype[n.iterator]=function(e)return e:entries()end
  828. function t.prototype.entries(e)local o=e.items
  829. local t=e.nextKey
  830. local e=e.firstKey
  831. return{[n.iterator]=function(e)return e
  832. end,next=function(n)local n={done=not e,value={e,o[e]}}e=t[e]return n
  833. end}end
  834. function t.prototype.keys(e)local t=e.nextKey
  835. local e=e.firstKey
  836. return{[n.iterator]=function(e)return e
  837. end,next=function(n)local n={done=not e,value=e}e=t[e]return n
  838. end}end
  839. function t.prototype.values(e)local o=e.items
  840. local l=e.nextKey
  841. local e=e.firstKey
  842. return{[n.iterator]=function(e)return e
  843. end,next=function(n)local n={done=not e,value=o[e]}e=l[e]return n
  844. end}end
  845. t[n.species]=t
  846. end
  847. local f=string.match
  848. local He=math.atan2 or math.atan
  849. local M=math.modf
  850. local function Ie(e)if e>0 then
  851. return 1
  852. elseif e<0 then
  853. return-1
  854. end
  855. return 0
  856. end
  857. local function Me(e)local n=type(e)if n=="number"then
  858. return e
  859. elseif n=="string"then
  860. local n=tonumber(e)if n then
  861. return n
  862. end
  863. if e=="Infinity"then
  864. return math.huge
  865. end
  866. if e=="-Infinity"then
  867. return-math.huge
  868. end
  869. local e=string.gsub(e,"%s","")if e==""then
  870. return 0
  871. end
  872. return 0/0
  873. elseif n=="boolean"then
  874. return e and 1 or 0
  875. else
  876. return 0/0
  877. end
  878. end
  879. local function Ve(e)return type(e)=="number"and e==e and e~=math.huge and e~=-math.huge
  880. end
  881. local function Ee(e)return e~=e
  882. end
  883. local P
  884. do
  885. local r="0123456789abcdefghijklmnopqrstuvwxyz"function P(t,e)if e==nil or e==10 or t==math.huge or t==-math.huge or t~=t then
  886. return tostring(t)end
  887. e=math.floor(e)if e<2 or e>36 then
  888. error("toString() radix argument must be between 2 and 36",0)end
  889. local l,o=M(math.abs(t))local n=""if e==8 then
  890. n=string.format("%o",l)elseif e==16 then
  891. n=string.format("%x",l)else
  892. repeat
  893. do
  894. n=m(r,l%e)..n
  895. l=math.floor(l/e)end
  896. until not(l~=0)end
  897. if o~=0 then
  898. n=n.."."local t=1e-16
  899. repeat
  900. do
  901. o=o*e
  902. t=t*e
  903. local e=math.floor(o)n=n..m(r,e)o=o-e
  904. end
  905. until not(o>=t)end
  906. if t<0 then
  907. n="-"..n
  908. end
  909. return n
  910. end
  911. end
  912. local function De(e,n)if math.abs(e)>=1e21 or e~=e then
  913. return tostring(e)end
  914. local n=math.floor(n or 0)if n<0 or n>99 then
  915. error("toFixed() digits argument must be between 0 and 99",0)end
  916. return string.format(("%."..tostring(n)).."f",e)end
  917. local function Pe(t,n,e)local i=type(n)=="number"and n+1 or n
  918. local o=rawget(t,i)local l=e.get~=nil or e.set~=nil
  919. local a
  920. if l then
  921. if o~=nil then
  922. error("Cannot redefine property: "..tostring(n),0)end
  923. a=e
  924. else
  925. local n=o~=nil
  926. local d=e.set
  927. local i=e.get
  928. local r
  929. if e.configurable~=nil then
  930. r=e.configurable
  931. else
  932. r=n
  933. end
  934. local t
  935. if e.enumerable~=nil then
  936. t=e.enumerable
  937. else
  938. t=n
  939. end
  940. local l
  941. if e.writable~=nil then
  942. l=e.writable
  943. else
  944. l=n
  945. end
  946. local n
  947. if e.value~=nil then
  948. n=e.value
  949. else
  950. n=o
  951. end
  952. a={set=d,get=i,configurable=r,enumerable=t,writable=l,value=n}end
  953. b(t,i,a)return t
  954. end
  955. local function Ae(o)local t={}local e=0
  956. for n in pairs(o)do
  957. e=e+1
  958. t[e]={n,o[n]}end
  959. return t
  960. end
  961. local function Ge(o)local e={}local t=o
  962. if t[n.iterator]then
  963. local n=t[n.iterator](t)while true do
  964. local n=n:next()if n.done then
  965. break
  966. end
  967. local n=n.value
  968. e[n[1]]=n[2]end
  969. else
  970. for t,n in ipairs(o)do
  971. e[n[1]]=n[2]end
  972. end
  973. return e
  974. end
  975. local function Xe(t)local n={}local e=0
  976. for t in pairs(t)do
  977. e=e+1
  978. n[e]=t
  979. end
  980. return n
  981. end
  982. local function Re(t,o)local n={}for e in pairs(t)do
  983. if not o[e]then
  984. n[e]=t[e]end
  985. end
  986. return n
  987. end
  988. local function qe(t)local n={}local e=0
  989. for o in pairs(t)do
  990. e=e+1
  991. n[e]=t[o]end
  992. return n
  993. end
  994. local function We(n)local e=f(n,"^%s*(-?Infinity)")if e~=nil then
  995. return m(e,0)=="-"and-math.huge or math.huge
  996. end
  997. local e=tonumber(f(n,"^%s*(-?%d+%.?%d*)"))return e or 0/0
  998. end
  999. local function p(t,n,e)if e~=e then
  1000. e=0
  1001. end
  1002. if e~=nil and n>e then
  1003. n,e=e,n
  1004. end
  1005. if n>=0 then
  1006. n=n+1
  1007. else
  1008. n=1
  1009. end
  1010. if e~=nil and e<0 then
  1011. e=0
  1012. end
  1013. return string.sub(t,n,e)end
  1014. local H
  1015. do
  1016. local o="0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTvVwWxXyYzZ"function H(n,e)if e==nil then
  1017. e=10
  1018. local t=f(n,"^%s*-?0[xX]")if t~=nil then
  1019. e=16
  1020. n=f(t,"-")and"-"..p(n,#t)or p(n,#t)end
  1021. end
  1022. if e<2 or e>36 then
  1023. return 0/0
  1024. end
  1025. local t=e<=10 and p(o,0,e)or p(o,0,10+2*(e-10))local t=("^%s*(-?["..t).."]*)"local e=tonumber(f(n,t),e)if e==nil then
  1026. return 0/0
  1027. end
  1028. if e>=0 then
  1029. return math.floor(e)else
  1030. return math.ceil(e)end
  1031. end
  1032. end
  1033. local function Ke(n)local a={}local i={}local t=0
  1034. local o=0
  1035. for l,n in r(n)do
  1036. if c(n,e)then
  1037. if n.state==1 then
  1038. a[o+1]=n.value
  1039. elseif n.state==2 then
  1040. return e.reject(n.rejectionReason)else
  1041. t=t+1
  1042. i[o]=n
  1043. end
  1044. else
  1045. a[o+1]=n
  1046. end
  1047. o=o+1
  1048. end
  1049. if t==0 then
  1050. return e.resolve(a)end
  1051. return l(e,function(e,l,n)for o,e in pairs(i)do
  1052. e["then"](e,function(n,e)a[o+1]=e
  1053. t=t-1
  1054. if t==0 then
  1055. l(nil,a)end
  1056. end,function(t,e)n(nil,e)end)end
  1057. end)end
  1058. local function Oe(o)local t={}local i={}local n=0
  1059. local a=0
  1060. for l,o in r(o)do
  1061. if c(o,e)then
  1062. if o.state==1 then
  1063. t[a+1]={status="fulfilled",value=o.value}elseif o.state==2 then
  1064. t[a+1]={status="rejected",reason=o.rejectionReason}else
  1065. n=n+1
  1066. i[a]=o
  1067. end
  1068. else
  1069. t[a+1]={status="fulfilled",value=o}end
  1070. a=a+1
  1071. end
  1072. if n==0 then
  1073. return e.resolve(t)end
  1074. return l(e,function(o,e)for o,l in pairs(i)do
  1075. l["then"](l,function(r,l)t[o+1]={status="fulfilled",value=l}n=n-1
  1076. if n==0 then
  1077. e(nil,t)end
  1078. end,function(r,l)t[o+1]={status="rejected",reason=l}n=n-1
  1079. if n==0 then
  1080. e(nil,t)end
  1081. end)end
  1082. end)end
  1083. local function Le(n)local o={}local t={}for l,n in r(n)do
  1084. if c(n,e)then
  1085. if n.state==1 then
  1086. return e.resolve(n.value)elseif n.state==2 then
  1087. o[#o+1]=n.rejectionReason
  1088. else
  1089. t[#t+1]=n
  1090. end
  1091. else
  1092. return e.resolve(n)end
  1093. end
  1094. if#t==0 then
  1095. return e.reject("No promises to resolve with .any()")end
  1096. local n=0
  1097. return l(e,function(e,l,r)for a,e in ipairs(t)do
  1098. e["then"](e,function(n,e)l(nil,e)end,function(l,e)o[#o+1]=e
  1099. n=n+1
  1100. if n==#t then
  1101. r(nil,{name="AggregateError",message="All Promises rejected",errors=o})end
  1102. end)end
  1103. end)end
  1104. local function je(n)local t={}for o,n in r(n)do
  1105. if c(n,e)then
  1106. if n.state==1 then
  1107. return e.resolve(n.value)elseif n.state==2 then
  1108. return e.reject(n.rejectionReason)else
  1109. t[#t+1]=n
  1110. end
  1111. else
  1112. return e.resolve(n)end
  1113. end
  1114. return l(e,function(e,n,o)for t,e in ipairs(t)do
  1115. e["then"](e,function(t,e)return n(nil,e)end,function(n,e)return o(nil,e)end)end
  1116. end)end
  1117. local o
  1118. do
  1119. o=d()o.name="Set"function o.prototype.____constructor(e,t)e[n.toStringTag]="Set"e.size=0
  1120. e.nextKey={}e.previousKey={}if t==nil then
  1121. return
  1122. end
  1123. local o=t
  1124. if o[n.iterator]then
  1125. local n=o[n.iterator](o)while true do
  1126. local n=n:next()if n.done then
  1127. break
  1128. end
  1129. e:add(n.value)end
  1130. else
  1131. local n=t
  1132. for t,n in ipairs(n)do
  1133. e:add(n)end
  1134. end
  1135. end
  1136. function o.prototype.add(e,n)local t=not e:has(n)if t then
  1137. e.size=e.size+1
  1138. end
  1139. if e.firstKey==nil then
  1140. e.firstKey=n
  1141. e.lastKey=n
  1142. elseif t then
  1143. e.nextKey[e.lastKey]=n
  1144. e.previousKey[n]=e.lastKey
  1145. e.lastKey=n
  1146. end
  1147. return e
  1148. end
  1149. function o.prototype.clear(e)e.nextKey={}e.previousKey={}e.firstKey=nil
  1150. e.lastKey=nil
  1151. e.size=0
  1152. end
  1153. function o.prototype.delete(e,o)local l=e:has(o)if l then
  1154. e.size=e.size-1
  1155. local n=e.nextKey[o]local t=e.previousKey[o]if n~=nil and t~=nil then
  1156. e.nextKey[t]=n
  1157. e.previousKey[n]=t
  1158. elseif n~=nil then
  1159. e.firstKey=n
  1160. e.previousKey[n]=nil
  1161. elseif t~=nil then
  1162. e.lastKey=t
  1163. e.nextKey[t]=nil
  1164. else
  1165. e.firstKey=nil
  1166. e.lastKey=nil
  1167. end
  1168. e.nextKey[o]=nil
  1169. e.previousKey[o]=nil
  1170. end
  1171. return l
  1172. end
  1173. function o.prototype.forEach(e,t)for o,n in r(e:keys())do
  1174. t(nil,n,n,e)end
  1175. end
  1176. function o.prototype.has(e,n)return e.nextKey[n]~=nil or e.lastKey==n
  1177. end
  1178. o.prototype[n.iterator]=function(e)return e:values()end
  1179. function o.prototype.entries(e)local t=e.nextKey
  1180. local e=e.firstKey
  1181. return{[n.iterator]=function(e)return e
  1182. end,next=function(n)local n={done=not e,value={e,e}}e=t[e]return n
  1183. end}end
  1184. function o.prototype.keys(e)local t=e.nextKey
  1185. local e=e.firstKey
  1186. return{[n.iterator]=function(e)return e
  1187. end,next=function(n)local n={done=not e,value=e}e=t[e]return n
  1188. end}end
  1189. function o.prototype.values(e)local t=e.nextKey
  1190. local e=e.firstKey
  1191. return{[n.iterator]=function(e)return e
  1192. end,next=function(n)local n={done=not e,value=e}e=t[e]return n
  1193. end}end
  1194. o[n.species]=o
  1195. end
  1196. local function te(...)local e={...}e.sparseLength=s(...)return e
  1197. end
  1198. local function ne(e,...)local l={...}local o=s(...)local n=e.sparseLength
  1199. for t=1,o do
  1200. e[n+t]=l[t]end
  1201. e.sparseLength=n+o
  1202. end
  1203. local function W(e)local n=unpack or table.unpack
  1204. return n(e,1,e.sparseLength)end
  1205. local a
  1206. do
  1207. a=d()a.name="WeakMap"function a.prototype.____constructor(e,t)e[n.toStringTag]="WeakMap"e.items={}setmetatable(e.items,{__mode="k"})if t==nil then
  1208. return
  1209. end
  1210. local o=t
  1211. if o[n.iterator]then
  1212. local n=o[n.iterator](o)while true do
  1213. local n=n:next()if n.done then
  1214. break
  1215. end
  1216. local n=n.value
  1217. e.items[n[1]]=n[2]end
  1218. else
  1219. for t,n in ipairs(t)do
  1220. e.items[n[1]]=n[2]end
  1221. end
  1222. end
  1223. function a.prototype.delete(e,n)local t=e:has(n)e.items[n]=nil
  1224. return t
  1225. end
  1226. function a.prototype.get(e,n)return e.items[n]end
  1227. function a.prototype.has(n,e)return n.items[e]~=nil
  1228. end
  1229. function a.prototype.set(e,t,n)e.items[t]=n
  1230. return e
  1231. end
  1232. a[n.species]=a
  1233. end
  1234. local i
  1235. do
  1236. i=d()i.name="WeakSet"function i.prototype.____constructor(e,o)e[n.toStringTag]="WeakSet"e.items={}setmetatable(e.items,{__mode="k"})if o==nil then
  1237. return
  1238. end
  1239. local t=o
  1240. if t[n.iterator]then
  1241. local n=t[n.iterator](t)while true do
  1242. local n=n:next()if n.done then
  1243. break
  1244. end
  1245. e.items[n.value]=true
  1246. end
  1247. else
  1248. for t,n in ipairs(o)do
  1249. e.items[n]=true
  1250. end
  1251. end
  1252. end
  1253. function i.prototype.add(e,n)e.items[n]=true
  1254. return e
  1255. end
  1256. function i.prototype.delete(n,e)local t=n:has(e)n.items[e]=nil
  1257. return t
  1258. end
  1259. function i.prototype.has(e,n)return e.items[n]==true
  1260. end
  1261. i[n.species]=i
  1262. end
  1263. local function re(n,e)_G.__TS__sourcemap=_G.__TS__sourcemap or({})_G.__TS__sourcemap[n]=e
  1264. if _G.__TS__originalTraceback==nil then
  1265. local n=debug.traceback
  1266. _G.__TS__originalTraceback=n
  1267. debug.traceback=function(l,o,t)local e
  1268. if l==nil and o==nil and t==nil then
  1269. e=n()elseif g(_VERSION,"Lua 5.0")then
  1270. e=n((("[Level "..tostring(t)).."] ")..tostring(o))else
  1271. e=n(l,o,t)end
  1272. if type(e)~="string"then
  1273. return e
  1274. end
  1275. local function l(e,t,o,n)local e=_G.__TS__sourcemap[t]if e~=nil and e[n]~=nil then
  1276. local e=e[n]if type(e)=="number"then
  1277. return(o..":")..tostring(e)end
  1278. return(e.file..":")..tostring(e.line)end
  1279. return(t..":")..n
  1280. end
  1281. local n=string.gsub(e,"(%S+)%.lua:(%d+)",function(e,n)return l(nil,e..".lua",e..".ts",n)end)local function l(e,t,o)local e=_G.__TS__sourcemap[t]if e~=nil and e[o]~=nil then
  1282. local n=f(t,"%[string \"([^\"]+)\"%]")local n=string.gsub(n,".lua$",".ts")local e=e[o]if type(e)=="number"then
  1283. return(n..":")..tostring(e)end
  1284. return(e.file..":")..tostring(e.line)end
  1285. return(t..":")..o
  1286. end
  1287. n=string.gsub(n,"(%[string \"[^\"]+\"%]):(%d+)",function(e,n)return l(nil,e,n)end)return n
  1288. end
  1289. end
  1290. end
  1291. local function K(e)local n={}if type(e)=="string"then
  1292. for t=0,#e-1 do
  1293. n[t+1]=m(e,t)end
  1294. else
  1295. local t=0
  1296. for o,e in r(e)do
  1297. t=t+1
  1298. n[t]=e
  1299. end
  1300. end
  1301. return h(n)end
  1302. local function J(n,e)if e~=e then
  1303. e=0
  1304. end
  1305. if e<0 then
  1306. return""end
  1307. return string.sub(n,e+1,e+1)end
  1308. local function Y(n,e)if e~=e then
  1309. e=0
  1310. end
  1311. if e<0 then
  1312. return 0/0
  1313. end
  1314. return string.byte(n,e+1)or 0/0
  1315. end
  1316. local function N(n,t,e)if e==nil or e>#n then
  1317. e=#n
  1318. end
  1319. return string.sub(n,e-#t+1,e)==t
  1320. end
  1321. local function U(t,e,n)if n==nil then
  1322. n=" "end
  1323. if e~=e then
  1324. e=0
  1325. end
  1326. if e==-math.huge or e==math.huge then
  1327. error("Invalid string length",0)end
  1328. if#t>=e or#n==0 then
  1329. return t
  1330. end
  1331. e=e-#t
  1332. if e>#n then
  1333. n=n..string.rep(n,math.floor(e/#n))end
  1334. return t..string.sub(n,1,math.floor(e))end
  1335. local function le(t,e,n)if n==nil then
  1336. n=" "end
  1337. if e~=e then
  1338. e=0
  1339. end
  1340. if e==-math.huge or e==math.huge then
  1341. error("Invalid string length",0)end
  1342. if#t>=e or#n==0 then
  1343. return t
  1344. end
  1345. e=e-#t
  1346. if e>#n then
  1347. n=n..string.rep(n,math.floor(e/#n))end
  1348. return string.sub(n,1,math.floor(e))..t
  1349. end
  1350. local G
  1351. do
  1352. local o=string.sub
  1353. function G(e,l,t)local n,a=string.find(e,l,nil,true)if not n then
  1354. return e
  1355. end
  1356. local r=o(e,1,n-1)local n=type(t)=="string"and t or t(nil,l,n-1,e)local e=o(e,a+1)return(r..n)..e
  1357. end
  1358. end
  1359. local _
  1360. do
  1361. local a=string.sub
  1362. local i=string.find
  1363. function _(t,r,n)if n==nil then
  1364. n=4294967295
  1365. end
  1366. if n==0 then
  1367. return{}end
  1368. local o={}local e=1
  1369. if r==nil or r==""then
  1370. for n=1,#t do
  1371. o[e]=a(t,n,n)e=e+1
  1372. end
  1373. else
  1374. local l=1
  1375. while e<=n do
  1376. local n,r=i(t,r,l,true)if not n then
  1377. break
  1378. end
  1379. o[e]=a(t,l,n-1)e=e+1
  1380. l=r+1
  1381. end
  1382. if e<=n then
  1383. o[e]=a(t,l)end
  1384. end
  1385. return o
  1386. end
  1387. end
  1388. local V
  1389. do
  1390. local a=string.sub
  1391. local i=string.find
  1392. function V(n,l,o)if type(o)=="string"then
  1393. local e=table.concat(_(n,l),o)if#l==0 then
  1394. return(o..e)..o
  1395. end
  1396. return e
  1397. end
  1398. local t={}local e=1
  1399. if#l==0 then
  1400. t[1]=o(nil,"",0,n)e=2
  1401. for l=1,#n do
  1402. t[e]=a(n,l,l)t[e+1]=o(nil,"",l,n)e=e+2
  1403. end
  1404. else
  1405. local r=1
  1406. while true do
  1407. local i,d=i(n,l,r,true)if not i then
  1408. break
  1409. end
  1410. t[e]=a(n,r,i-1)t[e+1]=o(nil,l,i-1,n)e=e+2
  1411. r=d+1
  1412. end
  1413. t[e]=a(n,r)end
  1414. return table.concat(t)end
  1415. end
  1416. local function q(t,n,e)if n==nil or n~=n then
  1417. n=0
  1418. end
  1419. if e~=e then
  1420. e=0
  1421. end
  1422. if n>=0 then
  1423. n=n+1
  1424. end
  1425. if e~=nil and e<0 then
  1426. e=e-1
  1427. end
  1428. return string.sub(t,n,e)end
  1429. local function oe(t,n,e)if e==nil or e<0 then
  1430. e=0
  1431. end
  1432. return string.sub(t,e+1,#n+e)==n
  1433. end
  1434. local function ee(t,e,n)if e~=e then
  1435. e=0
  1436. end
  1437. if n~=nil then
  1438. if n~=n or n<=0 then
  1439. return""end
  1440. n=n+e
  1441. end
  1442. if e>=0 then
  1443. e=e+1
  1444. end
  1445. return string.sub(t,e,n)end
  1446. local function ae(e)local e=string.gsub(e,"^[%s ]*(.-)[%s ]*$","%1")return e
  1447. end
  1448. local function Z(e)local e=string.gsub(e,"[%s ]*$","")return e
  1449. end
  1450. local function Q(e)local e=string.gsub(e,"^[%s ]*","")return e
  1451. end
  1452. local L,O
  1453. do
  1454. local e={}function L(n)if not e[n]then
  1455. e[n]=u(n)end
  1456. return e[n]end
  1457. function O(t)for n in pairs(e)do
  1458. if e[n]==t then
  1459. return n
  1460. end
  1461. end
  1462. return nil
  1463. end
  1464. end
  1465. local function R(e)local e=type(e)if e=="table"then
  1466. return"object"elseif e=="nil"then
  1467. return"undefined"else
  1468. return e
  1469. end
  1470. end
  1471. return{__TS__ArrayConcat=be,__TS__ArrayEntries=ye,__TS__ArrayEvery=me,__TS__ArrayFilter=ge,__TS__ArrayForEach=pe,__TS__ArrayFind=_e,__TS__ArrayFindIndex=Be,__TS__ArrayFrom=j,__TS__ArrayIncludes=Fe,__TS__ArrayIndexOf=ze,__TS__ArrayIsArray=y,__TS__ArrayJoin=xe,__TS__ArrayMap=we,__TS__ArrayPush=ve,__TS__ArrayPushArray=Te,__TS__ArrayReduce=Se,__TS__ArrayReduceRight=ke,__TS__ArrayReverse=Ce,__TS__ArrayUnshift=I,__TS__ArraySort=se,__TS__ArraySlice=ue,__TS__ArraySome=fe,__TS__ArraySplice=ie,__TS__ArrayToObject=ce,__TS__ArrayFlat=X,__TS__ArrayFlatMap=de,__TS__ArraySetLength=he,__TS__AsyncAwaiter=Ze,__TS__Await=Ne,__TS__Class=d,__TS__ClassExtends=z,__TS__CloneDescriptor=F,__TS__CountVarargs=s,__TS__Decorate=Ue,__TS__DecorateParam=nn,__TS__Delete=Qe,__TS__DelegatedYield=Ye,Error=w,RangeError=S,ReferenceError=k,SyntaxError=T,TypeError=x,URIError=B,__TS__FunctionBind=v,__TS__Generator=A,__TS__InstanceOf=c,__TS__InstanceOfObject=en,__TS__Iterator=r,__TS__LuaIteratorSpread=Je,Map=t,__TS__Match=f,__TS__MathAtan2=He,__TS__MathModf=M,__TS__MathSign=Ie,__TS__New=l,__TS__Number=Me,__TS__NumberIsFinite=Ve,__TS__NumberIsNaN=Ee,__TS__NumberToString=P,__TS__NumberToFixed=De,__TS__ObjectAssign=E,__TS__ObjectDefineProperty=Pe,__TS__ObjectEntries=Ae,__TS__ObjectFromEntries=Ge,__TS__ObjectGetOwnPropertyDescriptor=D,__TS__ObjectGetOwnPropertyDescriptors=C,__TS__ObjectKeys=Xe,__TS__ObjectRest=Re,__TS__ObjectValues=qe,__TS__ParseFloat=We,__TS__ParseInt=H,__TS__Promise=e,__TS__PromiseAll=Ke,__TS__PromiseAllSettled=Oe,__TS__PromiseAny=Le,__TS__PromiseRace=je,Set=o,__TS__SetDescriptor=b,__TS__SparseArrayNew=te,__TS__SparseArrayPush=ne,__TS__SparseArraySpread=W,WeakMap=a,WeakSet=i,__TS__SourceMapTraceBack=re,__TS__Spread=K,__TS__StringAccess=m,__TS__StringCharAt=J,__TS__StringCharCodeAt=Y,__TS__StringEndsWith=N,__TS__StringIncludes=g,__TS__StringPadEnd=U,__TS__StringPadStart=le,__TS__StringReplace=G,__TS__StringReplaceAll=V,__TS__StringSlice=q,__TS__StringSplit=_,__TS__StringStartsWith=oe,__TS__StringSubstr=ee,__TS__StringSubstring=p,__TS__StringTrim=ae,__TS__StringTrimEnd=Z,__TS__StringTrimStart=Q,__TS__Symbol=u,Symbol=n,__TS__SymbolRegistryFor=L,__TS__SymbolRegistryKeyFor=O,__TS__TypeOf=R,__TS__Unpack=h}end,["utils"]=function(...)local e={}function e.read_file(e)local e,n=io.open(e,"rb")if not e then
  1472. error("could not open file: "..n)end
  1473. local n=e:read("*a")if not n then
  1474. error"could not read file"end
  1475. e:close()return n
  1476. end
  1477. function e.write_file(e,t)local n,o=io.open(e,"wb")if not n then
  1478. error((("could not open file "..e)..": ")..o)end
  1479. local o,t=n:write(t)if not o then
  1480. error((("could not write to file "..e)..": ")..t)end
  1481. n:close()end
  1482. function e.log(e,o)local n,t=io.open(e,"a")if not n then
  1483. error((("could not open file "..e)..": ")..t)end
  1484. local t,o=n:write(o)if not t then
  1485. error((("could not write to file "..e)..": ")..o)end
  1486. n:close()end
  1487. function e.download(n)local e,t=http.get(n,nil,true)if not e or e==true then
  1488. error((("could not download "..n)..": ")..t)end
  1489. local n=e.readAll()e.close()return n or""end
  1490. return e
  1491. end,["game"]=function(...)local e=a("lualib_bundle")local o=e.__TS__Class
  1492. local n=e.__TS__Unpack
  1493. local s=e.__TS__ArrayMap
  1494. local r=e.__TS__ArrayIndexOf
  1495. local p=e.__TS__StringAccess
  1496. local i=e.__TS__StringSubstring
  1497. local f=e.__TS__ArrayConcat
  1498. local c=e.__TS__New
  1499. local v=e.__TS__ArrayForEach
  1500. local b=e.__TS__StringEndsWith
  1501. local k=e.__TS__ObjectValues
  1502. local l=e.__TS__ArrayUnshift
  1503. local S={}local g,d,T,t
  1504. local u=a("pine3d.Pine3D")local h=a("basalt.basalt")local y=a("kernel")local m=a("utils")local F=a("nbs")function g()local t=500
  1505. local n={}for e=1,300 do
  1506. local o,e=math.random()<.2,math.random()<.6
  1507. local l=o and(e and colours.lightBlue or colours.red)or(e and colours.white or colours.yellow)local o=2*math.pi*math.pow(2*math.random()-1,2)local e=2*math.pi*math.pow(2*math.random()-1,2)local e,t,o=t*math.sin(o)*math.cos(e),t*math.sin(e),t*math.cos(o)*math.cos(e)n[#n+1]={l,e,t,o}end
  1508. return n
  1509. end
  1510. function d(e,n)if n==nil then
  1511. n=1
  1512. end
  1513. local n=math.sqrt(e[1]*e[1]+e[2]*e[2]+e[3]*e[3])*1/n
  1514. if n>1e-5 then
  1515. return{e[1]/n,e[2]/n,e[3]/n}else
  1516. return{0,0,0}end
  1517. end
  1518. function T(r,o,n,l,a,e)local o=r-o
  1519. local r=string.format("%.2f",n)local i=string.format("%.2f",n/o*100)local l=string.format("%.2f",l)local n=string.format("%.2f",a)t(((((((("fps "..l).." ui ")..r).." max ")..n).." (")..i).."%)")for n=0,#e-1 do
  1520. local o=string.format("%.2f",e[n+1][1]/o*100)local l=string.format("%.2f",e[n+1][1])local e=string.format("%.2f",e[n+1][2])t(((((((("-> thread "..tostring(n)).." time ")..l).." max ")..e).." (")..o).."%)")end
  1521. end
  1522. function t(...)local n={...}local e=debug.getinfo(2)local o=e and e.name or"?"local a=e and e.namewhat or""local r=e and e.short_src or"?"local t=e and e.currentline or"?"local e=string.format("%.3f",os.clock())l(n,((((((((("["..e).." ")..a).." ")..o).." at ")..r)..":")..tostring(t)).."]")m.log("/pg-log.txt",table.concat(s(n,function(n,e)return tostring(e)end),"\t").."\n")end
  1523. local C={arid={"dry",("Dry, rocky world with a nitrogen-oxygen atmosphere. ".."The dust-covered terrain consists largely of mesas and canyons. ").."Forests can be found in the more temperate polar regions, but vegetation is otherwise scarce."},desert={"dry",(("Dry, rocky world with a nitrogen-oxygen atmosphere. ".."Precipitation and major bodies of surface water are relatively rare. Significant ").."temperature variations between day and night cycles. Vegetation is scarce, but even ").."moderate precipitation can make the desert bloom."},savanna={"dry",("Rocky world dominated by dry, arid plains covered by a nitrogen-oxygen ".."atmosphere. The small hydrosphere allows for brief wet seasons, but aside from a few ").."ubiquitous grasses vegetation is largely concentrated around shallow oases."},alpine={"frozen",(("Mountainous world with a nitrogen-oxygen atmosphere. Snow covers the ".."mountaintops and frozen-over lakes dot the valleys. While the planet experiences the minimal ").."seasonal variations, the still-liquid water beneath the frozen surface of the lakes is enough ").."to sustain some hardy vegetation."},arctic={"frozen",("Frigid, rocky world with a nitrogen-oxygen atmosphere. The poles are big, ".."and significant water deposits can be found permanently frozen as glacial ice. However, the planet ").."experiences seasonal variations and the equatorial band is covered by vegetation."},tundra={"frozen",("Cold and rocky world with a nitrogen-oxygen atmosphere. Permafrost covers most ".."of the surface except for the more temperate equatorial regions. A stable biosphere exists but ").."vegetation is mostly limited to mosses and lichens."},continental={"wet",("Rocky world with a nitrogen-oxygen atmosphere. Active and stable hydrosphere. ".."Great landmasses are separated by oceans, with large climate variations depending on latitude and ").."precipitation."},ocean={"wet","Rocky world with a nitrogen-oxygen atmosphere and a significant hydrosphere. ".."Oceans cover more than 90% of the surface, with scattered islands making up the remaining percentage."},tropical={"wet",("Humid, rocky world with a thick nitrogen-oxygen atmosphere. Seasons with ".."significant precipitation are interchanged with drier periods. Most landmasses are covered ").."in dense vegetation."},asteroid={false,("A rocky or metallic object that orbits a star. It is too small to be ".."considered a planet and can vary greatly in size. Some asteroids may be rich in valuable minerals, ").."while others may be little more than space rocks."},["gas giant"]={false,("A massive planet composed mainly of hydrogen and helium gases. ".."These planets have thick atmospheres and strong winds, but no solid surface. Gas giants ").."often have a system of rings and numerous moons."},["frozen world"]={false,("A frigid planet with a surface temperature well below freezing. ".."These worlds are often covered in ice and snow, and may have frozen oceans or lakes. Life is ").."scarce on frozen worlds, but some extremophile organisms may exist."},["barren world"]={false,("A rocky planet with a thin or nonexistent atmosphere. Barren worlds may ".."have little or no water, and are often subject to extreme temperatures and radiation. ").."These worlds are generally inhospitable to life."}}local e=StarType or({})e.ClassB="Class B"e.ClassA="Class A"e.ClassF="Class F"e.ClassG="Class G"e.ClassK="Class K"e.ClassM="Class M"e.ClassMRedGiant="Class M Red Giant"e.ClassTBrownDwarf="Class T Brown Dwarf"local z={["Class B"]="The large class B main-sequence stars are very bright and blue. ".."Although somewhat rare, the luminosity of these stars make them among the most visible to the naked eye.",["Class A"]=("These relatively young white or bluish-white main-sequence stars are ".."typically among the most visible to the naked eye. They are large and rotate very ").."quickly, but will eventually evolve into slower and cooler red giants.",["Class F"]=("F-type stars are fairly large and often referred to as yellow-white dwarves. ".."Although they often emit significant amounts of UV radiation, their wide habitable zones ").."have a good chance of supporting life-bearing worlds.",["Class G"]=(("Often referred to as yellow dwarves, G-type stars actually range in color from white ".."to slightly yellow. Main-sequence stars fuse hydrogen for roughly 10 billion years before they ").."expand and become red giants. Although their lifespans are shorter than K-type stars, worlds ").."inside the habitable zone of a G star often enjoy optimal conditions for the development of life.",["Class K"]=("These main-sequence stars, sometimes referred to as orange dwarves, are a fairly ".."common sight. They are stable on the main-sequence for up to 30 billion years, meaning that ").."worlds orbiting a K-type star have a longer than average window to evolve life.",["Class M"]=(("The most common stars in the universe, often referred to as red dwarves. ".."Their low luminosity means they are difficult to observe with the naked eye from afar. ").."Although they typically have an extremely long lifespan, red dwarves emit almost no UV ").."light resulting in unfavorable conditions for most forms of life.",["Class M Red Giant"]=("With a large radius and comparatively low surface temperature, red giants ".."are stars of moderate mass in a late stage of stellar evolution. Their expanded stellar ").."atmosphere and high luminosity make for distant habitable zone orbits.",["Class T Brown Dwarf"]=(("Brown dwarfs are substellar objects that lack the mass to sustain ".."hydrogen fusion. Roughly the size of large gas giants, they have a much greater density. ").."Their low luminosity and comparatively small heat generation means that planets orbiting ").."them are unlikely to support life."}local B={[e.ClassB]={15,45},[e.ClassA]={15,45},[e.ClassF]={10,60},[e.ClassG]={15,45},[e.ClassK]={15,45},[e.ClassM]={10,30},[e.ClassMRedGiant]={40,80},[e.ClassTBrownDwarf]={5,20}}local a=o()a.name="Music"function a.prototype.____constructor(e,o,n,t,l)e.artist=o
  1524. e.name=n
  1525. e.url=t
  1526. e.data=l
  1527. end
  1528. local x=o()x.name="StarSystem"function x.prototype.____constructor(e,t,n)e.star=t
  1529. e.planets=n
  1530. end
  1531. local w=o()w.name="Galaxy"function w.prototype.____constructor(n,e)n.systems=e
  1532. end
  1533. local _=o()_.name="UIState"function _.prototype.____constructor(e,n,t,o,r,l,a)e.sidebar_list=n
  1534. e.side_tabs=t
  1535. e.info_label=o
  1536. e.speaker_button=r
  1537. e.animations=l
  1538. e.main_frame=a
  1539. end
  1540. local o=o()o.name="GameState"function o.prototype.____constructor(e,n,f,m,h,p,_,w,g,b,y,d,i,a,l,o,t,r,c,s,u)e.mode=n
  1541. e.last_mouse_click=f
  1542. e.clouds=m
  1543. e.objects=h
  1544. e.object_names=p
  1545. e.frame=_
  1546. e.camera=w
  1547. e.camera_target=g
  1548. e.camera_angle_x=b
  1549. e.camera_angle_y=y
  1550. e.camera_angle_y_limits=d
  1551. e.dist_to_target=i
  1552. e.pressed_keys=a
  1553. e.tracks=l
  1554. e.playing=o
  1555. e.speaker_available=t
  1556. e.galaxy=r
  1557. e.current_system=c
  1558. e.trace_overlay=s
  1559. e.ui_state=u
  1560. end
  1561. function o.prototype.change_mode(e,n)if n=="system"then
  1562. e.mode="system"e:set_up_system_scene()elseif n=="galaxy"then
  1563. e.mode="galaxy"e:set_up_galaxy_scene()end
  1564. end
  1565. function o.prototype.process_click(e,r,o,l)if r-e.last_mouse_click<.3 then
  1566. local o=e.frame:getObjectIndexTrace(e.objects,{{x=o,y=l}})local l=o[1].objectIndex
  1567. t(((((("trace returned "..tostring(l)).." / ")..tostring(#e.objects)).." (")..tostring(#e.object_names))..")")if l and l<=#e.objects then
  1568. local o=e.object_names[l]if e.mode=="galaxy"then
  1569. e.current_system=o
  1570. e:change_mode("system")else
  1571. t((((((("double click in system mode, "..tostring(e.current_system))..", ")..tostring(l))..", ")..tostring(o))..", \nall names are: ")..table.concat(e.object_names,","))local t=e.galaxy.systems[e.current_system+1][2]local t,n,l=n(o==-1 and({0,0,0})or t.planets[o+1][1])e.camera_target={t,n,l}e:change_info_tab(e:describe(o))end
  1572. end
  1573. end
  1574. end
  1575. function o.prototype.draw_starfield(e,t)local l=e.frame.buffer.setPixel
  1576. local o=e.frame.map3dTo2d
  1577. local r=e.frame.buffer
  1578. for a=0,#t-1 do
  1579. local a,n,t,i=n(t[a+1])local o,t,n=o(e.frame,n,t,i)if n then
  1580. l(r,o,t,e.mode=="system"and a or colours.lightGrey)end
  1581. end
  1582. end
  1583. function o.prototype.change_info_tab(e,o)local e=e.ui_state
  1584. local n=r(s(e.side_tabs,function(n,e)return e[1]end),"info")local t=e.sidebar_list:getAll()e.sidebar_list:editItem(n+1,t[n+1].text,t[n+1].bgCol,colours.lime)e.info_label:setText(o)end
  1585. function o.prototype.describe(e,t)if t==-1 then
  1586. local e=e.galaxy.systems[e.current_system+1][2].star
  1587. return((string.upper(p(e.name,0))..i(e.name,1))..(" ("..e.type).." star)\n\n")..z[e.type]end
  1588. local n,e=n(e.galaxy.systems[e.current_system+1][2].planets[t+1])local n=C[e.params.type]local e=(e.name.."\ntype: ")..e.params.type
  1589. if n[1]then
  1590. e=e.."\nclimate: "..n[1]end
  1591. e=e.."\n\n"..n[2]return e
  1592. end
  1593. function o.prototype.update(t,l,e)t:update_camera(e)local o={}local e=t.ui_state
  1594. for a=1,e and#e.animations or 0 do
  1595. local e,r=n(t.ui_state.animations[a])if l>e.birth+e.dur then
  1596. r(e.to)o[#o+1]=a
  1597. else
  1598. local n=(l-e.birth)/e.dur
  1599. local t
  1600. if e.easing=="outCubic"then
  1601. t=1-(1-n)^3
  1602. elseif e.easing=="inOutCubic"then
  1603. t=n<.5 and 4*n*n*n or 1-(-2*n+2)^3/2
  1604. else
  1605. error("unhandled easing "..tostring(e.easing))end
  1606. r(t*(e.to-e.from)+e.from)end
  1607. end
  1608. for e=#o,1,-1 do
  1609. table.remove(t.ui_state.animations,o[e])end
  1610. end
  1611. function o.prototype.update_camera(e,r)local n=e.camera
  1612. local t=e.camera_target
  1613. n.rotY=180-e.camera_angle_x*180/math.pi
  1614. n.rotZ=180-e.camera_angle_y*180/math.pi
  1615. local l,o=-e.camera_angle_x,-e.camera_angle_y
  1616. n.x=e.dist_to_target*-math.cos(o)*math.cos(l)n.y=e.dist_to_target*math.sin(o)n.z=e.dist_to_target*-math.cos(o)*math.sin(l)local l,o=e:pressed(keys.s)-e:pressed(keys.w),e:pressed(keys.d)-e:pressed(keys.a)local o={math.cos(math.rad(n.rotY))*l-math.sin(math.rad(n.rotY))*o,math.sin(math.rad(n.rotY))*l+math.cos(math.rad(n.rotY))*o}t={t[1]+e.dist_to_target/2*r*o[1],t[2],t[3]+e.dist_to_target/2*r*o[2]}n.x=n.x+t[1]n.y=n.y+t[2]n.z=n.z+t[3]e.camera_target=t
  1617. end
  1618. function o.prototype.process_drag(e,a,t)local o=os.clock()local l,r=term.getSize()local l,t=e.camera_angle_x+10*a/l/math.pi,e.camera_angle_y+10*t/r/math.pi
  1619. local n,r=n(e.camera_angle_y_limits)t=math.max(n,math.min(r,t))local l={birth=o-.05,dur=.2,from=e.camera_angle_x,to=l,easing="outCubic"}local t={birth=o-.05,dur=.2,from=e.camera_angle_y,to=t,easing="outCubic"}local n=e.ui_state.animations
  1620. n[#n+1]={l,function(n)local n=n
  1621. e.camera_angle_x=n
  1622. return n
  1623. end}local n=e.ui_state.animations
  1624. n[#n+1]={t,function(n)local n=n
  1625. e.camera_angle_y=n
  1626. return n
  1627. end}end
  1628. function o.prototype.pressed(n,e)return n.pressed_keys[e]~=nil and 1 or 0
  1629. end
  1630. function o.prototype.set_up_galaxy_scene(e)local t={}local o={}e.clouds={}e.camera_angle_x=0
  1631. e.camera_angle_y=.25*math.pi
  1632. e.camera_angle_y_limits={-math.pi/4,.8*math.pi/2}e.dist_to_target=1000
  1633. e.camera_target=e.galaxy.systems[e.current_system+1][1]e:update_camera(0)for l=0,#e.galaxy.systems-1 do
  1634. local n=e.galaxy.systems[l+1]local i=n[1][1]local a=n[1][2]local r=n[1][3]local n=n[2]t[#t+1]=e.frame:newObject(n.star.model,i,a,r)o[#o+1]=l
  1635. end
  1636. e.objects=t
  1637. e.object_names=o
  1638. end
  1639. function o.prototype.set_up_system_scene(e)local t,a=n(e.galaxy.systems[e.current_system+1])local o=a.planets
  1640. local r={}local t={}local l={}local i={}t[#t+1]=e.frame:newObject(a.star.model,0,0,0)l[#l+1]=-1
  1641. for a=0,#o-1 do
  1642. local o=o[a+1]local s=o[1][1]local d=o[1][2]local c=o[1][3]local u=o[2].model
  1643. local o=o[2].atmo
  1644. t[#t+1]=e.frame:newObject(u,s,d,c)l[#l+1]=a
  1645. if o then
  1646. for t=1,#o do
  1647. local n,t=n(o[t])r[#r+1]={n,e.frame:newObject(t,s,d,c)}i[#i+1]=a
  1648. end
  1649. end
  1650. end
  1651. for n=0,#r-1 do
  1652. t[#t+1]=r[n+1][2]end
  1653. e.objects=t
  1654. e.object_names=f(l,i)e.clouds=r
  1655. e.camera_target={0,0,0}e.dist_to_target=a.star.radius*2
  1656. e.camera_angle_y_limits={.95*-math.pi/2,.95*math.pi/2}end
  1657. function o.prototype.load_music(l)t"loading music"local n,e=pcall(m.download,"https://cc.viluon.me/pg-music/index.lua")if not n then
  1658. print("could not download soundtrack information! "..(e or""))return
  1659. end
  1660. local n=load(e,"index.lua","bt",getfenv(1))local e={}for t,n in ipairs(n())do
  1661. local t=n.name
  1662. local o=n.url
  1663. local t,n=string.match(t,"^(.-)%s%-%s(.*)$")if t and n then
  1664. e[#e+1]=c(a,t,n,o)end
  1665. end
  1666. l.tracks=e
  1667. end
  1668. function o.prototype.build_soundtrack_ui(e,o)t()local r=string.char(16).." "local l=string.char(4).." "local t={}local function c(e,t,n)local t=t and l or r
  1669. local n=(t..i(e.." ",n+1))..i(e,0,n)local e=o:getSize()-3
  1670. return i(n,0,e)end
  1671. local function d(a,e,r)local t=t[e+1]local l,i,o,n=n(t)local n=r or n
  1672. local e=a.playing==e
  1673. l:setText(c(o,e,n)):setForeground(e and colours.white or colours.lightGrey)t[4]=n
  1674. end
  1675. local s=o:addButton():setText(""):setHorizontalAlign("center"):setSize("parent.w",1):setForeground(colours.pink)local c=2
  1676. for n=0,#e.tracks-1 do
  1677. local l=e.tracks[n+1]local l=((l.name.." (")..l.artist)..")"local a=o:addButton():setSize("parent.w - 2",1):setText(r..i(l,0,o:getSize()-5)):setHorizontalAlign("left")local i=a.setPosition
  1678. local r=c
  1679. c=r+1
  1680. local r=i(a,2,r)local o=o:addAnimation():setObject(r)t[#t+1]={r,o,l,0}for t=0,#l do
  1681. o:add(function()return d(e,n,t)end):wait(.15)end
  1682. o:wait(5):add(function()return o:play()end):play()r:onClick(function()if e.playing then
  1683. os.queueEvent("music:stop",e.playing)end
  1684. if e.playing~=n then
  1685. os.queueEvent("music:play",n)end
  1686. v(t,function(t,t,n)return d(e,n)end)return true
  1687. end)end
  1688. return s
  1689. end
  1690. function o.prototype.draw_labels(e)term.setBackgroundColour(colours.black)term.setTextColour(colours.lightGrey)for n=0,#e.objects-1 do
  1691. local n=e.object_names[n+1]e:draw_label_for(n)end
  1692. end
  1693. function o.prototype.draw_label_for(e,a)local c,s,i=e.camera.x,e.camera.y,e.camera.z
  1694. local r
  1695. local o
  1696. local t
  1697. local l
  1698. if a==-1 then
  1699. local e=e.galaxy.systems[e.current_system+1][2].star
  1700. r=e.name
  1701. o,t,l=0,e.radius*.8,0
  1702. elseif e.mode=="system"then
  1703. local a,e=n(e.galaxy.systems[e.current_system+1][2].planets[a+1])r=e.name
  1704. o,t,l=n(a)t=t+e.params.size*.8
  1705. else
  1706. local a,e=n(e.galaxy.systems[a+1])r=e.star.name
  1707. o,t,l=n(a)t=t+(e.star.radius*.8+math.sqrt((o-c)^2+(t-s)^2+(l-i)^2)/40)end
  1708. local a,n,i=n(d({c-o,s-t,i-l},10))o,t,l=o+a,t+n,l+i
  1709. local n,a,i=e.frame:map3dTo2d(o,t,l)if i then
  1710. n,a=math.floor(.5+n/2),math.floor(.5+a/3)local d=e.frame:getObjectIndexTrace(e.objects,{{x=n,y=a}})local c=d[1].objectIndex
  1711. local d=d[1].depth
  1712. if c then
  1713. local r,e,n=e.camera.x,e.camera.y,e.camera.z
  1714. local e=(o-r)^2+(t-e)^2+(l-n)^2
  1715. i=e<d
  1716. end
  1717. if i then
  1718. term.setCursorPos(math.floor(n-#r/2),a)term.write(r)end
  1719. end
  1720. end
  1721. local a={"harp","basedrum","bass","snare","hat","guitar","flute","bell","chime","xylophone","iron_xylophone","cow_bell","didgeridoo","bit","banjo","pling"}local function l(e,n)n=n/2
  1722. local function t(e,o,t)local l=math.sqrt(e*e+o*o+t*t)local n=n/l
  1723. return n*e,n*o,n*t
  1724. end
  1725. local n={t(e.x1,e.y1,e.z1)}e.x1=n[1]e.y1=n[2]e.z1=n[3]local n={t(e.x2,e.y2,e.z2)}e.x2=n[1]e.y2=n[2]e.z2=n[3]local n={t(e.x3,e.y3,e.z3)}e.x3=n[1]e.y3=n[2]e.z3=n[3]end
  1726. local function f(...)local e={...}return e[math.random(1,#e)]end
  1727. local function p()t()local e={peripheral.find("speaker")}local e=n(e)if e then
  1728. return e
  1729. end
  1730. local t,e=pcall(function()return{{_G.periphemu.create("left","speaker")}}end,nil)if not t then
  1731. error("no speaker found, peripheral emulation not available: "..e)end
  1732. local e,t=n(e[1])if not e then
  1733. error("could not attach speaker: "..t)end
  1734. local e={peripheral.find("speaker")}local e=n(e)return assert(e)end
  1735. local function r(e)local t=p()local e,n=F.load(e)if not e then
  1736. error("could not load soundtrack: "..n)end
  1737. local n=e.delay
  1738. local o=e.layers
  1739. local t=t.playNote
  1740. for l=0,#e-1 do
  1741. local e=e[l+1]for e,n in pairs(e)do
  1742. local e=a[e+1]for n,l in pairs(n)do
  1743. t(e,o[n+1].volume/100,l)end
  1744. end
  1745. sleep(n)end
  1746. end
  1747. local function a(e)local n=p()y.play_dfpwm(n,e)end
  1748. local function i(e)if b(e,".dfpwm")then
  1749. return a(e)end
  1750. if b(e,".nbs")then
  1751. return r(e)end
  1752. error("unknown extension in "..e)end
  1753. local function i(e)local o=u.models:icosphere({res=e.resolution,colors={-1,e.cloud_colour,e.cloud_colour,e.cloud_colour,e.cloud_colour,e.cloud_colour,-1}})local t=o
  1754. local r=e.planet_size*1.1
  1755. local n={}for o=0,#t-1 do
  1756. local t=t[o+1]if t.c~=-1 and math.random()<e.cloud_cover then
  1757. l(t,r)else
  1758. n[#n+1]=o+1
  1759. end
  1760. end
  1761. for e=#n-1,0,-1 do
  1762. table.remove(t,n[e+1])end
  1763. local e=math.random()<.3 and-1 or 1
  1764. return{{e/math.random(4,32),o}}end
  1765. local r={[e.ClassB]={size=5,rot=1,primary=colours.white,alt=colours.lightBlue},[e.ClassA]={size=5,rot=12,primary=colours.white,alt=colours.lightGrey,ratio=4},[e.ClassF]={size=5,rot=1,primary=colours.yellow,alt=colours.white},[e.ClassG]={size=5,rot=1,primary=colours.yellow,alt=colours.white},[e.ClassK]={size=5,rot=1,primary=colours.yellow,alt=colours.orange},[e.ClassM]={size=5,rot=1,primary=colours.red,alt=colours.black,ratio=4},[e.ClassMRedGiant]={size=15,rot=1,primary=colours.red,alt=colours.black,ratio=4},[e.ClassTBrownDwarf]={size=5,rot=1,primary=colours.red,alt=colours.black,ratio=4}}local function D(e)local e=r[e]local o=e.primary
  1766. local a=e.alt
  1767. local t=e.size
  1768. local n=e.rot
  1769. local e=e.ratio
  1770. n=n*(math.random(.8,1.2)*(math.random()<.2 and 1 or-1))if not e then
  1771. e=2
  1772. end
  1773. local r=u.models:icosphere({res=3,colors={o}})local t=t+math.random(2,5)local o=r
  1774. for r=0,#o-1 do
  1775. local n=o[r+1]if r%e==0 then
  1776. n.c=a
  1777. end
  1778. l(n,t)end
  1779. return t,r,n
  1780. end
  1781. local function b(n)local e=u.models:icosphere({res=n.resolution,colors={0}})local r=e
  1782. local a=n.planet_size*1.1
  1783. local o={}local t={}for n in pairs(e)do
  1784. o[n]=e[n]t[n]=e[n]end
  1785. for e=0,#r-1 do
  1786. local e=r[e+1]if e.c~=-1 and math.random()<.3 then
  1787. if math.floor(e.y1)%2==0 then
  1788. e.c=n.cloud_colour
  1789. l(e,a*.9)o[#o+1]=e
  1790. else
  1791. e.c=n.alt_cloud_colour
  1792. l(e,a*1.05)t[#t+1]=e
  1793. end
  1794. end
  1795. end
  1796. return{{1/math.random(4,32),o},{-1/math.random(4,32),t}}end
  1797. local function C(e)local n=e.ice_cap_north and({-1})or({})for t=1,e.water_level do
  1798. local t=t==math.floor(.5+e.water_level/2)local e=e.type=="arctic"and t and e.landmass_colour or e.water_colour
  1799. n[#n+1]=e
  1800. end
  1801. if e.ice_cap_south then
  1802. n[#n+1]=-1
  1803. end
  1804. local o=u.models:icosphere({res=e.resolution,colors=n})local t=false
  1805. local n=o
  1806. for o=0,#n-1 do
  1807. local n=n[o+1]l(n,e.size)if n.c~=-1 and math.random()<e.landmass*(t and .5 or .1)then
  1808. if e.landmass_alt_colour then
  1809. n.c=math.random()<.8 and e.landmass_colour or e.landmass_alt_colour
  1810. else
  1811. n.c=e.landmass_colour
  1812. end
  1813. t=true
  1814. else
  1815. if n.c==-1 then
  1816. n.c=colours.white
  1817. end
  1818. t=false
  1819. end
  1820. end
  1821. local n={resolution=e.resolution+1,planet_size=e.size,cloud_colour=e.atmosphere_colour or colours.white,alt_cloud_colour=e.type=="gas giant"and e.landmass_colour or nil,cloud_cover=e.atmosphere_density or .1}local e=e.type=="gas giant"and b(n)or i(n)return{planet_model=o,atmo=e,atmo_params=n}end
  1822. local l={arid={.8,3.5},desert={.8,3.5},savanna={.8,3.5},alpine={.8,3.5},arctic={.8,3.5},tundra={.8,3.5},continental={.8,3.5},ocean={.8,3.5},tropical={.8,3.5},asteroid={.1,.6},["barren world"]={.8,5},["frozen world"]={.8,5},["gas giant"]={4,9}}local a={arid={water_level={3,6},water_colour=colours.yellow,landmass={1,2},landmass_colour=colours.brown,landmass_alt_colour=colours.green,ice_cap_north=.3,ice_cap_south=.2,atmosphere_density={.07,.1},atmosphere_colour=colours.white},desert={water_level={3,6},water_colour=colours.yellow,landmass={1,2},landmass_colour=colours.brown,landmass_alt_colour=colours.orange,ice_cap_north=.05,ice_cap_south=.03,atmosphere_density={.02,.06},atmosphere_colour=colours.white},savanna={water_level={3,6},water_colour=colours.yellow,landmass={1,2},landmass_colour=colours.green,landmass_alt_colour=colours.blue,ice_cap_north=.5,ice_cap_south=.3,atmosphere_density={.08,.12},atmosphere_colour=colours.white},alpine={water_level={3,6},water_colour=colours.lightBlue,landmass={3,4},landmass_colour=colours.green,landmass_alt_colour=colours.white,ice_cap_north=1,ice_cap_south=1,atmosphere_density={.08,.12},atmosphere_colour=colours.white},arctic={water_level={5,8},water_colour=colours.white,landmass={2,3},landmass_colour=colours.brown,landmass_alt_colour=colours.green,ice_cap_north=1,ice_cap_south=1,atmosphere_density={.08,.12},atmosphere_colour=colours.white},tundra={water_level={3,5},water_colour=colours.grey,landmass={2,3},landmass_colour=colours.green,landmass_alt_colour=colours.lightBlue,ice_cap_north=1,ice_cap_south=1,atmosphere_density={.08,.12},atmosphere_colour=colours.white},continental={water_level={5,8},water_colour=colours.blue,landmass={1.4,2},landmass_colour=colours.green,landmass_alt_colour=colours.yellow,ice_cap_north=1,ice_cap_south=1,atmosphere_density={.08,.12},atmosphere_colour=colours.white},ocean={water_level={5,8},water_colour=colours.blue,landmass={.4,1},landmass_colour=colours.green,landmass_alt_colour=colours.cyan,ice_cap_north=.2,ice_cap_south=.1,atmosphere_density={.08,.12},atmosphere_colour=colours.white},tropical={water_level={5,8},water_colour=colours.cyan,landmass={2,3},landmass_colour=colours.green,landmass_alt_colour=colours.blue,ice_cap_north=.1,ice_cap_south=.05,atmosphere_density={.08,.12},atmosphere_colour=colours.white},asteroid={water_level={2,4},water_colour=colours.grey,landmass={1,5},landmass_colour=colours.brown,landmass_alt_colour=colours.lightGrey,ice_cap_north=0,ice_cap_south=0,atmosphere_density={0,0},atmosphere_colour=colours.white},["barren world"]={water_level={5,8},water_colour=colours.brown,landmass={.3,3},landmass_colour=colours.grey,landmass_alt_colour=colours.red,ice_cap_north=0,ice_cap_south=0,atmosphere_density={0,0},atmosphere_colour=colours.white},["frozen world"]={water_level={5,8},water_colour=colours.lightGrey,landmass={2,5},landmass_colour=colours.lightBlue,landmass_alt_colour=colours.white,ice_cap_north=1,ice_cap_south=1,atmosphere_density={.01,.05},atmosphere_colour=colours.white},["gas giant"]={water_level={5,8},water_colour=colours.green,landmass={2,5},landmass_colour=colours.grey,landmass_alt_colour=colours.lightGrey,ice_cap_north=0,ice_cap_south=0,atmosphere_density={.2,.4},atmosphere_colour=colours.green}}local function z(t)local r=t~="asteroid"and t~="barren world"and t~="frozen world"local o=math.random(n(l[t]))local e=a[t]local e={type=t,size=o,resolution=math.max(2,math.ceil(math.log(o*2))),water_level=math.random(n(e.water_level)),water_colour=e.water_colour,landmass=math.random(n(e.landmass)),landmass_colour=e.landmass_colour,landmass_alt_colour=e.landmass_alt_colour,ice_cap_north=math.random()<e.ice_cap_north,ice_cap_south=math.random()<e.ice_cap_south,atmosphere_density=math.random(n(e.atmosphere_density)),atmosphere_colour=e.atmosphere_colour}return r,e
  1823. end
  1824. local function l()local e={{"The Moon",false,{type="barren world",size=.4,resolution=2,water_level=1,water_colour=colours.lightGrey,landmass=1,landmass_colour=colours.grey}},{"Earth",true,{type="continental",size=1.3,resolution=3,water_level=7,water_colour=colours.blue,landmass=1.4,landmass_colour=colours.green,landmass_alt_colour=colours.yellow,ice_cap_north=true,ice_cap_south=true}},{"Mars",true,{type="frozen world",size=.9,resolution=3,water_level=5,water_colour=colours.red,landmass=1,landmass_colour=colours.grey,ice_cap_north=true,ice_cap_south=true,atmosphere_density=.03,atmosphere_colour=colours.lightGrey}}}return s(e,function(n,e)local n
  1825. local t
  1826. local o
  1827. o=e[1]t=e[2]n=e[3]local e=C(n)local r=e.planet_model
  1828. local l=e.atmo
  1829. local e=e.atmo_params
  1830. return{name=o,params=n,atmo_params=e,model=r:toLoD({qualityHalvingDistance=20}),clouds=t and s(l,function(e,n)local e
  1831. local t
  1832. t=n[1]e=n[2]return{t,e:toLoD({qualityHalvingDistance=30})}end)or nil}end)end
  1833. local function b(e)e.frame:setCamera(e.camera)e.frame:setFoV(60)e.frame:highResMode(true)e.frame:setBackgroundColor(colours.black)local f=g()local u=os.clock()local s=-1
  1834. local n=false
  1835. local c,a,i,d=0,0,0,0
  1836. while true do
  1837. if not n then
  1838. os.queueEvent("end_of_queue")n=true
  1839. end
  1840. local o=os.pullEvent()if o=="end_of_queue"then
  1841. n=false
  1842. end
  1843. local o=os.clock()local l=e
  1844. local h=l.clouds
  1845. local r=l.objects
  1846. local n=l.frame
  1847. local l=l.camera
  1848. n:setCamera(0,0,0,l.rotX,l.rotY,l.rotZ)e:draw_starfield(f)n:setCamera(l)if e.trace_overlay then
  1849. n:drawBuffer()local t,e=term.getSize()term.setBackgroundColour(colours.black)term.setTextColour(colours.white)for e=1,e do
  1850. for t=1,t do
  1851. local n=n:getObjectIndexTrace(r,{{x=t,y=e}})[1]local n=n.objectIndex
  1852. if n then
  1853. term.setCursorPos(t,e)term.write(tostring(n))end
  1854. end
  1855. end
  1856. else
  1857. local l=os.clock()v(h,function(n,e)return e[2]:setRot(nil,e[1]*o)end)for n=1,#r do
  1858. local t=e.object_names[n]if t==-1 then
  1859. r[n]:setRot(nil,e.galaxy.systems[e.current_system+1][2].star.rotation_speed/100*o)break
  1860. end
  1861. end
  1862. local o=os.clock()n:drawObjects(r)local t=os.clock()n:drawBuffer()local n=os.clock()e:draw_labels()local e=os.clock()c=c+(o-l)a=a+(t-o)i=i+(n-t)d=d+(e-n)end
  1863. if o-s>5 then
  1864. t("render stats: "..string.format("r %.2f d %.2f b %.2f l %.2f",c,a,i,d))s=o
  1865. end
  1866. u=o
  1867. end
  1868. end
  1869. local function l(n,e)return{n[2]*e[3]-n[3]*e[2],n[3]*e[1]-n[1]*e[3],n[1]*e[2]-n[2]*e[1]}end
  1870. local function r(n,e)return{n[1]-e[1],n[2]-e[2],n[3]-e[3]}end
  1871. local function a(n,e,t)local e=d(r(n,e))local t=d(l(t,e))local o=d(l(e,t))return{t[1],t[2],t[3],0,o[1],o[2],o[3],0,e[1],e[2],e[3],0,n[1],n[2],n[3],1}end
  1872. local function r(e)local o,n=pcall(p)local l=o and n or nil
  1873. t("speaker setup",o,n)if l then
  1874. e.speaker_available=true
  1875. else
  1876. local e=e.ui_state
  1877. if e~=nil then
  1878. e.speaker_button:setText("no speaker")end
  1879. end
  1880. while true do
  1881. local o,n=coroutine.yield()if not l then
  1882. e.playing=nil
  1883. else
  1884. if o=="music:play"then
  1885. e.playing=n
  1886. local o=e.tracks[n+1]t("playing",n,(o or({})).name)if not o.data then
  1887. o.data=m.download(o.url)end
  1888. y.play_dfpwm(l,o.data)e.playing=nil
  1889. if n<#e.tracks-1 then
  1890. os.queueEvent("music:play",n+1)end
  1891. end
  1892. end
  1893. end
  1894. end
  1895. local function F(o)o:change_mode("system")local p=0
  1896. local m=0
  1897. local a={{0,0,coroutine.create(function()return r(o)end)},{0,0,coroutine.create(function()return b(o)end)}}local e=#a
  1898. local c=nil
  1899. local w=os.clock()local h=w
  1900. local l=""local b=h
  1901. local s=0
  1902. local g=0
  1903. while#a>=e do
  1904. local e=os.clock()local _,r,f,u,C,k=os.pullEvent()local y
  1905. local v
  1906. local x
  1907. local i
  1908. local d
  1909. local l=os.clock()local e=l-e
  1910. p=p+e
  1911. m=math.max(m,e)local S=l-h
  1912. repeat
  1913. local t=_
  1914. local e=t=="mouse_click"if e then
  1915. y,i,d=r,f,u
  1916. c={i,d}o:process_click(l,i,d)o.last_mouse_click=l
  1917. break
  1918. end
  1919. e=e or t=="mouse_drag"if e then
  1920. y,i,d=n({r,f,u})v,x=n(assert(c))c={i,d}i,d=i-v,d-x
  1921. o:process_drag(i,d)break
  1922. end
  1923. e=e or t=="mouse_up"if e then
  1924. y,i,d=r,f,u
  1925. c=nil
  1926. break
  1927. end
  1928. e=e or t=="mouse_scroll"if e then
  1929. o.dist_to_target=o.dist_to_target*(1+r/10)break
  1930. end
  1931. e=e or t=="key"if e then
  1932. o.pressed_keys[r]=true
  1933. break
  1934. end
  1935. e=e or t=="key_up"if e then
  1936. o.pressed_keys[r]=nil
  1937. break
  1938. end
  1939. e=e or t=="char"if e then
  1940. if r=="q"then
  1941. return
  1942. end
  1943. if r=="t"then
  1944. o.trace_overlay=not o.trace_overlay
  1945. end
  1946. if r=="e"or r=="E"then
  1947. o:change_mode(o.mode=="galaxy"and"system"or"galaxy")end
  1948. break
  1949. end
  1950. do
  1951. break
  1952. end
  1953. until true
  1954. o:update(l,S)local n={}local i=l
  1955. for e=0,#a-1 do
  1956. local l=a[e+1][3]local s,r,o,o=coroutine.resume(l,_,r,f,u,C,k)local o=os.clock()local c,d=a[e+1],1
  1957. c[d]=c[d]+(o-i)a[e+1][2]=math.max(a[e+1][2],o-i)i=o
  1958. if not s then
  1959. t("thread",e,"crashed",r)error(r)end
  1960. if coroutine.status(l)=="dead"then
  1961. n[#n+1]=e
  1962. end
  1963. end
  1964. for e=#n-1,0,-1 do
  1965. table.remove(a,n[e+1]+1)end
  1966. if l-b>1 then
  1967. g=s/(l-b)b=l
  1968. s=0
  1969. T(l,w,p,g,m,a)end
  1970. s=s+1
  1971. term.setCursorPos(1,1)term.write(string.format("%.2f fps, in %s, curr sys: %d",g,o.galaxy.systems[o.current_system+1][2].star.name,o.current_system))h=l
  1972. end
  1973. end
  1974. local function p(l,r)local n={}local o={}local t
  1975. local e
  1976. e=l:addFrame():setSize("0.33 * parent.w","parent.h"):setPosition("parent.w",1):onGetFocus(function()local n=l:getSize()-e:getSize()+1
  1977. o[#o+1]={{birth=os.clock(),dur=.5,from=e:getPosition(),to=n,easing="inOutCubic"},function(n)return e:setPosition(math.floor(n),select(2,e:getPosition()))end}return true
  1978. end):onLoseFocus(function()o[#o+1]={{birth=os.clock(),dur=.5,from=e:getPosition(),to=l:getSize(),easing="inOutCubic"},function(n)return e:setPosition(math.floor(n),select(2,e:getPosition()))end}local e=t:getAll()for n=1,#e do
  1979. local e=e[n]local o=e.fgCol==colours.white and colours.lightGrey or e.fgCol
  1980. t:editItem(n,e.text,e.bgCol,o)end
  1981. return true
  1982. end)t=e:addList():setSize(1,"parent.h"):setPosition(1,1):setBackground(colours.black):setForeground(colours.lightGrey):setSelectedItem(colours.black,colours.lightGrey):onChange(function()v(n,function(n,e)local n
  1983. local t=e[1]n=e[2]return n:hide()end)local o=t:getItemIndex()if o then
  1984. n[o][2]:show()end
  1985. local n=t:getAll()for e=1,#n do
  1986. t:editItem(e,n[e].text,n[e].bgCol,e==o and colours.white or colours.lightGrey)end
  1987. return true
  1988. end):addItem(string.char(15)):addItem("i"):addItem(string.char(215))local a=e:addFrame():setPosition(2,1):setSize("parent.w","parent.h")local d=r:build_soundtrack_ui(a)n[#n+1]={"music",a}local a=e:addFrame():setPosition(2,1):setScrollable(true):setSize("parent.w","parent.h"):hide()local i=a:addLabel():setText(((((((((((((((((((((((("Space. The final fun tier. (That's a quote from Wall-E.) ".."").."Eventually, all things must go to space. The Brave Toaster, The ").."").."Leprechaun, Air Buddies. Space represents infinite, boundless ").."").."possibilities, but for ComputerCraft, it actually meant more ").."").."limitations. You no longer have interaction with the Minecraft ").."").."world. Custom shells and scripts are gone. The entire game is ").."").."laser-focused on an immersive emulator experience. You won't run ").."").."this thing on a turtle. But the beauty of Planet Garden lies in ").."").."its acceptance of the boundaries it's been given. Instead of ").."").."pretending ComputerCraft is something it's not, it relies on its ").."").."constraints to define an art style that fits on a 51 by 19 ").."").."terminal. The result is a glitchy, low-poly look coloured with ").."").."CC's vanilla palette."):setPosition(2,2)n[#n+1]={"info",a}local e=e:addFrame():setPosition(2,1):setSize("parent.w","parent.h"):hide()e:addButton():setSize("parent.w - 1",1):setPosition(1,2):setText("save")e:addButton():setSize("parent.w - 1",1):setPosition(1,4):setText("load")e:addButton():setSize("parent.w - 1",1):setPosition(1,6):setText("quit"):onClick(function()h.stop()return true
  1989. end)n[#n+1]={"save",e}r.ui_state=c(_,t,n,i,d,o,l)end
  1990. local function g(a,o,r)local n,e=n(B[r])local n=o>=n and o<=e
  1991. local e
  1992. if not n or math.random()<.2 then
  1993. if o>35 then
  1994. e=f("asteroid","barren world","frozen world","gas giant")else
  1995. e=f("asteroid","barren world")end
  1996. else
  1997. e=f("arid","desert","savanna","alpine","arctic","tundra","continental","ocean","tropical")end
  1998. local u,l=z(e)local n=C(l)local c=n.planet_model
  1999. local d=n.atmo
  2000. local i=n.atmo_params
  2001. local n=math.log(1+l.size)*20
  2002. local d=u and s(d,function(t,e)local t
  2003. local o
  2004. o=e[1]t=e[2]return{o,t:toLoD({qualityHalvingDistance=n})}end)or nil
  2005. t(((((((("generated planet "..a).." (")..e)..", ")..string.format("%.1f",o)).." far from a ")..r)..")")return{name=a,params=l,atmo_params=i,model=c:toLoD({qualityHalvingDistance=n}),atmo=d}end
  2006. local function m(e)if e==nil then
  2007. e={"C","V","C","V"," ","GLN"}end
  2008. local d={"a","e","i","o","u"}local a={"ai","au","aw","ay","ea","ee","ei","eu","ew","ey","ie","oi","oo","ou","ow","oy"}local i={"b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w","x","y","z"}local r={"bl","br","ch","ck","cl","cr","dr","fl","fr","gh","gl","gr","ng","ph","pl","pr","qu","sc","sh","sk","sl","sm","sn","sp","st","sw","th","tr","tw","wh","wr"}local o={"nth","sch","scr","shr","spl","spr","squ","str","thr"}local l={"Alpha","Beta","Gamma","Delta","Epsilon","Zeta","Eta","Theta","Iota","Kappa","Lambda","Mu","Nu","Xi","Omicron","Pi","Rho","Sigma","Tau","Upsilon","Phi","Chi","Psi","Omega"}local c={"Major","Minor"}local s={"er","ury","ion","opa","asi","esi","isi","osi","usi","as","es","is","os","us","on","ov","uv","ald","eld","ild","old","uld","alt","elt","ilt","olt","ult","alv","elv","ilv","olv","ulv","agh","egh","igh","ogh","ugh","ayt","eyt","iyt","oyt","uyt","and","end","ind","ond","und"}local f={"@","#","-"}local n=""for e,u in ipairs(e)do
  2009. repeat
  2010. local t=u
  2011. local e=t=="V"if e then
  2012. n=n..d[math.random(0,#d-1)+1]break
  2013. end
  2014. e=e or t=="VD"if e then
  2015. n=n..a[math.random(0,#a-1)+1]break
  2016. end
  2017. e=e or t=="C"if e then
  2018. n=n..i[math.random(0,#i-1)+1]break
  2019. end
  2020. e=e or t=="CD"if e then
  2021. n=n..r[math.random(0,#r-1)+1]break
  2022. end
  2023. e=e or t=="CT"if e then
  2024. n=n..o[math.random(0,#o-1)+1]break
  2025. end
  2026. e=e or t=="GLN"if e then
  2027. n=n..l[math.random(0,#l-1)+1]break
  2028. end
  2029. e=e or t=="MN"if e then
  2030. n=n..c[math.random(0,#c-1)+1]break
  2031. end
  2032. e=e or t=="FA"if e then
  2033. n=n..s[math.random(0,#s-1)+1]break
  2034. end
  2035. e=e or t=="S"if e then
  2036. n=n..f[math.random(0,#f-1)+1]break
  2037. end
  2038. do
  2039. n=n..u
  2040. break
  2041. end
  2042. until true
  2043. end
  2044. return n
  2045. end
  2046. local function d(n)local t={{1000,"M"},{900,"CM"},{500,"D"},{400,"CD"},{100,"C"},{90,"XC"},{50,"L"},{40,"XL"},{10,"X"},{9,"IX"},{5,"V"},{4,"IV"},{1,"I"}}local e=""for o,t in ipairs(t)do
  2047. local o=t[1]local t=t[2]while n>=o do
  2048. n=n-o
  2049. e=e..t
  2050. end
  2051. end
  2052. return e
  2053. end
  2054. local function r()local function e(n,o,t)local e
  2055. if math.random()<n then
  2056. e=o
  2057. else
  2058. e=t
  2059. end
  2060. return e
  2061. end
  2062. local function l(t)local n={}local o=0
  2063. for e=1,#t do
  2064. local e=string.sub(t,e,e)local t=(n[e]or 0)+1
  2065. if({string.find(e,"[aeiou]")})==nil then
  2066. o=math.max(o,t)end
  2067. n[e]=t
  2068. end
  2069. local function e(e)return n[e]or 0
  2070. end
  2071. local function n(e)return({string.find(t,e)})~=nil and 1 or 0
  2072. end
  2073. return-o-e("w")*e("x")-e("x")*e("z")+n("ri")+n("arr")-2*n("^s")end
  2074. local n={}for t=1,5 do
  2075. local e=e(.5,{e(.5,"CD","C"),e(.5,"VD","V"),"C",e(.5,"FA","")},{"CT","V","C",e(.5,"V","VD")})n[#n+1]=string.lower(m(e))end
  2076. table.sort(n,function(e,n)return l(e)>l(n)end)return n[1]end
  2077. local function i()local e=f(n(k(e)))local n,o,t=D(e)local l={type=e,name=r(),rotation_speed=t,model=o:toLoD({qualityHalvingDistance=130,variantCount=6}),radius=n}local t={}for r=1,math.random(0,5)do
  2078. local n=n+6*math.random(0,7)local o=2*math.pi*math.random()local o,a=n*math.sin(o),n*math.cos(o)local l=(l.name.." ")..d(r)t[#t+1]={{o,math.random(-.5,.5),a},g(l,n,e)}end
  2079. return c(x,l,t)end
  2080. local function l()t"generating galaxy"local e={}local o=20
  2081. local l,r=term.getCursorPos()for a=1,o do
  2082. local t=100*math.random(2,10)local n=2*math.pi*math.random()local n,t=t*math.sin(n),t*math.cos(n)e[#e+1]={{n,math.random(-4,4),t},i()}sleep(nil)term.setCursorPos(l,r)term.clearLine()term.write(string.format("generating galaxy %.2f%%",100*a/o))end
  2083. print()t"done"return c(w,e)end
  2084. local function e()local t=u.newFrame()local n={x=0,y=0,z=0,rotX=0,rotY=0,rotZ=0}local e=l()return c(o,"galaxy",-1,{},{},{},t,n,{0,0,0},0,0,{0,0},2,{},{},nil,false,e,0,false)end
  2085. local function r(...)t("starting Planet Garden on",tostring(_HOST),pcall(nil,os.date))local l=h.createFrame():setTheme({FrameBG=colours.black,FrameText=colours.white,ButtonBG=colours.black,ButtonText=colours.white,LabelBG=false,LabelText=colours.white})local e=e()local n
  2086. n=l:addProgram():setSize("parent.w - 1","parent.h"):execute(function()return F(e)end):onDone(function()t"program is done, stopping"h.stop()end):onError(function(n,e)error(e)end):onResize(function()local o,n=n:getSize()t((("resized game window to "..tostring(o)).." by ")..tostring(n))e.frame:setSize(1,1,o,n)return true
  2087. end)e:load_music()p(l,e)n:setFocus(true)os.queueEvent("begin")t"starting basalt loop"h.autoUpdate()end
  2088. local n,e=pcall(r,...)if not n then
  2089. t("game crashed with "..tostring(e))print(e)read()end
  2090. return S
  2091. end,["nbs"]=function(...)local r={}local function i()os.queueEvent("yield")os.pullEvent("yield")end
  2092. local function o(e)return e.read()+e.read()*256
  2093. end
  2094. _G.readShort=o
  2095. local function l(e)return e.read()+e.read()*256+e.read()*65536+e.read()*16777216
  2096. end
  2097. local function t(t)local e,n=""local o=l(t)for o=1,o do
  2098. n=t.read()if not n then
  2099. break
  2100. end
  2101. e=e..string.char(n)end
  2102. return e
  2103. end
  2104. local function n(n,t)local e=""for t=0,t-1 do
  2105. e=e..string.char(bit32.band(bit32.rshift(n,t*8),255))end
  2106. return e
  2107. end
  2108. local function e(t,e)t.write(n(e,2))end
  2109. local function a(e,t)e.write(n(t,4))end
  2110. local function e(n,e)a(n,#e)n.write(e)end
  2111. local function s(n)local e={}e.lenght=o(n)if e.lenght>0 then
  2112. e.nbs_version=0
  2113. e.height=o(n)e.name=t(n)if e.name==""then
  2114. e.name="Untitled"end
  2115. e.author=t(n)if e.author==""then
  2116. e.author="Unknown"end
  2117. e.original_author=t(n)if e.original_author==""then
  2118. e.original_author="Unknown"end
  2119. e.description=t(n)e.tempo=o(n)/100
  2120. e.autosave=n.read()e.autosave_duration=n.read()e.time_signature=n.read()e.minutes_spent=l(n)e.left_clicks=l(n)e.right_clicks=l(n)e.blocks_added=l(n)e.blocks_removed=l(n)e.filename=t(n)else
  2121. e.nbs_version=n.read()e.vanilla_instruments=n.read()e.lenght=o(n)e.height=o(n)e.name=t(n)if e.name==""then
  2122. e.name="Untitled"end
  2123. e.author=t(n)if e.author==""then
  2124. e.author="Unknown"end
  2125. e.original_author=t(n)if e.original_author==""then
  2126. e.original_author="Unknown"end
  2127. e.description=t(n)e.tempo=o(n)/100
  2128. e.autosave=n.read()e.autosave_duration=n.read()e.time_signature=n.read()e.minutes_spent=l(n)e.left_clicks=l(n)e.right_clicks=l(n)e.blocks_added=l(n)e.blocks_removed=l(n)e.filename=t(n)e.looping=n.read()e.max_looping=n.read()e.loop_start=o(n)end
  2129. return e
  2130. end
  2131. local function d(n,e)local n=o(n)for n=1,n-1 do
  2132. e[#e+1]={}end
  2133. return n>0
  2134. end
  2135. local function c(e)local l={}local a=0
  2136. local r=o(e)while r>0 do
  2137. a=a+r
  2138. local t=e.read()+1
  2139. if t>16 then
  2140. return nil,"(v5) Can't convert custom instruments"end
  2141. local n=e.read()-33
  2142. local i=e.read()local i=e.read()local i=o(e)if n<0 or n>24 then
  2143. return nil,"(v5) Notes must be in Minecraft's 2 octaves ("..n..")"end
  2144. if not l[t]then
  2145. l[t]={}end
  2146. l[t][a]=n
  2147. r=o(e)end
  2148. return l
  2149. end
  2150. function r.saveSong(t,n)local e=fs.open(n,"w")if e then
  2151. e.write(textutils.serialize(t))e.close()return true
  2152. end
  2153. return false,"Error opening file "..n
  2154. end
  2155. function r.saveSongNBS(e,e)end
  2156. function r.load(r,l)local e=fs.open(r,"rb")if e then
  2157. if l then
  2158. print"Reading header..."end
  2159. local n={}local o=s(e)n.header=o
  2160. n.name=o.name
  2161. n.author=o.author
  2162. n.original_author=o.original_author
  2163. n.lenght=o.lenght/o.tempo
  2164. n.delay=1/o.tempo
  2165. if l then
  2166. print"Reading ticks..."end
  2167. if o.nbs_version==0 then
  2168. while d(e,n)do
  2169. local t,o=c(e,n)if t then
  2170. table.insert(n,t)else
  2171. e.close()return nil,o
  2172. end
  2173. i()end
  2174. pcall(function()local l={}for o=1,o.height do
  2175. table.insert(l,{name=t(e),volume=e.read()+0})end
  2176. n.layers=l
  2177. local o={}for l=1,e.read()+0 do
  2178. o[#o+1]={name=t(e),file=t(e),pitch=e.read()+0,key=(e.read()+0)~=0}end
  2179. n.instruments=o
  2180. end)else
  2181. while d(e,n)do
  2182. local t,o=c(e,n)if t then
  2183. table.insert(n,t)else
  2184. e.close()return nil,o
  2185. end
  2186. i()end
  2187. pcall(function()local l={}for o=1,o.height do
  2188. table.insert(l,{name=t(e),lock=e.read(),volume=e.read(),pan=e.read()})end
  2189. n.layers=l
  2190. local o={}for l=1,e.read()+0 do
  2191. o[#o+1]={name=t(e),file=t(e),pitch=e.read()+0,key=(e.read()+0)~=0}end
  2192. n.instruments=o
  2193. end)end
  2194. e.close()return n
  2195. end
  2196. return nil,"Error opening file "..r
  2197. end
  2198. return r
  2199. end,["kernel"]=function(...)local a={}local u,s,h=string.byte,bit32.band,bit32.arshift
  2200. local e=10
  2201. local i=2^e
  2202. local o=2^(e-1)local d=2^(e-8+1)local function f()local n,r,l=0,0,false
  2203. return function(t)local e=t and 127 or-128
  2204. local o=(r*(e-n)+o)/i
  2205. local o=n+(o-o%1)if o==n and o~=e then
  2206. o=o+(t and 1 or-1)end
  2207. local a=t==l and i-1 or 0
  2208. local e=r
  2209. if e~=a then e=e+(t==l and 1 or-1)end
  2210. if e<d then e=d end
  2211. n,r,l=o,e,t
  2212. return n
  2213. end
  2214. end
  2215. local function c()local r=f()local e=0
  2216. local i,d=0,false
  2217. return function(n)local a,o={},0
  2218. for t=1,#n do
  2219. local l=u(n,t)for n=1,8 do
  2220. local t=s(l,1)~=0
  2221. local n=r(t)local r=n
  2222. if t~=d then
  2223. local e=(n+i+1)/2
  2224. r=e-e%1
  2225. end
  2226. i,d=n,t
  2227. local n=((r-e)*140+128)/256
  2228. e=e+(n-n%1)o=o+1
  2229. a[o]=e
  2230. l=h(l,1)end
  2231. end
  2232. return a
  2233. end
  2234. end
  2235. function a.play_dfpwm(e,n)local o=c()local l=string.sub
  2236. for t=1,#n,16*1024 do
  2237. local n=l(n,t,t+16*1024-1)local n=o(n)while not e.playAudio(n)do
  2238. local n=coroutine.yield()if n=="music:stop"then
  2239. e.stop()return
  2240. end
  2241. end
  2242. end
  2243. end
  2244. return a
  2245. end,["basalt.basalt"]=function(...)local r={}local t=true local o=a
  2246. local l=function(e)for t,n in pairs(r)do
  2247. if(type(n)=="table")then for t,n in pairs(n)do if(t==e)then
  2248. return n()end end else if(t==e)then return n()end end end return o(e)end
  2249. local n=function(e)if(e~=nil)then return r[e]end return r end
  2250. r["module"]=function(...)return
  2251. function(e)local e,n=pcall(l,e)return e and n or nil end end
  2252. r["loadObjects"]=function(...)local e={}if(t)then
  2253. for n,t in pairs(n("objects"))do e[n]=t()end return e end local t=table.pack(...)local n=fs.getDir(t[2]or"Basalt")if(n==nil)then
  2254. error("Unable to find directory "..t[2].." please report this bug to our discord.")end for t,n in
  2255. pairs(fs.list(fs.combine(n,"objects")))do
  2256. if(n~="example.lua")then local n=n:gsub(".lua","")e[n]=l(n)end end return e end
  2257. r["main"]=function(...)local z=l("basaltEvent")()local F=l("Frame")local h=l("theme")local e=l("utils")local D=l("basaltLogs")local A=e.uuid
  2258. local x=e.createText local H=e.tableCount local y=300 local m=50 local o=term.current()local P="1.6.5"local w=fs.getDir(table.pack(...)[2]or"")local p,s,d,i,f,t={},{},{},{},{},{}local n,l,a,c local e={}if
  2259. not term.isColor or not term.isColor()then
  2260. error('Basalt requires an advanced (golden) computer to run.',0)end local u={}for n,e in
  2261. pairs(colors)do if(type(e)=="number")then
  2262. u[n]={o.getPaletteColor(e)}end end
  2263. local function b()c=false o.clear()o.setCursorPos(1,1)for n,e in pairs(colors)do if(type(e)=="number")then
  2264. o.setPaletteColor(e,colors.packRGB(table.unpack(u[n])))end end end
  2265. local function u(n)o.clear()o.setBackgroundColor(colors.black)o.setTextColor(colors.red)local t,l=o.getSize()if(e.logging)then D(n,"Error")end local n=x("Basalt error: "..n,t)local e=1 for t,n in pairs(n)do
  2266. o.setCursorPos(1,e)o.write(n)e=e+1 end o.setCursorPos(1,e+1)c=false end
  2267. local function k(e)assert(e~="function","Schedule needs a function in order to work!")return function(...)local e=coroutine.create(e)local o,n=coroutine.resume(e,...)if(o)then table.insert(t,{e,n})else u(n)end end end local T=function(n,e)f[n]=e end
  2268. local C=function(e)return f[e]end local E=function(e)h=e end
  2269. local v=function(e)return h[e]end
  2270. local M={getDynamicValueEventSetting=function()return e.dynamicValueEvents end,getMainFrame=function()return n end,setVariable=T,getVariable=C,getTheme=v,setMainFrame=function(e)n=e end,getActiveFrame=function()return l end,setActiveFrame=function(e)l=e end,getFocusedObject=function()return a end,setFocusedObject=function(e)a=e end,getMonitorFrame=function(e)return
  2271. d[e]or i[e][1]end,setMonitorFrame=function(t,e,o)if(n==e)then
  2272. n=nil end
  2273. if(o)then i[t]={e,sides}else d[t]=e end if(e==nil)then i[t]=nil end end,getBaseTerm=function()return
  2274. o end,schedule=k,stop=b,newFrame=F,getDirectory=function()return w end}local function h(n,...)if(#t>0)then local o={}for e=1,#t do
  2275. if(t[e]~=nil)then
  2276. if(coroutine.status(t[e][1])=="suspended")then
  2277. if(t[e][2]~=nil)then
  2278. if(t[e][2]==n)then
  2279. local o,n=coroutine.resume(t[e][1],n,...)t[e][2]=n if not(o)then u(n)end end else local o,n=coroutine.resume(t[e][1],n,...)t[e][2]=n if not(o)then u(n)end end else table.insert(o,e)end end end
  2280. for e=1,#o do table.remove(t,o[e]-(e-1))end end end
  2281. local function a()if(c==false)then return end if(n~=nil)then n:draw()n:updateTerm()end
  2282. for n,e in pairs(d)do e:draw()e:updateTerm()end
  2283. for n,e in pairs(i)do e[1]:draw()e[1]:updateTerm()end end local _,f,t=nil,nil,nil local g=nil
  2284. local function j(l,o,e,n)_,f,t=o,e,n if(g==nil)then
  2285. g=os.startTimer(y/1000)end end
  2286. local function I()g=nil n:hoverHandler(f,t,_)l=n end local S,B,t=nil,nil,nil local f=nil local function _()f=nil n:dragHandler(S,B,t)l=n end local function V(l,o,e,n)S,B,t=o,e,n
  2287. if(m<50)then _()else if(f==nil)then f=os.startTimer(m/1000)end end end
  2288. local function S(t,...)local o={...}if(z:sendEvent("basaltEventCycle",t,...)==false)then return end if(t=="terminate")then e.stop()end
  2289. if(n~=nil)then
  2290. local e={mouse_click=n.mouseHandler,mouse_up=n.mouseUpHandler,mouse_scroll=n.scrollHandler,mouse_drag=V,mouse_move=j}local e=e[t]if(e~=nil)then e(n,...)h(t,...)a()return end end
  2291. if(t=="monitor_touch")then if(d[o[1]]~=nil)then
  2292. d[o[1]]:mouseHandler(1,o[2],o[3],true)l=d[o[1]]end
  2293. if(H(i)>0)then for n,e in pairs(i)do
  2294. e[1]:mouseHandler(1,o[2],o[3],true,o[1])end end h(t,...)a()return end
  2295. if(l~=nil)then
  2296. local e={char=l.charHandler,key=l.keyHandler,key_up=l.keyUpHandler}local e=e[t]if(e~=nil)then if(t=="key")then p[o[1]]=true elseif(t=="key_up")then
  2297. p[o[1]]=false end e(l,...)h(t,...)a()return end end
  2298. if(t=="timer")and(o[1]==g)then I()elseif(t=="timer")and(o[1]==f)then _()else
  2299. for n,e in pairs(s)do e:eventHandler(t,...)end end h(t,...)a()end
  2300. e={logging=false,dynamicValueEvents=false,setTheme=E,getTheme=v,drawFrames=a,getVersion=function()return P end,setVariable=T,getVariable=C,setBaseTerm=function(e)o=e end,log=function(...)D(...)end,setMouseMoveThrottle=function(e)if(_HOST:find("CraftOS%-PC"))then if(config.get("mouse_move_throttle")~=10)then
  2301. config.set("mouse_move_throttle",10)end
  2302. if(e<100)then y=100 else y=e end return true end return false end,setMouseDragThrottle=function(e)if(e<=0)then m=0 else f=nil m=e end end,autoUpdate=function(e)c=e if(e==nil)then c=true end local function e()a()while c do
  2303. S(os.pullEventRaw())end end
  2304. local e,n=xpcall(e,debug.traceback)if not(e)then u(n)return end end,update=function(e,...)if(e~=nil)then local e,n=xpcall(S,debug.traceback,e,...)if not(e)then
  2305. u(n)return end end end,stop=b,stopUpdate=b,isKeyDown=function(e)if(p[e]==nil)then return false end return p[e]end,getFrame=function(n)for t,e in
  2306. pairs(s)do if(e.name==n)then return e end end end,getActiveFrame=function()return
  2307. l end,setActiveFrame=function(e)if(e:getType()=="Frame")then l=e return true end return false end,onEvent=function(...)for n,e in
  2308. pairs(table.pack(...))do if(type(e)=="function")then
  2309. z:registerEvent("basaltEventCycle",e)end end end,schedule=k,createFrame=function(e)e=e or A()for t,n in pairs(s)do if(n.name==e)then return nil end end local e=F(e,nil,nil,M)e:init()table.insert(s,e)if(n==nil)and(e:getName()~="basaltDebuggingFrame")then e:show()end return e end,removeFrame=function(e)s[e]=nil end,setProjectDir=function(e)w=e end,debug=function(...)local t={...}if(n==nil)then print(...)return end
  2310. if(n.name~="basaltDebuggingFrame")then if(n~=e.debugFrame)then
  2311. e.debugLabel:setParent(n)end end local n=""for o,e in pairs(t)do n=n..tostring(e)..(#t~=o and", "or"")end e.debugLabel:setText("[Debug] "..n)for t,n in
  2312. pairs(x(n,e.debugList:getWidth()))do e.debugList:addItem(n)end if(e.debugList:getItemCount()>50)then
  2313. e.debugList:removeItem(1)end
  2314. e.debugList:setValue(e.debugList:getItem(e.debugList:getItemCount()))if(e.debugList.getItemCount()>e.debugList:getHeight())then
  2315. e.debugList:setOffset(e.debugList:getItemCount()-e.debugList:getHeight())end
  2316. e.debugLabel:show()end}e.debugFrame=e.createFrame("basaltDebuggingFrame"):showBar():setBackground(colors.lightGray):setBar("Debug",colors.black,colors.gray)e.debugFrame:addButton("back"):setAnchor("topRight"):setSize(1,1):setText("\22"):onClick(function()if(e.oldFrame~=nil)then e.oldFrame:show()end end):setBackground(colors.red):show()e.debugList=e.debugFrame:addList("debugList"):setSize("parent.w - 2","parent.h - 3"):setPosition(2,3):setScrollable(true):show()e.debugLabel=e.debugFrame:addLabel("debugLabel"):onClick(function()e.oldFrame=n e.debugFrame:show()end):setBackground(colors.black):setForeground(colors.white):setAnchor("bottomLeft"):ignoreOffset():setZIndex(20):show()return e end
  2317. r["theme"]=function(...)return{BasaltBG=colors.lightGray,BasaltText=colors.black,FrameBG=colors.gray,FrameText=colors.black,ButtonBG=colors.gray,ButtonText=colors.black,CheckboxBG=colors.gray,CheckboxText=colors.black,InputBG=colors.gray,InputText=colors.black,TextfieldBG=colors.gray,TextfieldText=colors.black,ListBG=colors.gray,ListText=colors.black,MenubarBG=colors.gray,MenubarText=colors.black,DropdownBG=colors.gray,DropdownText=colors.black,RadioBG=colors.gray,RadioText=colors.black,SelectionBG=colors.black,SelectionText=colors.lightGray,GraphicBG=colors.black,ImageBG=colors.black,PaneBG=colors.black,ProgramBG=colors.black,ProgressbarBG=colors.gray,ProgressbarText=colors.black,ProgressbarActiveBG=colors.black,ScrollbarBG=colors.lightGray,ScrollbarText=colors.gray,ScrollbarSymbolColor=colors.black,SliderBG=false,SliderText=colors.gray,SliderSymbolColor=colors.black,SwitchBG=colors.lightGray,SwitchText=colors.gray,SwitchBGSymbol=colors.black,SwitchInactive=colors.red,SwitchActive=colors.green,LabelBG=false,LabelText=colors.black,GraphBG=colors.gray,GraphText=colors.black}end
  2318. r["Frame"]=function(...)local e=l("module")local a=l("Object")local Q=l("loadObjects")local A=l("basaltDraw")local C=l("utils")local J=e("layout")local fe=e("basaltMon")local R=C.uuid local g=C.rpairs local o=C.getValueFromXML local b=C.tableCount
  2319. local c,ue,e=string.sub,math.min,math.max
  2320. return
  2321. function(n,D,t,l)local r=a(n)local ce="Frame"local d={}local m={}local _={}local n={}local a={}local i={}local O={}local u={}local k=0 local t=t or term.current()local f=""local p=false
  2322. local x=false local w=false local N=0 local q=0 local W=false local z=0 local j=false local se=false local F=""local E=false
  2323. local P=false local i local s local S=true local I=true local Y=false local y={}local B={}r:setZIndex(10)local i=A(t)local L=false local U=1 local Z=1 local H=colors.white local T,h=0,0 local X={}local function v(n,e)if(e~=nil)then e:setValuesByXMLData(n)end end
  2324. local function G(e,n,t)if(e~=nil)then if(e.properties~=nil)then e={e}end for o,e in pairs(e)do local n=n(t,e["@id"]or R())table.insert(X,n)v(e,n)end end end
  2325. local function v(e)if(type(e)~="string")then e=e.name end for t,n in pairs(d)do
  2326. for t,n in
  2327. pairs(n)do if(n:getName()==e)then return n end end end end
  2328. local function ae(n)local e=v(n)if(e~=nil)then return e end
  2329. for t,e in pairs(d)do
  2330. for t,e in pairs(e)do if(e:getType()=="Frame")then local e=e:getDeepObject(n)if(e~=nil)then return e end end end end end
  2331. local function V(n)local e=n:getZIndex()if(v(n.name)~=nil)then return nil end
  2332. if(d[e]==nil)then
  2333. for n=1,#m+1 do if(m[n]~=nil)then if(e==m[n])then break end if(e>m[n])then table.insert(m,n,e)break end else
  2334. table.insert(m,e)end end if(#m<=0)then table.insert(m,e)end d[e]={}end n.parent=_ if(n.init~=nil)then n:init()end
  2335. table.insert(d[e],n)return n end
  2336. local function M(e,a)for t,o in pairs(n)do
  2337. for l,o in pairs(o)do
  2338. for r,o in pairs(o)do
  2339. if(o==a)then
  2340. table.remove(n[t][l],r)if(e.parent~=nil)then if(b(n[t])<=0)then
  2341. e.parent:removeEvent(t,e)end end end end end end end
  2342. local function ie(o,n)for l,e in pairs(d)do
  2343. for t,e in pairs(e)do
  2344. if(type(n)=="string")then
  2345. if(e:getName()==n)then
  2346. table.remove(d[l],t)M(_,e)o:updateDraw()return true end else if(e==n)then table.remove(d[l],t)M(_,e)o:updateDraw()return true end end end end return false end local function K(o,e,t)for n,e in pairs(n[e])do for n,e in pairs(e)do
  2347. if(e:getName()==t)then return e end end end end
  2348. local function te(l,e,o)local t=o:getZIndex()if(n[e]==nil)then n[e]={}end if(a[e]==nil)then
  2349. a[e]={}end
  2350. if(K(l,e,o.name)~=nil)then return nil end
  2351. if(l.parent~=nil)then l.parent:addEvent(e,l)end y[e]=true
  2352. if(n[e][t]==nil)then
  2353. for n=1,#a[e]+1 do
  2354. if(a[e][n]~=nil)then if(t==a[e][n])then break end if(t>a[e][n])then
  2355. table.insert(a[e],n,t)break end else
  2356. table.insert(a[e],t)end end
  2357. if(#a[e]<=0)then table.insert(a[e],t)end n[e][t]={}end table.insert(n[e][t],o)return o end
  2358. local function ee(t,e,r)if(n[e]~=nil)then
  2359. for o,l in pairs(n[e])do
  2360. for l,a in pairs(l)do
  2361. if(a==r)then
  2362. table.remove(n[e][o],l)if(#n[e][o]<=0)then n[e][o]=nil
  2363. if(t.parent~=nil)then if(b(n[e])<=0)then y[e]=false
  2364. t.parent:removeEvent(e,t)end end end return
  2365. true end end end end return false end local b=math
  2366. local function ne(e)local n,t=pcall(load("return "..e,"",nil,{math=b}))if not(n)then
  2367. error(e.." is not a valid dynamic code")end return t end
  2368. local function oe(e,t,n)for o,e in pairs(u)do
  2369. if(e[2]==n)and(e[4]==t)then return e end end k=k+1
  2370. u[k]={0,n,{},t,k}return u[k]end
  2371. local function le(o,t)local e={}local n={}for n in t:gmatch("%a+%.x")do local n=n:gsub("%.x","")if(n~="self")and(n~="parent")then table.insert(e,n)end end
  2372. for n in
  2373. t:gmatch("%w+%.y")do local n=n:gsub("%.y","")if(n~="self")and(n~="parent")then
  2374. table.insert(e,n)end end for n in t:gmatch("%a+%.w")do local n=n:gsub("%.w","")if(n~="self")and(n~="parent")then table.insert(e,n)end end
  2375. for n in
  2376. t:gmatch("%a+%.h")do local n=n:gsub("%.h","")if(n~="self")and(n~="parent")then
  2377. table.insert(e,n)end end
  2378. for t,e in pairs(e)do n[e]=v(e)if(n[e]==nil)then
  2379. error("Dynamic Values - unable to find object "..e)end end n["self"]=o n["parent"]=o:getParent()return n end
  2380. local function re(n,t)local e=n for n in n:gmatch("%w+%.x")do
  2381. e=e:gsub(n,t[n:gsub("%.x","")]:getX())end for n in n:gmatch("%w+%.y")do
  2382. e=e:gsub(n,t[n:gsub("%.y","")]:getY())end for n in n:gmatch("%w+%.w")do
  2383. e=e:gsub(n,t[n:gsub("%.w","")]:getWidth())end for n in n:gmatch("%w+%.h")do
  2384. e=e:gsub(n,t[n:gsub("%.h","")]:getHeight())end return e end
  2385. local function de(t)if(#u>0)then
  2386. for e=1,k do
  2387. if(u[e]~=nil)then local n if(#u[e][3]<=0)then
  2388. u[e][3]=le(u[e][4],u[e][2])end
  2389. n=re(u[e][2],u[e][3])u[e][1]=ne(n)if(u[e][4]:getType()=="Frame")then
  2390. u[e][4]:recalculateDynamicValues()end end end
  2391. for n,e in pairs(m)do
  2392. if(d[e]~=nil)then
  2393. for n,e in pairs(d[e])do
  2394. if(l.getDynamicValueEventSetting())then if(e.eventHandler~=nil)then
  2395. e:eventHandler("basalt_dynamicvalue",t)end end if(e.customEventHandler~=nil)then
  2396. e:customEventHandler("basalt_resize",t)end end end end end end local function ne(e)return u[e][1]end
  2397. local function u(o)local t=0
  2398. for l,n in pairs(d)do
  2399. for l,n in pairs(n)do
  2400. if(n.getHeight~=nil)and(n.getY~=nil)then
  2401. if(n:getType()=="Dropdown")then local l,r=n:getHeight(),n:getY()local a,n=n:getDropdownSize()l=l+n-1
  2402. if(l+r-o:getHeight()>=t)then t=e(l+r-o:getHeight(),0)end else local n,l=n:getHeight(),n:getY()if(n+l-o:getHeight()>=t)then
  2403. t=e(n+l-o:getHeight(),0)end end end end end return t end
  2404. local function le(o)local t=0
  2405. for l,n in pairs(d)do
  2406. for l,n in pairs(n)do
  2407. if(n.getWidth~=nil)and(n.getX~=nil)then local l,n=n:getWidth(),n:getX()if(l+n-o:getWidth()>=t)then
  2408. t=e(l+n-o:getWidth(),0)end end end end return t end local function k(e)if(I)then z=u(e)end end
  2409. _={barActive=false,barBackground=colors.gray,barTextcolor=colors.black,barText="New Frame",barTextAlign="left",addEvent=te,removeEvent=ee,removeEvents=M,getEvent=K,newDynamicValue=oe,recalculateDynamicValues=de,getDynamicValue=ne,getType=function(e)return
  2410. ce end,setZIndex=function(e,n)r.setZIndex(e,n)for n,t in pairs(y)do if(t)then
  2411. e.parent:addEvent(n,e)end end return e end,setFocusedObject=function(n,e)if(s~=e)then if(s~=nil)then
  2412. if(v(s)~=nil)then s:loseFocusHandler()end end if(e~=nil)then if(v(e)~=nil)then
  2413. e:getFocusHandler()end end s=e end return n end,getVariable=function(n,e)return
  2414. l.getVariable(e)end,setSize=function(e,o,n,l)r.setSize(e,o,n,l)if(e.parent==nil)then i=A(t)end
  2415. for t,n in pairs(m)do if(d[n]~=nil)then
  2416. for t,n in
  2417. pairs(d[n])do if(n.customEventHandler~=nil)then
  2418. n:customEventHandler("basalt_resize",e)end end end end e:recalculateDynamicValues()S=false return e end,setTheme=function(n,e,t)if(type(e)=="table")then O=e elseif(type(e)=="string")then O[e]=t end n:updateDraw()return n end,getTheme=function(n,e)return
  2419. O[e]or(n.parent~=nil and n.parent:getTheme(e)or
  2420. l.getTheme(e))end,getThemeColor=function(n,e)return
  2421. e~=nil and B[e]or B end,setThemeColor=function(o,e,...)if(o.parent==nil)then
  2422. if(o==l.getActiveFrame())then
  2423. if(type(e)=="string")then B[e]=...t.setPaletteColor(type(e)=="number"and e or colors[e],...)elseif(type(e)=="table")then
  2424. for e,n in pairs(e)do B[e]=n
  2425. if(type(n)=="number")then
  2426. t.setPaletteColor(type(e)=="number"and e or colors[e],n)else local o,l,n=table.unpack(n)t.setPaletteColor(type(e)=="number"and e or colors[e],o,l,n)end end end end end return o end,setPosition=function(e,o,t,n)r.setPosition(e,o,t,n)e:recalculateDynamicValues()return e end,getBasaltInstance=function(e)return
  2427. l end,setOffset=function(t,e,n)T=e~=nil and
  2428. b.floor(e<0 and b.abs(e)or-e)or T
  2429. h=n~=nil and
  2430. b.floor(n<0 and b.abs(n)or-n)or h t:updateDraw()return t end,getOffsetInternal=function(e)return
  2431. T,h end,getOffset=function(e)return T<0 and b.abs(T)or-T,h<0 and
  2432. b.abs(h)or-h end,removeFocusedObject=function(e)if(s~=nil)then
  2433. if(v(s)~=nil)then s:loseFocusHandler()end end s=nil return e end,getFocusedObject=function(e)return
  2434. s end,setCursor=function(e,l,o,n,r)if(e.parent~=nil)then
  2435. local a,t=e:getAnchorPosition()e.parent:setCursor(l or false,(o or 0)+a-1,(n or 0)+t-1,r or H)else
  2436. local a,e=e:getAbsolutePosition(e:getAnchorPosition(e:getX(),e:getY(),true))L=l or false if(o~=nil)then U=a+o-1 end if(n~=nil)then Z=e+n-1 end H=r or H if(L)then
  2437. t.setTextColor(H)t.setCursorPos(U,Z)t.setCursorBlink(L)else
  2438. t.setCursorBlink(false)end end return e end,setMovable=function(e,n)if(e.parent~=nil)then E=n or not E
  2439. e.parent:addEvent("mouse_click",e)y["mouse_click"]=true
  2440. e.parent:addEvent("mouse_up",e)y["mouse_up"]=true
  2441. e.parent:addEvent("mouse_drag",e)y["mouse_drag"]=true end return e end,setScrollable=function(e,n)W=(n or n==nil)and true or false
  2442. if(e.parent~=nil)then e.parent:addEvent("mouse_scroll",e)end y["mouse_scroll"]=true return e end,setScrollAmount=function(n,e)z=e or z I=false return n end,getScrollAmount=function(e)return I and k(e)or
  2443. z end,getCalculatedVerticalScroll=u,getCalculatedHorizontalScroll=le,show=function(e)r.show(e)if(e.parent==nil)then l.setActiveFrame(e)for n,e in pairs(colors)do if(type(e)=="number")then
  2444. t.setPaletteColor(e,colors.packRGB(term.nativePaletteColor((e))))end end
  2445. for e,n in pairs(B)do
  2446. if(type(n)=="number")then
  2447. t.setPaletteColor(type(e)=="number"and e or colors[e],n)else local o,n,l=table.unpack(n)t.setPaletteColor(type(e)=="number"and e or colors[e],o,n,l)end end
  2448. if(p)and not(x)then l.setMonitorFrame(f,e)elseif(x)then
  2449. l.setMonitorFrame(e:getName(),e,f)else l.setMainFrame(e)end end return e end,hide=function(e)r.hide(e)if(e.parent==nil)then if(activeFrame==e)then activeFrame=nil end
  2450. if(p)and
  2451. not(x)then if(l.getMonitorFrame(f)==e)then
  2452. l.setActiveFrame(nil)end elseif(x)then
  2453. if(l.getMonitorFrame(e:getName())==e)then l.setActiveFrame(nil)end else
  2454. if(l.getMainFrame()==e)then l.setMainFrame(nil)end end end return e end,addLayout=function(n,e)if(e~=nil)then
  2455. if(fs.exists(e))then local e=fs.open(e,"r")local t=J:ParseXmlText(e.readAll())e.close()X={}n:setValuesByXMLData(t)end end return n end,getLastLayout=function(e)return
  2456. X end,addLayoutFromString=function(n,e)if(e~=nil)then local e=J:ParseXmlText(e)n:setValuesByXMLData(e)end return n end,setValuesByXMLData=function(n,e)r.setValuesByXMLData(n,e)if(o("movable",e)~=nil)then if(o("movable",e))then
  2457. n:setMovable(true)end end if(o("scrollable",e)~=nil)then
  2458. if(o("scrollable",e))then n:setScrollable(true)end end if(o("monitor",e)~=nil)then
  2459. n:setMonitor(o("monitor",e)):show()end if(o("mirror",e)~=nil)then
  2460. n:setMirror(o("mirror",e))end
  2461. if(o("bar",e)~=nil)then if(o("bar",e))then
  2462. n:showBar(true)else n:showBar(false)end end
  2463. if(o("barText",e)~=nil)then n.barText=o("barText",e)end if(o("barBG",e)~=nil)then
  2464. n.barBackground=colors[o("barBG",e)]end if(o("barFG",e)~=nil)then
  2465. n.barTextcolor=colors[o("barFG",e)]end if(o("barAlign",e)~=nil)then
  2466. n.barTextAlign=o("barAlign",e)end if(o("layout",e)~=nil)then
  2467. n:addLayout(o("layout",e))end if(o("xOffset",e)~=nil)then
  2468. n:setOffset(o("xOffset",e),h)end if(o("yOffset",e)~=nil)then
  2469. n:setOffset(h,o("yOffset",e))end if(o("scrollAmount",e)~=nil)then
  2470. n:setScrollAmount(o("scrollAmount",e))end local t=e:children()for t,e in
  2471. pairs(t)do if(e.___name~="animation")then
  2472. local t=e.___name:gsub("^%l",string.upper)if(Q[t]~=nil)then G(e,n["add"..t],n)end end end G(e["frame"],n.addFrame,n)G(e["animation"],n.addAnimation,n)return n end,showBar=function(e,n)e.barActive=n or not e.barActive e:updateDraw()return e end,setBar=function(e,n,o,t)e.barText=n or""e.barBackground=o or e.barBackground
  2473. e.barTextcolor=t or e.barTextcolor e:updateDraw()return e end,setBarTextAlign=function(e,n)e.barTextAlign=n or"left"e:updateDraw()return e end,setMirror=function(e,n)if(e.parent~=nil)then
  2474. error"Frame has to be a base frame in order to attach a mirror."end F=n if(mirror~=nil)then
  2475. i.setMirror(mirror)end j=true return e end,removeMirror=function(e)mirror=nil j=false i.setMirror(nil)return e end,setMonitorScale=function(e,n)if(p)then t.setTextScale(n)end return e end,setMonitor=function(e,n,o)if(n~=nil)and(n~=false)then
  2476. if(type(n)=="string")then
  2477. if(peripheral.getType(n)=="monitor")then t=peripheral.wrap(n)w=true end
  2478. if(e.parent~=nil)then e.parent:removeObject(e)end p=true l.setMonitorFrame(n,e)elseif(type(n)=="table")then
  2479. t=fe(n)w=true p=true x=true
  2480. l.setMonitorFrame(e:getName(),e,true)end else t=parentTerminal p=false x=false
  2481. if(type(f)=="string")then
  2482. if(l.getMonitorFrame(f)==e)then l.setMonitorFrame(f,nil)end else
  2483. if(l.getMonitorFrame(e:getName())==e)then l.setMonitorFrame(e:getName(),nil)end end end if(o~=nil)then t.setTextScale(o)end i=A(t)e:setSize(t.getSize())S=true f=n or nil e:updateDraw()return e end,loseFocusHandler=function(e)r.loseFocusHandler(e)if(s~=nil)then s:loseFocusHandler()s=nil end end,getFocusHandler=function(e)r.getFocusHandler(e)if(e.parent~=nil)then
  2484. if(E)then e.parent:removeEvents(e)e.parent:removeObject(e)e.parent:addObject(e)for t,n in pairs(y)do if(n)then
  2485. e.parent:addEvent(t,e)end end
  2486. e:updateDraw()end end if(s~=nil)then s:getFocusHandler()end end,eventHandler=function(e,o,...)r.eventHandler(e,o,...)if(n["other_event"]~=nil)then
  2487. for t,e in ipairs(a["other_event"])do if(n["other_event"][e]~=nil)then
  2488. for n,e in g(n["other_event"][e])do if(e.eventHandler~=nil)then e:eventHandler(o,...)end end end end end
  2489. if(S)and not(p)then if(e.parent==nil)then
  2490. if(o=="term_resize")then
  2491. e:sendEvent("basalt_resize",e,o,...)e:setSize(t.getSize())S=true end end end
  2492. if(p)then
  2493. if(S)then
  2494. if(o=="monitor_resize")then
  2495. if(type(f)=="string")then
  2496. e:setSize(t.getSize())elseif(type(f)=="table")then
  2497. for o,n in pairs(f)do for o,n in pairs(n)do if(p1==n)then
  2498. e:setSize(t.getSize())end end end end S=true e:updateDraw()end end
  2499. if(o=="peripheral")and(p1==f)then if(peripheral.getType(f)=="monitor")then w=true t=peripheral.wrap(f)i=A(t)e:updateDraw()end end
  2500. if(o=="peripheral_detach")and(p1==f)then w=false end end
  2501. if(j)then if(peripheral.getType(F)=="monitor")then se=true
  2502. i.setMirror(peripheral.wrap(F))end if(o=="peripheral_detach")and(p1==F)then w=false end
  2503. if(o=="monitor_touch")and(F==p1)then e:mouseHandler(1,p2,p3,true)end end end,mouseHandler=function(o,i,e,l,c,d)if(x)then if(t.calculateClick~=nil)then
  2504. e,l=t.calculateClick(d,e,l)end end
  2505. if(r.mouseHandler(o,i,e,l))then
  2506. if(n["mouse_click"]~=nil)then
  2507. o:setCursor(false)for o,t in ipairs(a["mouse_click"])do
  2508. if(n["mouse_click"][t]~=nil)then for t,n in g(n["mouse_click"][t])do
  2509. if(n.mouseHandler~=nil)then if(n:mouseHandler(i,e,l))then return true end end end end end end
  2510. if(E)then
  2511. local n,t=o:getAbsolutePosition(o:getAnchorPosition())if(e>=n)and(e<=n+o:getWidth()-1)and(l==t)then P=true N=n-e
  2512. q=yOff and 1 or 0 end end o:removeFocusedObject()return true end return false end,mouseUpHandler=function(e,l,o,t)if(P)then P=false end
  2513. if(r.mouseUpHandler(e,l,o,t))then
  2514. if(n["mouse_up"]~=nil)then
  2515. for r,e in ipairs(a["mouse_up"])do
  2516. if(n["mouse_up"][e]~=nil)then
  2517. for n,e in
  2518. g(n["mouse_up"][e])do if(e.mouseUpHandler~=nil)then
  2519. if(e:mouseUpHandler(l,o,t))then return true end end end end end end return true end return false end,scrollHandler=function(o,t,i,l)if(r.scrollHandler(o,t,i,l))then
  2520. if(n["mouse_scroll"]~=nil)then
  2521. for o,e in pairs(a["mouse_scroll"])do
  2522. if(n["mouse_scroll"][e]~=nil)then
  2523. for n,e in g(n["mouse_scroll"][e])do if(e.scrollHandler~=nil)then
  2524. if(e:scrollHandler(t,i,l))then return true end end end end end end local n=h
  2525. if(W)then k(o)if(t>0)or(t<0)then
  2526. h=e(ue(h-t,0),-z)o:updateDraw()end end if(h==n)then return false end o:removeFocusedObject()return true end return false end,hoverHandler=function(l,t,e,o)if(r.hoverHandler(l,t,e,o))then
  2527. if(n["mouse_move"]~=nil)then
  2528. for r,l in pairs(a["mouse_move"])do
  2529. if(n["mouse_move"][l]~=nil)then for l,n in g(n["mouse_move"][l])do
  2530. if(n.hoverHandler~=nil)then if(n:hoverHandler(t,e,o))then return true end end end end end end end return false end,dragHandler=function(e,i,l,o)if(P)then local n,t=e.parent:getOffsetInternal()n=n<0 and
  2531. b.abs(n)or-n t=t<0 and b.abs(t)or-t local r=1 local a=1 if(e.parent~=nil)then
  2532. r,a=e.parent:getAbsolutePosition(e.parent:getAnchorPosition())end
  2533. e:setPosition(l+N-(r-1)+n,o+q-(a-1)+t)e:updateDraw()return true end
  2534. if(e:isVisible())and(e:isEnabled())then
  2535. if(n["mouse_drag"]~=nil)then
  2536. for t,e in ipairs(a["mouse_drag"])do
  2537. if(n["mouse_drag"][e]~=nil)then for n,e in g(n["mouse_drag"][e])do
  2538. if(e.dragHandler~=nil)then if(e:dragHandler(i,l,o))then return true end end end end end end end r.dragHandler(e,i,l,o)return false end,keyHandler=function(e,t,o)if(e:isFocused())or(e.parent==nil)then
  2539. local e=e:getEventSystem():sendEvent("key",e,"key",t)if(e==false)then return false end
  2540. if(n["key"]~=nil)then
  2541. for l,e in pairs(a["key"])do
  2542. if(n["key"][e]~=nil)then
  2543. for n,e in g(n["key"][e])do if(e.keyHandler~=nil)then if(e:keyHandler(t,o))then return true end end end end end end end return false end,keyUpHandler=function(e,t)if(e:isFocused())or(e.parent==nil)then
  2544. local e=e:getEventSystem():sendEvent("key_up",e,"key_up",t)if(e==false)then return false end
  2545. if(n["key_up"]~=nil)then
  2546. for o,e in
  2547. pairs(a["key_up"])do
  2548. if(n["key_up"][e]~=nil)then for n,e in g(n["key_up"][e])do
  2549. if(e.keyUpHandler~=nil)then if(e:keyUpHandler(t))then return true end end end end end end end return false end,charHandler=function(e,t)if(e:isFocused())or(e.parent==nil)then
  2550. local e=e:getEventSystem():sendEvent("char",e,"char",t)if(e==false)then return false end
  2551. if(n["char"]~=nil)then
  2552. for o,e in
  2553. pairs(a["char"])do
  2554. if(n["char"][e]~=nil)then for n,e in g(n["char"][e])do
  2555. if(e.charHandler~=nil)then if(e:charHandler(t))then return true end end end end end end end return false end,setText=function(n,t,o,a)local l,r=n:getAnchorPosition()if(o>=1)and(o<=n:getHeight())then
  2556. if(n.parent~=nil)then
  2557. n.parent:setText(e(t+(l-1),l),r+o-1,c(a,e(1-t+1,1),e(n:getWidth()-t+1,1)))else
  2558. i.setText(e(t+(l-1),l),r+o-1,c(a,e(1-t+1,1),e(n:getWidth()-t+1,1)))end end end,setBG=function(t,n,o,r)local l,a=t:getAnchorPosition()if(o>=1)and(o<=t:getHeight())then
  2559. if(t.parent~=nil)then
  2560. t.parent:setBG(e(n+(l-1),l),a+o-1,c(r,e(1-n+1,1),e(t:getWidth()-n+1,1)))else
  2561. i.setBG(e(n+(l-1),l),a+o-1,c(r,e(1-n+1,1),e(t:getWidth()-n+1,1)))end end end,setFG=function(t,n,o,r)local l,a=t:getAnchorPosition()if(o>=1)and(o<=t:getHeight())then
  2562. if(t.parent~=nil)then
  2563. t.parent:setFG(e(n+(l-1),l),a+o-1,c(r,e(1-n+1,1),e(t:getWidth()-n+1,1)))else
  2564. i.setFG(e(n+(l-1),l),a+o-1,c(r,e(1-n+1,1),e(t:getWidth()-n+1,1)))end end end,writeText=function(t,n,o,d,a,r)local l,s=t:getAnchorPosition()if(o>=1)and(o<=t:getHeight())then
  2565. if(t.parent~=nil)then
  2566. t.parent:writeText(e(n+(l-1),l),s+o-1,c(d,e(1-n+1,1),t:getWidth()-n+1),a,r)else
  2567. i.writeText(e(n+(l-1),l),s+o-1,c(d,e(1-n+1,1),e(t:getWidth()-n+1,1)),a,r)end end end,blit=function(a,n,s,l,t,o)local d,u=a:getAnchorPosition()if(s>=1)and(s<=a:getHeight())then
  2568. local r=a:getWidth()if(a.parent~=nil)then
  2569. l=c(l,e(1-n+1,1),r-n+1)t=c(t,e(1-n+1,1),r-n+1)o=c(o,e(1-n+1,1),r-n+1)a.parent:blit(e(n+(d-1),d),u+s-1,l,t,o)else
  2570. l=c(l,e(1-n+1,1),e(r-n+1,1))t=c(t,e(1-n+1,1),e(r-n+1,1))o=c(o,e(1-n+1,1),e(r-n+1,1))i.blit(e(n+(d-1),d),u+s-1,l,t,o)end end end,drawBackgroundBox=function(n,t,o,r,l,c)local d,a=n:getAnchorPosition()l=(o<1 and(l+o>n:getHeight()and n:getHeight()or l+o-1)or(l+o>n:getHeight()and n:getHeight()-o+1 or l))r=(t<1 and(r+t>n:getWidth()and n:getWidth()or r+t-1)or(r+t>n:getWidth()and n:getWidth()-t+1 or r))if(n.parent~=nil)then
  2571. n.parent:drawBackgroundBox(e(t+(d-1),d),e(o+(a-1),a),r,l,c)else
  2572. i.drawBackgroundBox(e(t+(d-1),d),e(o+(a-1),a),r,l,c)end end,drawTextBox=function(n,l,o,r,t,s)local a,d=n:getAnchorPosition()t=(o<1 and(t+o>n:getHeight()and n:getHeight()or t+o-1)or(t+o>n:getHeight()and n:getHeight()-o+1 or t))r=(l<1 and(r+l>n:getWidth()and n:getWidth()or r+l-1)or(r+l>n:getWidth()and n:getWidth()-l+1 or r))if(n.parent~=nil)then
  2573. n.parent:drawTextBox(e(l+(a-1),a),e(o+(d-1),d),r,t,c(s,1,1))else
  2574. i.drawTextBox(e(l+(a-1),a),e(o+(d-1),d),r,t,c(s,1,1))end end,drawForegroundBox=function(n,o,r,l,t,c)local d,a=n:getAnchorPosition()t=(r<1 and(t+r>n:getHeight()and n:getHeight()or t+r-1)or(t+r>n:getHeight()and n:getHeight()-r+1 or t))l=(o<1 and(l+o>n:getWidth()and n:getWidth()or l+o-1)or(l+o>n:getWidth()and n:getWidth()-o+1 or l))if(n.parent~=nil)then
  2575. n.parent:drawForegroundBox(e(o+(d-1),d),e(r+(a-1),a),l,t,c)else
  2576. i.drawForegroundBox(e(o+(d-1),d),e(r+(a-1),a),l,t,c)end end,draw=function(e,n)if(p)and not(w)then return false end
  2577. if(e.parent==nil)then if(e:getDraw()==false)then return false end end
  2578. if(r.draw(e))then
  2579. local n,n=e:getAbsolutePosition(e:getAnchorPosition())local n,t=e:getAnchorPosition()local o,l=e:getSize()if(e.parent==nil)then
  2580. if(e.bgColor~=false)then
  2581. i.drawBackgroundBox(n,t,o,l,e.bgColor)i.drawTextBox(n,t,o,l," ")end if(e.fgColor~=false)then
  2582. i.drawForegroundBox(n,t,o,l,e.fgColor)end end
  2583. if(e.barActive)then
  2584. if(e.parent~=nil)then
  2585. e.parent:writeText(n,t,C.getTextHorizontalAlign(e.barText,o,e.barTextAlign),e.barBackground,e.barTextcolor)else
  2586. i.writeText(n,t,C.getTextHorizontalAlign(e.barText,o,e.barTextAlign),e.barBackground,e.barTextcolor)end
  2587. if(e:getBorder("left"))then
  2588. if(e.parent~=nil)then
  2589. e.parent:drawBackgroundBox(n-1,t,1,1,e.barBackground)if(e.bgColor~=false)then
  2590. e.parent:drawBackgroundBox(n-1,t+1,1,l-1,e.bgColor)end end end
  2591. if(e:getBorder("top"))then if(e.parent~=nil)then
  2592. e.parent:drawBackgroundBox(n-1,t-1,o+1,1,e.barBackground)end end end for n,e in g(m)do
  2593. if(d[e]~=nil)then for n,e in pairs(d[e])do
  2594. if(e.draw~=nil)then e:draw()end end end end end end,updateTerm=function(e)if(p)and not(w)then return false end i.update()end,addObject=function(n,e)return
  2595. V(e)end,removeObject=ie,getObject=function(n,e)return v(e)end,getDeepObject=function(n,e)return ae(e)end,addFrame=function(e,n)local e=l.newFrame(n or R(),e,nil,l)return V(e)end,init=function(e)if
  2596. not(Y)then
  2597. if(D~=nil)then r.width,r.height=D:getSize()e:setBackground(D:getTheme("FrameBG"))e:setForeground(D:getTheme("FrameText"))else r.width,r.height=t.getSize()e:setBackground(l.getTheme("BasaltBG"))e:setForeground(l.getTheme("BasaltText"))end Y=true end end}for e,t in pairs(Q)do _["add"..e]=function(e,n)return V(t(n or R(),e))end end setmetatable(_,r)return _ end end
  2598. r["Object"]=function(...)local t=l("basaltEvent")local e=l("utils")local n=l("module")local g=n("images")local n=e.splitString local n=e.numberFromString
  2599. local n=e.getValueFromXML local F,p=table.unpack,string.sub
  2600. return
  2601. function(e)local M="Object"local T={}local D=1 local C
  2602. local f="topLeft"local z=false local u=true local P=false local S=false local B=false local _=false
  2603. local r={left=false,right=false,top=false,bottom=false}local y=colors.black local h=true local w=false local x,v,H,A=0,0,0,0 local i local c local s=1 local k
  2604. local m local E=true local b=true local a={}local d=t()T={x=1,y=1,width=1,height=1,bgColor=colors.black,bgSymbol=" ",bgSymbolColor=colors.black,fgColor=colors.white,transparentColor=false,name=e or"Object",parent=nil,show=function(e)u=true e:updateDraw()return e end,hide=function(e)u=false
  2605. e:updateDraw()return e end,enable=function(e)h=true return e end,disable=function(e)h=false
  2606. return e end,isEnabled=function(e)return h end,generateXMLEventFunction=function(e,t,n)local t=function(n)if(n:sub(1,1)=="#")then
  2607. local n=e:getBaseFrame():getDeepObject(n:sub(2,n:len()))if(n~=nil)and(n.internalObjetCall~=nil)then t(e,function()n:internalObjetCall()end)end else
  2608. t(e,e:getBaseFrame():getVariable(n))end end if(type(n)=="string")then t(n)elseif(type(n)=="table")then
  2609. for n,e in pairs(n)do t(e)end end return e end,setValuesByXMLData=function(t,e)local o=t:getBaseFrame()local o,d,i
  2610. if(n("texture",e)~=nil)then o=n("texture",e)end if(n("mode",e)~=nil)then d=n("mode",e)end
  2611. if(n("texturePlay",e)~=nil)then i=n("texturePlay",e)end local l,a if(n("x",e)~=nil)then l=n("x",e)end if(n("y",e)~=nil)then a=n("y",e)end if(l~=nil)or(a~=nil)then t:setPosition(l,a)end local l,a if(n("width",e)~=nil)then l=n("width",e)end if(n("height",e)~=nil)then a=n("height",e)end if(l~=nil)or(a~=nil)then t:setSize(l,a)end if(n("bg",e)~=nil)then
  2612. t:setBackground(colors[n("bg",e)])end if(n("bgSymbol",e)~=nil)then
  2613. t:setBackground(t.bgColor,n("bgSymbol",e))end if(n("bgSymbolColor",e)~=nil)then
  2614. t:setBackground(t.bgColor,t.bgSymbol,colors[n("bgSymbolColor",e)])end
  2615. if(n("fg",e)~=nil)then t:setForeground(colors[n("fg",e)])end if(n("value",e)~=nil)then
  2616. t:setValue(colors[n("value",e)])end
  2617. if(n("visible",e)~=nil)then if(n("visible",e))then t:show()else t:hide()end end
  2618. if(n("enabled",e)~=nil)then if(n("enabled",e))then t:enable()else
  2619. t:disable()end end if(n("zIndex",e)~=nil)then
  2620. t:setZIndex(n("zIndex",e))end if(n("anchor",e)~=nil)then
  2621. t:setAnchor(n("anchor",e))end if(n("shadowColor",e)~=nil)then
  2622. t:setShadow(colors[n("shadowColor",e)])end if(n("border",e)~=nil)then
  2623. t:setBorder(colors[n("border",e)])end if(n("borderLeft",e)~=nil)then
  2624. r["left"]=n("borderLeft",e)end if(n("borderTop",e)~=nil)then
  2625. r["top"]=n("borderTop",e)end if(n("borderRight",e)~=nil)then
  2626. r["right"]=n("borderRight",e)end if(n("borderBottom",e)~=nil)then
  2627. r["bottom"]=n("borderBottom",e)end if(n("borderColor",e)~=nil)then
  2628. t:setBorder(colors[n("borderColor",e)])end if(n("ignoreOffset",e)~=nil)then
  2629. if(n("ignoreOffset",e))then t:ignoreOffset(true)end end if(n("onClick",e)~=nil)then
  2630. t:generateXMLEventFunction(t.onClick,n("onClick",e))end if(n("onClickUp",e)~=nil)then
  2631. t:generateXMLEventFunction(t.onClickUp,n("onClickUp",e))end if(n("onScroll",e)~=nil)then
  2632. t:generateXMLEventFunction(t.onScroll,n("onScroll",e))end if(n("onDrag",e)~=nil)then
  2633. t:generateXMLEventFunction(t.onDrag,n("onDrag",e))end if(n("onHover",e)~=nil)then
  2634. t:generateXMLEventFunction(t.onHover,n("onHover",e))end if(n("onLeave",e)~=nil)then
  2635. t:generateXMLEventFunction(t.onLeave,n("onLeave",e))end if(n("onKey",e)~=nil)then
  2636. t:generateXMLEventFunction(t.onKey,n("onKey",e))end if(n("onKeyUp",e)~=nil)then
  2637. t:generateXMLEventFunction(t.onKeyUp,n("onKeyUp",e))end if(n("onChange",e)~=nil)then
  2638. t:generateXMLEventFunction(t.onChange,n("onChange",e))end if(n("onResize",e)~=nil)then
  2639. t:generateXMLEventFunction(t.onResize,n("onResize",e))end if(n("onReposition",e)~=nil)then
  2640. t:generateXMLEventFunction(t.onReposition,n("onReposition",e))end if(n("onEvent",e)~=nil)then
  2641. t:generateXMLEventFunction(t.onEvent,n("onEvent",e))end if(n("onGetFocus",e)~=nil)then
  2642. t:generateXMLEventFunction(t.onGetFocus,n("onGetFocus",e))end if(n("onLoseFocus",e)~=nil)then
  2643. t:generateXMLEventFunction(t.onLoseFocus,n("onLoseFocus",e))end if(o~=nil)then
  2644. t:setTexture(o,d,i)end t:updateDraw()return t end,isVisible=function(e)return
  2645. u end,setFocus=function(e)if(e.parent~=nil)then
  2646. e.parent:setFocusedObject(e)end return e end,setZIndex=function(e,n)D=n
  2647. if(e.parent~=nil)then e.parent:removeObject(e)e.parent:addObject(e)e:updateEventHandlers()end return e end,updateEventHandlers=function(e)for t,n in
  2648. pairs(a)do if(n)then e.parent:addEvent(t,e)end end end,getZIndex=function(e)return D end,getType=function(e)return M end,getName=function(e)return
  2649. e.name end,remove=function(e)if(e.parent~=nil)then
  2650. e.parent:removeObject(e)end e:updateDraw()return e end,setParent=function(e,n)if(n.getType~=nil and n:getType()=="Frame")then
  2651. e:remove()n:addObject(e)if(e.draw)then e:show()end end return e end,setValue=function(e,n,t)if(C~=n)then C=n e:updateDraw()if(t~=false)then
  2652. e:valueChangedHandler()end end
  2653. return e end,getValue=function(e)return C end,getDraw=function(e)return
  2654. b end,updateDraw=function(e,n)b=n if(n==nil)then b=true end if(b)then if(e.parent~=nil)then
  2655. e.parent:updateDraw()end end return e end,getEventSystem=function(e)return
  2656. d end,getParent=function(e)return e.parent end,setPosition=function(e,n,t,o)if(type(n)=="number")then e.x=o and e:getX()+n or n end if(type(t)=="number")then
  2657. e.y=o and e:getY()+t or t end
  2658. if(e.parent~=nil)then if(type(n)=="string")then
  2659. e.x=e.parent:newDynamicValue(e,n)end if(type(t)=="string")then
  2660. e.y=e.parent:newDynamicValue(e,t)end
  2661. e.parent:recalculateDynamicValues()end e:customEventHandler("basalt_reposition")e:updateDraw()return e end,getX=function(e)return
  2662. type(e.x)=="number"and e.x or math.floor(e.x[1]+.5)end,getY=function(e)return
  2663. type(e.y)=="number"and e.y or math.floor(e.y[1]+.5)end,getPosition=function(e)return
  2664. e:getX(),e:getY()end,getVisibility=function(e)return u end,setVisibility=function(e,n)u=n or not u e:updateDraw()return e end,setSize=function(e,n,t,o)if(type(n)=="number")then
  2665. e.width=o and e:getWidth()+n or n end
  2666. if(type(t)=="number")then e.height=o and
  2667. e:getHeight()+t or t end
  2668. if(e.parent~=nil)then if(type(n)=="string")then
  2669. e.width=e.parent:newDynamicValue(e,n)end if(type(t)=="string")then
  2670. e.height=e.parent:newDynamicValue(e,t)end
  2671. e.parent:recalculateDynamicValues()end if(i~=nil)and(m=="stretch")then
  2672. c=g.resizeBIMG(i,e:getSize())[s]end
  2673. e:customEventHandler("basalt_resize")e:updateDraw()return e end,getHeight=function(e)return
  2674. type(e.height)=="number"and e.height or
  2675. math.floor(e.height[1]+.5)end,getWidth=function(e)return
  2676. type(e.width)=="number"and e.width or math.floor(e.width[1]+.5)end,getSize=function(e)return
  2677. e:getWidth(),e:getHeight()end,calculateDynamicValues=function(e)if(type(e.width)=="table")then e.width:calculate()end
  2678. if(type(e.height)=="table")then e.height:calculate()end
  2679. if(type(e.x)=="table")then e.x:calculate()end
  2680. if(type(e.y)=="table")then e.y:calculate()end e:updateDraw()return e end,setBackground=function(e,o,n,t)e.bgColor=o or false
  2681. e.bgSymbol=n or(e.bgColor~=false and e.bgSymbol or
  2682. false)e.bgSymbolColor=t or e.bgSymbolColor
  2683. e:updateDraw()return e end,setTexture=function(e,n,o,t)if(type(n)=="string")then i=g.loadImageAsBimg(n)elseif(type(n)=="table")then
  2684. i=n end
  2685. if(i.animated)then local n=i[s].duration or
  2686. i.secondsPerFrame or .2
  2687. k=os.startTimer(n)e.parent:addEvent("other_event",e)a["other_event"]=true end E=t==false and false or true s=1
  2688. m=o or"normal"if(m=="stretch")then
  2689. c=g.resizeBIMG(i,e:getSize())[1]else c=i[1]end
  2690. e:updateDraw()return e end,setTransparent=function(e,n)e.transparentColor=n or false if(n~=false)then e.bgSymbol=false
  2691. e.bgSymbolColor=false end e:updateDraw()return e end,getBackground=function(e)return
  2692. e.bgColor end,setForeground=function(e,n)e.fgColor=n or false
  2693. e:updateDraw()return e end,getForeground=function(e)return e.fgColor end,setShadow=function(n,e)if(e==false)then _=false else y=e _=true end
  2694. n:updateDraw()return n end,isShadowActive=function(e)return _ end,setBorder=function(t,...)if(...~=nil)then local e={...}for t,n in pairs(e)do if(n=="left")or(#e==1)then
  2695. r["left"]=e[1]end if(n=="top")or(#e==1)then
  2696. r["top"]=e[1]end if(n=="right")or(#e==1)then
  2697. r["right"]=e[1]end if(n=="bottom")or(#e==1)then
  2698. r["bottom"]=e[1]end end end t:updateDraw()return t end,getBorder=function(n,e)if(e=="left")then return borderLeft end
  2699. if(e=="top")then return borderTop end if(e=="right")then return borderRight end if(e=="bottom")then
  2700. return borderBottom end end,draw=function(e)if(u)then
  2701. if(e.parent~=nil)then local n,t=e:getAnchorPosition()local o,l=e:getSize()local i,a=e.parent:getSize()if(n+o<1)or(n>i)or(t+l<1)or(t>a)then return false end if(e.transparentColor~=false)then
  2702. e.parent:drawForegroundBox(n,t,o,l,e.transparentColor)end if(e.bgColor~=false)then
  2703. e.parent:drawBackgroundBox(n,t,o,l,e.bgColor)end
  2704. if(e.bgSymbol~=false)then
  2705. e.parent:drawTextBox(n,t,o,l,e.bgSymbol)if(e.bgSymbol~=" ")then
  2706. e.parent:drawForegroundBox(n,t,o,l,e.bgSymbolColor)end end
  2707. if(c~=nil)then
  2708. if(m=="center")then local a,r=#c[1][1],#c
  2709. local f=a<o and math.floor((o-a)/2)or 0
  2710. local h=r<l and math.floor((l-r)/2)or 0
  2711. local i=a<o and 1 or math.floor((a-o)/2)local a=a<o and o or
  2712. o-math.floor((o-a)/2+.5)-1
  2713. local o=r<l and 1 or math.floor((r-l)/2)local u=r<l and l or
  2714. l-math.floor((l-r)/2+.5)-1 local s=1
  2715. for d=o,#c do
  2716. if(c[d]~=nil)then local l,r,o=F(c[d])l=p(l,i,a)r=p(r,i,a)o=p(o,i,a)e.parent:blit(n+f,t+s-1+h,l,r,o)end s=s+1 if(d==u)then break end end else
  2717. for d,r in pairs(c)do local a,i,r=F(r)a=p(a,1,o)i=p(i,1,o)r=p(r,1,o)e.parent:blit(n,t+d-1,a,i,r)if(d==l)then break end end end end
  2718. if(_)then
  2719. e.parent:drawBackgroundBox(n+1,t+l,o,1,y)e.parent:drawBackgroundBox(n+o,t+1,1,l,y)e.parent:drawForegroundBox(n+1,t+l,o,1,y)e.parent:drawForegroundBox(n+o,t+1,1,l,y)end local a=e.bgColor
  2720. if(r["left"]~=false)then
  2721. e.parent:drawTextBox(n,t,1,l,"\149")if(a~=false)then
  2722. e.parent:drawBackgroundBox(n,t,1,l,a)end
  2723. e.parent:drawForegroundBox(n,t,1,l,r["left"])end
  2724. if(r["top"]~=false)then
  2725. e.parent:drawTextBox(n,t,o,1,"\131")if(a~=false)then
  2726. e.parent:drawBackgroundBox(n,t,o,1,e.bgColor)end
  2727. e.parent:drawForegroundBox(n,t,o,1,r["top"])end
  2728. if(r["left"]~=false)and(r["top"]~=false)then
  2729. e.parent:drawTextBox(n,t,1,1,"\151")if(a~=false)then
  2730. e.parent:drawBackgroundBox(n,t,1,1,e.bgColor)end
  2731. e.parent:drawForegroundBox(n,t,1,1,r["left"])end
  2732. if(r["right"]~=false)then
  2733. e.parent:drawTextBox(n+o-1,t,1,l,"\149")if(a~=false)then
  2734. e.parent:drawForegroundBox(n+o-1,t,1,l,e.bgColor)end
  2735. e.parent:drawBackgroundBox(n+o-1,t,1,l,r["right"])end
  2736. if(r["bottom"]~=false)then
  2737. e.parent:drawTextBox(n,t+l-1,o,1,"\143")if(a~=false)then
  2738. e.parent:drawForegroundBox(n,t+l-1,o,1,e.bgColor)end
  2739. e.parent:drawBackgroundBox(n,t+l-1,o,1,r["bottom"])end
  2740. if(r["top"]~=false)and(r["right"]~=false)then e.parent:drawTextBox(n+o-1,t,1,1,"\148")if(a~=false)then
  2741. e.parent:drawForegroundBox(n+o-1,t,1,1,e.bgColor)end
  2742. e.parent:drawBackgroundBox(n+o-1,t,1,1,r["right"])end
  2743. if(r["right"]~=false)and(r["bottom"]~=false)then
  2744. e.parent:drawTextBox(n+o-1,t+l-1,1,1,"\133")if(a~=false)then
  2745. e.parent:drawForegroundBox(n+o-1,t+l-1,1,1,e.bgColor)end
  2746. e.parent:drawBackgroundBox(n+o-1,t+l-1,1,1,r["right"])end
  2747. if(r["bottom"]~=false)and(r["left"]~=false)then e.parent:drawTextBox(n,t+l-1,1,1,"\138")if(a~=false)then
  2748. e.parent:drawForegroundBox(n-1,t+l-1,1,1,e.bgColor)end
  2749. e.parent:drawBackgroundBox(n,t+l-1,1,1,r["left"])end end b=false return true end return false end,getAbsolutePosition=function(t,n,e)if(n==nil)or(e==nil)then n,e=t:getAnchorPosition()end
  2750. if(t.parent~=nil)then
  2751. local t,o=t.parent:getAbsolutePosition()n=t+n-1 e=o+e-1 end return n,e end,getAnchorPosition=function(l,n,e,r)if(n==nil)then n=l:getX()end
  2752. if(e==nil)then e=l:getY()end
  2753. if(l.parent~=nil)then local t,o=l.parent:getSize()if(f=="top")then n=math.floor(t/2)+n-1 elseif(f=="topRight")then
  2754. n=t+n-1 elseif(f=="right")then n=t+n-1
  2755. e=math.floor(o/2)+e-1 elseif(f=="bottomRight")then n=t+n-1 e=o+e-1 elseif(f=="bottom")then n=math.floor(t/2)+n-1 e=o+e-1 elseif(f=="bottomLeft")then e=o+e-1 elseif(f=="left")then
  2756. e=math.floor(o/2)+e-1 elseif(f=="center")then n=math.floor(t/2)+n-1 e=math.floor(o/2)+e-1 end local o,t=l.parent:getOffsetInternal()if not(z or r)then return
  2757. n+o,e+t end end return n,e end,ignoreOffset=function(n,e)z=e if(e==nil)then z=true end return n end,getBaseFrame=function(e)if(e.parent~=nil)then return e.parent:getBaseFrame()end return e end,setAnchor=function(e,n)f=n
  2758. e:updateDraw()return e end,getAnchor=function(e)return f end,onChange=function(e,...)for t,n in
  2759. pairs(table.pack(...))do if(type(n)=="function")then
  2760. e:registerEvent("value_changed",n)end end return e end,onClick=function(e,...)for t,n in
  2761. pairs(table.pack(...))do if(type(n)=="function")then
  2762. e:registerEvent("mouse_click",n)end end
  2763. if(e.parent~=nil)then
  2764. e.parent:addEvent("mouse_click",e)a["mouse_click"]=true
  2765. e.parent:addEvent("mouse_up",e)a["mouse_up"]=true end return e end,onClickUp=function(e,...)for t,n in
  2766. pairs(table.pack(...))do
  2767. if(type(n)=="function")then e:registerEvent("mouse_up",n)end end
  2768. if(e.parent~=nil)then
  2769. e.parent:addEvent("mouse_click",e)a["mouse_click"]=true
  2770. e.parent:addEvent("mouse_up",e)a["mouse_up"]=true end return e end,onRelease=function(e,...)for t,n in
  2771. pairs(table.pack(...))do if(type(n)=="function")then
  2772. e:registerEvent("mouse_release",n)end end
  2773. if(e.parent~=nil)then
  2774. e.parent:addEvent("mouse_click",e)a["mouse_click"]=true
  2775. e.parent:addEvent("mouse_up",e)a["mouse_up"]=true end return e end,onScroll=function(e,...)for t,n in
  2776. pairs(table.pack(...))do if(type(n)=="function")then
  2777. e:registerEvent("mouse_scroll",n)end end
  2778. if(e.parent~=nil)then
  2779. e.parent:addEvent("mouse_scroll",e)a["mouse_scroll"]=true end return e end,onHover=function(e,...)for t,n in
  2780. pairs(table.pack(...))do if(type(n)=="function")then
  2781. e:registerEvent("mouse_hover",n)end end if(e.parent~=nil)then
  2782. e.parent:addEvent("mouse_move",e)a["mouse_move"]=true end
  2783. return e end,onLeave=function(e,...)for t,n in
  2784. pairs(table.pack(...))do if(type(n)=="function")then
  2785. e:registerEvent("mouse_leave",n)end end if(e.parent~=nil)then
  2786. e.parent:addEvent("mouse_move",e)a["mouse_move"]=true end
  2787. return e end,onDrag=function(e,...)for t,n in
  2788. pairs(table.pack(...))do if(type(n)=="function")then
  2789. e:registerEvent("mouse_drag",n)end end
  2790. if(e.parent~=nil)then
  2791. e.parent:addEvent("mouse_drag",e)a["mouse_drag"]=true
  2792. e.parent:addEvent("mouse_click",e)a["mouse_click"]=true
  2793. e.parent:addEvent("mouse_up",e)a["mouse_up"]=true end return e end,onEvent=function(e,...)for t,n in
  2794. pairs(table.pack(...))do if(type(n)=="function")then
  2795. e:registerEvent("other_event",n)end end if(e.parent~=nil)then
  2796. e.parent:addEvent("other_event",e)a["other_event"]=true end return
  2797. e end,onKey=function(e,...)if(h)then
  2798. for t,n in pairs(table.pack(...))do if(type(n)=="function")then
  2799. e:registerEvent("key",n)end end if(e.parent~=nil)then e.parent:addEvent("key",e)a["key"]=true end end return e end,onChar=function(e,...)if(h)then
  2800. for t,n in pairs(table.pack(...))do if(type(n)=="function")then
  2801. e:registerEvent("char",n)end end if(e.parent~=nil)then e.parent:addEvent("char",e)a["char"]=true end end return e end,onResize=function(e,...)for t,n in
  2802. pairs(table.pack(...))do if(type(n)=="function")then
  2803. e:registerEvent("basalt_resize",n)end end return e end,onReposition=function(e,...)for t,n in
  2804. pairs(table.pack(...))do if(type(n)=="function")then
  2805. e:registerEvent("basalt_reposition",n)end end return e end,onKeyUp=function(e,...)for t,n in
  2806. pairs(table.pack(...))do
  2807. if(type(n)=="function")then e:registerEvent("key_up",n)end end if(e.parent~=nil)then
  2808. e.parent:addEvent("key_up",e)a["key_up"]=true end return e end,isFocused=function(e)if(e.parent~=nil)then
  2809. return e.parent:getFocusedObject()==e end return false end,onGetFocus=function(e,...)for t,n in
  2810. pairs(table.pack(...))do if(type(n)=="function")then
  2811. e:registerEvent("get_focus",n)end end if(e.parent~=nil)then
  2812. e.parent:addEvent("mouse_click",e)a["mouse_click"]=true end return
  2813. e end,onLoseFocus=function(e,...)for t,n in
  2814. pairs(table.pack(...))do if(type(n)=="function")then
  2815. e:registerEvent("lose_focus",n)end end if(e.parent~=nil)then
  2816. e.parent:addEvent("mouse_click",e)a["mouse_click"]=true end return
  2817. e end,registerEvent=function(t,e,n)return
  2818. d:registerEvent(e,n)end,removeEvent=function(t,e,n)return d:removeEvent(e,n)end,sendEvent=function(e,n,...)return d:sendEvent(n,e,...)end,isCoordsInObject=function(l,n,e)if(u)and(h)then if(n==nil)or(e==nil)then return false end
  2819. local o,t=l:getAbsolutePosition()local r,l=l:getSize()if(o<=n)and(o+r>n)and(t<=e)and(t+l>e)then return true end end return false end,mouseHandler=function(e,a,t,n,r)if(e:isCoordsInObject(t,n))then local o,l=e:getAbsolutePosition()local o=d:sendEvent("mouse_click",e,"mouse_click",a,t-(o-1),n-(l-1),t,n,r)if(o==false)then return false end if(e.parent~=nil)then
  2820. e.parent:setFocusedObject(e)end B=true w=true x,v=t,n return true end return false end,mouseUpHandler=function(t,o,n,e)w=false
  2821. if(B)then local l,r=t:getAbsolutePosition()local e=d:sendEvent("mouse_release",t,"mouse_release",o,n-(l-1),e-(r-1),n,e)B=false end
  2822. if(t:isCoordsInObject(n,e))then local r,l=t:getAbsolutePosition()local e=d:sendEvent("mouse_up",t,"mouse_up",o,n-(r-1),e-(l-1),n,e)if(e==false)then return false end return true end return false end,dragHandler=function(e,r,n,t)if(w)then local l,o=e:getAbsolutePosition()local o=d:sendEvent("mouse_drag",e,"mouse_drag",r,n-(l-1),t-(o-1),x-n,v-t,n,t)x,v=n,t if(o~=nil)then return o end if(e.parent~=nil)then
  2823. e.parent:setFocusedObject(e)end return true end
  2824. if(e:isCoordsInObject(n,t))then
  2825. local e,o=e:getAbsolutePosition(e:getAnchorPosition())x,v=n,t H,A=e-n,o-t end return false end,scrollHandler=function(e,o,t,n)if(e:isCoordsInObject(t,n))then local l,r=e:getAbsolutePosition()local n=d:sendEvent("mouse_scroll",e,"mouse_scroll",o,t-(l-1),n-(r-1))if(n==false)then return false end if(e.parent~=nil)then
  2826. e.parent:setFocusedObject(e)end return true end return false end,hoverHandler=function(e,n,t,o)if(e:isCoordsInObject(n,t))then
  2827. local e=d:sendEvent("mouse_hover",e,"mouse_hover",n,t,o)if(e==false)then return false end S=true return true end
  2828. if(S)then
  2829. local e=d:sendEvent("mouse_leave",e,"mouse_leave",n,t,o)if(e==false)then return false end S=false end return false end,keyHandler=function(e,t,n)if(h)and(u)then
  2830. if(e:isFocused())then
  2831. local e=d:sendEvent("key",e,"key",t,n)if(e==false)then return false end return true end end return
  2832. false end,keyUpHandler=function(e,n)if(h)and(u)then
  2833. if(e:isFocused())then
  2834. local e=d:sendEvent("key_up",e,"key_up",n)if(e==false)then return false end return true end end return
  2835. false end,charHandler=function(e,n)if(h)and(u)then
  2836. if(e:isFocused())then
  2837. local e=d:sendEvent("char",e,"char",n)if(e==false)then return false end return true end end return
  2838. false end,valueChangedHandler=function(e)d:sendEvent("value_changed",e,C)end,eventHandler=function(e,n,...)local t={...}if(n=="timer")and(t[1]==k)then
  2839. if(i[s+1]~=nil)then s=s+1 if(m=="stretch")then
  2840. c=g.resizeBIMG(i,e:getSize())[s]else c=i[s]end local e=i[s].duration or
  2841. i.secondsPerFrame or .2
  2842. k=os.startTimer(e)else
  2843. if(E)then s=1 if(m=="stretch")then
  2844. c=g.resizeBIMG(i,e:getSize())[1]else c=i[1]end local e=i[1].duration or i.secondsPerFrame or .2
  2845. k=os.startTimer(e)end end e:updateDraw()end local e=d:sendEvent("other_event",e,n,...)if(e~=nil)then
  2846. return e end end,customEventHandler=function(e,n,...)if(i~=nil)and(m=="stretch")and(n=="basalt_resize")then
  2847. c=g.resizeBIMG(i,e:getSize())[s]e:updateDraw()end local e=d:sendEvent("custom_event",e,n,...)if(e~=nil)then
  2848. return e end return true end,getFocusHandler=function(e)local e=d:sendEvent("get_focus",e)if(e~=nil)then return e end return true end,loseFocusHandler=function(e)w=false local e=d:sendEvent("lose_focus",e)if(e~=nil)then return e end return true end,init=function(e)if(e.parent~=nil)then for n,t in pairs(a)do
  2849. if(t)then e.parent:addEvent(n,e)end end end if not(P)then P=true return true end return false end}T.__index=T return T end end r["objects"]={}r["objects"]["Input"]=function(...)local e=l("Object")local h=l("utils")local n=l("basaltLogs")local o=h.getValueFromXML
  2850. return
  2851. function(n)local t=e(n)local r="Input"local i="text"local c=0 t:setZIndex(5)t:setValue("")t.width=10 t.height=1
  2852. local e=1 local n=1 local l=""local s local u local d=l local a=false
  2853. local e={getType=function(e)return r end,setInputType=function(n,e)if(e=="password")or(e=="number")or(e=="text")then i=e end n:updateDraw()return n end,setDefaultText=function(e,t,o,n)l=t s=n or s u=o or u
  2854. if(e:isFocused())then d=""else d=l end e:updateDraw()return e end,getInputType=function(e)return
  2855. i end,setValue=function(o,l)t.setValue(o,tostring(l))if not(a)then e=tostring(l):len()+1
  2856. n=math.max(1,e-o:getWidth()+1)if(o:isFocused())then local l,t=o:getAnchorPosition()o.parent:setCursor(true,l+e-n,t+math.floor(o:getHeight()/2),o.fgColor)end end o:updateDraw()return o end,getValue=function(e)local e=t.getValue(e)return i=="number"and tonumber(e)or e end,setInputLimit=function(e,n)c=tonumber(n)or c e:updateDraw()return e end,getInputLimit=function(e)return c end,setValuesByXMLData=function(n,e)t.setValuesByXMLData(n,e)local t,l
  2857. if(o("defaultBG",e)~=nil)then t=o("defaultBG",e)end
  2858. if(o("defaultFG",e)~=nil)then l=o("defaultFG",e)end if(o("default",e)~=nil)then
  2859. n:setDefaultText(o("default",e),l~=nil and colors[l],t~=nil and colors[t])end
  2860. if(o("limit",e)~=nil)then n:setInputLimit(o("limit",e))end if(o("type",e)~=nil)then
  2861. n:setInputType(o("type",e))end return n end,getFocusHandler=function(o)t.getFocusHandler(o)if(o.parent~=nil)then local r,t=o:getAnchorPosition()d=""if(l~="")then
  2862. o:updateDraw()end
  2863. o.parent:setCursor(true,r+e-n,t+math.max(math.ceil(o:getHeight()/2-1,1)),o.fgColor)end end,loseFocusHandler=function(e)t.loseFocusHandler(e)if(e.parent~=nil)then d=l if(l~="")then e:updateDraw()end
  2864. e.parent:setCursor(false)end end,keyHandler=function(o,r)if(t.keyHandler(o,r))then local l,i=o:getSize()a=true
  2865. if(r==keys.backspace)then
  2866. local t=tostring(t.getValue())if(e>1)then
  2867. o:setValue(t:sub(1,e-2)..t:sub(e,t:len()))if(e>1)then e=e-1 end
  2868. if(n>1)then if(e<n)then n=n-1 end end end end if(r==keys.enter)then if(o.parent~=nil)then end end
  2869. if(r==keys.right)then
  2870. local t=tostring(t.getValue()):len()e=e+1 if(e>t)then e=t+1 end if(e<1)then e=1 end if(e<n)or(e>=l+n)then n=e-l+1 end if(n<1)then n=1 end end
  2871. if(r==keys.left)then e=e-1 if(e>=1)then
  2872. if(e<n)or(e>=l+n)then n=e end end if(e<1)then e=1 end if(n<1)then n=1 end end local r,d=o:getAnchorPosition()local t=tostring(t.getValue())local e=(e<=t:len()and e-1 or t:len())-(n-1)local n=o:getX()if(e>n+l-1)then e=n+l-1 end if(o.parent~=nil)then
  2873. o.parent:setCursor(true,r+e,d+math.max(math.ceil(i/2-1,1)),o.fgColor)end
  2874. o:updateDraw()a=false return true end return false end,charHandler=function(o,r)if(t.charHandler(o,r))then a=true local d,s=o:getSize()local l=t.getValue()if(l:len()<c or c<=0)then
  2875. if(i=="number")then local n=l
  2876. if(e==1 and r=="-")or(r==".")or(tonumber(r)~=nil)then
  2877. o:setValue(l:sub(1,e-1)..r..l:sub(e,l:len()))e=e+1 if(r==".")or(r=="-")and(#l>0)then
  2878. if(tonumber(t.getValue())==nil)then o:setValue(n)e=e-1 end end end else
  2879. o:setValue(l:sub(1,e-1)..r..l:sub(e,l:len()))e=e+1 end if(e>=d+n)then n=n+1 end end local r,l=o:getAnchorPosition()local t=tostring(t.getValue())local e=(e<=t:len()and e-1 or t:len())-(n-1)local n=o:getX()if(e>n+d-1)then e=n+d-1 end if(o.parent~=nil)then
  2880. o.parent:setCursor(true,r+e,l+math.max(math.ceil(s/2-1,1)),o.fgColor)end a=false
  2881. o:updateDraw()return true end return false end,mouseHandler=function(o,r,l,a)if(t.mouseHandler(o,r,l,a))then local r,a=o:getAnchorPosition()local i,d=o:getAbsolutePosition(r,a)local c,d=o:getSize()e=l-i+n local t=t.getValue()if(e>t:len())then e=t:len()+1 end if(e<n)then n=e-1
  2882. if(n<1)then n=1 end end
  2883. o.parent:setCursor(true,r+e-n,a+math.max(math.ceil(d/2-1,1)),o.fgColor)return true end end,dragHandler=function(e,l,o,n,a,r)if(e:isFocused())then if(e:isCoordsInObject(o,n))then
  2884. if(t.dragHandler(e,l,o,n,a,r))then return true end end
  2885. e.parent:removeFocusedObject()end end,eventHandler=function(o,r,l,...)t.eventHandler(o,r,l,...)if(r=="paste")then
  2886. if(o:isFocused())then local r=t.getValue()local d,c=o:getSize()a=true
  2887. if(i=="number")then local n=r
  2888. if(l==".")or(tonumber(l)~=nil)then
  2889. o:setValue(r:sub(1,e-1)..l..r:sub(e,r:len()))e=e+l:len()end
  2890. if(tonumber(t.getValue())==nil)then o:setValue(n)end else
  2891. o:setValue(r:sub(1,e-1)..l..r:sub(e,r:len()))e=e+l:len()end if(e>=d+n)then n=(e+1)-d end
  2892. local l,r=o:getAnchorPosition()local t=tostring(t.getValue())local e=(e<=t:len()and e-1 or t:len())-(n-1)local n=o:getX()if(e>n+d-1)then e=n+d-1 end if(o.parent~=nil)then
  2893. o.parent:setCursor(true,l+e,r+math.max(math.ceil(c/2-1,1)),o.fgColor)end
  2894. o:updateDraw()a=false end end end,draw=function(o)if(t.draw(o))then
  2895. if(o.parent~=nil)then local f,c=o:getAnchorPosition()local a,l=o:getSize()local r=h.getTextVerticalAlign(l,"center")if(o.bgColor~=false)then
  2896. o.parent:drawBackgroundBox(f,c,a,l,o.bgColor)end
  2897. for h=1,l do
  2898. if(h==r)then
  2899. local t=tostring(t.getValue())local l=o.bgColor local r=o.fgColor local e if(t:len()<=0)then e=d
  2900. l=s or l r=u or r end e=d
  2901. if(t~="")then e=t end e=e:sub(n,a+n-1)local n=a-e:len()if(n<0)then
  2902. n=0 end if(i=="password")and(t~="")then
  2903. e=string.rep("*",e:len())end
  2904. e=e..string.rep(o.bgSymbol,n)o.parent:writeText(f,c+(h-1),e,l,r)end end if(o:isFocused())then
  2905. o.parent:setCursor(true,f+e-n,c+math.floor(o:getHeight()/2),o.fgColor)end end end end,init=function(e)if(e.parent~=nil)then e.parent:addEvent("mouse_click",e)e.parent:addEvent("key",e)e.parent:addEvent("char",e)e.parent:addEvent("other_event",e)e.parent:addEvent("mouse_drag",e)end
  2906. if(t.init(e))then
  2907. e.bgColor=e.parent:getTheme("InputBG")e.fgColor=e.parent:getTheme("InputText")end end}return setmetatable(e,t)end end
  2908. r["objects"]["Button"]=function(...)local n=l("Object")local o=l("utils")local t=o.getValueFromXML local c=l("tHex")return
  2909. function(e)local e=n(e)local a="Button"local l="center"local r="center"e:setZIndex(5)e:setValue("Button")e.width=12 e.height=3
  2910. local n={init=function(n)if(e.init(n))then
  2911. n.bgColor=n.parent:getTheme("ButtonBG")n.fgColor=n.parent:getTheme("ButtonText")end end,getType=function(e)return a end,setHorizontalAlign=function(e,n)l=n e:updateDraw()return e end,setVerticalAlign=function(e,n)r=n
  2912. e:updateDraw()return e end,setText=function(n,t)e:setValue(tostring(t))n:updateDraw()return n end,setValuesByXMLData=function(o,n)e.setValuesByXMLData(o,n)if(t("text",n)~=nil)then o:setText(t("text",n))end if(t("horizontalAlign",n)~=nil)then
  2913. l=t("horizontalAlign",n)end if(t("verticalAlign",n)~=nil)then
  2914. r=t("verticalAlign",n)end return o end,draw=function(n)if(e.draw(n))then
  2915. if(n.parent~=nil)then local d,i=n:getAnchorPosition()local a,e=n:getSize()local r=o.getTextVerticalAlign(e,r)for t=1,e do
  2916. if(t==r)then
  2917. local e=n:getValue()n.parent:setText(d+(a/2-e:len()/2),i+(t-1),o.getTextHorizontalAlign(e,e:len(),l))n.parent:setFG(d+(a/2-e:len()/2),i+(t-1),o.getTextHorizontalAlign(c[n.fgColor]:rep(e:len()),e:len(),l))end end end end end}return setmetatable(n,e)end end
  2918. r["objects"]["Graphic"]=function(...)local e=l("Object")local n=l("tHex")local n=l("utils").getValueFromXML local i=l("bimg")local d=l("images")local n,n,n,n=string.sub,string.len,math.max,math.min
  2919. return
  2920. function(n)local r=e(n)local c="Graphic"local e=i()local n=e.getFrameObject(1)local t
  2921. local a=1 r:setZIndex(5)local l,o=0,0
  2922. local e={getType=function(e)return c end,setOffset=function(e,t,n,r)if(r)then
  2923. l=l+t or 0 o=o+n or 0 else l=t or l o=n or o end e:updateDraw()return e end,getOffset=function(e)return
  2924. l,o end,setValuesByXMLData=function(e,n)r.setValuesByXMLData(e,n)return e end,selectFrame=function(l,o)if(e.getFrameObject(o)==nil)then e.addFrame(o)end
  2925. n=e.getFrameObject(o)t=n.getImage(o)a=o l:updateDraw()end,addFrame=function(t,n)e.addFrame(n)return t end,getFrameMetadata=function(o,t,n)return e.getFrameData(t,n)end,setFrameMetadata=function(o,l,t,n)e.setFrameData(l,t,n)return o end,getMetadata=function(t,n)return e.getMetadata(n)end,setMetadata=function(o,n,t)return
  2926. e.setMetadata(n,t)end,getFrame=function(t,n)return e.getFrame(n)end,getFrameObject=function(t,n)return
  2927. e.getFrameObject(n)end,removeFrame=function(n,t)e.removeFrame(t)return n end,moveFrame=function(t,o,n)e.moveFrame(o,n)return t end,getFrames=function(n)return e.getFrames()end,getFrameCount=function(n)return#e.getFrames()end,getSelectedFrame=function(e)return a end,blit=function(e,r,a,i,o,l)x=o or x y=l or y n.blit(r,a,i,x,y)t=n.getImage()e:updateDraw()return e end,setText=function(e,r,l,o)x=l or x y=o or y n.text(r,x,y)t=n.getImage()e:updateDraw()return e end,setBg=function(e,l,r,o)x=r or x y=o or y n.bg(l,x,y)t=n.getImage()e:updateDraw()return e end,setFg=function(e,o,l,r)x=l or x y=r or
  2928. y n.fg(o,x,y)t=n.getImage()e:updateDraw()return e end,getImageSize=function(n)return e.getSize()end,setImageSize=function(o,l,r)e.setSize(l,r)t=n.getImage()o:updateDraw()return o end,resizeImage=function(o,r,l)local l=d.resizeBIMG(e.createBimg(),r,l)e=i(l)a=1 n=e.getFrameObject(1)t=n.getImage()o:updateDraw()return o end,loadImage=function(o,l)if(fs.exists(l))then local l=d.loadBIMG(l)e=i(l)a=1
  2929. n=e.getFrameObject(1)t=n.getImage()o:updateDraw()end return o end,clear=function(n)e=i()t=nil n:updateDraw()return n end,getImage=function(n)return
  2930. e.createBimg()end,draw=function(e)if(r.draw(e))then
  2931. if(e.parent~=nil)then
  2932. local i,r=e:getAnchorPosition()local n,a=e:getSize()if(t~=nil)then
  2933. for n,t in pairs(t)do if(n<=a-o)and(n+o>=1)then
  2934. e.parent:blit(i+l,r+n-1+o,t[1],t[2],t[3])end end end end end end,init=function(e)if(r.init(e))then e.bgColor=e.parent:getTheme("GraphicBG")end end}return setmetatable(e,r)end end
  2935. r["objects"]["Checkbox"]=function(...)local e=l("Object")local t=l("utils")local o=t.getValueFromXML
  2936. return
  2937. function(n)local n=e(n)local e="Checkbox"n:setZIndex(5)n:setValue(false)n.width=1 n.height=1 local a="\42"local e={getType=function(n)return e end,setSymbol=function(e,n)a=n
  2938. e:updateDraw()return e end,mouseHandler=function(e,t,l,o)if(n.mouseHandler(e,t,l,o))then
  2939. if(t==1)then
  2940. if(e:getValue()~=true)and(e:getValue()~=false)then
  2941. e:setValue(false)else e:setValue(not e:getValue())end e:updateDraw()return true end end return false end,touchHandler=function(e,n,t)return
  2942. e:mouseHandler(1,n,t)end,setValuesByXMLData=function(e,t)n.setValuesByXMLData(e,t)if(o("checked",t)~=nil)then if(o("checked",t))then e:setValue(true)else
  2943. e:setValue(false)end end return e end,draw=function(e)if(n.draw(e))then
  2944. if(e.parent~=nil)then local r,l=e:getAnchorPosition()local o,n=e:getSize()local i=t.getTextVerticalAlign(n,"center")if(e.bgColor~=false)then
  2945. e.parent:drawBackgroundBox(r,l,o,n,e.bgColor)end
  2946. for n=1,n do
  2947. if(n==i)then
  2948. if(e:getValue()==true)then
  2949. e.parent:writeText(r,l+(n-1),t.getTextHorizontalAlign(a,o,"center"),e.bgColor,e.fgColor)else
  2950. e.parent:writeText(r,l+(n-1),t.getTextHorizontalAlign(" ",o,"center"),e.bgColor,e.fgColor)end end end end end end,init=function(e)e.parent:addEvent("mouse_click",e)e.parent:addEvent("mouse_up",e)if(n.init(e))then
  2951. e.bgColor=e.parent:getTheme("CheckboxBG")e.fgColor=e.parent:getTheme("CheckboxText")end end}return setmetatable(e,n)end end
  2952. r["objects"]["Label"]=function(...)local n=l("Object")local d=l("utils")local t=d.getValueFromXML local i=d.createText local e=l("tHex")local f=l("bigfont")return
  2953. function(e)local n=n(e)local e="Label"n:setZIndex(3)local l=true n:setValue("Label")n.width=5
  2954. local c="left"local r="top"local a=0 local u,s=false,false
  2955. local e={getType=function(n)return e end,setText=function(e,t)t=tostring(t)n:setValue(t)if(l)then local o=e.parent:getOffset()if(t:len()+e:getX()>e.parent:getWidth()+o)then local o=e.parent:getWidth()+o-e:getX()n.setSize(e,o,#i(t,o))else
  2956. n.setSize(e,t:len(),1)end end e:updateDraw()return e end,setBackground=function(e,t)n.setBackground(e,t)s=true e:updateDraw()return e end,setForeground=function(e,t)n.setForeground(e,t)u=true e:updateDraw()return e end,setTextAlign=function(e,n,t)c=n or c r=t or r e:updateDraw()return e end,setFontSize=function(n,e)if(e>0)and(e<=4)then a=e-1 or 0 end
  2957. n:updateDraw()return n end,getFontSize=function(e)return a+1 end,setValuesByXMLData=function(o,e)n.setValuesByXMLData(o,e)if(t("text",e)~=nil)then o:setText(t("text",e))end
  2958. if(t("verticalAlign",e)~=nil)then r=t("verticalAlign",e)end if(t("horizontalAlign",e)~=nil)then
  2959. c=t("horizontalAlign",e)end if(t("font",e)~=nil)then
  2960. o:setFontSize(t("font",e))end return o end,setSize=function(e,t,o,r)n.setSize(e,t,o,r)l=false e:updateDraw()return e end,eventHandler=function(e,t)if(t=="basalt_resize")then
  2961. if(l)then local t=e:getValue()if(t:len()+e:getX()>e.parent:getWidth())then local o=e.parent:getWidth()-e:getX()n.setSize(e,o,#i(t,o))else n.setSize(e,t:len(),1)end else end end end,draw=function(e)if(n.draw(e))then
  2962. if(e.parent~=nil)then local n,t=e:getAnchorPosition()local c,o=e:getSize()local r=d.getTextVerticalAlign(o,r)if(a==0)then
  2963. if not(l)then
  2964. local l=i(e:getValue(),e:getWidth())for l,r in pairs(l)do if(l<=o)then
  2965. e.parent:writeText(n,t+l-1,r,e.bgColor,e.fgColor)end end else
  2966. if(#e:getValue()+n>e.parent:getWidth())then local l=i(e:getValue(),e:getWidth())for l,r in
  2967. pairs(l)do if(l<=o)then
  2968. e.parent:writeText(n,t+l-1,r,e.bgColor,e.fgColor)end end else
  2969. e.parent:writeText(n,t,e:getValue(),e.bgColor,e.fgColor)end end else
  2970. local o=f(a,e:getValue(),e.fgColor,e.bgColor or colors.lightGray)if(l)then e:setSize(#o[1][1],#o[1]-1)end local i,a=e.parent:getSize()local r,l=#o[1][1],#o[1]n=n or math.floor((i-r)/2)+1
  2971. t=t or math.floor((a-l)/2)+1
  2972. for l=1,l do
  2973. e.parent:setFG(n,t+l-1,o[2][l])e.parent:setBG(n,t+l-1,o[3][l])e.parent:setText(n,t+l-1,o[1][l])end end end end end,init=function(e)e.parent:addEvent("other_event",e)if(n.init(e))then
  2974. e.bgColor=e.parent:getTheme("LabelBG")e.fgColor=e.parent:getTheme("LabelText")if(e.parent.bgColor==colors.black)and(e.fgColor==colors.black)then e.fgColor=colors.lightGray end end end}return setmetatable(e,n)end end
  2975. r["objects"]["Image"]=function(...)local e=l("Object")local c=l("utils").getValueFromXML local d=l("images")local s,a=table.unpack,string.sub
  2976. return
  2977. function(n)local o=e(n)local u="Image"o:setZIndex(2)local e local l local n=1 local i=false local t local r=false o.width=24
  2978. o.height=8
  2979. local function f(t)if(e~=nil)then local n={}for t,e in pairs(colors)do if(type(e)=="number")then
  2980. n[t]={term.nativePaletteColor(e)}end end if(e.palette~=nil)then
  2981. for t,e in pairs(e.palette)do n[t]=tonumber(e)end end
  2982. if(e[t]~=nil)and(e[t].palette~=nil)then for e,t in pairs(e[t].palette)do
  2983. n[e]=tonumber(t)end end return n end end
  2984. local e={init=function(e)if(o.init(e))then
  2985. e.bgColor=e.parent:getTheme("ImageBG")end end,getType=function(e)return
  2986. u end,loadImage=function(r,o,a)if not(fs.exists(o))then
  2987. error("No valid path: "..o)end e=d.loadImageAsBimg(o,a)n=1 l=e if(t~=nil)then os.cancelTimer(t)end
  2988. r:updateDraw()return r end,setImage=function(o,r)e=r l=e n=1 if(t~=nil)then os.cancelTimer(t)end
  2989. o:updateDraw()return o end,usePalette=function(n,e)r=e~=nil and e or true return n end,play=function(o,l)if(e.animated)then
  2990. local e=e[n].duration or e.secondsPerFrame or .2 o.parent:addEvent("other_event",o)t=os.startTimer(e)i=l or false end return o end,selectFrame=function(l,o)if(e[o]~=nil)then n=o if(t~=nil)then os.cancelTimer(t)end
  2991. l:updateDraw()end end,eventHandler=function(l,r,a,...)o.eventHandler(l,r,a,...)if(r=="timer")then
  2992. if(a==t)then
  2993. if(e[n+1]~=nil)then n=n+1 local e=e[n].duration or e.secondsPerFrame or .2
  2994. t=os.startTimer(e)else
  2995. if(i)then n=1
  2996. local e=e[n].duration or e.secondsPerFrame or .2 t=os.startTimer(e)end end l:updateDraw()end end end,getMetadata=function(t,n)return
  2997. e[n]end,getImageSize=function(n)return e.width,e.height end,resizeImage=function(n,t,o)l=d.resizeBIMG(e,t,o)n:updateDraw()return n end,setValuesByXMLData=function(e,n)o.setValuesByXMLData(e,n)if(c("path",n)~=nil)then e:loadImage(c("path",n))end return e end,draw=function(e)if(o.draw(e))then
  2998. if(l~=nil)then if(r)then
  2999. e:getBaseFrame():setThemeColor(f(n))end local i,c=e:getAnchorPosition()local r,d=e:getSize()for l,n in ipairs(l[n])do local o,t,n=s(n)o=a(o,1,r)t=a(t,1,r)n=a(n,1,r)e.parent:blit(i,c+l-1,o,t,n)if(l==d)then break end end end end end}return setmetatable(e,o)end end
  3000. r["objects"]["Menubar"]=function(...)local e=l("Object")local n=l("utils")local t=n.getValueFromXML local c=l("tHex")return
  3001. function(n)local l=e(n)local a="Menubar"local h={}l.width=30 l.height=1
  3002. l:setZIndex(5)local e={}local s local u local i=true local n="left"local n=0 local o=1 local d=false
  3003. local function f()local n=0 local t=0
  3004. local r=h:getWidth()for l=1,#e do if(t+e[l].text:len()+o*2>r)then
  3005. if(t<r)then
  3006. n=n+(e[l].text:len()+o*2-(r-t))else n=n+e[l].text:len()+o*2 end end t=t+e[l].text:len()+o*2 end return n end
  3007. h={getType=function(e)return a end,addItem=function(n,l,o,t,...)table.insert(e,{text=tostring(l),bgCol=o or n.bgColor,fgCol=t or n.fgColor,args={...}})if(#e==1)then n:setValue(e[1])end
  3008. n:updateDraw()return n end,getAll=function(n)return
  3009. e end,getItemIndex=function(n)local n=n:getValue()for e,t in pairs(e)do
  3010. if(t==n)then return e end end end,clear=function(n)e={}n:setValue({},false)n:updateDraw()return n end,setSpace=function(e,n)o=n or o e:updateDraw()return e end,setOffset=function(t,e)n=e or 0 if(n<0)then n=0 end local e=f()if(n>e)then n=e end
  3011. t:updateDraw()return t end,getOffset=function(e)return n end,setScrollable=function(n,e)d=e if(e==nil)then d=true end return n end,setValuesByXMLData=function(n,e)l.setValuesByXMLData(n,e)if(t("selectionBG",e)~=nil)then
  3012. s=colors[t("selectionBG",e)]end if(t("selectionFG",e)~=nil)then
  3013. u=colors[t("selectionFG",e)]end if(t("scrollable",e)~=nil)then
  3014. if(t("scrollable",e))then n:setScrollable(true)else n:setScrollable(false)end end
  3015. if(t("offset",e)~=nil)then n:setOffset(t("offset",e))end
  3016. if(t("space",e)~=nil)then o=t("space",e)end
  3017. if(e["item"]~=nil)then local e=e["item"]if(e.properties~=nil)then e={e}end for o,e in pairs(e)do
  3018. n:addItem(t("text",e),colors[t("bg",e)],colors[t("fg",e)])end end return n end,removeItem=function(n,t)table.remove(e,t)n:updateDraw()return n end,getItem=function(t,n)return e[n]end,getItemCount=function(n)return#e end,editItem=function(n,t,r,o,l,...)table.remove(e,t)table.insert(e,t,{text=r,bgCol=o or n.bgColor,fgCol=l or n.fgColor,args={...}})n:updateDraw()return n end,selectItem=function(n,t)n:setValue(e[t]or{},false)n:updateDraw()return n end,setSelectedItem=function(e,o,t,n)s=o or e.bgColor u=t or e.fgColor i=n
  3019. e:updateDraw()return e end,mouseHandler=function(t,r,a,i)if(l.mouseHandler(t,r,a,i))then
  3020. local d,c=t:getAbsolutePosition(t:getAnchorPosition())local l,l=t:getSize()local r=0
  3021. for l=1,#e do
  3022. if(e[l]~=nil)then
  3023. if(d+r<=a+n)and(d+r+e[l].text:len()+(o*2)>a+n)and(c==i)then
  3024. t:setValue(e[l])t:getEventSystem():sendEvent(event,t,event,0,a,i,e[l])end r=r+e[l].text:len()+o*2 end end t:updateDraw()return true end return false end,scrollHandler=function(t,e,o,r)if(l.scrollHandler(t,e,o,r))then if(d)then n=n+e if(n<0)then n=0 end local e=f()if(n>e)then n=e end
  3025. t:updateDraw()end return true end return false end,draw=function(t)if(l.draw(t))then
  3026. if(t.parent~=nil)then local d,i=t:getAnchorPosition()local a,l=t:getSize()if(t.bgColor~=false)then
  3027. t.parent:drawBackgroundBox(d,i,a,l,t.bgColor)end local f=""local l=""local r=""for n,e in pairs(e)do
  3028. local n=(" "):rep(o)..e.text..(" "):rep(o)f=f..n
  3029. if(e==t:getValue())then l=l..c[s or e.bgCol or t.bgColor]:rep(n:len())r=r..c[u or e.FgCol or t.fgColor]:rep(n:len())else l=l..c[e.bgCol or t.bgColor]:rep(n:len())r=r..c[e.FgCol or t.fgColor]:rep(n:len())end end
  3030. t.parent:setText(d,i,f:sub(n+1,a+n))t.parent:setBG(d,i,l:sub(n+1,a+n))t.parent:setFG(d,i,r:sub(n+1,a+n))end end end,init=function(e)e.parent:addEvent("mouse_click",e)e.parent:addEvent("mouse_scroll",e)if(l.init(e))then e.bgColor=e.parent:getTheme("MenubarBG")e.fgColor=e.parent:getTheme("MenubarText")s=e.parent:getTheme("SelectionBG")u=e.parent:getTheme("SelectionText")end end}return setmetatable(h,l)end end
  3031. r["objects"]["Dropdown"]=function(...)local n=l("Object")local d=l("utils")local t=l("utils").getValueFromXML
  3032. return
  3033. function(e)local a=n(e)local i="Dropdown"a.width=12 a.height=1 a:setZIndex(6)local e={}local c local s local m=true local u="left"local n=0 local r=16 local l=6 local g="\16"local p="\31"local o=false
  3034. local e={getType=function(e)return
  3035. i end,setValuesByXMLData=function(o,e)a.setValuesByXMLData(o,e)if(t("selectionBG",e)~=nil)then c=colors[t("selectionBG",e)]end if(t("selectionFG",e)~=nil)then
  3036. s=colors[t("selectionFG",e)]end if(t("dropdownWidth",e)~=nil)then
  3037. r=t("dropdownWidth",e)end if(t("dropdownHeight",e)~=nil)then
  3038. l=t("dropdownHeight",e)end if(t("offset",e)~=nil)then
  3039. n=t("offset",e)end
  3040. if(e["item"]~=nil)then local e=e["item"]if(e.properties~=nil)then e={e}end for n,e in pairs(e)do
  3041. o:addItem(t("text",e),colors[t("bg",e)],colors[t("fg",e)])end end end,setOffset=function(e,t)n=t e:updateDraw()return e end,getOffset=function(e)return n end,addItem=function(n,t,o,l,...)table.insert(e,{text=t,bgCol=o or n.bgColor,fgCol=l or n.fgColor,args={...}})n:updateDraw()return n end,getAll=function(n)return
  3042. e end,removeItem=function(n,t)table.remove(e,t)n:updateDraw()return n end,getItem=function(t,n)return e[n]end,getItemIndex=function(n)local t=n:getValue()for n,e in pairs(e)do if(e==t)then return n end end end,clear=function(n)e={}n:setValue({},false)n:updateDraw()return n end,getItemCount=function(n)return#e end,editItem=function(n,t,l,r,o,...)table.remove(e,t)table.insert(e,t,{text=l,bgCol=r or n.bgColor,fgCol=o or n.fgColor,args={...}})n:updateDraw()return n end,selectItem=function(n,t)n:setValue(e[t]or{},false)n:updateDraw()return n end,setSelectedItem=function(e,o,t,n)c=o or e.bgColor s=t or e.fgColor
  3043. m=n~=nil and n e:updateDraw()return e end,setDropdownSize=function(e,n,t)r,l=n,t e:updateDraw()return e end,getDropdownSize=function(e)return r,l end,mouseHandler=function(t,c,i,d)if(o)then
  3044. local a,s=t:getAbsolutePosition(t:getAnchorPosition())if(c==1)then
  3045. if(#e>0)then
  3046. for o=1,l do
  3047. if(e[o+n]~=nil)then
  3048. if(a<=i)and(a+r>i)and(s+o==d)then t:setValue(e[o+n])t:updateDraw()local e=t:getEventSystem():sendEvent("mouse_click",t,"mouse_click",dir,i,d)if(e==false)then return e end return true end end end end end end
  3049. if(a.mouseHandler(t,c,i,d))then o=(not o)t:updateDraw()return true else if(o)then t:updateDraw()o=false end return false end end,mouseUpHandler=function(t,c,a,i)if(o)then
  3050. local d,s=t:getAbsolutePosition(t:getAnchorPosition())if(c==1)then
  3051. if(#e>0)then
  3052. for l=1,l do
  3053. if(e[l+n]~=nil)then
  3054. if(d<=a)and(d+r>a)and(s+l==i)then o=false t:updateDraw()local e=t:getEventSystem():sendEvent("mouse_up",t,"mouse_up",dir,a,i)if(e==false)then return e end return true end end end end end end end,scrollHandler=function(t,r,a,i)if(o)and(t:isFocused())then n=n+r if(n<0)then n=0 end if(r==1)then
  3055. if(#e>l)then if(n>#e-l)then n=#e-l end else n=math.min(#e-1,0)end end
  3056. local e=t:getEventSystem():sendEvent("mouse_scroll",t,"mouse_scroll",r,a,i)if(e==false)then return e end t:updateDraw()return true end end,draw=function(t)if(a.draw(t))then local a,i=t:getAnchorPosition()local f,h=t:getSize()if(t.parent~=nil)then if(t.bgColor~=false)then
  3057. t.parent:drawBackgroundBox(a,i,f,h,t.bgColor)end local h=t:getValue()local f=d.getTextHorizontalAlign((h~=nil and h.text or""),f,u):sub(1,f-1)..(o and p or g)t.parent:writeText(a,i,f,t.bgColor,t.fgColor)if(o)then
  3058. for o=1,l do
  3059. if(e[o+n]~=nil)then
  3060. if(e[o+n]==h)then
  3061. if(m)then
  3062. t.parent:writeText(a,i+o,d.getTextHorizontalAlign(e[o+n].text,r,u),c,s)else
  3063. t.parent:writeText(a,i+o,d.getTextHorizontalAlign(e[o+n].text,r,u),e[o+n].bgCol,e[o+n].fgCol)end else
  3064. t.parent:writeText(a,i+o,d.getTextHorizontalAlign(e[o+n].text,r,u),e[o+n].bgCol,e[o+n].fgCol)end end end end end end end,init=function(e)e.parent:addEvent("mouse_click",e)e.parent:addEvent("mouse_up",e)e.parent:addEvent("mouse_scroll",e)if(a.init(e))then
  3065. e.bgColor=e.parent:getTheme("DropdownBG")e.fgColor=e.parent:getTheme("DropdownText")c=e.parent:getTheme("SelectionBG")s=e.parent:getTheme("SelectionText")end end}return setmetatable(e,a)end end
  3066. r["objects"]["Animation"]=function(...)local t=l("utils").getValueFromXML
  3067. local f=l("basaltEvent")local e,o,s,n,l,i=math.floor,math.sin,math.cos,math.pi,math.sqrt,math.pow
  3068. local c=function(e,n,t)return e+(n-e)*t end local h=function(e)return e end
  3069. local a=function(e)return 1-e end local d=function(e)return e*e*e end local u=function(e)return
  3070. a(d(a(e)))end local z=function(e)return
  3071. c(d(e),u(e),e)end local F=function(e)return
  3072. o((e*n)/2)end local D=function(e)return
  3073. a(s((e*n)/2))end local H=function(e)return-(s(n*x)-1)/2 end
  3074. local E=function(e)local n=1.70158 local t=n+1 return t*e^3-n*e^2 end local V=function(e)return e^3 end
  3075. local M=function(e)local n=(2*n)/3 return
  3076. e==0 and 0 or(e==1 and 1 or(-2^(10*e-10)*o((e*10-10.75)*n)))end
  3077. local function e(e)return e==0 and 0 or 2^(10*e-10)end
  3078. local function P(e)return e==0 and 0 or 2^(10*e-10)end
  3079. local function A(e)local n=1.70158 local n=n*1.525 return
  3080. e<.5 and((2*e)^2*((n+1)*2*e-n))/2 or((2*e-2)^2*((n+1)*(e*2-2)+n)+2)/2 end local function B(e)return
  3081. e<.5 and 4*e^3 or 1-(-2*e+2)^3/2 end
  3082. local function _(e)local n=(2*n)/4.5
  3083. return
  3084. e==0 and 0 or(e==1 and 1 or(e<.5 and-(2^(20*e-10)*o((20*e-11.125)*n))/2 or(2^(-20*e+10)*o((20*e-11.125)*n))/2+1))end
  3085. local function y(e)return
  3086. e==0 and 0 or(e==1 and 1 or(e<.5 and 2^(20*e-10)/2 or(2-2^(-20*e+10))/2))end local function g(e)return
  3087. e<.5 and 2*e^2 or 1-(-2*e+2)^2/2 end local function b(e)return
  3088. e<.5 and 8*e^4 or 1-(-2*e+2)^4/2 end local function p(e)return
  3089. e<.5 and 16*e^5 or 1-(-2*e+2)^5/2 end local function s(e)return e^2 end local function m(e)return e^4 end
  3090. local function w(e)return e^5 end local function v(e)local n=1.70158 local t=n+1 return
  3091. 1+t*(e-1)^3+n*(e-1)^2 end local function S(e)return 1-(1-e)^3 end
  3092. local function k(e)local n=(2*n)/3 return
  3093. e==0 and 0 or(e==1 and 1 or(2^(-10*e)*o((e*10-.75)*n)+1))end
  3094. local function C(e)return e==1 and 1 or 1-2^(-10*e)end local function T(e)return 1-(1-e)*(1-e)end local function I(e)return 1-(1-e)^4 end local function j(e)return 1-(1-e)^5 end
  3095. local function G(e)return 1-l(1-i(e,2))end local function L(e)return l(1-i(e-1,2))end
  3096. local function O(e)return
  3097. e<.5 and(1-l(1-i(2*e,2)))/2 or(l(1-i(-2*e+2,2))+1)/2 end
  3098. local function o(e)local t=7.5625 local n=2.75
  3099. if(e<1/n)then return t*e*e elseif(e<2/n)then local e=e-1.5/n return t*e*e+.75 elseif(e<2.5/n)then local e=e-2.25/n return t*e*e+.9375 else
  3100. local e=e-2.625/n return t*e*e+.984375 end end local function n(e)return 1-o(1-e)end local function l(e)return
  3101. x<.5 and(1-o(1-2*e))/2 or(1+o(2*e-1))/2 end
  3102. local c={linear=h,lerp=c,flip=a,easeIn=d,easeInSine=D,easeInBack=E,easeInCubic=V,easeInElastic=M,easeInExpo=P,easeInQuad=s,easeInQuart=m,easeInQuint=w,easeInCirc=G,easeInBounce=n,easeOut=u,easeOutSine=F,easeOutBack=v,easeOutCubic=S,easeOutElastic=k,easeOutExpo=C,easeOutQuad=T,easeOutQuart=I,easeOutQuint=j,easeOutCirc=L,easeOutBounce=o,easeInOut=z,easeInOutSine=H,easeInOutBack=A,easeInOutCubic=B,easeInOutElastic=_,easeInOutExpo=y,easeInOutQuad=g,easeInOutQuart=b,easeInOutQuint=p,easeInOutCirc=O,easeInOutBounce=l}local a={}return
  3103. function(v)local i={}local x="Animation"local u local n={}local d=0 local _=false local l=1 local p=false
  3104. local m=f()local h=0 local f local b=false local g=false local s="easeOut"local o local function r(e)for t,e in pairs(e)do
  3105. e(i,n[l].t,l)end end
  3106. local function y(e)if(l==1)then
  3107. e:animationStartHandler()end if(n[l]~=nil)then r(n[l].f)d=n[l].t end l=l+1
  3108. if(n[l]==nil)then if(p)then l=1 d=0 else
  3109. e:animationDoneHandler()return end end if(n[l].t>0)then
  3110. u=os.startTimer(n[l].t-d)else y(e)end end
  3111. local function r(e,o)for t=1,#n do
  3112. if(n[t].t==e)then table.insert(n[t].f,o)return end end
  3113. for t=1,#n do
  3114. if(n[t].t>e)then if(n[t-1]~=nil)then if(n[t-1].t<e)then
  3115. table.insert(n,t-1,{t=e,f={o}})return end else
  3116. table.insert(n,t,{t=e,f={o}})return end end end
  3117. if(#n<=0)then table.insert(n,1,{t=e,f={o}})return elseif(n[#n].t<e)then table.insert(n,{t=e,f={o}})end end
  3118. local function w(b,g,l,u,m,p,e,d)local t=o local f,h local n=""if(t.parent~=nil)then
  3119. n=t.parent:getName()end n=n..t:getName()r(u+.05,function()if(e~=nil)then if(a[e]==nil)then a[e]={}end if(a[e][n]~=nil)then
  3120. if(a[e][n]~=d)then a[e][n]:cancel()end end a[e][n]=d end f,h=m(t)end)for o=.05,l+.01,.05 do
  3121. r(u+o,function()local r=math.floor(c.lerp(f,b,c[s](o/l))+.5)local i=math.floor(c.lerp(h,g,c[s](o/l))+.5)p(t,r,i)if(e~=nil)then if(o>=l-.01)then if(a[e][n]==d)then a[e][n]=nil end end end end)end end
  3122. i={name=v,getType=function(e)return x end,getBaseFrame=function(e)if(e.parent~=nil)then
  3123. return e.parent:getBaseFrame()end return e end,setMode=function(n,e)s=e return n end,addMode=function(t,e,n)c[e]=n return t end,generateXMLEventFunction=function(e,t,n)local t=function(n)if(n:sub(1,1)=="#")then
  3124. local n=e:getBaseFrame():getDeepObject(n:sub(2,n:len()))if(n~=nil)and(n.internalObjetCall~=nil)then t(e,function()n:internalObjetCall()end)end else
  3125. t(e,e:getBaseFrame():getVariable(n))end end if(type(n)=="string")then t(n)elseif(type(n)=="table")then
  3126. for n,e in pairs(n)do t(e)end end return e end,setValuesByXMLData=function(n,e)b=t("loop",e)==true and true or false
  3127. if(t("object",e)~=nil)then
  3128. local o=n:getBaseFrame():getDeepObject(t("object",e))if(o==nil)then
  3129. o=n:getBaseFrame():getVariable(t("object",e))end
  3130. if(o~=nil)then n:setObject(o)end end
  3131. if(e["move"]~=nil)then local o=t("x",e["move"])local l=t("y",e["move"])local r=t("duration",e["move"])local e=t("time",e["move"])n:move(o,l,r,e)end
  3132. if(e["size"]~=nil)then local o=t("width",e["size"])local r=t("height",e["size"])local l=t("duration",e["size"])local e=t("time",e["size"])n:size(o,r,l,e)end
  3133. if(e["offset"]~=nil)then local r=t("x",e["offset"])local o=t("y",e["offset"])local l=t("duration",e["offset"])local e=t("time",e["offset"])n:offset(r,o,l,e)end
  3134. if(e["textColor"]~=nil)then
  3135. local o=t("duration",e["textColor"])local l=t("time",e["textColor"])local t={}local e=e["textColor"]["color"]if(e~=nil)then if(e.properties~=nil)then e={e}end for n,e in pairs(e)do
  3136. table.insert(t,colors[e:value()])end end if(o~=nil)and(#t>0)then
  3137. n:changeTextColor(o,l or 0,table.unpack(t))end end
  3138. if(e["background"]~=nil)then
  3139. local o=t("duration",e["background"])local l=t("time",e["background"])local t={}local e=e["background"]["color"]if(e~=nil)then if(e.properties~=nil)then e={e}end for n,e in pairs(e)do
  3140. table.insert(t,colors[e:value()])end end if(o~=nil)and(#t>0)then
  3141. n:changeBackground(o,l or 0,table.unpack(t))end end
  3142. if(e["text"]~=nil)then local o=t("duration",e["text"])local l=t("time",e["text"])local t={}local e=e["text"]["text"]if(e~=nil)then if(e.properties~=nil)then
  3143. e={e}end for n,e in pairs(e)do
  3144. table.insert(t,e:value())end end if(o~=nil)and(#t>0)then
  3145. n:changeText(o,l or 0,table.unpack(t))end end if(t("onDone",e)~=nil)then
  3146. n:generateXMLEventFunction(n.onDone,t("onDone",e))end if(t("onStart",e)~=nil)then
  3147. n:generateXMLEventFunction(n.onDone,t("onStart",e))end
  3148. if(t("autoDestroy",e)~=nil)then if(t("autoDestroy",e))then g=true end end s=t("mode",e)or s
  3149. if(t("play",e)~=nil)then if(t("play",e))then n:play(b)end end return n end,getZIndex=function(e)return
  3150. 1 end,getName=function(e)return e.name end,setObject=function(n,e)o=e return n end,move=function(e,a,r,l,n,t)o=t or o
  3151. w(a,r,l,n or 0,o.getPosition,o.setPosition,"position",e)return e end,offset=function(e,n,t,l,a,r)o=r or o
  3152. w(n,t,l,a or 0,o.getOffset,o.setOffset,"offset",e)return e end,size=function(e,a,l,r,t,n)o=n or
  3153. o
  3154. w(a,l,r,t or 0,o.getSize,o.setSize,"size",e)return e end,changeText=function(l,a,e,...)local n={...}e=e or 0 o=obj or o for t=1,#n do
  3155. r(e+t*(a/#n),function()o.setText(o,n[t])end)end return l end,changeBackground=function(a,l,n,...)local e={...}n=n or 0 o=obj or o for t=1,#e do
  3156. r(n+t*(l/#e),function()o.setBackground(o,e[t])end)end return a end,changeTextColor=function(a,l,n,...)local e={...}n=n or 0 o=obj or o for t=1,#e do
  3157. r(n+t*(l/#e),function()o.setForeground(o,e[t])end)end return a end,add=function(t,e,o)f=e
  3158. r((o or h)+(n[#n]~=nil and n[#n].t or 0),e)return t end,wait=function(e,n)h=n return e end,rep=function(e,t)if(f~=nil)then for e=1,t or 1 do
  3159. r((wait or h)+(n[#n]~=nil and n[#n].t or 0),f)end end return e end,onDone=function(e,n)m:registerEvent("animation_done",n)return e end,onStart=function(e,n)m:registerEvent("animation_start",n)return e end,setAutoDestroy=function(n,e)g=e~=nil and e or true return n end,animationDoneHandler=function(e)m:sendEvent("animation_done",e)e.parent:removeEvent("other_event",e)if(g)then
  3160. e.parent:removeObject(e)e=nil end end,animationStartHandler=function(e)m:sendEvent("animation_start",e)end,clear=function(e)n={}f=nil h=0 l=1 d=0 p=false return e end,play=function(e,t)e:cancel()_=true p=t and true or false l=1 d=0
  3161. if(n[l]~=nil)then
  3162. if(n[l].t>0)then u=os.startTimer(n[l].t)else y(e)end else e:animationDoneHandler()end e.parent:addEvent("other_event",e)return e end,cancel=function(e)if(u~=nil)then os.cancelTimer(u)p=false end
  3163. _=false e.parent:removeEvent("other_event",e)return e end,internalObjetCall=function(e)e:play(b)end,eventHandler=function(e,o,t)if(_)then
  3164. if(o=="timer")and(t==u)then if(n[l]~=nil)then
  3165. y(e)else e:animationDoneHandler()end end end end}i.__index=i return i end end
  3166. r["objects"]["List"]=function(...)local n=l("Object")local i=l("utils")local t=i.getValueFromXML
  3167. return
  3168. function(e)local l=n(e)local o="List"l.width=16 l.height=6 l:setZIndex(5)local e={}local a local r local u=true local s="left"local n=0 local d=true
  3169. local e={getType=function(e)return o end,addItem=function(n,t,l,o,...)table.insert(e,{text=t,bgCol=l or n.bgColor,fgCol=o or n.fgColor,args={...}})if(#e<=1)then n:setValue(e[1],false)end
  3170. n:updateDraw()return n end,setOffset=function(e,t)n=t e:updateDraw()return e end,getOffset=function(e)return n end,removeItem=function(n,t)table.remove(e,t)n:updateDraw()return n end,getItem=function(t,n)return e[n]end,getAll=function(n)return e end,getItemIndex=function(n)local n=n:getValue()for e,t in pairs(e)do if(t==n)then return e end end end,clear=function(n)e={}n:setValue({},false)n:updateDraw()return n end,getItemCount=function(n)return#e end,editItem=function(n,t,l,o,r,...)table.remove(e,t)table.insert(e,t,{text=l,bgCol=o or n.bgColor,fgCol=r or n.fgColor,args={...}})n:updateDraw()return n end,selectItem=function(n,t)n:setValue(e[t]or{},false)n:updateDraw()return n end,setSelectedItem=function(e,t,o,n)a=t or e.bgColor r=o or e.fgColor u=n~=nil and n or
  3171. true e:updateDraw()return e end,setScrollable=function(n,e)d=e if(e==nil)then d=true end n:updateDraw()return n end,setValuesByXMLData=function(o,e)l.setValuesByXMLData(o,e)if(t("selectionBG",e)~=nil)then
  3172. a=colors[t("selectionBG",e)]end if(t("selectionFG",e)~=nil)then
  3173. r=colors[t("selectionFG",e)]end if(t("scrollable",e)~=nil)then
  3174. if(t("scrollable",e))then o:setScrollable(true)else o:setScrollable(false)end end if(t("offset",e)~=nil)then n=t("offset",e)end
  3175. if(e["item"]~=nil)then local e=e["item"]if(e.properties~=nil)then e={e}end for n,e in pairs(e)do
  3176. o:addItem(t("text",e),colors[t("bg",e)],colors[t("fg",e)])end end return o end,scrollHandler=function(o,t,r,a)if(l.scrollHandler(o,t,r,a))then
  3177. if(d)then local r,l=o:getSize()n=n+t if(n<0)then n=0 end
  3178. if(t>=1)then if(#e>l)then if(n>#e-l)then n=#e-l end if(n>=#e)then n=#e-1 end else n=n-1 end end o:updateDraw()end return true end return false end,mouseHandler=function(t,o,r,a)if(l.mouseHandler(t,o,r,a))then
  3179. local l,d=t:getAbsolutePosition(t:getAnchorPosition())local i,o=t:getSize()if(#e>0)then for o=1,o do
  3180. if(e[o+n]~=nil)then if(l<=r)and(l+i>r)and(d+o-1==a)then
  3181. t:setValue(e[o+n])t:updateDraw()end end end end return true end return false end,dragHandler=function(t,o,e,n)return
  3182. t:mouseHandler(o,e,n)end,touchHandler=function(t,n,e)return
  3183. t:mouseHandler(1,n,e)end,draw=function(o)if(l.draw(o))then
  3184. if(o.parent~=nil)then local d,l=o:getAnchorPosition()local c,t=o:getSize()if(o.bgColor~=false)then
  3185. o.parent:drawBackgroundBox(d,l,c,t,o.bgColor)end
  3186. for t=1,t do
  3187. if(e[t+n]~=nil)then
  3188. if(e[t+n]==o:getValue())then
  3189. if(u)then
  3190. o.parent:writeText(d,l+t-1,i.getTextHorizontalAlign(e[t+n].text,c,s),a,r)else
  3191. o.parent:writeText(d,l+t-1,i.getTextHorizontalAlign(e[t+n].text,c,s),e[t+n].bgCol,e[t+n].fgCol)end else
  3192. o.parent:writeText(d,l+t-1,i.getTextHorizontalAlign(e[t+n].text,c,s),e[t+n].bgCol,e[t+n].fgCol)end end end end end end,init=function(e)e.parent:addEvent("mouse_click",e)e.parent:addEvent("mouse_drag",e)e.parent:addEvent("mouse_scroll",e)if(l.init(e))then e.bgColor=e.parent:getTheme("ListBG")e.fgColor=e.parent:getTheme("ListText")a=e.parent:getTheme("SelectionBG")r=e.parent:getTheme("SelectionText")end end}return setmetatable(e,l)end end
  3193. r["objects"]["Pane"]=function(...)local n=l("Object")local e=l("basaltLogs")return
  3194. function(e)local n=n(e)local e="Pane"local e={getType=function(n)return e end,setBackground=function(e,t,l,o)n.setBackground(e,t,l,o)return e end,init=function(e)if(n.init(e))then
  3195. e.bgColor=e.parent:getTheme("PaneBG")e.fgColor=e.parent:getTheme("PaneBG")end end}return setmetatable(e,n)end end
  3196. r["objects"]["Program"]=function(...)local t=l("Object")local a=l("tHex")local E=l("process")local _=l("utils").getValueFromXML local n=string.sub
  3197. return
  3198. function(e,f)local t=t(e)local D="Program"t:setZIndex(5)local p local m local F={}local function P(g,y,e,d,o)local h,o=1,1
  3199. local u,s=colors.black,colors.white local z=false local c=false local i={}local r={}local l={}local _={}local C local b={}for e=0,15 do local e=2^e
  3200. _[e]={f:getBasaltInstance().getBaseTerm().getPaletteColour(e)}end local function m()C=(" "):rep(e)for n=0,15 do local n=2^n local t=a[n]b[n]=t:rep(e)end end
  3201. local function B()m()local a=C
  3202. local c=b[colors.white]local o=b[colors.black]for t=1,d do
  3203. i[t]=n(i[t]==nil and a or i[t]..a:sub(1,e-i[t]:len()),1,e)l[t]=n(l[t]==nil and c or l[t]..c:sub(1,e-l[t]:len()),1,e)r[t]=n(r[t]==nil and o or r[t]..o:sub(1,e-r[t]:len()),1,e)end t.updateDraw(t)end B()local function m()if
  3204. h>=1 and o>=1 and h<=e and o<=d then else end end
  3205. local function S(s,g,f)local t=h local a=t+#s-1
  3206. if o>=1 and o<=d then
  3207. if t<=e and a>=1 then
  3208. if t==1 and a==e then i[o]=s l[o]=g r[o]=f else local d,c,u
  3209. if t<1 then local o=1-t+1 local e=e-t+1 d=n(s,o,e)c=n(g,o,e)u=n(f,o,e)elseif a>e then local e=e-t+1 d=n(s,1,e)c=n(g,1,e)u=n(f,1,e)else d=s c=g u=f end local p=i[o]local m=l[o]local g=r[o]local f,s,h
  3210. if t>1 then local e=t-1 f=n(p,1,e)..d s=n(m,1,e)..c
  3211. h=n(g,1,e)..u else f=d s=c h=u end
  3212. if a<e then local t=a+1 f=f..n(p,t,e)s=s..n(m,t,e)h=h..n(g,t,e)end i[o]=f l[o]=s r[o]=h end p:updateDraw()end h=a+1 if(c)then m()end end end
  3213. local function w(r,l,o)if(o~=nil)then local t=i[l]if(t~=nil)then
  3214. i[l]=n(t:sub(1,r-1)..o..t:sub(r+(o:len()),e),1,e)end end p:updateDraw()end
  3215. local function x(a,l,o)if(o~=nil)then local t=r[l]if(t~=nil)then
  3216. r[l]=n(t:sub(1,a-1)..o..t:sub(a+(o:len()),e),1,e)end end p:updateDraw()end
  3217. local function v(a,r,o)if(o~=nil)then local t=l[r]if(t~=nil)then
  3218. l[r]=n(t:sub(1,a-1)..o..t:sub(a+(o:len()),e),1,e)end end p:updateDraw()end
  3219. local k=function(e)if type(e)~="number"then
  3220. error("bad argument #1 (expected number, got "..type(e)..")",2)elseif a[e]==nil then
  3221. error("Invalid color (got "..e..")",2)end s=e end
  3222. local T=function(e)if type(e)~="number"then
  3223. error("bad argument #1 (expected number, got "..type(e)..")",2)elseif a[e]==nil then
  3224. error("Invalid color (got "..e..")",2)end u=e end
  3225. local p=function(n,t,l,o)if type(n)~="number"then
  3226. error("bad argument #1 (expected number, got "..type(n)..")",2)end
  3227. if a[n]==nil then error("Invalid color (got "..n..")",2)end local e
  3228. if
  3229. type(t)=="number"and l==nil and o==nil then e={colours.rgb8(t)}_[n]=e else if
  3230. type(t)~="number"then
  3231. error("bad argument #2 (expected number, got "..type(t)..")",2)end if type(l)~="number"then
  3232. error("bad argument #3 (expected number, got "..type(l)..")",2)end if type(o)~="number"then
  3233. error("bad argument #4 (expected number, got "..type(o)..")",2)end e=_[n]e[1]=t
  3234. e[2]=l e[3]=o end end
  3235. local t=function(e)if type(e)~="number"then
  3236. error("bad argument #1 (expected number, got "..type(e)..")",2)end
  3237. if a[e]==nil then error("Invalid color (got "..e..")",2)end local e=_[e]return e[1],e[2],e[3]end
  3238. local e={setCursorPos=function(n,e)if type(n)~="number"then
  3239. error("bad argument #1 (expected number, got "..type(n)..")",2)end if type(e)~="number"then
  3240. error("bad argument #2 (expected number, got "..type(e)..")",2)end h=math.floor(n)o=math.floor(e)if(c)then m()end end,getCursorPos=function()return
  3241. h,o end,setCursorBlink=function(e)if type(e)~="boolean"then
  3242. error("bad argument #1 (expected boolean, got "..type(e)..")",2)end z=e end,getCursorBlink=function()return
  3243. z end,getPaletteColor=t,getPaletteColour=t,setBackgroundColor=T,setBackgroundColour=T,setTextColor=k,setTextColour=k,setPaletteColor=p,setPaletteColour=p,getBackgroundColor=function()return u end,getBackgroundColour=function()return u end,getSize=function()return e,d end,getTextColor=function()return s end,getTextColour=function()return s end,basalt_resize=function(t,n)e,d=t,n B()end,basalt_reposition=function(n,e)g,y=n,e end,basalt_setVisible=function(e)c=e end,drawBackgroundBox=function(t,o,l,n,e)for n=1,n do
  3244. x(t,o+(n-1),a[e]:rep(l))end end,drawForegroundBox=function(e,n,t,o,l)for o=1,o do v(e,n+(o-1),a[l]:rep(t))end end,drawTextBox=function(t,l,o,e,n)for e=1,e do
  3245. w(t,l+(e-1),n:rep(o))end end,writeText=function(l,o,n,t,e)t=t or u e=e or s w(g,o,n)x(l,o,a[t]:rep(n:len()))v(l,o,a[e]:rep(n:len()))end,basalt_update=function()if(f~=nil)then for e=1,d do f:setText(g,y+(e-1),i[e])f:setBG(g,y+(e-1),r[e])f:setFG(g,y+(e-1),l[e])end end end,scroll=function(n)if
  3246. type(n)~="number"then
  3247. error("bad argument #1 (expected number, got "..type(n)..")",2)end
  3248. if n~=0 then local t=C
  3249. local o=b[s]local a=b[u]for e=1,d do local n=e+n
  3250. if n>=1 and n<=d then
  3251. i[e]=i[n]r[e]=r[n]l[e]=l[n]else i[e]=t
  3252. l[e]=o r[e]=a end end end if(c)then m()end end,isColor=function()return
  3253. f:getBasaltInstance().getBaseTerm().isColor()end,isColour=function()return
  3254. f:getBasaltInstance().getBaseTerm().isColor()end,write=function(e)e=tostring(e)if(c)then
  3255. S(e,a[s]:rep(e:len()),a[u]:rep(e:len()))end end,clearLine=function()if(c)then w(1,o,(" "):rep(e))x(1,o,a[u]:rep(e))v(1,o,a[s]:rep(e))end if(c)then m()end end,clear=function()for n=1,d
  3256. do w(1,n,(" "):rep(e))x(1,n,a[u]:rep(e))v(1,n,a[s]:rep(e))end if(c)then m()end end,blit=function(e,n,t)if
  3257. type(e)~="string"then
  3258. error("bad argument #1 (expected string, got "..type(e)..")",2)end if type(n)~="string"then
  3259. error("bad argument #2 (expected string, got "..type(n)..")",2)end if type(t)~="string"then
  3260. error("bad argument #3 (expected string, got "..type(t)..")",2)end
  3261. if#n~=#e or#t~=#e then error("Arguments must be the same length",2)end if(c)then S(e,n,t)end end}return e end t.width=30 t.height=12 local e=P(1,1,t.width,t.height)local n
  3262. local o=false local a={}local function d(o)local l,r=e.getCursorPos()local t,n=o:getAnchorPosition()local a,i=o:getSize()if(t+l-1>=1 and
  3263. t+l-1<=t+a-1 and r+n-1>=1 and
  3264. r+n-1<=n+i-1)then
  3265. o.parent:setCursor(o:isFocused()and e.getCursorBlink(),t+l-1,r+n-1,e.getTextColor())end end
  3266. local function l(t,e,...)local o,e=n:resume(e,...)if(o==false)and(e~=nil)and(e~="Terminated")then
  3267. local n=t:sendEvent("program_error",e)if(n~=false)then error("Basalt Program - "..e)end end
  3268. if(n:getStatus()=="dead")then t:sendEvent("program_done")end end
  3269. local function r(e,c,i,a,r)if(n==nil)then return false end
  3270. if not(n:isDead())then if not(o)then
  3271. local t,n=e:getAbsolutePosition(e:getAnchorPosition(nil,nil,true))l(e,c,i,a-t+1,r-n+1)d(e)end end end
  3272. local function i(e,t,a,r)if(n==nil)then return false end
  3273. if not(n:isDead())then if not(o)then if(e.draw)then
  3274. l(e,t,a,r)d(e)end end end end
  3275. p={getType=function(e)return D end,show=function(n)t.show(n)e.setBackgroundColor(n.bgColor)e.setTextColor(n.fgColor)e.basalt_setVisible(true)return n end,hide=function(n)t.hide(n)e.basalt_setVisible(false)return n end,setPosition=function(n,l,o,r)t.setPosition(n,l,o,r)e.basalt_reposition(n:getAnchorPosition())return n end,setValuesByXMLData=function(n,e)t.setValuesByXMLData(n,e)if(_("path",e)~=nil)then m=_("path",e)end
  3276. if(_("execute",e)~=nil)then if(_("execute",e))then
  3277. if(m~=nil)then n:execute(m)end end end end,getBasaltWindow=function()return
  3278. e end,getBasaltProcess=function()return n end,setSize=function(n,o,l,r)t.setSize(n,o,l,r)e.basalt_resize(n:getWidth(),n:getHeight())return n end,getStatus=function(e)if(n~=nil)then return
  3279. n:getStatus()end return"inactive"end,setEnviroment=function(e,n)F=n or{}return e end,execute=function(t,r,...)m=r or m
  3280. n=E:new(m,e,F,...)e.setBackgroundColor(colors.black)e.setTextColor(colors.white)e.clear()e.setCursorPos(1,1)e.setBackgroundColor(t.bgColor)e.setTextColor(t.fgColor)e.basalt_setVisible(true)l(t)o=false
  3281. if(t.parent~=nil)then
  3282. t.parent:addEvent("mouse_click",t)t.parent:addEvent("mouse_up",t)t.parent:addEvent("mouse_drag",t)t.parent:addEvent("mouse_scroll",t)t.parent:addEvent("key",t)t.parent:addEvent("key_up",t)t.parent:addEvent("char",t)t.parent:addEvent("other_event",t)end return t end,stop=function(e)if(n~=nil)then
  3283. if not(n:isDead())then l(e,"terminate")if(n:isDead())then
  3284. if(e.parent~=nil)then e.parent:setCursor(false)end end end end e.parent:removeEvents(e)return e end,pause=function(e,t)o=t or(not o)if(n~=nil)then if not(n:isDead())then if not(o)then
  3285. e:injectEvents(a)a={}end end end return e end,isPaused=function(e)return
  3286. o end,injectEvent=function(e,t,r,i,d,c,s)if(n~=nil)then
  3287. if not(n:isDead())then if(o==false)or(s)then
  3288. l(e,t,r,i,d,c)else
  3289. table.insert(a,{event=t,args={r,i,d,c}})end end end return e end,getQueuedEvents=function(e)return
  3290. a end,updateQueuedEvents=function(n,e)a=e or a return n end,injectEvents=function(e,t)if(n~=nil)then
  3291. if not(n:isDead())then for t,n in pairs(t)do
  3292. l(e,n.event,table.unpack(n.args))end end end return e end,mouseHandler=function(o,l,n,e)if(t.mouseHandler(o,l,n,e))then r(o,"mouse_click",l,n,e)return true end return false end,mouseUpHandler=function(o,n,e,l)if(t.mouseUpHandler(o,n,e,l))then r(o,"mouse_up",n,e,l)return true end return false end,scrollHandler=function(o,l,e,n)if(t.scrollHandler(o,l,e,n))then r(o,"mouse_scroll",l,e,n)return true end return false end,dragHandler=function(l,o,n,e)if(t.dragHandler(l,o,n,e))then r(l,"mouse_drag",o,n,e)return true end return false end,keyHandler=function(e,o,n)if(t.keyHandler(e,o,n))then i(e,"key",o,n)return true end return
  3293. false end,keyUpHandler=function(n,e)if(t.keyUpHandler(n,e))then i(n,"key_up",e)return true end
  3294. return false end,charHandler=function(n,e)if(t.charHandler(n,e))then i(n,"char",e)return true end
  3295. return false end,getFocusHandler=function(l)t.getFocusHandler(l)if(n~=nil)then
  3296. if not(n:isDead())then
  3297. if not(o)then
  3298. if(l.parent~=nil)then
  3299. local o,r=e.getCursorPos()local n,t=l:getAnchorPosition()local a,i=l:getSize()if(n+o-1>=1 and n+o-1<=n+a-1 and
  3300. r+t-1>=1 and r+t-1<=t+i-1)then
  3301. l.parent:setCursor(e.getCursorBlink(),n+o-1,r+t-1,e.getTextColor())end end end end end end,loseFocusHandler=function(e)t.loseFocusHandler(e)if(n~=nil)then if not(n:isDead())then if(e.parent~=nil)then
  3302. e.parent:setCursor(false)end end end end,customEventHandler=function(o,r,...)t.customEventHandler(o,r,...)if(n==nil)then return end
  3303. if(r=="basalt_resize")then local i,a=e.getSize()local t,r=o:getSize()if(i~=t)or(a~=r)then e.basalt_resize(t,r)if not(n:isDead())then l(o,"term_resize")end end
  3304. e.basalt_reposition(o:getAnchorPosition())end end,eventHandler=function(r,i,u,s,c,d)t.eventHandler(r,i,u,s,c,d)if(n==nil)then return end
  3305. if not(n:isDead())then
  3306. if not(o)then if(i~="terminate")then
  3307. l(r,i,u,s,c,d)end
  3308. if(r:isFocused())then
  3309. local n,t=r:getAnchorPosition()local o,a=e.getCursorPos()if(r.parent~=nil)then
  3310. local l,i=r:getSize()if(n+o-1>=1 and n+o-1<=n+l-1 and
  3311. a+t-1>=1 and a+t-1<=t+i-1)then
  3312. r.parent:setCursor(e.getCursorBlink(),n+o-1,a+t-1,e.getTextColor())end end if(i=="terminate")then l(r,i)r.parent:setCursor(false)return true end end else
  3313. table.insert(a,{event=i,args={u,s,c,d}})end end end,draw=function(n)if(t.draw(n))then
  3314. if(n.parent~=nil)then local t,o=n:getAnchorPosition()local r,l=e.getCursorPos()local a,i=n:getSize()e.basalt_reposition(t,o)e.basalt_update()if(t+r-1>=1 and t+r-1<=t+a-1 and
  3315. l+o-1>=1 and l+o-1<=o+i-1)then
  3316. n.parent:setCursor(n:isFocused()and e.getCursorBlink(),t+r-1,l+o-1,e.getTextColor())end end end end,onError=function(e,...)for t,n in
  3317. pairs(table.pack(...))do if(type(n)=="function")then
  3318. e:registerEvent("program_error",n)end end if(e.parent~=nil)then
  3319. e.parent:addEvent("other_event",e)end return e end,onDone=function(e,...)for t,n in
  3320. pairs(table.pack(...))do if(type(n)=="function")then
  3321. e:registerEvent("program_done",n)end end if(e.parent~=nil)then
  3322. e.parent:addEvent("other_event",e)end return e end,init=function(e)if(t.init(e))then e.bgColor=e.parent:getTheme("ProgramBG")end end}return setmetatable(p,t)end end
  3323. r["objects"]["Progressbar"]=function(...)local n=l("Object")local t=l("utils").getValueFromXML
  3324. return
  3325. function(e)local a=n(e)local o="Progressbar"local n=0 a:setZIndex(5)a:setValue(false)a.width=25 a.height=1 local i local d=""local c=colors.white local u=""local s=0
  3326. local e={init=function(e)if(a.init(e))then e.bgColor=e.parent:getTheme("ProgressbarBG")e.fgColor=e.parent:getTheme("ProgressbarText")i=e.parent:getTheme("ProgressbarActiveBG")end end,getType=function(e)return
  3327. o end,setValuesByXMLData=function(n,e)a.setValuesByXMLData(n,e)if(t("direction",e)~=nil)then s=t("direction",e)end
  3328. if(t("progressColor",e)~=nil)then i=colors[t("progressColor",e)]end
  3329. if(t("progressSymbol",e)~=nil)then d=t("progressSymbol",e)end if(t("backgroundSymbol",e)~=nil)then
  3330. u=t("backgroundSymbol",e)end
  3331. if(t("progressSymbolColor",e)~=nil)then c=colors[t("progressSymbolColor",e)]end if(t("onDone",e)~=nil)then
  3332. n:generateXMLEventFunction(n.onProgressDone,t("onDone",e))end return n end,setDirection=function(e,n)s=n e:updateDraw()return e end,setProgressBar=function(e,n,t,o)i=n or i
  3333. d=t or d c=o or c e:updateDraw()return e end,setBackgroundSymbol=function(e,n)u=n:sub(1,1)e:updateDraw()return e end,setProgress=function(e,t)if(t>=0)and(t<=100)and(n~=t)then n=t e:setValue(n)if(n==100)then
  3334. e:progressDoneHandler()end end
  3335. e:updateDraw()return e end,getProgress=function(e)return
  3336. n end,onProgressDone=function(e,n)e:registerEvent("progress_done",n)return e end,progressDoneHandler=function(e)e:sendEvent("progress_done",e)end,draw=function(e)if(a.draw(e))then
  3337. if(e.parent~=nil)then
  3338. local l,r=e:getAnchorPosition()local o,t=e:getSize()if(e.bgColor~=false)then
  3339. e.parent:drawBackgroundBox(l,r,o,t,e.bgColor)end if(u~="")then
  3340. e.parent:drawTextBox(l,r,o,t,u)end if(e.fgColor~=false)then
  3341. e.parent:drawForegroundBox(l,r,o,t,e.fgColor)end
  3342. if(s==1)then e.parent:drawBackgroundBox(l,r,o,t/100*n,i)e.parent:drawForegroundBox(l,r,o,t/100*n,c)e.parent:drawTextBox(l,r,o,t/100*n,d)elseif(s==2)then
  3343. e.parent:drawBackgroundBox(l,r+math.ceil(t-t/100*n),o,t/100*n,i)e.parent:drawForegroundBox(l,r+math.ceil(t-t/100*n),o,t/100*n,c)e.parent:drawTextBox(l,r+math.ceil(t-t/100*n),o,t/100*n,d)elseif(s==3)then
  3344. e.parent:drawBackgroundBox(l+math.ceil(o-o/100*n),r,o/100*n,t,i)e.parent:drawForegroundBox(l+math.ceil(o-o/100*n),r,o/100*n,t,c)e.parent:drawTextBox(l+math.ceil(o-o/100*n),r,o/100*n,t,d)else
  3345. e.parent:drawBackgroundBox(l,r,o/100*n,t,i)e.parent:drawForegroundBox(l,r,o/100*n,t,c)e.parent:drawTextBox(l,r,o/100*n,t,d)end end end end}return setmetatable(e,a)end end
  3346. r["objects"]["Scrollbar"]=function(...)local t=l("Object")local n=l("utils").getValueFromXML
  3347. return
  3348. function(e)local l=t(e)local f="Scrollbar"l.width=1 l.height=8 l:setValue(1)l:setZIndex(2)local o="vertical"local d=" "local a local i="\127"local r=l.height local e=1 local t=1
  3349. local function u(n,l,c,i)local d,s=n:getAbsolutePosition(n:getAnchorPosition())local a,l=n:getSize()if(o=="horizontal")then
  3350. for o=0,a do
  3351. if(d+o==c)and(s<=i)and(s+l>i)then
  3352. e=math.min(o+1,a-(t-1))n:setValue(r/a*(e))n:updateDraw()end end end
  3353. if(o=="vertical")then
  3354. for o=0,l do
  3355. if(s+o==i)and(d<=c)and(d+a>c)then e=math.min(o+1,l-(t-1))n:setValue(r/l*(e))n:updateDraw()end end end end
  3356. local e={getType=function(e)return f end,setSymbol=function(e,n)d=n:sub(1,1)e:updateDraw()return e end,setValuesByXMLData=function(t,e)l.setValuesByXMLData(t,e)if(n("maxValue",e)~=nil)then r=n("maxValue",e)end if(n("backgroundSymbol",e)~=nil)then
  3357. i=n("backgroundSymbol",e):sub(1,1)end if(n("symbol",e)~=nil)then
  3358. d=n("symbol",e):sub(1,1)end if(n("barType",e)~=nil)then
  3359. o=n("barType",e):lower()end if(n("symbolSize",e)~=nil)then
  3360. t:setSymbolSize(n("symbolSize",e))end if(n("symbolColor",e)~=nil)then
  3361. a=colors[n("symbolColor",e)]end if(n("index",e)~=nil)then
  3362. t:setIndex(n("index",e))end end,setIndex=function(n,l)e=l if(e<1)then e=1 end local a,l=n:getSize()e=math.min(e,(o=="vertical"and l or a)-(t-1))n:setValue(r/(o=="vertical"and l or a)*e)n:updateDraw()return n end,getIndex=function(n)return
  3363. e end,setSymbolSize=function(n,l)t=tonumber(l)or 1
  3364. local a,l=n:getSize()if(o=="vertical")then
  3365. n:setValue(e-1*(r/(l-(t-1)))-(r/(l-(t-1))))elseif(o=="horizontal")then
  3366. n:setValue(e-1*(r/(a-(t-1)))-(r/(a-(t-1))))end n:updateDraw()return n end,setMaxValue=function(e,n)r=n e:updateDraw()return e end,setBackgroundSymbol=function(e,n)i=string.sub(n,1,1)e:updateDraw()return e end,setSymbolColor=function(e,n)a=n
  3367. e:updateDraw()return e end,setBarType=function(e,n)o=n:lower()e:updateDraw()return e end,mouseHandler=function(t,n,o,e)if(l.mouseHandler(t,n,o,e))then
  3368. u(t,n,o,e)return true end return false end,dragHandler=function(n,e,t,o)if(l.dragHandler(n,e,t,o))then u(n,e,t,o)return true end
  3369. return false end,scrollHandler=function(n,a,d,i)if(l.scrollHandler(n,a,d,i))then local i,l=n:getSize()e=e+a if(e<1)then e=1 end
  3370. e=math.min(e,(o=="vertical"and l or i)-(t-1))n:setValue(r/(o=="vertical"and l or i)*e)n:updateDraw()end end,draw=function(n)if(l.draw(n))then
  3371. if(n.parent~=nil)then local r,l=n:getAnchorPosition()local s,c=n:getSize()if(o=="horizontal")then
  3372. n.parent:writeText(r,l,i:rep(e-1),n.bgColor,n.fgColor)n.parent:writeText(r+e-1,l,d:rep(t),a,a)n.parent:writeText(r+e+t-1,l,i:rep(s-(e+t-1)),n.bgColor,n.fgColor)end
  3373. if(o=="vertical")then
  3374. for o=0,c-1 do
  3375. if(e==o+1)then
  3376. for e=0,math.min(t-1,c)do n.parent:writeText(r,l+o+e,d,a,a)end else if(o+1<e)or(o+1>e-1+t)then
  3377. n.parent:writeText(r,l+o,i,n.bgColor,n.fgColor)end end end end end end end,init=function(e)e.parent:addEvent("mouse_click",e)e.parent:addEvent("mouse_drag",e)e.parent:addEvent("mouse_scroll",e)if(l.init(e))then
  3378. e.bgColor=e.parent:getTheme("ScrollbarBG")e.fgColor=e.parent:getTheme("ScrollbarText")a=e.parent:getTheme("ScrollbarSymbolColor")end end}return setmetatable(e,l)end end
  3379. r["objects"]["Radio"]=function(...)local t=l("Object")local e=l("utils")local e=e.getValueFromXML
  3380. return
  3381. function(n)local i=t(n)local n="Radio"i.width=8 i:setZIndex(5)local t={}local a local r
  3382. local l local o local s local d local f=true local c="\7"local u="left"local e={getType=function(e)return n end,setValuesByXMLData=function(t,n)i.setValuesByXMLData(t,n)if(e("selectionBG",n)~=nil)then
  3383. a=colors[e("selectionBG",n)]end if(e("selectionFG",n)~=nil)then
  3384. r=colors[e("selectionFG",n)]end if(e("boxBG",n)~=nil)then
  3385. l=colors[e("boxBG",n)]end if(e("inactiveBoxBG",n)~=nil)then
  3386. s=colors[e("inactiveBoxBG",n)]end if(e("inactiveBoxFG",n)~=nil)then
  3387. d=colors[e("inactiveBoxFG",n)]end if(e("boxFG",n)~=nil)then
  3388. o=colors[e("boxFG",n)]end if(e("symbol",n)~=nil)then
  3389. c=e("symbol",n)end
  3390. if(n["item"]~=nil)then local n=n["item"]if(n.properties~=nil)then n={n}end for o,n in pairs(n)do
  3391. t:addItem(e("text",n),e("x",n),e("y",n),colors[e("bg",n)],colors[e("fg",n)])end end return t end,addItem=function(e,a,r,o,l,n,...)table.insert(t,{x=r or 1,y=o or 1,text=a,bgCol=l or e.bgColor,fgCol=n or e.fgColor,args={...}})if(#t==1)then e:setValue(t[1])end
  3392. e:updateDraw()return e end,getAll=function(e)return
  3393. t end,removeItem=function(e,n)table.remove(t,n)e:updateDraw()return e end,getItem=function(n,e)return t[e]end,getItemIndex=function(e)local o=e:getValue()for e,n in pairs(t)do if(n==o)then return e end end end,clear=function(e)t={}e:setValue({},false)e:updateDraw()return e end,getItemCount=function(e)return#t end,editItem=function(e,n,o,a,i,r,l,...)table.remove(t,n)table.insert(t,n,{x=a or 1,y=i or 1,text=o,bgCol=r or e.bgColor,fgCol=l or e.fgColor,args={...}})e:updateDraw()return e end,selectItem=function(e,n)e:setValue(t[n]or{},false)e:updateDraw()return e end,setActiveSymbol=function(e,n)c=n:sub(1,1)e:updateDraw()return e end,setSelectedItem=function(n,c,i,d,t,e)a=c or a r=i or r l=d or l o=t or o
  3394. f=e~=nil and e or true n:updateDraw()return n end,mouseHandler=function(e,a,o,r)if(#t>0)then
  3395. local l,i=e:getAbsolutePosition(e:getAnchorPosition())for t,n in pairs(t)do
  3396. if(l+n.x-1<=o)and(l+n.x-1+n.text:len()+1>=o)and(i+n.y-1==r)then
  3397. e:setValue(n)local n=e:getEventSystem():sendEvent("mouse_click",e,"mouse_click",a,o,r)if(n==false)then return n end if(e.parent~=nil)then
  3398. e.parent:setFocusedObject(e)end e:updateDraw()return true end end end return false end,draw=function(n)if(n.parent~=nil)then local d,i=n:getAnchorPosition()for t,e in pairs(t)do
  3399. if(e==n:getValue())then if(u=="left")then
  3400. n.parent:writeText(e.x+d-1,e.y+i-1,c,l,o)n.parent:writeText(e.x+2+d-1,e.y+i-1,e.text,a,r)end else
  3401. n.parent:drawBackgroundBox(e.x+d-1,e.y+i-1,1,1,s or n.bgColor)n.parent:writeText(e.x+2+d-1,e.y+i-1,e.text,e.bgCol,e.fgCol)end end return true end end,init=function(e)e.parent:addEvent("mouse_click",e)if(i.init(e))then
  3402. e.bgColor=e.parent:getTheme("MenubarBG")e.fgColor=e.parent:getTheme("MenubarFG")a=e.parent:getTheme("SelectionBG")r=e.parent:getTheme("SelectionText")l=e.parent:getTheme("MenubarBG")o=e.parent:getTheme("MenubarText")end end}return setmetatable(e,i)end end
  3403. r["objects"]["Slider"]=function(...)local e=l("Object")local n=l("basaltLogs")local n=l("utils").getValueFromXML
  3404. return
  3405. function(t)local l=e(t)local f="Slider"l.width=8 l.height=1 l:setValue(1)local o="horizontal"local d=" "local a local i="\140"local r=l.width local e=1 local t=1
  3406. local function u(n,l,i,c)local d,s=n:getAbsolutePosition(n:getAnchorPosition())local a,l=n:getSize()if(o=="horizontal")then
  3407. for o=0,a do
  3408. if(d+o==i)and(s<=c)and(s+l>c)then
  3409. e=math.min(o+1,a-(t-1))n:setValue(r/a*(e))n:updateDraw()end end end
  3410. if(o=="vertical")then
  3411. for o=0,l do
  3412. if(s+o==c)and(d<=i)and(d+a>i)then e=math.min(o+1,l-(t-1))n:setValue(r/l*(e))n:updateDraw()end end end end
  3413. local e={getType=function(e)return f end,setSymbol=function(e,n)d=n:sub(1,1)e:updateDraw()return e end,setValuesByXMLData=function(t,e)l.setValuesByXMLData(t,e)if(n("maxValue",e)~=nil)then r=n("maxValue",e)end if(n("backgroundSymbol",e)~=nil)then
  3414. i=n("backgroundSymbol",e):sub(1,1)end if(n("barType",e)~=nil)then
  3415. o=n("barType",e):lower()end if(n("symbol",e)~=nil)then
  3416. d=n("symbol",e):sub(1,1)end if(n("symbolSize",e)~=nil)then
  3417. t:setSymbolSize(n("symbolSize",e))end if(n("symbolColor",e)~=nil)then
  3418. a=colors[n("symbolColor",e)]end if(n("index",e)~=nil)then
  3419. t:setIndex(n("index",e))end end,setIndex=function(n,l)e=l if(e<1)then e=1 end local a,l=n:getSize()e=math.min(e,(o=="vertical"and l or a)-(t-1))n:setValue(r/(o=="vertical"and l or a)*e)n:updateDraw()return n end,getIndex=function(n)return
  3420. e end,setSymbolSize=function(n,l)t=tonumber(l)or 1
  3421. if(o=="vertical")then
  3422. n:setValue(e-1*(r/(h-(t-1)))-(r/(h-(t-1))))elseif(o=="horizontal")then
  3423. n:setValue(e-1*(r/(w-(t-1)))-(r/(w-(t-1))))end n:updateDraw()return n end,setMaxValue=function(n,e)r=e return n end,setBackgroundSymbol=function(e,n)i=string.sub(n,1,1)e:updateDraw()return e end,setSymbolColor=function(e,n)a=n e:updateDraw()return e end,setBarType=function(e,n)o=n:lower()e:updateDraw()return e end,mouseHandler=function(t,o,n,e)if(l.mouseHandler(t,o,n,e))then
  3424. u(t,o,n,e)return true end return false end,dragHandler=function(e,o,n,t)if(l.dragHandler(e,o,n,t))then u(e,o,n,t)return true end
  3425. return false end,scrollHandler=function(n,a,i,d)if(l.scrollHandler(n,a,i,d))then local l,i=n:getSize()e=e+a if(e<1)then e=1 end
  3426. e=math.min(e,(o=="vertical"and i or l)-(t-1))n:setValue(r/(o=="vertical"and i or l)*e)n:updateDraw()return true end return false end,draw=function(n)if(l.draw(n))then
  3427. if(n.parent~=nil)then local l,r=n:getAnchorPosition()local s,c=n:getSize()if(o=="horizontal")then
  3428. n.parent:writeText(l,r,i:rep(e-1),n.bgColor,n.fgColor)n.parent:writeText(l+e-1,r,d:rep(t),a,a)n.parent:writeText(l+e+t-1,r,i:rep(s-(e+t-1)),n.bgColor,n.fgColor)end
  3429. if(o=="vertical")then
  3430. for o=0,c-1 do
  3431. if(e==o+1)then
  3432. for e=0,math.min(t-1,c)do n.parent:writeText(l,r+o+e,d,a,a)end else if(o+1<e)or(o+1>e-1+t)then
  3433. n.parent:writeText(l,r+o,i,n.bgColor,n.fgColor)end end end end end end end,init=function(e)e.parent:addEvent("mouse_click",e)e.parent:addEvent("mouse_drag",e)e.parent:addEvent("mouse_scroll",e)if(l.init(e))then
  3434. e.bgColor=e.parent:getTheme("SliderBG")e.fgColor=e.parent:getTheme("SliderText")a=e.parent:getTheme("SliderSymbolColor")end end}return setmetatable(e,l)end end
  3435. r["objects"]["Textfield"]=function(...)local n=l("Object")local i=l("tHex")local b=l("utils").getValueFromXML local e=l("basaltLogs")local g,B,S,v,e=string.rep,string.find,string.gmatch,string.sub,string.len
  3436. return
  3437. function(e)local d=n(e)local k="Textfield"local l,o,n,e=1,1,1,1 local t={" "}local r={""}local a={""}local p={}local m={}local u,c,f,s local T,C=colors.lightBlue,colors.black d.width=30
  3438. d.height=12 d:setZIndex(5)local function y()if(u~=nil)and(c~=nil)and(f~=nil)and(s~=nil)then return true end return false end
  3439. local function _()local e,t,n,o
  3440. if(y())then if(u>c)then e,t=c,u else e,t=u,c end if(f>s)then
  3441. n,o=s,f else n,o=f,s end end return e,t,n,o end local function h()end
  3442. local function w(p)local i,d,h,m=_(p)for e=m,h,-1 do
  3443. if(e==h)or(e==m)then local o=t[e]local l=r[e]local n=a[e]if(e==h)and(e==m)then o=o:sub(1,i-1)..o:sub(d+1,o:len())l=l:sub(1,i-1)..l:sub(d+1,l:len())n=n:sub(1,i-1)..n:sub(d+1,n:len())elseif(e==i)then
  3444. o=o:sub(1,i)l=l:sub(1,i)n=n:sub(1,i)elseif(e==h)then
  3445. o=o:sub(d,o:len())l=l:sub(d,l:len())n=n:sub(d,n:len())end t[e]=o r[e]=l a[e]=n else table.remove(t,e)table.remove(r,e)table.remove(a,e)end end n,e=u,f u,c,f,s=nil,nil,nil,nil return p end
  3446. local function x(e,n)local o={}if(e:len()>0)then
  3447. for l in S(e,n)do local n,t=B(e,l)if(n~=nil)and(t~=nil)then table.insert(o,n)table.insert(o,t)local n=v(e,1,(n-1))local t=v(e,t+1,e:len())e=n..(":"):rep(l:len())..t end end end return o end
  3448. local function h(d,o)o=o or e
  3449. local n=i[d.fgColor]:rep(a[o]:len())local l=i[d.bgColor]:rep(r[o]:len())for e,r in pairs(m)do local e=x(t[o],r[1])if(#e>0)then
  3450. for t=1,#e/2 do
  3451. local t=t*2-1 if(r[2]~=nil)then
  3452. n=n:sub(1,e[t]-1)..i[r[2]]:rep(e[t+1]-(e[t]-1))..n:sub(e[t+1]+1,n:len())end if(r[3]~=nil)then
  3453. l=l:sub(1,e[t]-1)..i[r[3]]:rep(e[t+1]-(e[t]-1))..l:sub(e[t+1]+1,l:len())end end end end
  3454. for l,e in pairs(p)do
  3455. for r,e in pairs(e)do local e=x(t[o],e)if(#e>0)then for t=1,#e/2 do
  3456. local t=t*2-1
  3457. n=n:sub(1,e[t]-1)..i[l]:rep(e[t+1]-(e[t]-1))..n:sub(e[t+1]+1,n:len())end end end end a[o]=n r[o]=l d:updateDraw()end local function x(e)for n=1,#t do h(e,n)end end
  3458. local e={getType=function(e)return k end,setBackground=function(e,n)d.setBackground(e,n)x(e)return e end,setForeground=function(e,n)d.setForeground(e,n)x(e)return e end,setValuesByXMLData=function(n,e)d.setValuesByXMLData(n,e)if(e["lines"]~=nil)then local e=e["lines"]["line"]if(e.properties~=nil)then e={e}end for t,e in pairs(e)do
  3459. n:addLine(e:value())end end
  3460. if(e["keywords"]~=nil)then
  3461. for o,e in pairs(e["keywords"])do
  3462. if(colors[o]~=nil)then
  3463. local e=e if(e.properties~=nil)then e={e}end local t={}for n,e in pairs(e)do
  3464. local n=e["keyword"]if(e["keyword"].properties~=nil)then
  3465. n={e["keyword"]}end for n,e in pairs(n)do
  3466. table.insert(t,e:value())end end n:addKeywords(colors[o],t)end end end
  3467. if(e["rules"]~=nil)then
  3468. if(e["rules"]["rule"]~=nil)then
  3469. local t=e["rules"]["rule"]if(e["rules"]["rule"].properties~=nil)then
  3470. t={e["rules"]["rule"]}end
  3471. for t,e in pairs(t)do if(b("pattern",e)~=nil)then
  3472. n:addRule(b("pattern",e),colors[b("fg",e)],colors[b("bg",e)])end end end end end,getLines=function(e)return
  3473. t end,getLine=function(n,e)return t[e]end,editLine=function(n,e,o)t[e]=o or t[e]h(n,e)n:updateDraw()return n end,clear=function(i)t={" "}r={""}a={""}u,c,f,s=nil,nil,nil,nil l,o,n,e=1,1,1,1
  3474. i:updateDraw()return i end,addLine=function(e,n,o)if(n~=nil)then
  3475. if(#t==1)and(t[1]=="")then t[1]=n
  3476. r[1]=i[e.bgColor]:rep(n:len())a[1]=i[e.fgColor]:rep(n:len())h(e,1)return e end
  3477. if(o~=nil)then table.insert(t,o,n)table.insert(r,o,i[e.bgColor]:rep(n:len()))table.insert(a,o,i[e.fgColor]:rep(n:len()))else table.insert(t,n)table.insert(r,i[e.bgColor]:rep(n:len()))table.insert(a,i[e.fgColor]:rep(n:len()))end end h(e,o or#t)e:updateDraw()return e end,addKeywords=function(n,e,t)if(p[e]==nil)then p[e]={}end for t,n in pairs(t)do
  3478. table.insert(p[e],n)end n:updateDraw()return n end,addRule=function(e,o,n,t)table.insert(m,{o,n,t})e:updateDraw()return e end,editRule=function(n,l,o,t)for e,n in
  3479. pairs(m)do
  3480. if(n[1]==l)then m[e][2]=o m[e][3]=t end end n:updateDraw()return n end,removeRule=function(e,n)for e,t in
  3481. pairs(m)do if(t[1]==n)then table.remove(m,e)end end e:updateDraw()return e end,setKeywords=function(e,n,t)p[n]=t e:updateDraw()return e end,removeLine=function(n,e)if(#t>1)then table.remove(t,e or#t)table.remove(r,e or#r)table.remove(a,e or#a)else t={" "}r={""}a={""}end n:updateDraw()return n end,getTextCursor=function(t)return
  3482. n,e end,getFocusHandler=function(t)d.getFocusHandler(t)if(t.parent~=nil)then
  3483. local a,r=t:getAnchorPosition()if(t.parent~=nil)then
  3484. t.parent:setCursor(true,a+n-o,r+e-l,t.fgColor)end end end,loseFocusHandler=function(e)d.loseFocusHandler(e)if(e.parent~=nil)then e.parent:setCursor(false)end end,keyHandler=function(i,c)if(d.keyHandler(i,event,c))then local s,u=i:getAnchorPosition()local d,f=i:getSize()if(c==keys.backspace)then
  3485. if(t[e]=="")then
  3486. if(e>1)then table.remove(t,e)table.remove(a,e)table.remove(r,e)n=t[e-1]:len()+1 o=n-d+1 if(o<1)then o=1 end e=e-1 end elseif(n<=1)then
  3487. if(e>1)then n=t[e-1]:len()+1
  3488. o=n-d+1 if(o<1)then o=1 end t[e-1]=t[e-1]..t[e]a[e-1]=a[e-1]..a[e]r[e-1]=r[e-1]..r[e]table.remove(t,e)table.remove(a,e)table.remove(r,e)e=e-1 end else t[e]=t[e]:sub(1,n-2)..t[e]:sub(n,t[e]:len())a[e]=a[e]:sub(1,n-2)..a[e]:sub(n,a[e]:len())r[e]=r[e]:sub(1,n-2)..r[e]:sub(n,r[e]:len())if(n>1)then
  3489. n=n-1 end if(o>1)then if(n<o)then o=o-1 end end end if(e<l)then l=l-1 end h(i)i:setValue("")end
  3490. if(c==keys.delete)then
  3491. if(y())then w(i)else
  3492. if(n>t[e]:len())then
  3493. if(t[e+1]~=nil)then t[e]=t[e]..t[e+1]table.remove(t,e+1)table.remove(r,e+1)table.remove(a,e+1)end else t[e]=t[e]:sub(1,n-1)..t[e]:sub(n+1,t[e]:len())a[e]=a[e]:sub(1,n-1)..a[e]:sub(n+1,a[e]:len())r[e]=r[e]:sub(1,n-1)..r[e]:sub(n+1,r[e]:len())end end h(i)end
  3494. if(c==keys.enter)then
  3495. table.insert(t,e+1,t[e]:sub(n,t[e]:len()))table.insert(a,e+1,a[e]:sub(n,a[e]:len()))table.insert(r,e+1,r[e]:sub(n,r[e]:len()))t[e]=t[e]:sub(1,n-1)a[e]=a[e]:sub(1,n-1)r[e]=r[e]:sub(1,n-1)e=e+1 n=1 o=1 if(e-l>=f)then l=l+1 end i:setValue("")end
  3496. if(c==keys.up)then
  3497. if(e>1)then e=e-1 if(n>t[e]:len()+1)then n=t[e]:len()+1 end
  3498. if(o>1)then if(n<o)then
  3499. o=n-d+1 if(o<1)then o=1 end end end if(l>1)then if(e<l)then l=l-1 end end end end
  3500. if(c==keys.down)then
  3501. if(e<#t)then e=e+1 if(n>t[e]:len()+1)then n=t[e]:len()+1 end
  3502. if(o>1)then if(n<o)then o=n-d+1 if(o<1)then o=1 end end end if(e>=l+f)then l=l+1 end end end
  3503. if(c==keys.right)then n=n+1
  3504. if(e<#t)then if(n>t[e]:len()+1)then n=1 e=e+1 end elseif(n>t[e]:len())then n=t[e]:len()+1 end if(n<1)then n=1 end
  3505. if(n<o)or(n>=d+o)then o=n-d+1 end if(o<1)then o=1 end end
  3506. if(c==keys.left)then n=n-1 if(n>=1)then
  3507. if(n<o)or(n>=d+o)then o=n end end
  3508. if(e>1)then if(n<1)then e=e-1
  3509. n=t[e]:len()+1 o=n-d+1 end end if(n<1)then n=1 end if(o<1)then o=1 end end
  3510. if not((s+n-o>=s and s+n-o<s+d)and(u+e-l>=u and u+e-l<u+f))then o=math.max(1,t[e]:len()-d+1)l=math.max(1,e-f+1)end local n=(n<=t[e]:len()and n-1 or t[e]:len())-(o-1)if(n>i:getX()+d-1)then n=i:getX()+d-1 end
  3511. local e=(e-l<f and e-l or e-l-1)if(n<1)then n=0 end
  3512. i.parent:setCursor(true,s+n,u+e,i.fgColor)i:updateDraw()return true end end,charHandler=function(c,m)if(d.charHandler(c,m))then local s,u=c:getAnchorPosition()local d,f=c:getSize()t[e]=t[e]:sub(1,n-1)..m..t[e]:sub(n,t[e]:len())a[e]=a[e]:sub(1,n-1)..i[c.fgColor]..a[e]:sub(n,a[e]:len())r[e]=r[e]:sub(1,n-1)..i[c.bgColor]..r[e]:sub(n,r[e]:len())n=n+1 if(n>=d+o)then o=o+1 end h(c)c:setValue("")if not((s+n-o>=s and s+n-o<s+d)and(u+e-l>=u and u+e-l<u+f))then o=math.max(1,t[e]:len()-d+1)l=math.max(1,e-f+1)end local n=(n<=t[e]:len()and n-1 or t[e]:len())-(o-1)if(n>c:getX()+d-1)then n=c:getX()+d-1 end
  3513. local e=(e-l<f and e-l or e-l-1)if(n<1)then n=0 end if(y())then w(c)end c.parent:setCursor(true,s+n,u+e,c.fgColor)c:updateDraw()return true end end,dragHandler=function(r,a,i,u)if(d.dragHandler(r,a,i,u))then
  3514. local d,f=r:getAbsolutePosition(r:getAnchorPosition())local a,m=r:getAnchorPosition()local h,p=r:getSize()if(t[u-f+l]~=nil)then
  3515. if(a+h>a+i-(d+1)+o)and(a<a+i-d+o)then
  3516. n=i-d+o e=u-f+l c=n s=e if(n>t[e]:len())then n=t[e]:len()+1 c=n end if(n<o)then o=n-1 if(o<1)then o=1 end end r.parent:setCursor(true,a+n-o,m+e-l,r.fgColor)r:updateDraw()end end return true end end,scrollHandler=function(r,c,a,i)if(d.scrollHandler(r,c,a,i))then
  3517. local i,a=r:getAbsolutePosition(r:getAnchorPosition())local s,a=r:getAnchorPosition()local u,d=r:getSize()l=l+c if(l>#t-(d-1))then l=#t-(d-1)end if(l<1)then l=1 end
  3518. if(i+n-o>=i and i+n-o<i+u)and(a+e-l>=a and a+e-l<a+d)then
  3519. r.parent:setCursor(true,s+n-o,a+e-l,r.fgColor)else r.parent:setCursor(false)end r:updateDraw()return true end end,mouseHandler=function(r,h,i,a)if(d.mouseHandler(r,h,i,a))then
  3520. local m,d=r:getAbsolutePosition(r:getAnchorPosition())local h,p=r:getAnchorPosition()if(t[a-d+l]~=nil)then n=i-m+o e=a-d+l c=nil s=nil u=n f=e
  3521. if(n>t[e]:len())then n=t[e]:len()+1 u=n end if(n<o)then o=n-1 if(o<1)then o=1 end end
  3522. r:updateDraw()end if(r.parent~=nil)then
  3523. r.parent:setCursor(true,h+n-o,p+e-l,r.fgColor)end return true end end,mouseUpHandler=function(e,r,a,n)if(d.mouseUpHandler(e,r,a,n))then
  3524. local i,r=e:getAbsolutePosition(e:getAnchorPosition())local d,d=e:getAnchorPosition()if(t[n-r+l]~=nil)then c=a-i+o s=n-r+l if(c>t[s]:len())then c=t[s]:len()+1 end if(u==c)and(f==s)then u,c,f,s=nil,nil,nil,nil end
  3525. e:updateDraw()end return true end end,eventHandler=function(c,u,s,f,p,m)if(d.eventHandler(c,u,s,f,p,m))then
  3526. if(u=="paste")then
  3527. if(c:isFocused())then local d,u=c:getSize()t[e]=t[e]:sub(1,n-1)..s..t[e]:sub(n,t[e]:len())a[e]=a[e]:sub(1,n-1)..i[c.fgColor]:rep(s:len())..a[e]:sub(n,a[e]:len())r[e]=r[e]:sub(1,n-1)..i[c.bgColor]:rep(s:len())..r[e]:sub(n,r[e]:len())n=n+s:len()if(n>=d+o)then o=(n+1)-d end local t,r=c:getAnchorPosition()c.parent:setCursor(true,t+n-o,r+e-l,c.fgColor)h(c)c:updateDraw()end end end end,draw=function(e)if(d.draw(e))then
  3528. if(e.parent~=nil)then local m,h=e:getAnchorPosition()local p,n=e:getSize()for d=1,n do local n=""local s=""local c=""if(t[d+l-1]~=nil)then n=t[d+l-1]c=a[d+l-1]s=r[d+l-1]end n=n:sub(o,p+o-1)s=s:sub(o,p+o-1)c=c:sub(o,p+o-1)local t=p-n:len()if(t<0)then
  3529. t=0 end n=n..g(e.bgSymbol,t)s=s..g(i[e.bgColor],t)c=c..g(i[e.fgColor],t)e.parent:setText(m,h+d-1,n)e.parent:setBG(m,h+d-1,s)e.parent:setFG(m,h+d-1,c)end
  3530. if(u~=nil)and(c~=nil)and(f~=nil)and(s~=nil)then local l,d,r,a=_(e)for o=r,a do local n=t[o]:len()local t=0
  3531. if(o==r)and(o==a)then t=l-1 n=n-(l-1)-(n-d)elseif(o==a)then
  3532. n=n-(n-d)elseif(o==r)then n=n-(l-1)t=l-1 end
  3533. e.parent:setBG(m+t,h+o-1,g(i[T],n))e.parent:setFG(m+t,h+o-1,g(i[C],n))end end
  3534. if(e:isFocused())then local e,e=e:getAnchorPosition()end end end end,init=function(e)e.parent:addEvent("mouse_click",e)e.parent:addEvent("mouse_up",e)e.parent:addEvent("mouse_scroll",e)e.parent:addEvent("mouse_drag",e)e.parent:addEvent("key",e)e.parent:addEvent("char",e)e.parent:addEvent("other_event",e)if(d.init(e))then
  3535. e.bgColor=e.parent:getTheme("TextfieldBG")e.fgColor=e.parent:getTheme("TextfieldText")end end}return setmetatable(e,d)end end
  3536. r["objects"]["Thread"]=function(...)local l=l("utils").getValueFromXML
  3537. return
  3538. function(c)local o
  3539. local d="Thread"local a local n local r=false local t
  3540. local i=function(n,e)if(e:sub(1,1)=="#")then
  3541. local e=n:getBaseFrame():getDeepObject(e:sub(2,e:len()))if(e~=nil)and(e.internalObjetCall~=nil)then return(function()e:internalObjetCall()end)end else return n:getBaseFrame():getVariable(e)end return n end
  3542. o={name=c,getType=function(e)return d end,getZIndex=function(e)return 1 end,getName=function(e)return e.name end,getBaseFrame=function(e)if(e.parent~=nil)then return e.parent:getBaseFrame()end
  3543. return e end,setValuesByXMLData=function(t,e)local n if(l("thread",e)~=nil)then
  3544. n=i(t,l("thread",e))end
  3545. if(l("start",e)~=nil)then if(l("start",e))and(n~=nil)then t:start(n)end end return t end,start=function(e,o)if(o==nil)then error"Function provided to thread is nil"end a=o n=coroutine.create(a)r=true t=nil
  3546. local o,n=coroutine.resume(n)t=n if not(o)then if(n~="Terminated")then
  3547. error("Thread Error Occurred - "..n)end end
  3548. e.parent:addEvent("mouse_click",e)e.parent:addEvent("mouse_up",e)e.parent:addEvent("mouse_scroll",e)e.parent:addEvent("mouse_drag",e)e.parent:addEvent("key",e)e.parent:addEvent("key_up",e)e.parent:addEvent("char",e)e.parent:addEvent("other_event",e)return e end,getStatus=function(e,e)if(n~=nil)then return coroutine.status(n)end return nil end,stop=function(e,n)r=false e.parent:removeEvent("mouse_click",e)e.parent:removeEvent("mouse_up",e)e.parent:removeEvent("mouse_scroll",e)e.parent:removeEvent("mouse_drag",e)e.parent:removeEvent("key",e)e.parent:removeEvent("key_up",e)e.parent:removeEvent("char",e)e.parent:removeEvent("other_event",e)return e end,mouseHandler=function(e,...)e:eventHandler("mouse_click",...)end,mouseUpHandler=function(e,...)e:eventHandler("mouse_up",...)end,mouseScrollHandler=function(e,...)e:eventHandler("mouse_scroll",...)end,mouseDragHandler=function(e,...)e:eventHandler("mouse_drag",...)end,mouseMoveHandler=function(e,...)e:eventHandler("mouse_move",...)end,keyHandler=function(e,...)e:eventHandler("key",...)end,keyUpHandler=function(e,...)e:eventHandler("key_up",...)end,charHandler=function(e,...)e:eventHandler("char",...)end,eventHandler=function(o,e,...)if(r)then
  3549. if(coroutine.status(n)=="suspended")then if(t~=nil)then if(e~=t)then return end t=nil end
  3550. local n,e=coroutine.resume(n,e,...)t=e if not(n)then if(e~="Terminated")then
  3551. error("Thread Error Occurred - "..e)end end else
  3552. o:stop()end end end}o.__index=o return o end end
  3553. r["objects"]["Timer"]=function(...)local n=l("basaltEvent")local e=l("utils").getValueFromXML
  3554. return
  3555. function(c)local d="Timer"local r=0 local a=0 local o=0 local t local i=n()local l=false
  3556. local s=function(e,o,t)local n=function(n)if(n:sub(1,1)=="#")then
  3557. local n=e:getBaseFrame():getDeepObject(n:sub(2,n:len()))if(n~=nil)and(n.internalObjetCall~=nil)then o(e,function()n:internalObjetCall()end)end else
  3558. o(e,e:getBaseFrame():getVariable(n))end end if(type(t)=="string")then n(t)elseif(type(t)=="table")then
  3559. for t,e in pairs(t)do n(e)end end return e end
  3560. local e={name=c,getType=function(e)return d end,setValuesByXMLData=function(t,n)if(e("time",n)~=nil)then r=e("time",n)end if(e("repeat",n)~=nil)then a=e("repeat",n)end
  3561. if(e("start",n)~=nil)then if(e("start",n))then t:start()end end if(e("onCall",n)~=nil)then
  3562. s(t,t.onCall,e("onCall",n))end return t end,getBaseFrame=function(e)if(e.parent~=nil)then return e.parent:getBaseFrame()end return e end,getZIndex=function(e)return 1 end,getName=function(e)return e.name end,setTime=function(e,n,t)r=n or 0 a=t or 1 return e end,start=function(e)if(l)then
  3563. os.cancelTimer(t)end o=a t=os.startTimer(r)l=true
  3564. e.parent:addEvent("other_event",e)return e end,isActive=function(e)return l end,cancel=function(e)if(t~=nil)then os.cancelTimer(t)end l=false
  3565. e.parent:removeEvent("other_event",e)return e end,onCall=function(e,n)i:registerEvent("timed_event",n)return e end,eventHandler=function(a,n,e)if
  3566. n=="timer"and e==t and l then i:sendEvent("timed_event",a)if(o>=1)then o=o-1 if(o>=1)then
  3567. t=os.startTimer(r)end elseif(o==-1)then t=os.startTimer(r)end end end}e.__index=e return e end end
  3568. r["objects"]["Switch"]=function(...)local e=l("Object")local t=l("utils").getValueFromXML
  3569. return
  3570. function(n)local n=e(n)local e="Switch"n.width=2 n.height=1
  3571. n.bgColor=colors.lightGray n.fgColor=colors.gray n:setValue(false)n:setZIndex(5)local o=colors.black local a=colors.red local r=colors.green
  3572. local e={getType=function(n)return e end,setSymbolColor=function(e,n)o=n
  3573. e:updateDraw()return e end,setActiveBackground=function(e,n)r=n e:updateDraw()return e end,setInactiveBackground=function(e,n)a=n e:updateDraw()return e end,setValuesByXMLData=function(l,e)n.setValuesByXMLData(l,e)if(t("inactiveBG",e)~=nil)then
  3574. a=colors[t("inactiveBG",e)]end if(t("activeBG",e)~=nil)then
  3575. r=colors[t("activeBG",e)]end if(t("symbolColor",e)~=nil)then
  3576. o=colors[t("symbolColor",e)]end end,mouseHandler=function(e,l,o,t)if(n.mouseHandler(e,l,o,t))then
  3577. local n,n=e:getAbsolutePosition(e:getAnchorPosition())e:setValue(not e:getValue())e:updateDraw()return true end end,draw=function(e)if(n.draw(e))then
  3578. if(e.parent~=nil)then local t,n=e:getAnchorPosition()local i,l=e:getSize()e.parent:drawBackgroundBox(t,n,i,l,e.bgColor)if(e:getValue())then
  3579. e.parent:drawBackgroundBox(t,n,1,l,r)e.parent:drawBackgroundBox(t+1,n,1,l,o)else
  3580. e.parent:drawBackgroundBox(t,n,1,l,o)e.parent:drawBackgroundBox(t+1,n,1,l,a)end end end end,init=function(e)e.parent:addEvent("mouse_click",e)if(n.init(e))then e.bgColor=e.parent:getTheme("SwitchBG")e.fgColor=e.parent:getTheme("SwitchText")o=e.parent:getTheme("SwitchBGSymbol")a=e.parent:getTheme("SwitchInactive")r=e.parent:getTheme("SwitchActive")end end}return setmetatable(e,n)end end r["libraries"]={}r["libraries"]["basaltEvent"]=function(...)return
  3581. function()local n={}local t={}local e={registerEvent=function(l,e,o)if(n[e]==nil)then n[e]={}t[e]=1 end
  3582. n[e][t[e]]=o t[e]=t[e]+1 return t[e]-1 end,removeEvent=function(o,e,t)n[e][t[e]]=nil end,sendEvent=function(e,t,...)local e
  3583. if(n[t]~=nil)then for t,n in pairs(n[t])do
  3584. local n=n(...)if(n==false)then e=n end end end return e end}e.__index=e return e end end
  3585. r["libraries"]["basaltLogs"]=function(...)local e=""local n="basaltLog.txt"local l="Debug"fs.delete(e~=""and e.."/"..n or n)local e={__call=function(r,t,o)if(t==nil)then return end
  3586. local e=e~=""and e.."/"..n or n
  3587. local e=fs.open(e,fs.exists(e)and"a"or"w")e.writeLine("[Basalt]["..(o and o or l).."]: "..tostring(t))e.close()end}return setmetatable({},e)end
  3588. r["libraries"]["basaltMon"]=function(...)local b={[colors.white]="0",[colors.orange]="1",[colors.magenta]="2",[colors.lightBlue]="3",[colors.yellow]="4",[colors.lime]="5",[colors.pink]="6",[colors.gray]="7",[colors.lightGray]="8",[colors.cyan]="9",[colors.purple]="a",[colors.blue]="b",[colors.brown]="c",[colors.green]="d",[colors.red]="e",[colors.black]="f"}local e,d,y,e=type,string.len,string.rep,string.sub
  3589. return
  3590. function(n)local e={}for t,n in pairs(n)do
  3591. e[t]={}for l,n in pairs(n)do local o=peripheral.wrap(n)if(o==nil)then
  3592. error("Unable to find monitor "..n)end e[t][l]=o
  3593. e[t][l].name=n end end local n,l,o,t,r,r,m,f=1,1,1,1,0,0,0,0 local i,h=false,1
  3594. local u,s=colors.white,colors.black
  3595. local function c()local t,o=0,0
  3596. for e,l in pairs(e)do local e,n=0,0
  3597. for o,t in pairs(l)do local o,t=t.getSize()e=e+o n=t>n and t or n end t=t>e and t or e o=o+n end m,f=t,o end c()local function a()local r=0 local a,i=0,0
  3598. for s,o in pairs(e)do local e=0 local t=0
  3599. for c,o in pairs(o)do
  3600. local d,i=o.getSize()if(n-e>=1)and(n-e<=d)then a=c end o.setCursorPos(n-e,l-r)e=e+d
  3601. if(t<i)then t=i end end if(l-r>=1)and(l-r<=t)then i=s end
  3602. r=r+t end o,t=a,i end a()local function r(n,...)local t={...}return
  3603. function()for o,e in pairs(e)do for o,e in pairs(e)do
  3604. e[n](table.unpack(t))end end end end
  3605. local function g()r("setCursorBlink",false)()if not(i)then return end if(e[t]==nil)then return end local e=e[t][o]if(e==nil)then return end e.setCursorBlink(i)end
  3606. local function p(l,c,i)if(e[t]==nil)then return end local r=e[t][o]if(r==nil)then return end r.blit(l,c,i)local r,s=r.getSize()if(d(l)+n>r)then local e=e[t][o+1]if(e~=nil)then e.blit(l,c,i)o=o+1 n=n+d(l)end end a()end
  3607. return{clear=r("clear"),setCursorBlink=function(e)i=e g()end,getCursorBlink=function()return i end,getCursorPos=function()return n,l end,setCursorPos=function(e,t)n,l=e,t a()g()end,setTextScale=function(e)r("setTextScale",e)()c()a()h=e end,getTextScale=function()return h end,blit=function(n,e,t)p(n,e,t)end,write=function(e)e=tostring(e)local n=d(e)p(e,y(b[u],n),y(b[s],n))end,getSize=function()return m,f end,setBackgroundColor=function(e)r("setBackgroundColor",e)()s=e end,setTextColor=function(e)r("setTextColor",e)()u=e end,calculateClick=function(d,a,r)local t=0
  3608. for e,o in pairs(e)do local e=0 local n=0
  3609. for o,l in pairs(o)do
  3610. local i,o=l.getSize()if(l.name==d)then return a+e,r+t end
  3611. e=e+i if(o>n)then n=o end end t=t+n end return a,r end}end end
  3612. r["libraries"]["basaltDraw"]=function(...)local h=l("tHex")local n,u=string.sub,string.rep
  3613. return
  3614. function(e)local o=e or term.current()local l local e,s=o.getSize()local r={}local a={}local i={}local t={}local t={}local t={}local c local t={}local function d()c=u(" ",e)for n=0,15 do local n=2^n
  3615. local o=h[n]t[n]=u(o,e)end end d()local function b()d()local o=c local l=t[colors.white]local d=t[colors.black]for t=1,s do
  3616. r[t]=n(r[t]==nil and o or r[t]..o:sub(1,e-r[t]:len()),1,e)i[t]=n(i[t]==nil and l or i[t]..l:sub(1,e-i[t]:len()),1,e)a[t]=n(a[t]==nil and d or a[t]..d:sub(1,e-a[t]:len()),1,e)end end b()local function p(t,a,o)if(a>=1)and(a<=s)then
  3617. if(t+o:len()>0)and(t<=e)then local d=r[a]local l local i=t+#o-1
  3618. if(t<1)then local l=1-t+1
  3619. local e=e-t+1 o=n(o,l,e)elseif(i>e)then local e=e-t+1 o=n(o,1,e)end
  3620. if(t>1)then local e=t-1 l=n(d,1,e)..o else l=o end if i<e then l=l..n(d,i+1,e)end
  3621. r[a]=l end end end
  3622. local function g(t,r,o)if(r>=1)and(r<=s)then
  3623. if(t+o:len()>0)and(t<=e)then
  3624. local d=a[r]local l local i=t+#o-1
  3625. if(t<1)then
  3626. o=n(o,1-t+1,e-t+1)elseif(i>e)then o=n(o,1,e-t+1)end
  3627. if(t>1)then l=n(d,1,t-1)..o else l=o end if i<e then l=l..n(d,i+1,e)end
  3628. a[r]=l end end end
  3629. local function m(t,r,o)if(r>=1)and(r<=s)then
  3630. if(t+o:len()>0)and(t<=e)then
  3631. local d=i[r]local l local a=t+#o-1
  3632. if(t<1)then local l=1-t+1 local e=e-t+1
  3633. o=n(o,l,e)elseif(a>e)then local e=e-t+1 o=n(o,1,e)end
  3634. if(t>1)then local e=t-1 l=n(d,1,e)..o else l=o end if a<e then l=l..n(d,a+1,e)end
  3635. i[r]=l end end end
  3636. local function y(o,l,t,c,d)if(#t==#c)or(#t==#d)then
  3637. if(l>=1)and(l<=s)then
  3638. if(o+t:len()>0)and(o<=e)then local g=r[l]local m=i[l]local p=a[l]local h,s,u local f=o+#t-1
  3639. if(o<1)then local l=1-o+1 local e=e-o+1
  3640. t=n(t,l,e)c=n(c,l,e)d=n(d,l,e)elseif(f>e)then local e=e-o+1
  3641. t=n(t,1,e)c=n(c,1,e)d=n(d,1,e)end
  3642. if(o>1)then local e=o-1 h=n(g,1,e)..t
  3643. s=n(m,1,e)..c u=n(p,1,e)..d else h=t s=c u=d end
  3644. if f<e then h=h..n(g,f+1,e)s=s..n(m,f+1,e)u=u..n(p,f+1,e)end r[l]=h i[l]=s a[l]=u end end end end
  3645. local e={setSize=function(n,t)e,s=n,t b()end,setMirror=function(e)l=e end,setBG=function(n,e,t)g(n,e,t)end,setText=function(t,e,n)p(t,e,n)end,setFG=function(t,e,n)m(t,e,n)end,blit=function(l,o,t,n,e)y(l,o,t,n,e)end,drawBackgroundBox=function(t,n,e,o,l)for o=1,o
  3646. do g(t,n+(o-1),u(h[l],e))end end,drawForegroundBox=function(l,t,o,n,e)for n=1,n do
  3647. m(l,t+(n-1),u(h[e],o))end end,drawTextBox=function(e,t,n,o,l)for o=1,o do p(e,t+(o-1),u(l,n))end end,writeText=function(t,n,e,l,o)if(e~=nil)then p(t,n,e)if(l~=nil)and(l~=false)then
  3648. g(t,n,u(h[l],e:len()))end if(o~=nil)and(o~=false)then
  3649. m(t,n,u(h[o],e:len()))end end end,update=function()local t,d=o.getCursorPos()local n=false
  3650. if(o.getCursorBlink~=nil)then n=o.getCursorBlink()end o.setCursorBlink(false)if(l~=nil)then
  3651. l.setCursorBlink(false)end
  3652. for e=1,s do o.setCursorPos(1,e)o.blit(r[e],i[e],a[e])if(l~=nil)then l.setCursorPos(1,e)l.blit(r[e],i[e],a[e])end end o.setBackgroundColor(colors.black)o.setCursorBlink(n)o.setCursorPos(t,d)if(l~=nil)then
  3653. l.setBackgroundColor(colors.black)l.setCursorBlink(n)l.setCursorPos(t,d)end end,setTerm=function(e)o=e end}return e end end
  3654. r["libraries"]["bigfont"]=function(...)local h=l("tHex")local n={{"\32\32\32\137\156\148\158\159\148\135\135\144\159\139\32\136\157\32\159\139\32\32\143\32\32\143\32\32\32\32\32\32\32\32\147\148\150\131\148\32\32\32\151\140\148\151\140\147","\32\32\32\149\132\149\136\156\149\144\32\133\139\159\129\143\159\133\143\159\133\138\32\133\138\32\133\32\32\32\32\32\32\150\150\129\137\156\129\32\32\32\133\131\129\133\131\132","\32\32\32\130\131\32\130\131\32\32\129\32\32\32\32\130\131\32\130\131\32\32\32\32\143\143\143\32\32\32\32\32\32\130\129\32\130\135\32\32\32\32\131\32\32\131\32\131","\139\144\32\32\143\148\135\130\144\149\32\149\150\151\149\158\140\129\32\32\32\135\130\144\135\130\144\32\149\32\32\139\32\159\148\32\32\32\32\159\32\144\32\148\32\147\131\132","\159\135\129\131\143\149\143\138\144\138\32\133\130\149\149\137\155\149\159\143\144\147\130\132\32\149\32\147\130\132\131\159\129\139\151\129\148\32\32\139\131\135\133\32\144\130\151\32","\32\32\32\32\32\32\130\135\32\130\32\129\32\129\129\131\131\32\130\131\129\140\141\132\32\129\32\32\129\32\32\32\32\32\32\32\131\131\129\32\32\32\32\32\32\32\32\32","\32\32\32\32\149\32\159\154\133\133\133\144\152\141\132\133\151\129\136\153\32\32\154\32\159\134\129\130\137\144\159\32\144\32\148\32\32\32\32\32\32\32\32\32\32\32\151\129","\32\32\32\32\133\32\32\32\32\145\145\132\141\140\132\151\129\144\150\146\129\32\32\32\138\144\32\32\159\133\136\131\132\131\151\129\32\144\32\131\131\129\32\144\32\151\129\32","\32\32\32\32\129\32\32\32\32\130\130\32\32\129\32\129\32\129\130\129\129\32\32\32\32\130\129\130\129\32\32\32\32\32\32\32\32\133\32\32\32\32\32\129\32\129\32\32","\150\156\148\136\149\32\134\131\148\134\131\148\159\134\149\136\140\129\152\131\32\135\131\149\150\131\148\150\131\148\32\148\32\32\148\32\32\152\129\143\143\144\130\155\32\134\131\148","\157\129\149\32\149\32\152\131\144\144\131\148\141\140\149\144\32\149\151\131\148\32\150\32\150\131\148\130\156\133\32\144\32\32\144\32\130\155\32\143\143\144\32\152\129\32\134\32","\130\131\32\131\131\129\131\131\129\130\131\32\32\32\129\130\131\32\130\131\32\32\129\32\130\131\32\130\129\32\32\129\32\32\133\32\32\32\129\32\32\32\130\32\32\32\129\32","\150\140\150\137\140\148\136\140\132\150\131\132\151\131\148\136\147\129\136\147\129\150\156\145\138\143\149\130\151\32\32\32\149\138\152\129\149\32\32\157\152\149\157\144\149\150\131\148","\149\143\142\149\32\149\149\32\149\149\32\144\149\32\149\149\32\32\149\32\32\149\32\149\149\32\149\32\149\32\144\32\149\149\130\148\149\32\32\149\32\149\149\130\149\149\32\149","\130\131\129\129\32\129\131\131\32\130\131\32\131\131\32\131\131\129\129\32\32\130\131\32\129\32\129\130\131\32\130\131\32\129\32\129\131\131\129\129\32\129\129\32\129\130\131\32","\136\140\132\150\131\148\136\140\132\153\140\129\131\151\129\149\32\149\149\32\149\149\32\149\137\152\129\137\152\129\131\156\133\149\131\32\150\32\32\130\148\32\152\137\144\32\32\32","\149\32\32\149\159\133\149\32\149\144\32\149\32\149\32\149\32\149\150\151\129\138\155\149\150\130\148\32\149\32\152\129\32\149\32\32\32\150\32\32\149\32\32\32\32\32\32\32","\129\32\32\130\129\129\129\32\129\130\131\32\32\129\32\130\131\32\32\129\32\129\32\129\129\32\129\32\129\32\131\131\129\130\131\32\32\32\129\130\131\32\32\32\32\140\140\132","\32\154\32\159\143\32\149\143\32\159\143\32\159\144\149\159\143\32\159\137\145\159\143\144\149\143\32\32\145\32\32\32\145\149\32\144\32\149\32\143\159\32\143\143\32\159\143\32","\32\32\32\152\140\149\151\32\149\149\32\145\149\130\149\157\140\133\32\149\32\154\143\149\151\32\149\32\149\32\144\32\149\149\153\32\32\149\32\149\133\149\149\32\149\149\32\149","\32\32\32\130\131\129\131\131\32\130\131\32\130\131\129\130\131\129\32\129\32\140\140\129\129\32\129\32\129\32\137\140\129\130\32\129\32\130\32\129\32\129\129\32\129\130\131\32","\144\143\32\159\144\144\144\143\32\159\143\144\159\138\32\144\32\144\144\32\144\144\32\144\144\32\144\144\32\144\143\143\144\32\150\129\32\149\32\130\150\32\134\137\134\134\131\148","\136\143\133\154\141\149\151\32\129\137\140\144\32\149\32\149\32\149\154\159\133\149\148\149\157\153\32\154\143\149\159\134\32\130\148\32\32\149\32\32\151\129\32\32\32\32\134\32","\133\32\32\32\32\133\129\32\32\131\131\32\32\130\32\130\131\129\32\129\32\130\131\129\129\32\129\140\140\129\131\131\129\32\130\129\32\129\32\130\129\32\32\32\32\32\129\32","\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32","\32\32\32\32\32\32\32\32\32\32\32\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\32\32\32\32\32\32\32\32\32\32\32","\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32\32","\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32\32\32\32\32\149\32\32\149\32\32\32\32","\32\32\32\32\32\32\32\32\32\32\32\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\32\32\32\32\32\32\32\32\32\32\32","\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32\32\149\32","\32\32\32\32\145\32\159\139\32\151\131\132\155\143\132\134\135\145\32\149\32\158\140\129\130\130\32\152\147\155\157\134\32\32\144\144\32\32\32\32\32\32\152\131\155\131\131\129","\32\32\32\32\149\32\149\32\145\148\131\32\149\32\149\140\157\132\32\148\32\137\155\149\32\32\32\149\154\149\137\142\32\153\153\32\131\131\149\131\131\129\149\135\145\32\32\32","\32\32\32\32\129\32\130\135\32\131\131\129\134\131\132\32\129\32\32\129\32\131\131\32\32\32\32\130\131\129\32\32\32\32\129\129\32\32\32\32\32\32\130\131\129\32\32\32","\150\150\32\32\148\32\134\32\32\132\32\32\134\32\32\144\32\144\150\151\149\32\32\32\32\32\32\145\32\32\152\140\144\144\144\32\133\151\129\133\151\129\132\151\129\32\145\32","\130\129\32\131\151\129\141\32\32\142\32\32\32\32\32\149\32\149\130\149\149\32\143\32\32\32\32\142\132\32\154\143\133\157\153\132\151\150\148\151\158\132\151\150\148\144\130\148","\32\32\32\140\140\132\32\32\32\32\32\32\32\32\32\151\131\32\32\129\129\32\32\32\32\134\32\32\32\32\32\32\32\129\129\32\129\32\129\129\130\129\129\32\129\130\131\32","\156\143\32\159\141\129\153\140\132\153\137\32\157\141\32\159\142\32\150\151\129\150\131\132\140\143\144\143\141\145\137\140\148\141\141\144\157\142\32\159\140\32\151\134\32\157\141\32","\157\140\149\157\140\149\157\140\149\157\140\149\157\140\149\157\140\149\151\151\32\154\143\132\157\140\32\157\140\32\157\140\32\157\140\32\32\149\32\32\149\32\32\149\32\32\149\32","\129\32\129\129\32\129\129\32\129\129\32\129\129\32\129\129\32\129\129\131\129\32\134\32\131\131\129\131\131\129\131\131\129\131\131\129\130\131\32\130\131\32\130\131\32\130\131\32","\151\131\148\152\137\145\155\140\144\152\142\145\153\140\132\153\137\32\154\142\144\155\159\132\150\156\148\147\32\144\144\130\145\136\137\32\146\130\144\144\130\145\130\136\32\151\140\132","\151\32\149\151\155\149\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\152\137\144\157\129\149\149\32\149\149\32\149\149\32\149\149\32\149\130\150\32\32\157\129\149\32\149","\131\131\32\129\32\129\130\131\32\130\131\32\130\131\32\130\131\32\130\131\32\32\32\32\130\131\32\130\131\32\130\131\32\130\131\32\130\131\32\32\129\32\130\131\32\133\131\32","\156\143\32\159\141\129\153\140\132\153\137\32\157\141\32\159\142\32\159\159\144\152\140\144\156\143\32\159\141\129\153\140\132\157\141\32\130\145\32\32\147\32\136\153\32\130\146\32","\152\140\149\152\140\149\152\140\149\152\140\149\152\140\149\152\140\149\149\157\134\154\143\132\157\140\133\157\140\133\157\140\133\157\140\133\32\149\32\32\149\32\32\149\32\32\149\32","\130\131\129\130\131\129\130\131\129\130\131\129\130\131\129\130\131\129\130\130\131\32\134\32\130\131\129\130\131\129\130\131\129\130\131\129\32\129\32\32\129\32\32\129\32\32\129\32","\159\134\144\137\137\32\156\143\32\159\141\129\153\140\132\153\137\32\157\141\32\32\132\32\159\143\32\147\32\144\144\130\145\136\137\32\146\130\144\144\130\145\130\138\32\146\130\144","\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\149\32\149\131\147\129\138\134\149\149\32\149\149\32\149\149\32\149\149\32\149\154\143\149\32\157\129\154\143\149","\130\131\32\129\32\129\130\131\32\130\131\32\130\131\32\130\131\32\130\131\32\32\32\32\130\131\32\130\131\129\130\131\129\130\131\129\130\131\129\140\140\129\130\131\32\140\140\129"},{"000110000110110000110010101000000010000000100101","000000110110000000000010101000000010000000100101","000000000000000000000000000000000000000000000000","100010110100000010000110110000010100000100000110","000000110000000010110110000110000000000000110000","000000000000000000000000000000000000000000000000","000000110110000010000000100000100000000000000010","000000000110110100010000000010000000000000000100","000000000000000000000000000000000000000000000000","010000000000100110000000000000000000000110010000","000000000000000000000000000010000000010110000000","000000000000000000000000000000000000000000000000","011110110000000100100010110000000100000000000000","000000000000000000000000000000000000000000000000","000000000000000000000000000000000000000000000000","110000110110000000000000000000010100100010000000","000010000000000000110110000000000100010010000000","000000000000000000000000000000000000000000000000","010110010110100110110110010000000100000110110110","000000000000000000000110000000000110000000000000","000000000000000000000000000000000000000000000000","010100010110110000000000000000110000000010000000","110110000000000000110000110110100000000010000000","000000000000000000000000000000000000000000000000","000100011111000100011111000100011111000100011111","000000000000100100100100011011011011111111111111","000000000000000000000000000000000000000000000000","000100011111000100011111000100011111000100011111","000000000000100100100100011011011011111111111111","100100100100100100100100100100100100100100100100","000000110100110110000010000011110000000000011000","000000000100000000000010000011000110000000001000","000000000000000000000000000000000000000000000000","010000100100000000000000000100000000010010110000","000000000000000000000000000000110110110110110000","000000000000000000000000000000000000000000000000","110110110110110110000000110110110110110110110110","000000000000000000000110000000000000000000000000","000000000000000000000000000000000000000000000000","000000000000110110000110010000000000000000010010","000010000000000000000000000000000000000000000000","000000000000000000000000000000000000000000000000","110110110110110110110000110110110110000000000000","000000000000000000000110000000000000000000000000","000000000000000000000000000000000000000000000000","110110110110110110110000110000000000000000010000","000000000000000000000000100000000000000110000110","000000000000000000000000000000000000000000000000"}}local t={}local o={}do local a=0 local e=#n[1]local l=#n[1][1]for t=1,e,3 do
  3655. for e=1,l,3 do
  3656. local i=string.char(a)local r={}r[1]=n[1][t]:sub(e,e+2)r[2]=n[1][t+1]:sub(e,e+2)r[3]=n[1][t+2]:sub(e,e+2)local l={}l[1]=n[2][t]:sub(e,e+2)l[2]=n[2][t+1]:sub(e,e+2)l[3]=n[2][t+2]:sub(e,e+2)o[i]={r,l}a=a+1 end end t[1]=o end
  3657. local function g(e,l)local u={["0"]="1",["1"]="0"}if e<=#t then return true end
  3658. for s=#t+1,e do local h={}local n=t[s-1]for m=0,255 do local c=string.char(m)local r={}local t={}local e=n[c][1]local p=n[c][2]for a=1,#e do local c,f,s,l,i,d={},{},{},{},{},{}for n=1,#e[1]do
  3659. local t=o[e[a]:sub(n,n)][1]table.insert(c,t[1])table.insert(f,t[2])table.insert(s,t[3])local e=o[e[a]:sub(n,n)][2]if p[a]:sub(n,n)=="1"then
  3660. table.insert(l,(e[1]:gsub("[01]",u)))table.insert(i,(e[2]:gsub("[01]",u)))table.insert(d,(e[3]:gsub("[01]",u)))else table.insert(l,e[1])table.insert(i,e[2])table.insert(d,e[3])end end table.insert(r,table.concat(c))table.insert(r,table.concat(f))table.insert(r,table.concat(s))table.insert(t,table.concat(l))table.insert(t,table.concat(i))table.insert(t,table.concat(d))end h[c]={r,t}if l then l="Font"..s.."Yeld"..m
  3661. os.queueEvent(l)os.pullEvent(l)end end t[s]=h end return true end
  3662. local function f(n,e,l,o,i)if not type(e)=="string"then error("Not a String",3)end
  3663. local a=type(l)=="string"and l:sub(1,1)or h[l]or
  3664. error("Wrong Front Color",3)local r=type(o)=="string"and o:sub(1,1)or h[o]or
  3665. error("Wrong Back Color",3)if(t[n]==nil)then g(3,false)end local t=t[n]or
  3666. error("Wrong font size selected",3)if e==""then
  3667. return{{""},{""},{""}}end local n={}for e in e:gmatch('.')do table.insert(n,e)end local d={}local c=#t[n[1]][1]for l=1,c do local o={}for e=1,#n do o[e]=t[n[e]]and
  3668. t[n[e]][1][l]or""end d[l]=table.concat(o)end local s={}local u={}local f={["0"]=a,["1"]=r}local h={["0"]=r,["1"]=a}for r=1,c do
  3669. local d={}local a={}for e=1,#n do
  3670. local n=t[n[e]]and t[n[e]][2][r]or""d[e]=n:gsub("[01]",i and{["0"]=l:sub(e,e),["1"]=o:sub(e,e)}or f)a[e]=n:gsub("[01]",i and{["0"]=o:sub(e,e),["1"]=l:sub(e,e)}or h)end s[r]=table.concat(d)u[r]=table.concat(a)end return{d,s,u}end return f end
  3671. r["libraries"]["bimg"]=function(...)local d,a=string.sub,string.rep
  3672. local function h(s,u)local n,i=0,0
  3673. local l,o,t={},{},{}local r,e=1,1 local c={}local function p()for e=1,i do if(l[e]==nil)then l[e]=a(" ",n)else l[e]=l[e]..a(" ",n-#l[e])end if(o[e]==nil)then o[e]=a("0",n)else
  3674. o[e]=o[e]..a("0",n-#o[e])end
  3675. if(t[e]==nil)then t[e]=a("f",n)else t[e]=t[e]..a("f",n-#t[e])end end end
  3676. local m=function(t,o,c)r=o or r e=c or e
  3677. if(l[e]==nil)then l[e]=a(" ",r-1)..t..a(" ",n-(#t+r))else l[e]=d(l[e],1,r-1)..a(" ",r-#l[e])..t..d(l[e],r+#t,n)end if(#l[e]>n)then n=#l[e]end if(e>i)then i=e end
  3678. u.updateSize(n,i)end
  3679. local h=function(o,c,l)r=c or r e=l or e
  3680. if(t[e]==nil)then t[e]=a("f",r-1)..o..a("f",n-(#o+r))else t[e]=d(t[e],1,r-1)..a("f",r-#t[e])..o..d(t[e],r+#o,n)end if(#t[e]>n)then n=#t[e]end if(e>i)then i=e end
  3681. u.updateSize(n,i)end
  3682. local f=function(t,l,c)r=l or r e=c or e
  3683. if(o[e]==nil)then o[e]=a("0",r-1)..t..a("0",n-(#t+r))else o[e]=d(o[e],1,r-1)..a("0",r-#o[e])..t..d(o[e],r+#t,n)end if(#o[e]>n)then n=#o[e]end if(e>i)then i=e end
  3684. u.updateSize(n,i)end
  3685. local function r(e)c={}l,o,t={},{},{}for e,n in pairs(s)do if(type(e)=="string")then c[e]=n else
  3686. l[e],o[e],t[e]=n[1],n[2],n[3]end end u.updateSize(n,i)end if(s~=nil)then n=#s[1][1]i=#s r(s)end
  3687. return{recalculateSize=p,setFrame=r,getFrame=function()local e={}for n,l in
  3688. pairs(l)do table.insert(e,{l,o[n],t[n]})end for n,t in pairs(c)do e[n]=t end return e,n,i end,getImage=function()local e={}for n,l in pairs(l)do
  3689. table.insert(e,{l,o[n],t[n]})end return e end,setFrameData=function(e,n)if(n~=nil)then c[e]=n else if(type(e)=="table")then c=e end end end,setFrameImage=function(n)for e,r in pairs(n.t)do
  3690. l[e]=n.t[e]o[e]=n.fg[e]t[e]=n.bg[e]end end,getFrameImage=function()return{t=l,fg=o,bg=t}end,getFrameData=function(e)return(e~=nil and c[e]or c)end,blit=function(t,o,l,n,e)m(t,n,e)f(o,n,e)h(l,n,e)end,text=m,fg=f,bg=h,getSize=function()return
  3691. n,i end,setSize=function(r,f)local c,u,s={},{},{}for e=1,f do
  3692. if(l[e]~=nil)then c[e]=d(l[e],1,r)..a(" ",r-n)else c[e]=a(" ",r)end if(o[e]~=nil)then
  3693. u[e]=d(o[e],1,r)..a("0",r-n)else u[e]=a("0",r)end if(t[e]~=nil)then s[e]=d(t[e],1,r)..a("f",r-n)else
  3694. s[e]=a("f",r)end end l,o,t=c,u,s n,i=r,f end}end
  3695. return
  3696. function(a)local e={}local n={creator="Bimg Library by NyoriE",date=os.date("!%Y-%m-%dT%TZ")}local o,t=0,0 local r={}local function l(n,l)n=n or#e+1
  3697. table.insert(e,n,h(l,r))if(l==nil)then e[n].setSize(o,t)end end local function i(n)table.remove(e,n or#e)end
  3698. local function d(n,t)local o=e[n]if(o~=nil)then local t=n+t if(t>=1)and(t<=#e)then table.remove(e,n)table.insert(e,t,o)end end end
  3699. r={updateSize=function(l,r,n)local n=n==true and true or false
  3700. if(l>o)then n=true o=l end if(r>t)then n=true t=r end
  3701. if(n)then for n,e in pairs(e)do e.setSize(o,t)e.recalculateSize()end end end,text=function(n,t,o,r)local e=e[n]if(e==nil)then e=l(n)end e.text(t,o,r)end,fg=function(n,r,t,o)local e=e[n]if(e==nil)then e=l(n)end e.fg(r,t,o)end,bg=function(n,t,r,o)local e=e[n]if(e==nil)then e=l(n)end e.bg(t,r,o)end,blit=function(n,i,a,o,t,r)local e=e[n]if(e==nil)then e=l(n)end e.blit(i,a,o,t,r)end,setSize=function(n,l)o=n t=l for t,e in pairs(e)do e.setSize(n,l)end end,getFrame=function(n)if(e[n]~=nil)then return e[n].getFrame()end end,getFrameObjects=function()return
  3702. e end,getFrames=function()local n={}for t,e in pairs(e)do local e=e.getFrame()table.insert(n,e)end return n end,getFrameObject=function(n)return
  3703. e[n]end,addFrame=function(t)local o=h()if(#e<=1)then
  3704. if(n.animated==nil)then n.animated=true end
  3705. if(n.secondsPerFrame==nil)then n.secondsPerFrame=.2 end end l(t)return o end,removeFrame=function(t)i(t)if(#e<=1)then if(n.animated==nil)then n.animated=true end if(n.secondsPerFrame==nil)then n.secondsPerFrame=.2 end end end,moveFrame=d,setFrameData=function(n,t,o)if(e[n]~=nil)then e[n].setFrameData(t,o)end end,getFrameData=function(n,t)return e[n]~=nil and
  3706. e[n].getFrameData(t)end,getSize=function()return
  3707. o,t end,setAnimation=function(e)n.animation=e end,setMetadata=function(e,t)if(t~=nil)then n[e]=t else if(type(e)=="table")then n=e end end end,getMetadata=function(e)return
  3708. e~=nil and n[e]or n end,createBimg=function()local l={}for n,e in pairs(e)do local e=e.getFrame()table.insert(l,e)end for e,n in pairs(n)do l[e]=n end l.width=o l.height=t return l end}if(a~=nil)then for e,t in pairs(a)do
  3709. if(type(e)=="string")then n[e]=t else l(e,t)end end
  3710. if(n.width==nil)or(n.height==nil)then for n,e in pairs(e)do local n,e=e.getSize()if(n>o)then n=o end
  3711. if(e>t)then e=t end end
  3712. r.updateSize(o,t,true)end else l(1)end return r end end
  3713. r["libraries"]["images"]=function(...)local i,c,t=string.sub,math.floor,string.rep
  3714. local function l(e)local o={{}}local n=fs.open(e,"r")if(n~=nil)then for e in n.readLine do
  3715. table.insert(o[1],{t(" ",#e),t(" ",#e),e})end n.close()return o end end
  3716. local function s(e)return paintutils.loadImage(e),"nfp"end
  3717. local function a(e)local e=fs.open(e,"rb")local n=textutils.unserialize(e.readAll())e.close()if(n~=nil)then return n,"bimg"end end local function t(e)end local function o(e)end local function p(e,n)if(n==nil)then if(e:find(".bimg"))then return a(e)elseif(e:find(".bbf"))then return t(e)else return s(e)end end end
  3718. local function h(e,n)if(n==nil)then
  3719. if(e:find(".bimg"))then return a(e)elseif(e:find(".bbf"))then return o(e)else return l(e)end end end
  3720. local function m(e,r,o)local u,f=e.width or#e[1][1][1],e.height or#e[1]local n={}for l,t in pairs(e)do
  3721. if(type(l)=="number")then local s={}for e=1,o do local l,d,a="","",""local n=c(e/o*f+.5)if(t[n]~=nil)then
  3722. for e=1,r do local e=c(e/r*u+.5)l=l..i(t[n][1],e,e)d=d..i(t[n][2],e,e)a=a..i(t[n][3],e,e)end table.insert(s,{l,d,a})end end table.insert(n,l,s)else n[l]=t end end n.width=r n.height=o return n end
  3723. return{loadNFP=s,loadBIMG=a,loadImage=p,resizeBIMG=m,loadImageAsBimg=h}end
  3724. r["libraries"]["layout"]=function(...)local function i(n)local e={}e.___value=nil e.___name=n
  3725. e.___children={}e.___props={}function e:value()return self.___value end function e:setValue(e)self.___value=e end function e:name()return self.___name end function e:setName(e)self.___name=e end function e:children()return self.___children end function e:numChildren()return#self.___children end
  3726. function e:addChild(e)if
  3727. self[e:name()]~=nil then if
  3728. type(self[e:name()].name)=="function"then local n={}table.insert(n,self[e:name()])self[e:name()]=n end
  3729. table.insert(self[e:name()],e)else self[e:name()]=e end table.insert(self.___children,e)end function e:properties()return self.___props end function e:numProperties()return#self.___props end
  3730. function e:addProperty(n,t)local e="@"..n
  3731. if self[e]~=nil then if
  3732. type(self[e])=="string"then local n={}table.insert(n,self[e])self[e]=n end
  3733. table.insert(self[e],t)else self[e]=t end
  3734. table.insert(self.___props,{name=n,value=self[n]})end return e end local o={}function o:ToXmlString(e)e=string.gsub(e,"&","&amp;")e=string.gsub(e,"<","&lt;")e=string.gsub(e,">","&gt;")e=string.gsub(e,"\"","&quot;")e=string.gsub(e,"([^%w%&%;%p%\t% ])",function(e)return string.format("&#x%X;",string.byte(e))end)return e end
  3735. function o:FromXmlString(e)e=string.gsub(e,"&#x([%x]+)%;",function(e)return string.char(tonumber(e,16))end)e=string.gsub(e,"&#([0-9]+)%;",function(e)return string.char(tonumber(e,10))end)e=string.gsub(e,"&quot;","\"")e=string.gsub(e,"&apos;","'")e=string.gsub(e,"&gt;",">")e=string.gsub(e,"&lt;","<")e=string.gsub(e,"&amp;","&")return e end function o:ParseArgs(e,n)string.gsub(n,"(%w+)=([\"'])(.-)%2",function(t,o,n)e:addProperty(t,self:FromXmlString(n))end)end
  3736. function o:ParseXmlText(a)local e={}local n=i()table.insert(e,n)local r,d,t,l,s local o,c=1,1
  3737. while true do
  3738. r,c,d,t,l,s=string.find(a,"<(%/?)([%w_:]+)(.-)(%/?)>",o)if not r then break end local r=string.sub(a,o,r-1)if not
  3739. string.find(r,"^%s*$")then
  3740. local n=(n:value()or"")..self:FromXmlString(r)e[#e]:setValue(n)end
  3741. if s=="/"then local e=i(t)self:ParseArgs(e,l)n:addChild(e)elseif d==""then local t=i(t)self:ParseArgs(t,l)table.insert(e,t)n=t else local o=table.remove(e)n=e[#e]if#e<1 then error("XmlParser: nothing to close with "..t)end if o:name()~=t then
  3742. error("XmlParser: trying to close "..o.name.." with "..t)end n:addChild(o)end o=c+1 end local t=string.sub(a,o)if#e>1 then
  3743. error("XmlParser: unclosed "..e[#e]:name())end return n end
  3744. function o:loadFile(n,e)if not e then e=system.ResourceDirectory end
  3745. local e=system.pathForFile(n,e)local e,n=io.open(e,"r")if e and not n then local n=e:read("*a")io.close(e)return self:ParseXmlText(n),nil else print(n)return nil end end return o end
  3746. r["libraries"]["module"]=function(...)return function(e)local e,n=pcall(l,e)return e and n or nil end end
  3747. r["libraries"]["process"]=function(...)local a={}local t={}local o=0
  3748. local i=dofile("rom/modules/main/cc/require.lua").make
  3749. function t:new(n,e,r,...)local l={...}local t=setmetatable({path=n},{__index=self})t.window=e e.current=term.current e.redirect=term.redirect
  3750. t.processId=o
  3751. if(type(n)=="string")then
  3752. t.coroutine=coroutine.create(function()local t=shell.resolveProgram(n)local e=setmetatable(r,{__index=_ENV})e.shell=shell
  3753. e.basaltProgram=true e.arg={[0]=n,table.unpack(l)}e.require,e.package=i(e,fs.getDir(t))if(fs.exists(t))then local t=fs.open(t,"r")local o=t.readAll()t.close()local e=load(o,n,"bt",e)if(e~=nil)then return e()end end end)elseif(type(n)=="function")then
  3754. t.coroutine=coroutine.create(function()n(table.unpack(l))end)else return end a[o]=t o=o+1 return t end
  3755. function t:resume(e,...)local t=term.current()term.redirect(self.window)if(self.filter~=nil)then if(e~=self.filter)then return end self.filter=nil end local n,e=coroutine.resume(self.coroutine,e,...)if n then
  3756. self.filter=e else printError(e)end term.redirect(t)return n,e end
  3757. function t:isDead()if(self.coroutine~=nil)then
  3758. if(coroutine.status(self.coroutine)=="dead")then table.remove(a,self.processId)return true end else return true end return false end
  3759. function t:getStatus()if(self.coroutine~=nil)then
  3760. return coroutine.status(self.coroutine)end return nil end
  3761. function t:start()coroutine.resume(self.coroutine)end return t end
  3762. r["libraries"]["tHex"]=function(...)return{[colors.white]="0",[colors.orange]="1",[colors.magenta]="2",[colors.lightBlue]="3",[colors.yellow]="4",[colors.lime]="5",[colors.pink]="6",[colors.gray]="7",[colors.lightGray]="8",[colors.cyan]="9",[colors.purple]="a",[colors.blue]="b",[colors.brown]="c",[colors.green]="d",[colors.red]="e",[colors.black]="f"}end
  3763. r["libraries"]["utils"]=function(...)local o,r,c=string.sub,string.find,string.reverse
  3764. local function d(e,l)local t={}if e==""or l==""then return t end local n=1
  3765. local a,i=r(e,l,n)while a do table.insert(t,o(e,n,a-1))n=i+1
  3766. a,i=r(e,l,n)end
  3767. table.insert(t,o(e,n))return t end
  3768. local a={[0]={8,4,3,6,5},{4,14,8,7},{6,10,8,7},{9,11,8,0},{1,14,8,0},{13,12,8,0},{2,10,8,0},{15,8,10,11,12,14},{0,7,1,9,2,13},{3,11,8,7},{2,6,7,15},{9,3,7,15},{13,5,7,15},{5,12,8,7},{1,4,7,15},{7,10,11,12,14}}local l,i,t={},{},{}for e=0,15 do i[2^e]=e end
  3769. do local n="0123456789abcdef"for e=1,16 do l[n:sub(e,e)]=e-1 l[e-1]=n:sub(e,e)t[n:sub(e,e)]=2^(e-1)t[2^(e-1)]=n:sub(e,e)local e=a[e-1]for n=1,#e do
  3770. e[n]=2^e[n]end end end
  3771. local function s(e)local n=a[i[e[#e][1]]]for t=1,#n do local t=n[t]for n=1,#e-1 do if
  3772. e[n][1]==t then return n end end end return 1 end
  3773. local function u(n,o)if not o then local t={}o={}for l=1,6 do local e=n[l]local n=o[e]o[e],t[l]=n and(n+1)or 1,e end n=t end local e={}for t,n in pairs(o)do e[#e+1]={t,n}end
  3774. if#e>1 then
  3775. while#e>2 do
  3776. table.sort(e,function(e,n)return e[2]>n[2]end)local t,l=s(e),#e local a,r=e[l][1],e[t][1]for o=1,6 do if n[o]==a then
  3777. n[o]=r e[t][2]=e[t][2]+1 end end e[l]=nil end local o=128
  3778. for e=1,#n-1 do if n[e]~=n[6]then o=o+2^(e-1)end end return string.char(o),t[e[1][1]==n[6]and e[2][1]or e[1][1]],t[n[6]]else
  3779. return"\128",t[n[1]],t[n[1]]end end
  3780. return{getTextHorizontalAlign=function(e,l,r,n)e=o(e,1,l)local t=l-string.len(e)if(r=="right")then e=string.rep(n or" ",t)..e elseif(r=="center")then
  3781. e=string.rep(n or" ",math.floor(t/2))..e..string.rep(n or" ",math.floor(t/2))e=e..(string.len(e)<l and(n or" ")or"")else e=e..string.rep(n or" ",t)end return e end,getTextVerticalAlign=function(n,t)local e=0
  3782. if(t=="center")then e=math.ceil(n/2)if(e<1)then e=1 end end if(t=="bottom")then e=n end if(e<1)then e=1 end return e end,rpairs=function(n)return function(n,e)e=e-1 if e~=0 then return e,n[e]end end,n,#n+1 end,tableCount=function(n)local e=0 if(n~=nil)then for n,n in pairs(n)do e=e+1 end end return e end,splitString=d,createText=function(e,l)local e=d(e,"\n")local t={}for n,e in pairs(e)do if(#e==0)then table.insert(t,"")end
  3783. while#e>l do local n=r(c(o(e,1,l))," ")if not n then n=l else
  3784. n=l-n+1 end local l=o(e,1,n)table.insert(t,l)e=o(e,n+1)end if#e>0 then table.insert(t,e)end end return t end,getValueFromXML=function(t,n)local e if(type(n)~="table")then return end if(n[t]~=nil)then
  3785. if(type(n[t])=="table")then if(n[t].value~=nil)then e=n[t]:value()end end end if(e==nil)then
  3786. e=n["@"..t]end if(e=="true")then e=true elseif(e=="false")then e=false elseif(tonumber(e)~=nil)then
  3787. e=tonumber(e)end return e end,numberFromString=function(e)return load("return "..e)()end,uuid=function()local e=math.random
  3788. local function t()local n='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'return
  3789. string.gsub(n,'[xy]',function(n)local e=(n=='x')and e(0,15)or e(8,11)return string.format('%x',e)end)end return t()end,array=function(e,n)return
  3790. load("return {"..("nil,"):rep(e)..("[0]=nil,"):rep(n).."}")()end,shrink=function(n,e)local e,l,t,c={{},{},{}},0,#n+#n%3,e or colours.black for e=1,#n do if#n[e]>l then l=#n[e]end end
  3791. for o=0,t-1,3 do
  3792. local i,d,s,t={},{},{},1
  3793. for a=0,l-1,2 do local e,l={},{}for t=1,3 do
  3794. for r=1,2 do
  3795. e[#e+1]=(n[o+t]and n[o+t][a+r])and(n[o+t][a+r]==0 and c or n[o+t][a+r])or c l[e[#e]]=l[e[#e]]and(l[e[#e]]+1)or 1 end end i[t],d[t],s[t]=u(e,l)t=t+1 end
  3796. e[1][#e[1]+1],e[2][#e[2]+1],e[3][#e[3]+1]=table.concat(i),table.concat(d),table.concat(s)end e.width,e.height=#e[1][1],#e[1]return e end}end return r["main"]()end,["pine3d.Pine3D"]=function(...)local T=a("pine3d.betterblittle")local u={}for e=1,16 do
  3797. u[2^(e-1)]=("0123456789abcdef"):sub(e,e)end
  3798. local n=math.pow(10,99)local function m(e,o,t,l)local t=t-e
  3799. if t==0 then
  3800. return n,-n*e
  3801. end
  3802. local n=(l-o)/t
  3803. return n,o-n*e
  3804. end
  3805. local t=math.min
  3806. local n=math.max
  3807. local o=math.floor
  3808. local s=math.ceil
  3809. local function S(a,r,e,l)local a={x1=a,y1=r,x2=e,y2=l,width=e-a+1,height=l-r+1,screenBuffer={{}},blittleWindow=nil,blittleOn=false,backgroundColor=colors.lightBlue}function a:setBufferSize(n,e,o,t)self.x1=n
  3810. self.y1=e
  3811. self.x2=o
  3812. self.y2=t
  3813. self.width=o-n+1
  3814. self.height=t-e+1
  3815. if self.blittleWindow then
  3816. self.blittleWindow=self.blittleWindow.reposition(self.x1,self.y1,self.x1+self.width-1,self.y1+self.height-1)end
  3817. self:clear()end
  3818. function a:clear()local e=self.screenBuffer
  3819. e.c2={}e.depth={}local t=e.c2
  3820. local n=e.depth
  3821. local l=math.huge
  3822. local r=self.width
  3823. local o=self.backgroundColor
  3824. if self.blittleOn then
  3825. for e=1,self.height do
  3826. t[e]={}n[e]={}local t=t[e]local n=n[e]for e=1,r do
  3827. t[e]=o
  3828. n[e]=l
  3829. end
  3830. end
  3831. else
  3832. local i=u[o]e.c1={}local a=e.c1
  3833. e.chars={}local o=e.chars
  3834. for e=1,self.height do
  3835. a[e]={}t[e]={}o[e]={}n[e]={}local a=a[e]local t=t[e]local o=o[e]local n=n[e]for e=1,r do
  3836. a[e]=i
  3837. t[e]=i
  3838. o[e]=" "n[e]=l
  3839. end
  3840. end
  3841. end
  3842. end
  3843. function a:fastClearNormal()local n=self.backgroundColor
  3844. local e=self.screenBuffer
  3845. local t=e.chars
  3846. local i=e.c1
  3847. local r=e.c2
  3848. local a=self.screenBuffer.depth
  3849. local n=u[n]local l=math.huge
  3850. local o=self.width
  3851. for e=1,self.height do
  3852. local t=t[e]local i=i[e]local d=r[e]local r=a[e]for e=1,o do
  3853. t[e]=" "i[e]=n
  3854. d[e]=n
  3855. r[e]=l
  3856. end
  3857. end
  3858. end
  3859. function a:fastClearBLittle()local r=self.backgroundColor
  3860. local n=self.screenBuffer.c2
  3861. local t=self.screenBuffer.depth
  3862. local o=math.huge
  3863. local l=self.width
  3864. for e=1,self.height do
  3865. local n=n[e]local t=t[e]for e=1,l do
  3866. n[e]=r
  3867. t[e]=o
  3868. end
  3869. end
  3870. end
  3871. function a:setPixel(e,n,o,l,t)e=math.floor(e+.5)n=math.floor(n+.5)if e>=1 and e<=self.width then
  3872. if n>=1 and n<=self.height then
  3873. local t=self.screenBuffer
  3874. if self.blittleOn then
  3875. t.c2[n][e]=l or o
  3876. else
  3877. t.c1[n][e]=u[o]t.c2[n][e]=u[l or o]t.chars[n][e]=" "end
  3878. end
  3879. end
  3880. end
  3881. function a:image(n,t,e)for o,e in pairs(e)do
  3882. for l,e in pairs(e)do
  3883. if e and e>0 then
  3884. if self.blittleOn then
  3885. self:setPixel(l+(n-1)*2,o+(t-1)*3,e,e," ")else
  3886. self:setPixel(l+n-1,o+t-1,e,e," ")end
  3887. end
  3888. end
  3889. end
  3890. end
  3891. function a:loadLineNormal(y,_,g,b,f,c,a,i,d,e)local l=self.screenBuffer
  3892. local u=l.c1
  3893. local m=l.c2
  3894. local p=l.chars
  3895. local l=l.depth
  3896. local h=self.width
  3897. local r=self.height
  3898. if g>=y then
  3899. for t=n(s(y),1),t(o(g),h)do
  3900. local n=o(i*t+d+.5)if n>0 and n<=r and e<=l[n][t]then
  3901. u[n][t]=a
  3902. m[n][t]=f
  3903. p[n][t]=c
  3904. l[n][t]=e
  3905. end
  3906. end
  3907. else
  3908. for t=n(s(g),1),t(o(y),h)do
  3909. local n=o(i*t+d+.5)if n>0 and n<=r and e<=l[n][t]then
  3910. u[n][t]=a
  3911. m[n][t]=f
  3912. p[n][t]=c
  3913. l[n][t]=e
  3914. end
  3915. end
  3916. end
  3917. if b>=_ then
  3918. for t=n(s(_),1),t(o(b),r)do
  3919. local n=o((t-d)/i+.5)local o=l[t]if n>0 and n<=h and e<=o[n]then
  3920. u[t][n]=a
  3921. m[t][n]=f
  3922. p[t][n]=c
  3923. o[n]=e
  3924. end
  3925. end
  3926. else
  3927. for t=n(s(b),1),t(o(_),r)do
  3928. local n=o((t-d)/i+.5)local o=l[t]if n>0 and n<=h and e<=o[n]then
  3929. u[t][n]=a
  3930. m[t][n]=f
  3931. p[t][n]=c
  3932. o[n]=e
  3933. end
  3934. end
  3935. end
  3936. end
  3937. function a:loadLineBLittle(f,h,m,p,d,c,r,e)local l=self.screenBuffer
  3938. local a=l.c2
  3939. local l=l.depth
  3940. local i=self.width
  3941. local u=self.height
  3942. if m>=f then
  3943. for t=n(s(f),1),t(o(m),i)do
  3944. local n=o(c*t+r+.5)if n>0 and n<=u and e<=l[n][t]then
  3945. a[n][t]=d
  3946. l[n][t]=e
  3947. end
  3948. end
  3949. else
  3950. for t=n(s(m),1),t(o(f),i)do
  3951. local n=o(c*t+r+.5)if n>0 and n<=u and e<=l[n][t]then
  3952. a[n][t]=d
  3953. l[n][t]=e
  3954. end
  3955. end
  3956. end
  3957. if p>=h then
  3958. for t=n(s(h),1),t(o(p),u)do
  3959. local n=o((t-r)/c+.5)local o=l[t]if n>0 and n<=i and e<=o[n]then
  3960. a[t][n]=d
  3961. o[n]=e
  3962. end
  3963. end
  3964. else
  3965. for t=n(s(p),1),t(o(h),u)do
  3966. local n=o((t-r)/c+.5)local o=l[t]if n>0 and n<=i and e<=o[n]then
  3967. a[t][n]=d
  3968. o[n]=e
  3969. end
  3970. end
  3971. end
  3972. end
  3973. local C=colors.black
  3974. function a:drawTriangleNormal(i,l,a,e,d,r,y,f,b,k,h)if i<1 and a<1 and d<1 or l<1 and e<1 and r<1 then return end
  3975. local c=self.width
  3976. if i>c and a>c and d>c then return end
  3977. local p=self.height
  3978. if l>p and e>p and r>p then return end
  3979. if l>e then
  3980. l,e=e,l
  3981. i,a=a,i
  3982. end
  3983. if e>r then
  3984. r,e=e,r
  3985. d,a=a,d
  3986. end
  3987. if l>e then
  3988. l,e=e,l
  3989. i,a=a,i
  3990. end
  3991. local g=self.screenBuffer
  3992. local o,s=o,s
  3993. local n,t=t,n
  3994. local S=n(t(1,s(l)),p)local _=n(t(0,o(e)),p)local B=n(t(1,o(r)),p)local w=g.c1
  3995. local p=g.c2
  3996. local x=g.chars
  3997. local v=g.depth
  3998. local n=(a-i)/(e-l)local T=(i-d)/(l-r)f=f or" "b=b or y
  3999. local g=u[y]local s=u[b]if l~=e and l~=r then
  4000. for e=S,_ do
  4001. local m=w[e]local u=p[e]local a=x[e]local t=v[e]local n=(e-l)*n+i
  4002. local e=(e-r)*T+d
  4003. if e<n then n,e=e,n end
  4004. if n<1 then n=1 end
  4005. if n>c then n=c+1 end
  4006. if e<1 then e=0 end
  4007. if e>c then e=c end
  4008. for e=o(n+.5),o(e+.5)do
  4009. if h<t[e]then
  4010. t[e]=h
  4011. m[e]=s
  4012. u[e]=g
  4013. a[e]=f
  4014. end
  4015. end
  4016. end
  4017. end
  4018. local n=(d-a)/(r-e)local b=(i-d)/(l-r)if r~=e and l~=r then
  4019. for t=_+1,B do
  4020. local i=w[t]local u=p[t]local m=x[t]local l=v[t]local n=(t-e)*n+a
  4021. local e=(t-r)*b+d
  4022. if e<n then n,e=e,n end
  4023. if n<1 then n=1 end
  4024. if n>c then n=c+1 end
  4025. if e<1 then e=0 end
  4026. if e>c then e=c end
  4027. for e=o(n+.5),o(e+.5)do
  4028. if h<l[e]then
  4029. l[e]=h
  4030. i[e]=s
  4031. u[e]=g
  4032. m[e]=f
  4033. end
  4034. end
  4035. end
  4036. end
  4037. local n=k
  4038. if n or self.triangleEdges then
  4039. local y,g=m(i,l,a,e)local b,p=m(a,e,d,r)local o,c=m(i,l,d,r)local t=self.loadLineNormal
  4040. local n=u[n or C]t(self,i,l,a,e,n,f,s,y,g,h)t(self,a,e,d,r,n,f,s,b,p,h)t(self,d,r,i,l,n,f,s,o,c,h)end
  4041. end
  4042. function a:drawTriangleBLittle(i,l,a,e,d,r,p,c,c,_,u)if i<1 and a<1 and d<1 or l<1 and e<1 and r<1 then return end
  4043. local c=self.width
  4044. if i>c and a>c and d>c then return end
  4045. local f=self.height
  4046. if l>f and e>f and r>f then return end
  4047. if l>e then
  4048. l,e=e,l
  4049. i,a=a,i
  4050. end
  4051. if e>r then
  4052. r,e=e,r
  4053. d,a=a,d
  4054. end
  4055. if l>e then
  4056. l,e=e,l
  4057. i,a=a,i
  4058. end
  4059. local g=self.screenBuffer
  4060. local o,s=o,s
  4061. local t,n=t,n
  4062. local b=t(n(1,s(l)),f)local h=t(n(0,o(e)),f)local y=t(n(1,o(r)),f)local f=g.c2
  4063. local s=g.depth
  4064. local n=(a-i)/(e-l)local g=(i-d)/(l-r)if l~=e and l~=r then
  4065. for e=b,h do
  4066. local a=f[e]local t=s[e]local n=(e-l)*n+i
  4067. local e=(e-r)*g+d
  4068. if e<n then n,e=e,n end
  4069. if n<1 then n=1 end
  4070. if n>c then n=c+1 end
  4071. if e<1 then e=0 end
  4072. if e>c then e=c end
  4073. for e=o(n+.5),o(e+.5)do
  4074. if u<t[e]then
  4075. t[e]=u
  4076. a[e]=p
  4077. end
  4078. end
  4079. end
  4080. end
  4081. local n=(d-a)/(r-e)local g=(i-d)/(l-r)if r~=e and l~=r then
  4082. for t=h+1,y do
  4083. local i=f[t]local l=s[t]local n=(t-e)*n+a
  4084. local e=(t-r)*g+d
  4085. if e<n then n,e=e,n end
  4086. if n<1 then n=1 end
  4087. if n>c then n=c+1 end
  4088. if e<1 then e=0 end
  4089. if e>c then e=c end
  4090. for e=o(n+.5),o(e+.5)do
  4091. if u<l[e]then
  4092. l[e]=u
  4093. i[e]=p
  4094. end
  4095. end
  4096. end
  4097. end
  4098. local n=_
  4099. if n or self.triangleEdges then
  4100. local p,h=m(i,l,a,e)local s,f=m(a,e,d,r)local o,c=m(i,l,d,r)local t=self.loadLineBLittle
  4101. local n=n or C
  4102. t(self,i,l,a,e,n,p,h,u)t(self,a,e,d,r,n,s,f,u)t(self,d,r,i,l,n,o,c,u)end
  4103. end
  4104. function a:drawBufferNormal()local d=self.x1
  4105. local i=self.y1
  4106. local e=self.screenBuffer
  4107. local a=term.setCursorPos
  4108. local r=term.blit
  4109. local t=e.chars
  4110. local o=e.c1
  4111. local l=e.c2
  4112. local n=table.concat
  4113. for e=1,self.height do
  4114. a(d,e+i-1)local a=n(t[e])local t=n(o[e])local e=n(l[e])r(a,t,e)end
  4115. end
  4116. function a:drawBufferBLittle()local e=self.blittleWindow
  4117. if not e then
  4118. self.blittleWindow=window.create(term.current(),self.x1,self.y1,self.x1+self.width-1,self.y1+self.height-1,false)e=self.blittleWindow
  4119. end
  4120. T.drawBuffer(self.screenBuffer.c2,e)e.setVisible(true)e.setVisible(false)end
  4121. function a:highResMode(e)self.blittleOn=e
  4122. self.drawTriangle=e and self.drawTriangleBLittle or self.drawTriangleNormal
  4123. self.fastClear=e and self.fastClearBLittle or self.fastClearNormal
  4124. self.drawBuffer=e and self.drawBufferBLittle or self.drawBufferNormal
  4125. self:clear()end
  4126. function a:useTriangleEdges(e)self.triangleEdges=e
  4127. end
  4128. a:highResMode(true)return a
  4129. end
  4130. local function z(l,o,t,n,e)local r=e[1]local a=e[2]local e=e[3]local o=o and(o-r)or 0
  4131. local t=t and(t-a)or 0
  4132. local r=n and(n-e)or 0
  4133. for e=1,#l do
  4134. local e=l[e]local n=o+(e[1]+e[4]+e[7])/3
  4135. local t=t+(e[2]+e[5]+e[8])/3
  4136. local o=r+(e[3]+e[6]+e[9])/3
  4137. e[16]=n*n+t*t+o*o
  4138. end
  4139. end
  4140. local k=math.rad
  4141. local b=math.sin
  4142. local y=math.cos
  4143. local function f(l,t,o,n,e)local r=e*o-n*t
  4144. local e=n*o+e*t
  4145. local n=r
  4146. return l,e,n
  4147. end
  4148. local function s(e,l,n,o,t)local r=t*n-o*e
  4149. local n=o*n+t*e
  4150. local e=r
  4151. return n,l,e
  4152. end
  4153. local function u(o,t,l,e,n)local l=n*t-e*o
  4154. local e=e*t+n*o
  4155. local n=l
  4156. return e,n
  4157. end
  4158. local function B(e,h,p,m)local C,T=0,1
  4159. local x,v=0,1
  4160. local w,_=0,1
  4161. if h==0 then h=nil end
  4162. if h then C,T=b(h),y(h)end
  4163. if p==0 then p=nil end
  4164. if p then x,v=b(p),y(p)end
  4165. if m==0 then m=nil end
  4166. if m then w,_=b(m),y(m)end
  4167. local n={}for t,e in pairs(e)do
  4168. local i,a,d=e[1],e[2],e[3]local t,r,c=e[4],e[5],e[6]local o,l,g=e[7],e[8],e[9]if p then
  4169. i,a,d=s(i,a,d,x,v)t,r,c=s(t,r,c,x,v)o,l,g=s(o,l,g,x,v)end
  4170. if m then
  4171. i,a=u(i,a,d,w,_)t,r=u(t,r,c,w,_)o,l=u(o,l,g,w,_)end
  4172. if h then
  4173. i,a,d=f(i,a,d,C,T)t,r,c=f(t,r,c,C,T)o,l,g=f(o,l,g,C,T)end
  4174. n[#n+1]={i,a,d,t,r,c,o,l,g}n[#n][10]=e[10]n[#n][11]=e[11]n[#n][12]=e[12]n[#n][13]=e[13]n[#n][14]=e[14]end
  4175. return n
  4176. end
  4177. local r={}function r.invertTriangles(n)if not n or type(n)~="table"then
  4178. error"transforms.invertTriangles expected arg#1 to be a table (model)"end
  4179. for t=1,#n do
  4180. local e=n[t]n[t]={x1=e.x1,y1=e.y1,z1=e.z1,x2=e.x3,y2=e.y3,z2=e.z3,x3=e.x2,y3=e.y2,z3=e.z2,c=e.c,char=e.char,charc=e.charc,forceRender=e.forceRender,outlineColor=e.outlineColor,}end
  4181. return n
  4182. end
  4183. function r.setOutline(e,n)if not e or type(e)~="table"then
  4184. error"transforms.invertTriangles expected arg#1 to be a table (model)"end
  4185. for t=1,#e do
  4186. local e=e[t]if type(n)=="table"then
  4187. e.outlineColor=n[e.c]or e.outlineColor
  4188. else
  4189. e.outlineColor=n
  4190. end
  4191. end
  4192. return e
  4193. end
  4194. function r.mapColor(e,n)if not e or type(e)~="table"then
  4195. error"transforms.mapColor expected arg#1 to be a table (model)"end
  4196. for t=1,#e do
  4197. local e=e[t]if type(n)=="table"then
  4198. e.c=n[e.c]or e.c
  4199. else
  4200. e.c=n
  4201. end
  4202. end
  4203. return e
  4204. end
  4205. function r.center(c)local o,r=math.huge,-math.huge
  4206. local l,a=math.huge,-math.huge
  4207. local d,i=math.huge,-math.huge
  4208. for e=1,#c do
  4209. local e=c[e]o,r=t(o,e.x1),n(r,e.x1)o,r=t(o,e.x2),n(r,e.x2)o,r=t(o,e.x3),n(r,e.x3)l,a=t(l,e.y1),n(a,e.y1)l,a=t(l,e.y2),n(a,e.y2)l,a=t(l,e.y3),n(a,e.y3)d,i=t(d,e.z1),n(i,e.z1)d,i=t(d,e.z2),n(i,e.z2)d,i=t(d,e.z3),n(i,e.z3)end
  4210. local t=-(r+o)*.5
  4211. local n=-(a+l)*.5
  4212. local o=-(i+d)*.5
  4213. for e=1,#c do
  4214. local e=c[e]e.x1=e.x1+t
  4215. e.x2=e.x2+t
  4216. e.x3=e.x3+t
  4217. e.y1=e.y1+n
  4218. e.y2=e.y2+n
  4219. e.y3=e.y3+n
  4220. e.z1=e.z1+o
  4221. e.z2=e.z2+o
  4222. e.z3=e.z3+o
  4223. end
  4224. return c
  4225. end
  4226. function r.normalizeScale(o)local e=-math.huge
  4227. for t=1,#o do
  4228. local t=o[t]e=n(e,t.x1)e=n(e,t.x2)e=n(e,t.x3)e=n(e,t.y1)e=n(e,t.y2)e=n(e,t.y3)e=n(e,t.z1)e=n(e,t.z2)e=n(e,t.z3)end
  4229. for n=1,#o do
  4230. local n=o[n]n.x1=n.x1/e
  4231. n.x2=n.x2/e
  4232. n.x3=n.x3/e
  4233. n.y1=n.y1/e
  4234. n.y2=n.y2/e
  4235. n.y3=n.y3/e
  4236. n.z1=n.z1/e
  4237. n.z2=n.z2/e
  4238. n.z3=n.z3/e
  4239. end
  4240. return o
  4241. end
  4242. function r.normalizeScaleY(o)local t=-math.huge
  4243. for e=1,#o do
  4244. local e=o[e]t=n(t,e.y1)t=n(t,e.y2)t=n(t,e.y3)end
  4245. for e=1,#o do
  4246. local e=o[e]e.x1=e.x1/t
  4247. e.x2=e.x2/t
  4248. e.x3=e.x3/t
  4249. e.y1=e.y1/t
  4250. e.y2=e.y2/t
  4251. e.y3=e.y3/t
  4252. e.z1=e.z1/t
  4253. e.z2=e.z2/t
  4254. e.z3=e.z3/t
  4255. end
  4256. return o
  4257. end
  4258. function r.scale(t,n)for e=1,#t do
  4259. local e=t[e]e.x1=e.x1*n
  4260. e.x2=e.x2*n
  4261. e.x3=e.x3*n
  4262. e.y1=e.y1*n
  4263. e.y2=e.y2*n
  4264. e.y3=e.y3*n
  4265. e.z1=e.z1*n
  4266. e.z2=e.z2*n
  4267. e.z3=e.z3*n
  4268. end
  4269. return t
  4270. end
  4271. function r.translate(l,o,t,n)for e=1,#l do
  4272. local e=l[e]e.x1=e.x1+(o or 0)e.x2=e.x2+(o or 0)e.x3=e.x3+(o or 0)e.y1=e.y1+(t or 0)e.y2=e.y2+(t or 0)e.y3=e.y3+(t or 0)e.z1=e.z1+(n or 0)e.z2=e.z2+(n or 0)e.z3=e.z3+(n or 0)end
  4273. return l
  4274. end
  4275. function r.rotate(T,m,h,p)local x,v=0,1
  4276. local C,w=0,1
  4277. local _,g=0,1
  4278. if m==0 then m=nil end
  4279. if m then x,v=b(m),y(m)end
  4280. if h==0 then h=nil end
  4281. if h then C,w=b(h),y(h)end
  4282. if p==0 then p=nil end
  4283. if p then _,g=b(p),y(p)end
  4284. for e=1,#T do
  4285. local e=T[e]local o,l,c=e.x1,e.y1,e.z1
  4286. local n,a,i=e.x2,e.y2,e.z2
  4287. local r,t,d=e.x3,e.y3,e.z3
  4288. if h then
  4289. o,l,c=s(o,l,c,C,w)n,a,i=s(n,a,i,C,w)r,t,d=s(r,t,d,C,w)end
  4290. if p then
  4291. o,l=u(o,l,c,_,g)n,a=u(n,a,i,_,g)r,t=u(r,t,d,_,g)end
  4292. if m then
  4293. o,l,c=f(o,l,c,x,v)n,a,i=f(n,a,i,x,v)r,t,d=f(r,t,d,x,v)end
  4294. e.x1,e.y1,e.z1=o,l,c
  4295. e.x2,e.y2,e.z2=n,a,i
  4296. e.x3,e.y3,e.z3=r,t,d
  4297. end
  4298. return T
  4299. end
  4300. function r.alignBottom(o)local e=math.huge
  4301. for n=1,#o do
  4302. local n=o[n]e=t(e,n.y1)e=t(e,n.y2)e=t(e,n.y3)end
  4303. for n=1,#o do
  4304. local n=o[n]n.y1=n.y1-e
  4305. n.y2=n.y2-e
  4306. n.y3=n.y3-e
  4307. end
  4308. return o
  4309. end
  4310. function r.decimate(a,i,d)local e={}local o={}local function t(t,o,l)for n=#e,1,-1 do
  4311. local e=e[n]if e[1]==t and e[2]==o and e[3]==l then
  4312. return n
  4313. end
  4314. end
  4315. end
  4316. for n=1,#a do
  4317. local n=a[n]local l=t(n.x1,n.y1,n.z1)if not l then
  4318. e[#e+1]={n.x1,n.y1,n.z1}l=#e
  4319. end
  4320. local r=t(n.x2,n.y2,n.z2)if not r then
  4321. e[#e+1]={n.x2,n.y2,n.z2}r=#e
  4322. end
  4323. local t=t(n.x3,n.y3,n.z3)if not t then
  4324. e[#e+1]={n.x3,n.y3,n.z3}t=#e
  4325. end
  4326. local e={l,r,t,n.c,n.char,n.charc,n.forceRender}o[#o+1]=e
  4327. end
  4328. local function l(n,e)local t=n[1]-e[1]local o=n[2]-e[2]local e=n[3]-e[3]return(t*t+o*o+e*e)^.5
  4329. end
  4330. local n={}for t=1,#o do
  4331. local t=o[t]local r=l(e[t[1]],e[t[2]])local o=l(e[t[2]],e[t[3]])local e=l(e[t[1]],e[t[3]])n[#n+1]={length=r,vA=t[1],vB=t[2],}n[#n+1]={length=o,vA=t[2],vB=t[3],}n[#n+1]={length=e,vA=t[1],vB=t[3],}end
  4332. local function c(n,t)local l=e[n]local r=e[t]local l={(l[1]+r[1])*.5,(l[2]+r[2])*.5,(l[3]+r[3])*.5,}e[#e+1]=l
  4333. local l=#e
  4334. for r=#o,1,-1 do
  4335. local e=o[r]if e[1]==n or e[1]==t or e[2]==n or e[2]==t or e[3]==n or e[3]==t then
  4336. if e[1]==n or e[1]==t then
  4337. e[1]=l
  4338. end
  4339. if e[2]==n or e[2]==t then
  4340. e[2]=l
  4341. end
  4342. if e[3]==n or e[3]==t then
  4343. e[3]=l
  4344. end
  4345. if e[1]==e[2]or e[2]==e[3]or e[1]==e[3]then
  4346. table.remove(o,r)end
  4347. end
  4348. end
  4349. return l
  4350. end
  4351. local t=i
  4352. if d~="polys"then
  4353. t=(#a)*i
  4354. end
  4355. while#o>t do
  4356. local o=math.huge
  4357. local l
  4358. for t=1,#n do
  4359. local e=n[t]if e.length<o then
  4360. o=e.length
  4361. l=t
  4362. end
  4363. end
  4364. local t=n[l]local l=c(t.vA,t.vB)for r=#n,1,-1 do
  4365. local e=n[r]local o=e.vA==t.vA or e.vA==t.vB
  4366. local t=e.vB==t.vA or e.vB==t.vB
  4367. if o and t then
  4368. table.remove(n,r)elseif o then
  4369. e.vA=l
  4370. elseif t then
  4371. e.vB=l
  4372. end
  4373. end
  4374. end
  4375. local t={}for n=1,#o do
  4376. local n=o[n]local o=e[n[1]]local l=e[n[2]]local e=e[n[3]]t[#t+1]={x1=o[1],y1=o[2],z1=o[3],x2=l[1],y2=l[2],z2=l[3],x3=e[1],y3=e[2],z3=e[3],c=n[4],char=n[5],charc=n[6],forceRender=n[7],}end
  4377. for n,e in pairs(r)do
  4378. t[n]=e
  4379. end
  4380. return t
  4381. end
  4382. local v,h
  4383. function r.toLoD(n,e)e=e or{}local e={minQuality=e.minQuality or .1,variantCount=e.variantCount or 4,qualityHalvingDistance=e.qualityHalvingDistance or 5,quickInitWorseRuntime=e.quickInitWorseRuntime or false,}local o,t=h(n)local o={{quality=1,collapsedModel=o,size=t,}}local n=n
  4384. local t=#n
  4385. for l=1,e.variantCount do
  4386. local e=(1-e.minQuality)*(1-l/e.variantCount)+e.minQuality
  4387. local t=math.floor(t*e+.5)local t=n:decimate(t,"polys")local l,r=h(t)n=t
  4388. local e={quality=e,collapsedModel=l,size=r,}o[#o+1]=e
  4389. end
  4390. local function r(e)local o={}for t=1,#e do
  4391. local n=e[t]local e=n.collapsedModel
  4392. local l={}for n=1,#e do
  4393. local e=e[n]local e={e[1],e[2],e[3],e[4],e[5],e[6],e[7],e[8],e[9],e[10],e[11],e[12],e[13],e[14],}l[n]=e
  4394. end
  4395. local e={quality=n.quality,size=n.size,collapsedModel=l,}o[t]=e
  4396. end
  4397. return o
  4398. end
  4399. local l={}function e:initObject(t)local n
  4400. if e.quickInitWorseRuntime then
  4401. n=o
  4402. else
  4403. n=r(o)end
  4404. l[t]=n
  4405. t[7]=n[1].collapsedModel
  4406. t[8]=n[1].size
  4407. t[9]=e
  4408. end
  4409. function e:update(n,t)local o=l[n]if o then
  4410. local r=t[1]-n[1]local l=t[2]-n[2]local t=t[3]-n[3]local t=(r*r+l*l+t*t)^.5
  4411. local t=math.min(1,math.max(e.minQuality,1/(t/e.qualityHalvingDistance)))local e=(e.variantCount+1)-e.variantCount*(t-e.minQuality)/(1-e.minQuality)local e=math.floor(e+.5)local e=o[e]n[7]=e.collapsedModel
  4412. n[8]=e.size
  4413. end
  4414. end
  4415. return e
  4416. end
  4417. local l=math.sqrt
  4418. function h(e)local n={}local t=0
  4419. for o=1,#e do
  4420. local e=e[o]n[#n+1]={}n[#n][1]=e.x1
  4421. n[#n][2]=e.y1
  4422. n[#n][3]=e.z1
  4423. n[#n][4]=e.x2
  4424. n[#n][5]=e.y2
  4425. n[#n][6]=e.z2
  4426. n[#n][7]=e.x3
  4427. n[#n][8]=e.y3
  4428. n[#n][9]=e.z3
  4429. n[#n][10]=e.forceRender
  4430. n[#n][11]=e.c
  4431. n[#n][12]=e.char
  4432. n[#n][13]=e.charc
  4433. n[#n][14]=e.outlineColor
  4434. local o=l(e.x1*e.x1+e.y1*e.y1+e.z1*e.z1)local n=l(e.x2*e.x2+e.y2*e.y2+e.z2*e.z2)local e=l(e.x3*e.x3+e.y3*e.y3+e.z3*e.z3)if o>t then
  4435. t=o
  4436. end
  4437. if n>t then
  4438. t=n
  4439. end
  4440. if e>t then
  4441. t=e
  4442. end
  4443. end
  4444. return n,t
  4445. end
  4446. function v(n)local e=fs.open(n,"r")if not e then
  4447. error("Could not find model for an object at path: "..n)end
  4448. local n=e.readAll()e.close()local e=textutils.unserialise(n)for n,t in pairs(r)do
  4449. e[n]=t
  4450. end
  4451. return e
  4452. end
  4453. local d=math.pi
  4454. local i=math.sin
  4455. local a=math.cos
  4456. local C=math.tan
  4457. local T=math.sqrt
  4458. local function F(n,e,d,r)local l,t=term.getSize()if n and d then
  4459. l=d-n+1
  4460. end
  4461. if e and r then
  4462. t=r-e+1
  4463. end
  4464. local n=n or 1
  4465. local e=e or 1
  4466. local d=d or(l-n+1)local r=r or(t-e+1)local n={camera={1e-6,1e-6,1e-6,nil,0,0,},buffer=S(n,e,d,r),x1=n,y1=e,x2=d,y2=r,width=l,height=t,blittleOn=false,pixelratio=1.5,}n.FoV=90
  4467. n.camera[7]=k(n.FoV)n.t=C(k(n.FoV/2))*2*1e-4
  4468. local x,y,b,w
  4469. function n:setBackgroundColor(n)local e=self.buffer
  4470. e.backgroundColor=n
  4471. e:fastClear()end
  4472. local function _()x=o(n.width*.5)+1
  4473. y=o(n.height*.5)b=1e-4*n.width/n.t
  4474. w=-1e-4*n.width/(n.t*n.height*n.pixelratio)*n.height
  4475. end
  4476. function n:setSize(n,e,t,o)self.x1=n
  4477. self.y1=e
  4478. self.x2=t
  4479. self.y2=o
  4480. if not self.blittleOn then
  4481. self.buffer:setBufferSize(n,e,t,o)self.width=t-n+1
  4482. self.height=o-e+1
  4483. self.pixelratio=1.5
  4484. else
  4485. self.width=(t-n+1)*2
  4486. self.height=(o-e+1)*3
  4487. self.pixelratio=1
  4488. self.buffer:setBufferSize(n,e,n+self.width-1,e+self.height-1)end
  4489. _()end
  4490. function n:highResMode(e)self.blittleOn=e
  4491. self.buffer:highResMode(e)if e then
  4492. self.width=(self.x2-self.x1+1)*2
  4493. self.height=(self.y2-self.y1+1)*3
  4494. self.buffer:setBufferSize(self.x1,self.y1,self.x1+self.width-1,self.y1+self.height-1)self.pixelratio=1
  4495. else
  4496. self.buffer:setBufferSize(self.x1,self.y1,self.x2,self.y2)self.width=self.x2-self.x1+1
  4497. self.height=self.y2-self.y1+1
  4498. self.pixelratio=1.5
  4499. end
  4500. _()end
  4501. function n:map3dTo2d(n,t,s)local e=self.camera
  4502. local o=i(e[4]or 0)local c=a(e[4]or 0)local d=i(-e[5])local l=a(-e[5])local r=i(e[6])local a=a(e[6])local n=n-e[1]local t=t-e[2]local e=s-e[3]local i=l*n-d*e
  4503. e=d*n+l*e
  4504. n=i
  4505. local l=a*t-r*n
  4506. n=r*t+a*n
  4507. t=l
  4508. if o~=0 then
  4509. local n=o*e-c*t
  4510. t=c*e+o*t
  4511. e=n
  4512. end
  4513. local e=(e/n)*b+x
  4514. local t=(t/n)*w+y
  4515. return e,t,n>=1e-4
  4516. end
  4517. function n:drawObject(e,t,n)local o=e[1]local r=e[2]local l=e[3]local k=n[1]local S=n[2]local s=n[3]local c=n[4]local m=n[5]local p=n[6]local d=o and(o-t[1])or 0
  4518. local h=r and(r-t[2])or 0
  4519. local _=l and(l-t[3])or 0
  4520. local n=e[9]if n then
  4521. n:update(e,t)end
  4522. local g=e[7]if#g<=0 then
  4523. return
  4524. end
  4525. local n=e[8]local u=d
  4526. local C=h
  4527. local f=_
  4528. local T=c*u-s*f
  4529. local v=s*u+c*f
  4530. local u=T
  4531. local u=m*C+p*u
  4532. if u<-n then
  4533. return
  4534. end
  4535. local f=.5*t[7]local i=i(f)local a=a(f)if(u+n)*i+(v+n)*a<0 then
  4536. return
  4537. end
  4538. if(u+n)*i-(v-n)*a<0 then
  4539. return
  4540. end
  4541. local a=e[4]local i=e[5]local e=e[6]if(a and a~=0)or(i and i~=0)or(e and e~=0)then
  4542. g=B(g,a,i,e)end
  4543. z(g,o,r,l,t)local v=d*d+h*h+_*_<n*n*4
  4544. local t=x
  4545. local r=y
  4546. local o=b
  4547. local l=w
  4548. local n=k
  4549. local f=S
  4550. local s=s
  4551. local c=c
  4552. local u=m
  4553. local a=p
  4554. local m=d
  4555. local p=h
  4556. local h=_
  4557. local function b(e,i,n)local d=c*e-s*n
  4558. n=s*e+c*n
  4559. e=d
  4560. local d=a*i-u*e
  4561. e=u*i+a*e
  4562. i=d
  4563. local t=(n/e)*o+t
  4564. local n=(i/e)*l+r
  4565. return t,n,e
  4566. end
  4567. if n~=0 then
  4568. function b(e,d,i)local h=c*e-s*i
  4569. i=s*e+c*i
  4570. e=h
  4571. local c=a*d-u*e
  4572. e=u*d+a*e
  4573. d=c
  4574. local a=n*i-f*d
  4575. d=f*i+n*d
  4576. i=a
  4577. local n=(i/e)*o+t
  4578. local t=(d/e)*l+r
  4579. return n,t,e
  4580. end
  4581. end
  4582. local e=g
  4583. local d=self.buffer
  4584. for i=1,#e do
  4585. local e=e[i]local i=e[16]local _,w,g=b(e[1]+m,e[2]+p,e[3]+h)if g>.00010000001 then
  4586. local g,y,x=b(e[4]+m,e[5]+p,e[6]+h)if x>.00010000001 then
  4587. local x,b,C=b(e[7]+m,e[8]+p,e[9]+h)if C>.00010000001 then
  4588. if e[10]or(g-_)*(b-y)-(y-w)*(x-g)<0 then
  4589. d:drawTriangle(_,w,g,y,x,b,e[11],e[12],e[13],e[14],i)end
  4590. elseif v then
  4591. local function g(e,i,d)local e=e+m
  4592. local i=i+p
  4593. local d=d+h
  4594. local h=c*e-s*d
  4595. d=s*e+c*d
  4596. e=h
  4597. local c=a*i-u*e
  4598. e=u*i+a*e
  4599. i=c
  4600. if n~=0 then
  4601. local e=n*d-f*i
  4602. i=f*d+n*i
  4603. d=e
  4604. end
  4605. local t=(d/e)*o+t
  4606. local n=(i/e)*l+r
  4607. return t,n,e,i,d
  4608. end
  4609. local m,h,s,_,y=g(e[1],e[2],e[3])local c,a,v,x,w=g(e[4],e[5],e[6])local u,u,n,p,b=g(e[7],e[8],e[9])local u=math.abs
  4610. local n=u(n-1e-4)local s=u(s-1e-4)local f=s+n
  4611. local y=(b*s+y*n)/f
  4612. local _=(p*s+_*n)/f
  4613. local g,f,r,s=t,o,r,l
  4614. local t=(y*10000)*f+g
  4615. local l=(_*10000)*s+r
  4616. if e[10]or(c-m)*(l-a)-(a-h)*(t-c)<0 then
  4617. d:drawTriangle(m,h,c,a,t,l,e[11],e[12],e[13],e[14],i)local o=u(v-1e-4)local u=o+n
  4618. local h=(w*n+b*o)/u
  4619. local n=(x*n+p*o)/u
  4620. local o=(h*10000)*f+g
  4621. local n=(n*10000)*s+r
  4622. d:drawTriangle(o,n,c,a,t,l,e[11],e[12],e[13],e[14],i)end
  4623. end
  4624. elseif v then
  4625. local function g(e,i,d)local e=e+m
  4626. local i=i+p
  4627. local d=d+h
  4628. local h=c*e-s*d
  4629. d=s*e+c*d
  4630. e=h
  4631. local c=a*i-u*e
  4632. e=u*i+a*e
  4633. i=c
  4634. if n~=0 then
  4635. local e=n*d-f*i
  4636. i=f*d+n*i
  4637. d=e
  4638. end
  4639. local t=(d/e)*o+t
  4640. local n=(i/e)*l+r
  4641. return t,n,e,i,d
  4642. end
  4643. local c,s,_,u,f=g(e[1],e[2],e[3])local n,n,v,y,b=g(e[4],e[5],e[6])local g,h,m,x,w=g(e[7],e[8],e[9])local n=math.abs
  4644. if m>.00010000001 then
  4645. local a=n(v-1e-4)local p=n(_-1e-4)local _=p+a
  4646. local v=(b*p+f*a)/_
  4647. local _=(y*p+u*a)/_
  4648. local r,u,p,f=t,o,r,l
  4649. local t=(v*10000)*u+r
  4650. local o=(_*10000)*f+p
  4651. if e[10]or(t-c)*(h-o)-(o-s)*(g-t)<0 then
  4652. d:drawTriangle(c,s,t,o,g,h,e[11],e[12],e[13],e[14],i)local n=n(m-1e-4)local l=a+n
  4653. local c=(b*n+w*a)/l
  4654. local n=(y*n+x*a)/l
  4655. local l=(c*10000)*u+r
  4656. local n=(n*10000)*f+p
  4657. d:drawTriangle(l,n,t,o,g,h,e[11],e[12],e[13],e[14],i)end
  4658. else
  4659. local a=n(_-1e-4)local h=n(v-1e-4)local m=n(m-1e-4)local n=a+h
  4660. local p=a+m
  4661. local g=(f*h+b*a)/n
  4662. local n=(u*h+y*a)/n
  4663. local h,r,o,l=t,o,r,l
  4664. local t=(g*10000)*r+h
  4665. local n=(n*10000)*l+o
  4666. local f=(f*m+w*a)/p
  4667. local a=(u*m+x*a)/p
  4668. local r=(f*10000)*r+h
  4669. local o=(a*10000)*l+o
  4670. if e[10]or(t-c)*(o-n)-(n-s)*(r-t)<0 then
  4671. d:drawTriangle(c,s,t,n,r,o,e[11],e[12],e[13],e[14],i)end
  4672. end
  4673. end
  4674. elseif v then
  4675. local function g(e,i,d)local e=e+m
  4676. local i=i+p
  4677. local d=d+h
  4678. local h=c*e-s*d
  4679. d=s*e+c*d
  4680. e=h
  4681. local c=a*i-u*e
  4682. e=u*i+a*e
  4683. i=c
  4684. if n~=0 then
  4685. local e=n*d-f*i
  4686. i=f*d+n*i
  4687. d=e
  4688. end
  4689. local n=(d/e)*o+t
  4690. local t=(i/e)*l+r
  4691. return n,t,e,i,d
  4692. end
  4693. local n,n,x,p,m=g(e[1],e[2],e[3])local c,a,y,_,b=g(e[4],e[5],e[6])local f,h,u,g,w=g(e[7],e[8],e[9])local n=math.abs
  4694. if y>.00010000001 then
  4695. if u>.00010000001 then
  4696. local s=n(x-1e-4)local y=n(y-1e-4)local x=s+y
  4697. local v=(m*y+b*s)/x
  4698. local x=(p*y+_*s)/x
  4699. local y,_,b,r=t,o,r,l
  4700. local t=(v*10000)*_+y
  4701. local o=(x*10000)*r+b
  4702. if e[10]or(c-t)*(h-a)-(a-o)*(f-c)<0 then
  4703. d:drawTriangle(t,o,c,a,f,h,e[11],e[12],e[13],e[14],i)local n=n(u-1e-4)local l=s+n
  4704. local a=(m*n+w*s)/l
  4705. local l=(p*n+g*s)/l
  4706. local n=(a*10000)*_+y
  4707. local l=(l*10000)*r+b
  4708. d:drawTriangle(t,o,n,l,f,h,e[11],e[12],e[13],e[14],i)end
  4709. else
  4710. local f=n(x-1e-4)local s=n(y-1e-4)local n=n(u-1e-4)local h=s+f
  4711. local u=s+n
  4712. local m=(m*s+b*f)/h
  4713. local f=(p*s+_*f)/h
  4714. local t,o,l,h=t,o,r,l
  4715. local r=(m*10000)*o+t
  4716. local f=(f*10000)*h+l
  4717. local m=(b*n+w*s)/u
  4718. local n=(_*n+g*s)/u
  4719. local t=(m*10000)*o+t
  4720. local n=(n*10000)*h+l
  4721. if e[10]or(c-r)*(n-a)-(a-f)*(t-c)<0 then
  4722. d:drawTriangle(r,f,c,a,t,n,e[11],e[12],e[13],e[14],i)end
  4723. end
  4724. else
  4725. if u>.00010000001 then
  4726. local a=n(x-1e-4)local c=n(y-1e-4)local n=n(u-1e-4)local s=n+a
  4727. local u=n+c
  4728. local y=(m*n+w*a)/s
  4729. local m=(p*n+g*a)/s
  4730. local s,t,r,a=t,o,r,l
  4731. local o=(y*10000)*t+s
  4732. local l=(m*10000)*a+r
  4733. local m=(b*n+w*c)/u
  4734. local n=(_*n+g*c)/u
  4735. local t=(m*10000)*t+s
  4736. local n=(n*10000)*a+r
  4737. if e[10]or(t-o)*(h-n)-(n-l)*(f-t)<0 then
  4738. d:drawTriangle(o,l,t,n,f,h,e[11],e[12],e[13],e[14],i)end
  4739. end
  4740. end
  4741. end
  4742. end
  4743. end
  4744. function n:drawObjects(n)local e=self.camera
  4745. local o={i(e[4]or 0),a(e[4]or 0),i(-e[5]),a(-e[5]),i(e[6]),a(e[6]),}local n=n
  4746. for t=1,#n do
  4747. self:drawObject(n[t],e,o)end
  4748. end
  4749. function n:drawBuffer()local e=self.buffer
  4750. e:drawBuffer()e:fastClear()end
  4751. function n:setCamera(t,i,a,o,l,r)local n=math.rad
  4752. if type(t)=="table"then
  4753. local e=t
  4754. self.camera={e.x or self.camera[1]or 0,e.y or self.camera[2]or 0,e.z or self.camera[3]or 0,e.rotX and n(e.rotX+90)or self.camera[4]or 0,e.rotY and n(e.rotY)or self.camera[5]or 0,e.rotZ and n(e.rotZ)or self.camera[6]or 0,self.camera[7],}else
  4755. self.camera={t or self.camera[1]or 0,i or self.camera[2]or 0,a or self.camera[3]or 0,o and n(o+90)or self.camera[4]or 0,l and n(l)or self.camera[5]or 0,r and n(r)or self.camera[6]or 0,self.camera[7],}end
  4756. if self.camera[4]==math.pi*.5 then
  4757. self.camera[4]=nil
  4758. end
  4759. end
  4760. function n:setFoV(e)self.FoV=e or 90
  4761. self.t=C(k(self.FoV/2))*2*1e-4
  4762. _()self.camera[7]=k(self.FoV)end
  4763. function n:setWireFrame(e)self.buffer:useTriangleEdges(e)end
  4764. function n:getObjectIndexTrace(l,n)local function e(t,r,o,l,n,e)return(t-n)*(l-e)-(o-n)*(r-e)end
  4765. local function v(n,t,i,a,d,r,o,l)local c=e(n,t,i,a,d,r)<0
  4766. local r=e(n,t,d,r,o,l)<0
  4767. if c~=r then return false end
  4768. return r==(e(n,t,o,l,i,a)<0)end
  4769. local d=self.blittleOn
  4770. local r=self.x1
  4771. local e=self.y1
  4772. local o=self.x2
  4773. local t=self.y2
  4774. if d then
  4775. r,e,o,t=(r-1)*2+1,(e-1)*3+1,(o)*2,(t+1)*3
  4776. end
  4777. for t=1,#n do
  4778. local o,e=n[t].x,n[t].y
  4779. e=e-1
  4780. if d then
  4781. o=o*2
  4782. e=e*3+1
  4783. end
  4784. n[t].x,n[t].y=o,e
  4785. end
  4786. local e=self.camera
  4787. local t={i(e[4]or 0),a(e[4]or 0),i(-e[5]),a(-e[5]),i(e[6]),a(e[6]),}local i=t[1]local c=t[2]local f=t[3]local h=t[4]local u=t[5]local s=t[6]local d={}for e=1,#n do
  4788. d[e]={depth=math.huge}end
  4789. for g=1,#l do
  4790. local t=l[g]local o=t[7]local a=t[4]local r=t[5]local l=t[6]if(a and a~=0)or(r and r~=0)or(l and l~=0)then
  4791. o=B(o,a,r,l)end
  4792. local r=t[1]local l=t[2]local t=t[3]local _=x
  4793. local a=y
  4794. local b=b
  4795. local y=w
  4796. local r=r-e[1]local m=l-e[2]local p=t-e[3]local function l(e,t,n)local e=e+r
  4797. local t=t+m
  4798. local n=n+p
  4799. local o=h*e-f*n
  4800. n=f*e+h*n
  4801. e=o
  4802. local o=s*t-u*e
  4803. e=u*t+s*e
  4804. t=o
  4805. if i~=0 then
  4806. local e=i*n-c*t
  4807. t=c*n+i*t
  4808. n=e
  4809. end
  4810. local n=(n/e)*b+_
  4811. local t=(t/e)*y+a
  4812. return n,t,e>0
  4813. end
  4814. for u=1,#o do
  4815. local e=o[u]local s,c,t=l(e[1],e[2],e[3])if t then
  4816. local o,t,a=l(e[4],e[5],e[6])if a then
  4817. local i,a,l=l(e[7],e[8],e[9])if l then
  4818. if e[10]or(o-s)*(a-t)-(t-c)*(i-o)<0 then
  4819. local r=r+(e[1]+e[4]+e[7])/3
  4820. local l=m+(e[2]+e[5]+e[8])/3
  4821. local e=p+(e[3]+e[6]+e[9])/3
  4822. local l=r*r+l*l+e*e
  4823. for e=1,#n do
  4824. local n=n[e]local e=d[e]local r,n=n.x,n.y
  4825. if v(r,n,s,c,o,t,i,a)and l<e.depth then
  4826. e.objectIndex=g
  4827. e.polygonIndex=u
  4828. e.depth=l
  4829. end
  4830. end
  4831. end
  4832. end
  4833. end
  4834. end
  4835. end
  4836. end
  4837. return d
  4838. end
  4839. function n:newObject(t,o,l,r,i,a,d)local n=nil
  4840. local e=nil
  4841. if type(t)=="table"then
  4842. if t.initObject then
  4843. else
  4844. n,e=h(t)end
  4845. else
  4846. local t=v(t)n,e=h(t)end
  4847. local o={o,l,r,i,a,d,n,e,}o.frame=self
  4848. function o:setPos(n,t,e)self[1]=n or self[1]self[2]=t or self[2]self[3]=e or self[3]end
  4849. function o:setRot(t,n,e)self[4]=t or self[4]self[5]=n or self[5]self[6]=e or self[6]end
  4850. function o:setModel(t)if type(t)=="table"then
  4851. n,e=h(t)self[7]=n
  4852. self[8]=e
  4853. else
  4854. local t=v(t)n,e=h(t)self[7]=n
  4855. self[8]=e
  4856. end
  4857. end
  4858. if type(t)=="table"then
  4859. if t.initObject then
  4860. t:initObject(o)end
  4861. end
  4862. return o
  4863. end
  4864. _()n:highResMode(true)return n
  4865. end
  4866. local c={}local function l(e,n,t,o,r,l,c,i,d,a)local e={x1=e,y1=n,z1=t,x2=o,y2=r,z2=l,x3=c,y3=i,z3=d,c=a,}return e
  4867. end
  4868. function c:cube(e)e.color=e.color or colors.red
  4869. local e={l(-.5,-.5,-.5,.5,-.5,.5,-.5,-.5,.5,e.bottom or e.color),l(-.5,-.5,-.5,.5,-.5,-.5,.5,-.5,.5,e.bottom2 or e.bottom or e.color),l(-.5,.5,-.5,-.5,.5,.5,.5,.5,.5,e.top or e.color),l(-.5,.5,-.5,.5,.5,.5,.5,.5,-.5,e.top or e.color),l(-.5,-.5,-.5,-.5,-.5,.5,-.5,.5,-.5,e.side or e.color),l(-.5,-.5,.5,-.5,.5,.5,-.5,.5,-.5,e.side2 or e.side or e.color),l(.5,-.5,-.5,.5,.5,.5,.5,-.5,.5,e.side or e.color),l(.5,-.5,-.5,.5,.5,-.5,.5,.5,.5,e.side2 or e.side or e.color),l(-.5,-.5,-.5,.5,.5,-.5,.5,-.5,-.5,e.side or e.color),l(-.5,-.5,-.5,-.5,.5,-.5,.5,.5,-.5,e.side2 or e.side or e.color),l(-.5,-.5,.5,.5,-.5,.5,-.5,.5,.5,e.side or e.color),l(.5,-.5,.5,.5,.5,.5,-.5,.5,.5,e.side2 or e.side or e.color),}for n,t in pairs(r)do
  4870. e[n]=t
  4871. end
  4872. return e
  4873. end
  4874. function c:sphere(e)e.res=e.res or 32
  4875. e.color=e.color or colors.red
  4876. local l={}local t={}for n=0,e.res do
  4877. local o=.5*a(n/e.res*d)local u={}for n=0,e.res do
  4878. local r=.5*T(1-(o*2)*(o*2))local s=a(n/e.res*d*2)*r
  4879. local c=i(n/e.res*d*2)*r
  4880. local a=a((n+1)/e.res*d*2)*r
  4881. local r=i((n+1)/e.res*d*2)*r
  4882. if(t[n])then
  4883. l[#l+1]={x1=t[(n+1)%e.res].x,y1=t[(n+1)%e.res].y,z1=t[(n+1)%e.res].z,x2=s,y2=o,z2=c,x3=t[n].x,y3=t[n].y,z3=t[n].z,c=e.color,}l[#l+1]={x1=a,y1=o,z1=r,x2=s,y2=o,z2=c,x3=t[(n+1)%e.res].x,y3=t[(n+1)%e.res].y,z3=t[(n+1)%e.res].z,c=e.color2 or e.color,}end
  4884. u[n]={x=s,y=o,z=c}end
  4885. t=u
  4886. end
  4887. if e.colors or e.top or e.bottom then
  4888. for n=1,#l do
  4889. local n=l[n]local t=(n.y1+n.y2+n.y3)/3
  4890. if e.colors then
  4891. local t=o((-t+.5)*(#e.colors)+1)n.c=e.colors[t]or n.c
  4892. else
  4893. if t>=0 then
  4894. n.c=e.top or n.c
  4895. else
  4896. n.c=e.bottom or n.c
  4897. end
  4898. end
  4899. end
  4900. end
  4901. for e,n in pairs(r)do
  4902. l[e]=n
  4903. end
  4904. return l
  4905. end
  4906. function c:icosphere(n)n.res=n.res or 1
  4907. local e=(1+T(5))/2
  4908. local t={{e,1,0},{e,-1,0},{-e,-1,0},{-e,1,0},{1,0,e},{-1,0,e},{-1,0,-e},{1,0,-e},{0,e,1},{0,e,-1},{0,-e,-1},{0,-e,1},}local function e(e,o,r)return l(t[e][1],t[e][2],t[e][3],t[o][1],t[o][2],t[o][3],t[r][1],t[r][2],t[r][3],n.colors and 1 or n.color)end
  4909. local i={e(11,2,12),e(11,8,2),e(11,7,8),e(11,3,7),e(11,12,3),e(4,7,3),e(4,10,7),e(4,9,10),e(4,6,9),e(4,3,6),e(5,6,12),e(5,9,6),e(5,1,9),e(5,2,1),e(5,12,2),e(3,12,6),e(1,8,10),e(1,10,9),e(1,2,8),e(10,8,7),}local function d()local a={}for e=1,#i do
  4910. local e=i[e]local r={x=(e.x1+e.x2)/2,y=(e.y1+e.y2)/2,z=(e.z1+e.z2)/2,}local t={x=(e.x1+e.x3)/2,y=(e.y1+e.y3)/2,z=(e.z1+e.z3)/2,}local o={x=(e.x2+e.x3)/2,y=(e.y2+e.y3)/2,z=(e.z2+e.z3)/2,}local i=e.c
  4911. if n.colorsFractal then
  4912. i=(i%#n.colors)+1
  4913. end
  4914. a[#a+1]=l(r.x,r.y,r.z,o.x,o.y,o.z,t.x,t.y,t.z,e.c)a[#a+1]=l(e.x1,e.y1,e.z1,r.x,r.y,r.z,t.x,t.y,t.z,i)a[#a+1]=l(r.x,r.y,r.z,e.x2,e.y2,e.z2,o.x,o.y,o.z,i)a[#a+1]=l(t.x,t.y,t.z,o.x,o.y,o.z,e.x3,e.y3,e.z3,i)end
  4915. i=a
  4916. end
  4917. for e=1,n.res-1 do
  4918. d()end
  4919. local function l(o,e,n)local t=math.sqrt(o*o+e*e+n*n)local t=.5/t
  4920. return o*t,e*t,n*t
  4921. end
  4922. for e=1,#i do
  4923. local e=i[e]e.x1,e.y1,e.z1=l(e.x1,e.y1,e.z1)e.x2,e.y2,e.z2=l(e.x2,e.y2,e.z2)e.x3,e.y3,e.z3=l(e.x3,e.y3,e.z3)if not n.colorsFractal then
  4924. local t=(e.y1+e.y2+e.y3)/3
  4925. if(n.colors)then
  4926. local t=math.floor((-t+.5)*(#n.colors)+1)e.c=n.colors[t]or e.c
  4927. else
  4928. if(t>=0)then
  4929. e.c=n.top or e.c
  4930. else
  4931. e.c=n.bottom or e.c
  4932. end
  4933. end
  4934. else
  4935. e.c=n.colors[e.c]end
  4936. end
  4937. for n,e in pairs(r)do
  4938. i[n]=e
  4939. end
  4940. return i
  4941. end
  4942. function c:plane(e)e.color=e.color or colors.lime
  4943. e.size=e.size or 1
  4944. e.y=e.y or 0
  4945. local e={l(-1*e.size,e.y,1*e.size,1*e.size,e.y,-1*e.size,-1*e.size,e.y,-1*e.size,e.color),l(-1*e.size,e.y,1*e.size,1*e.size,e.y,1*e.size,1*e.size,e.y,-1*e.size,e.color),}for n,t in pairs(r)do
  4946. e[n]=t
  4947. end
  4948. return e
  4949. end
  4950. function c:mountains(e)e.res=e.res or 20
  4951. e.randomOffset=e.randomOffset or 0
  4952. e.height=e.height or 1
  4953. e.randomHeight=e.randomHeight or 0
  4954. e.y=e.y or 0
  4955. e.scale=e.scale or 100
  4956. e.color=e.color or colors.green
  4957. e.snowColor=e.snowColor or colors.white
  4958. local p=3/e.res*e.height/(e.randomHeight+1)local u=3/e.res*e.height*(e.randomHeight+1)local l={}for r=0,e.res do
  4959. local o=math.random(-e.randomOffset*100,e.randomOffset*100)/100
  4960. local o=r+o
  4961. local f=a((o-1)/e.res*d*2)*e.scale
  4962. local h=i((o-1)/e.res*d*2)*e.scale
  4963. local c=a((o-.5)/e.res*d*2)*e.scale
  4964. local s=i((o-.5)/e.res*d*2)*e.scale
  4965. local m=a(o/e.res*d*2)*e.scale
  4966. local i=i(o/e.res*d*2)*e.scale
  4967. local a=math.random(p*100,u*100)/100*e.scale
  4968. local o={x1=f,y1=e.y,z1=h,x2=m,y2=e.y,z2=i,x3=c,y3=e.y+a,z3=s,c=e.color,forceRender=true,}l[#l+1]=o
  4969. if e.snow then
  4970. local r=.93
  4971. local o=e.snowHeight or .5
  4972. local o=1-(o*u)/(a/e.scale)o=n(0,t(1,o))if o>.2 then
  4973. local e={x1=(f*o+c*(1-o))*r,y1=e.y+a*(1-o),z1=(h*o+s*(1-o))*r,x2=(m*o+c*(1-o))*r,y2=e.y+a*(1-o),z2=(i*o+s*(1-o))*r,x3=c*r,y3=e.y+a,z3=s*r,c=e.snowColor,forceRender=true,}l[#l+1]=e
  4974. end
  4975. end
  4976. end
  4977. for e,n in pairs(r)do
  4978. l[e]=n
  4979. end
  4980. return l
  4981. end
  4982. return{newFrame=F,loadModel=v,newBuffer=S,linear=m,models=c,}end,["pine3d.betterblittle"]=function(...)local f=math.floor
  4983. local g=table.concat
  4984. local u={}for e=1,16 do
  4985. u[2^(e-1)]=("0123456789abcdef"):sub(e,e)end
  4986. local function m(o,a,l,r,n,t)local e={}e[o]=1
  4987. e[a]=(e[a]or 0)+1
  4988. e[l]=(e[l]or 0)+1
  4989. e[r]=(e[r]or 0)+1
  4990. e[n]=(e[n]or 0)+1
  4991. e[t]=(e[t]or 0)+1
  4992. local t=o
  4993. local n=0
  4994. local o=o
  4995. local l=0
  4996. for r,e in pairs(e)do
  4997. if e>l then
  4998. if e>n then
  4999. o=t
  5000. l=n
  5001. t=r
  5002. n=e
  5003. else
  5004. o=r
  5005. l=e
  5006. end
  5007. end
  5008. end
  5009. return t,o
  5010. end
  5011. local e={[0]={8,4,3,6,5},{4,14,8,7},{6,10,8,7},{9,11,8,0},{1,14,8,0},{13,12,8,0},{2,10,8,0},{15,8,10,11,12,14},{0,7,1,9,2,13},{3,11,8,7},{2,6,7,15},{9,3,7,15},{13,5,7,15},{5,12,8,7},{1,4,7,15},{7,10,11,12,14}}local t={}for n=0,15 do
  5012. local e=e[n]for n=1,#e do
  5013. e[n]=math.pow(2,e[n])end
  5014. t[math.pow(2,n)]=e
  5015. end
  5016. local function o(e,o,l)local e=t[e]for n=1,#e do
  5017. if e[n]==o then return true
  5018. elseif e[n]==l then return false end
  5019. end
  5020. return false
  5021. end
  5022. local n=string.char
  5023. local c={}for e=128,128+31 do
  5024. c[e]=n(e)end
  5025. local h=bit.bxor
  5026. local function w(n,e,s,d,a,l,r,i)local o=o
  5027. local t=128
  5028. if s==n or s~=e and o(s,n,e)then t=t+1 end
  5029. if d==n or d~=e and o(d,n,e)then t=t+2 end
  5030. if a==n or a~=e and o(a,n,e)then t=t+4 end
  5031. if l==n or l~=e and o(l,n,e)then t=t+8 end
  5032. if r==n or r~=e and o(r,n,e)then t=t+16 end
  5033. if i==n or i~=e and o(i,n,e)then
  5034. return c[h(31,t)],true
  5035. end
  5036. return c[t],false
  5037. end
  5038. local t={}for e=1,16 do
  5039. t[2^(e-1)]={}end
  5040. local function _(e,n)local l=#e
  5041. local o=#e[1]local o=f(o/2)local b=n.setCursorPos
  5042. local y=n.blit
  5043. local r=u
  5044. local t=t
  5045. for p=1,f(l/3)do
  5046. local n=(p-1)*3+1
  5047. local a=e[n]local i=e[n+1]local f=e[n+2]local l={nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}local d={nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}local h={nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil}for e=1,o do
  5048. local o=(e-1)*2+1
  5049. local n=a[o]local s=a[o+1]local u=i[o]local i=i[o+1]local c=f[o]local o=f[o+1]if n==s and s==u and u==i and i==c and c==o then
  5050. local n=r[n]l[e]=n
  5051. d[e]=n
  5052. h[e]="\x80"else
  5053. local a=s..u..i..c..o
  5054. local f=t[n][a]if f then
  5055. l[e]=f[1]d[e]=f[2]h[e]=f[3]else
  5056. local m,f=m(n,s,u,i,c,o)local o,i=w(m,f,n,s,u,i,c,o)if i then
  5057. local i=r[f]local r=r[m]l[e]=i
  5058. d[e]=r
  5059. if t[n]then
  5060. t[n][a]={i,r,o,}else
  5061. t[n]={[a]={i,r,o,}}end
  5062. else
  5063. local i=r[f]local r=r[m]l[e]=r
  5064. d[e]=i
  5065. if t[n]then
  5066. t[n][a]={r,i,o,}else
  5067. t[n]={[a]={r,i,o,}}end
  5068. end
  5069. h[e]=o
  5070. end
  5071. end
  5072. end
  5073. local e=g
  5074. local n=e(h)local t=e(l)local e=e(d)b(1,p)y(n,t,e)end
  5075. end
  5076. return{drawBuffer=_,}end,["pine3d.metadata.Buffer.methods"]=function(...)return{{name="setPixel",parameters={{name="x",type="number"},{name="y",type="number"},{name="c1",type="number",description="color for the pixel"},{name="c2",type="number",description="optional: char color for the pixel"},{name="char",type="number",description="optional: charfor the pixel"}}},{name="image",parameters={{name="x",type="number"},{name="y",type="number"},{name="image",type="PaintUtilsImage",description="load with paintutils"}}},{name="setBufferSize",parameters={{name="x1",type="number",description="x of starting position of the buffer's window"},{name="y1",type="number",description="y of starting position of the buffer's window"},{name="x2",type="number",description="x of ending position of the buffer's window"},{name="y2",type="number",description="y of ending position of the buffer's window"}}},{name="clear",parameters={{name="color",type="number",description="color from CC's colors library to use for clearning the buffer for the first time"}}},{name="fastClear",parameters={{name="color",type="number",description="color from CC's colors library to use for clearning the buffer quickly, after the screenBuffer has been initialized"}}},{name="drawTriangle",parameters={{name="x1",type="number"},{name="y1",type="number"},{name="x2",type="number"},{name="y2",type="number"},{name="x3",type="number"},{name="y3",type="number"},{name="c",type="number",description="fill color"},{name="char",type="char",description="fill character"},{name="charc",type="number",description="fill character color"}}},{name="useTriangleEdges",parameters={{name="enabled",type="boolean",description="if enabled, uses black as default outline color for triangles"}}}}end,["pine3d.metadata.Buffer.properties"]=function(...)return{{name="x1",type="number"},{name="y1",type="number"},{name="x2",type="number"},{name="y2",type="number"},{name="width",type="number"},{name="height",type="number"},{name="screenBuffer",type="table"},{name="blittleWindow",type="window"},{name="blittleOn",type="boolean"}}end,["pine3d.metadata.Buffer"]=function(...)local e={}local n=a("pine3d.metadata.Buffer.methods")local t=a("pine3d.metadata.Buffer.properties")e.methods=n
  5077. e.properties=t
  5078. return e
  5079. end,["pine3d.metadata.CameraAngles.methods"]=function(...)return{}end,["pine3d.metadata.CameraAngles.properties"]=function(...)return{{name="[1]: sin(Camera[4])",type="number"},{name="[2]: cos(Camera[4])",type="number"},{name="[3]: sin(Camera[5])",type="number"},{name="[4]: cos(Camera[5])",type="number"},{name="[5]: sin(Camera[6])",type="number"},{name="[6]: cos(Camera[6])",type="number"}}end,["pine3d.metadata.CameraAngles"]=function(...)local e={}local n=a("pine3d.metadata.CameraAngles.methods")local t=a("pine3d.metadata.CameraAngles.properties")e.methods=n
  5080. e.properties=t
  5081. return e
  5082. end,["pine3d.metadata.CollapsedCamera.methods"]=function(...)return{}end,["pine3d.metadata.CollapsedCamera.properties"]=function(...)return{{name="[1]: x",type="number"},{name="[2]: y",type="number"},{name="[3]: z",type="number"},{name="[4]: rotationX",type="number",description="the camera rotation around the x axis (why would you do this if you don't want to puke, unless you're making something fancy like KSP, Space Engineers or a racing game with curved roads and fancy cameras)"},{name="[5]: rotationY",type="number",description="the camera rotation around the y axis (horizontal rotation)"},{name="[6]: rotationZ",type="number",description="the camera rotation around the z axis (vertical rotation)"},{name="[7]: FoV",type="number",description="the Field of View in radians"}}end,["pine3d.metadata.CollapsedCamera"]=function(...)local e={}local n=a("pine3d.metadata.CollapsedCamera.methods")local t=a("pine3d.metadata.CollapsedCamera.properties")e.methods=n
  5083. e.properties=t
  5084. return e
  5085. end,["pine3d.metadata.CollapsedModel.methods"]=function(...)return{}end,["pine3d.metadata.CollapsedModel.properties"]=function(...)return{}end,["pine3d.metadata.CollapsedModel"]=function(...)local e={}local t=a("pine3d.metadata.CollapsedModel.methods")local n=a("pine3d.metadata.CollapsedModel.properties")e.methods=t
  5086. e.properties=n
  5087. return e
  5088. end,["pine3d.metadata.CollapsedPolygon.methods"]=function(...)return{}end,["pine3d.metadata.CollapsedPolygon.properties"]=function(...)return{{name="[1]: x1",type="number"},{name="[2]: y1",type="number"},{name="[3]: z1",type="number"},{name="[4]: x2",type="number"},{name="[5]: y2",type="number"},{name="[6]: z2",type="number"},{name="[7]: x3",type="number"},{name="[8]: y3",type="number"},{name="[9]: z3",type="number"},{name="[10]: forceRender",type="boolean",description="if true, always renders polygon from both sides, regardless of orientation"},{name="[11]: c",type="number",description="CC color from the colors library"},{name="[12]: char",type="char",description="character used to fill the polygon when drawn without BLittle mode"},{name="[13]: charc",type="number",description="color for the character used to fill the polygon when drawn without BLittle mode"},{name="[14]: outlineColor",type="number",description="color used as outline for the polygon"}}end,["pine3d.metadata.CollapsedPolygon"]=function(...)local e={}local t=a("pine3d.metadata.CollapsedPolygon.methods")local n=a("pine3d.metadata.CollapsedPolygon.properties")e.methods=t
  5089. e.properties=n
  5090. return e
  5091. end,["pine3d.metadata.Model.methods"]=function(...)return{{name="invertTriangles",parameters={{name="model",type="Model",description="Model to transform and invert the triangles of"}},["return"]={{name="model with polygons facing the other direction",type="Model"}}},{name="setOutline",parameters={{name="model",type="Model",description="Model to transform"},{name="options",type="color or table",description="if color, will set the outline color for each polygon. If table, it is a mapping of triangle colors to the outline color they should have"}},["return"]={{name="new model with changed outline colors",type="Model"}}},{name="mapColor",parameters={{name="model",type="Model",description="Model to transform"},{name="options",type="color or table",description="if color, will set the color for each polygon. If table, it is a mapping of triangle colors to the color they should have"}},["return"]={{name="new model with updated colors",type="Model"}}},{name="center",parameters={{name="model",type="Model",description="Model to center"}},["return"]={{name="new centered model",type="Model"}}},{name="normalizeScale",parameters={{name="model",type="Model",description="Model to update. Rescales the model such that the largest value of any coordinate is equal to 1"}},["return"]={{name="new model",type="Model"}}},{name="normalizeScaleY",parameters={{name="model",type="Model",description="Model to update. Similar to normalizeScale, rescales the model, but only uses the y coordinate to determine how much it is scaled (normalizes height)"}},["return"]={{name="new model",type="Model"}}},{name="scale",parameters={{name="model",type="Model",description="Model to scale"},{name="scale",type="number",description="factor to scale the model with"}},["return"]={{name="new model",type="Model"}}},{name="translate",parameters={{name="model",type="Model",description="Model to scale"},{name="dx",type="number",description="translation amount for the x-axis (optional)"},{name="dy",type="number",description="translation amount for the y-axis (optional)"},{name="dz",type="number",description="translation amount for the z-axis (optional)"}},["return"]={{name="new model",type="Model"}}},{name="rotate",parameters={{name="model",type="Model",description="Model to rotate"},{name="rotX",type="number",description="rotation around the x-axis (optional, radians)"},{name="rotY",type="number",description="rotation around the y-axis (optional, radians)"},{name="rotZ",type="number",description="rotation around the z-axis (optional, radians)"}},["return"]={{name="new model",type="Model"}}},{name="alignBottom",parameters={{name="model",type="Model",description="Model to align"}},["return"]={{name="new model",type="Model"}}}}end,["pine3d.metadata.Model.properties"]=function(...)return{}end,["pine3d.metadata.Model"]=function(...)local e={}local t=a("pine3d.metadata.Model.methods")local n=a("pine3d.metadata.Model.properties")e.methods=t
  5092. e.properties=n
  5093. return e
  5094. end,["pine3d.metadata.ModelGenerator.methods"]=function(...)return{{name="cube",parameters={{name="options",type="table",description="Options for the cube. Available options: color, bottom, bottom2, top, top2, side, side2"}},["return"]={{name="cube",type="Model"}}},{name="sphere",parameters={{name="options",type="table",description="Options for the sphere. Available options: res, color"}},["return"]={{name="sphere",type="Model"}}},{name="icosphere",parameters={{name="options",type="table",description="Options for the icosphere. Available options: res, color, top (color), bottom (color), colors (table of colors for gradient), colorsFractal"}},["return"]={{name="icosphere",type="Model"}}},{name="plane",parameters={{name="options",type="table",description="Options for the plane. Available options: color, size, y"}},["return"]={{name="flat plane",type="Model"}}},{name="mountains",parameters={{name="options",type="table",description="Options for the mountains. Available options: res, randomOffset, height, randomHeight, y, scale, color, snow (bool), snowColor"}},["return"]={{name="mountains",type="Model"}}}}end,["pine3d.metadata.ModelGenerator.properties"]=function(...)return{}end,["pine3d.metadata.ModelGenerator"]=function(...)local e={}local t=a("pine3d.metadata.ModelGenerator.methods")local n=a("pine3d.metadata.ModelGenerator.properties")e.methods=t
  5095. e.properties=n
  5096. return e
  5097. end,["pine3d.metadata.PineCamera.methods"]=function(...)return{}end,["pine3d.metadata.PineCamera.properties"]=function(...)return{{name="x",type="number"},{name="y",type="number"},{name="z",type="number"},{name="rotX",type="number",description="the camera rotation around the x axis (why would you do this if you don't want to puke, unless you're making something fancy like KSP, Space Engineers or a racing game with curved roads and fancy cameras)"},{name="rotY",type="number",description="the camera rotation around the y axis (horizontal rotation)"},{name="rotZ",type="number",description="the camera rotation around the z axis (vertical rotation)"}}end,["pine3d.metadata.PineCamera"]=function(...)local e={}local t=a("pine3d.metadata.PineCamera.methods")local n=a("pine3d.metadata.PineCamera.properties")e.methods=t
  5098. e.properties=n
  5099. return e
  5100. end,["pine3d.metadata.PineObject.methods"]=function(...)return{{name="setPos",parameters={{name="x",type="number",description="new x position (optional)"},{name="y",type="number",description="new y position (optional)"},{name="z",type="number",description="new z position (optional)"}}},{name="setRot",parameters={{name="rotX",type="number",description="new rotation around the x axis in radians (optional)"},{name="rotY",type="number",description="new rotation around the y axis in radians (optional)"},{name="rotZ",type="number",description="new rotation around the z axis in radians (optional)"}}},{name="setModel",parameters={{name="model",type="string or Model",description="if string, used as path to load the serialized Model"}}}}end,["pine3d.metadata.PineObject.properties"]=function(...)return{{name="[1]: x",type="number"},{name="[2]: y",type="number"},{name="[3]: z",type="number"},{name="[4]: rotationX",type="number",description="the objects rotation around the x axis (you're probably not using this unless you want to attempt 3d physics)"},{name="[5]: rotationY",type="number",description="the objects rotation around the y axis (horizontal rotation)"},{name="[6]: rotationZ",type="number",description="the objects rotation around the z axis (vertical rotation)"},{name="[7]: model",type="CollapsedModel",description="the model that is rendered for this object"},{name="[8]: modelSize",type="number",description="largest distance of a vertex from the center of the model"}}end,["pine3d.metadata.PineObject"]=function(...)local e={}local n=a("pine3d.metadata.PineObject.methods")local t=a("pine3d.metadata.PineObject.properties")e.methods=n
  5101. e.properties=t
  5102. return e
  5103. end,["pine3d.metadata.Polygon.methods"]=function(...)return{}end,["pine3d.metadata.Polygon.properties"]=function(...)return{{name="x1",type="number"},{name="y1",type="number"},{name="z1",type="number"},{name="x2",type="number"},{name="y2",type="number"},{name="z2",type="number"},{name="x3",type="number"},{name="y3",type="number"},{name="z3",type="number"},{name="forceRender",type="boolean",description="if true, always renders polygon from both sides, regardless of orientation"},{name="c",type="number",description="CC color from the colors library"},{name="char",type="char",description="character used to fill the polygon when drawn without BLittle mode"},{name="charc",type="number",description="color for the character used to fill the polygon when drawn without BLittle mode"},{name="outlineColor",type="number",description="color used as outline for the polygon"}}end,["pine3d.metadata.Polygon"]=function(...)local e={}local t=a("pine3d.metadata.Polygon.methods")local n=a("pine3d.metadata.Polygon.properties")e.methods=t
  5104. e.properties=n
  5105. return e
  5106. end,["pine3d.metadata.ThreeDFrame.methods"]=function(...)return{{name="setSize",parameters={{name="x1",type="number",description="x of starting position of the 3d rendering window"},{name="y1",type="number",description="y of starting position of the 3d rendering window"},{name="x2",type="number",description="x of ending position of the 3d rendering window"},{name="y2",type="number",description="y of ending position of the 3d rendering window"}}},{name="setBackgroundColor",parameters={{name="color",type="number",description="CC color from the colors library"}}},{name="highResMode",parameters={{name="enabled",type="boolean",description="if true, enables the use of characters 128-168 for a higher quality, seemingly larger resolution. Enabled by default"}}},{name="setCamera",parameters={{name="cameraX",type="number",description="x coordinate of the new camera position (optional)"},{name="cameraY",type="number",description="y coordinate of the new camera position (optional)"},{name="cameraZ",type="number",description="z coordinate of the new camera position (optional)"},{name="rotX",type="number",description="new camera rotation around the x axis (optional)"},{name="rotY",type="number",description="new camera rotation around the y axis (optional)"},{name="rotZ",type="number",description="new camera rotation around the z axis (optional)"}}},{name="setCamera",parameters={{name="camera",type="PineCamera",description="string indexed table with values for x, y, z, rotX, rotY, rotZ (all optional)"}}},{name="setFoV",parameters={{name="FoV",type="number",description="the new field of view of the camera in degrees"}}},{name="newObject",parameters={{name="model",type="string or Model",description="if string, used as path to load the serialized Model"},{name="x",type="number",description="x coordinate of the PineObject"},{name="y",type="number",description="y coordinate of the PineObject"},{name="z",type="number",description="z coordinate of the PineObject"},{name="rotX",type="number",description="rotation around the x axis (optional)"},{name="rotY",type="number",description="rotation around the y axis (optional)"},{name="rotZ",type="number",description="rotation around the z axis (optional)"}},["return"]={{name="object",type="PineObject",description="newly created object"}}},{name="getObjectIndexTrace",["return"]={{name="objectIndex",type="number",description="the index in the objects array for the PineObject that is rendered at the given position"},{name="polygonIndex",type="number",description="the index of the polygon in the Model rendered at the given position that corresponds to the PineObject at the given position"}},parameters={{name="objects",type="array of PineObject",description=""},{name="x",type="number",description="x coordinate on the screen"},{name="y",type="number",description="y coordinate on the screen"}}},{name="map3dTo2d",["return"]={{name="screenX",type="number"},{name="screenY",type="number"},{name="visible",type="boolean"}},parameters={{name="x",type="number",description="x coordinate in 3d space"},{name="y",type="number",description="y coordinate in 3d space"},{name="z",type="number",description="z coordinate in 3d space"}}},{name="drawObject",parameters={{name="object",type="PineObject",description="the PineObject to draw to the internal Buffer"},{name="cameraAngles",type="CameraAngles",description="CameraAngles for fast calculations. Can be dirived from CollapsedCamera"}}},{name="drawObjects",parameters={{name="objects",type="array of PineObject",description="table of objects to draw to the internal Buffer"}}},{name="drawBuffer",parameters={}}}end,["pine3d.metadata.ThreeDFrame.properties"]=function(...)return{{name="camera",type="CollapsedCamera"},{name="buffer",type="Buffer"},{name="x1",type="number"},{name="y1",type="number"},{name="x2",type="number"},{name="y2",type="number"},{name="width",type="number"},{name="height",type="number"}}end,["pine3d.metadata.ThreeDFrame"]=function(...)local e={}local n=a("pine3d.metadata.ThreeDFrame.methods")local t=a("pine3d.metadata.ThreeDFrame.properties")e.methods=n
  5107. e.properties=t
  5108. return e
  5109. end,["generate-typings"]=function(...)local e=a("lualib_bundle")local l=e.__TS__StringReplaceAll
  5110. local i=e.__TS__StringStartsWith
  5111. local d=e.__TS__ArrayFilter
  5112. local r=e.__TS__ArrayMap
  5113. local c=e.__TS__StringEndsWith
  5114. local s={}local u=a("pine3d.metadata.Buffer")local m=a("pine3d.metadata.CameraAngles")local f=a("pine3d.metadata.CollapsedCamera")local x=a("pine3d.metadata.CollapsedModel")local _=a("pine3d.metadata.CollapsedPolygon")local w=a("pine3d.metadata.Model")local y=a("pine3d.metadata.ModelGenerator")local p=a("pine3d.metadata.PineCamera")local g=a("pine3d.metadata.PineObject")local b=a("pine3d.metadata.Polygon")local v=a("pine3d.metadata.ThreeDFrame")local function e(e)local e,n=io.open(e,"rb")if not e then
  5115. error("could not open file: "..n)end
  5116. local n=e:read("*a")if not n then
  5117. error"could not read file"end
  5118. e:close()return n
  5119. end
  5120. local function C(e,o)local n,t=io.open(e,"wb")if not n then
  5121. error((("could not open file "..e)..": ")..t)end
  5122. local o,t=n:write(o)if not o then
  5123. error((("could not write to file "..e)..": ")..t)end
  5124. n:close()end
  5125. local function t(e)local n={{"(%w+) indexed table of (%w+)","LuaTable<%1, %2>"},{"table of (%w+)","LuaTable<number, %1>"},{"array of (%w+)","%1[]"},{"table","LuaTable<AnyNotNil, any>"}}for t,n in ipairs(n)do
  5126. local t=n[1]local n=n[2]e=string.gsub(e,t,n)end
  5127. return l(l(e," or ","|"),"char","string")end
  5128. local function h(o)local e={}local a={}for o,n in ipairs(o.properties)do
  5129. if i(n.name,"[")then
  5130. local e=string.match(n.name,"^%[(%d+)%]:")a[tonumber(e)]=t(n.type)..(" /*"..n.name).."*/"else
  5131. e[#e+1]=((n.name..": ")..t(n.type)).."\n"end
  5132. end
  5133. for n,o in ipairs(o.methods)do
  5134. e[#e+1]="\n/**\n"for t,n in ipairs(o.parameters)do
  5135. local t=n.description or""if#t>0 then
  5136. e[#e+1]=(((" * @param "..n.name).." ")..t).."\n"end
  5137. end
  5138. local n=o["return"]if n and#d(n,function(n,e)return e.description end)>0 then
  5139. e[#e+1]=" * @returns "..table.concat(r(n,function(n,e)return e.description or""end),"")end
  5140. e[#e+1]=" */\n"e[#e+1]=o.name
  5141. e[#e+1]="("local l={}for o,n in ipairs(o.parameters)do
  5142. local e=n.description or""local e=(i(e,"optional")or c(e,"(optional)"))and"?"or""l[#l+1]=((n.name..e)..": ")..t(n.type)end
  5143. e[#e+1]=table.concat(l,", ")e[#e+1]=")"if n then
  5144. if#n==1 then
  5145. e[#e+1]=": "..t(n[1].type)else
  5146. e[#e+1]=": LuaMultiReturn<["e[#e+1]=table.concat(r(n,function(n,e)return t(e.type)end),", ")e[#e+1]="]>"end
  5147. else
  5148. e[#e+1]=": void"end
  5149. e[#e+1]="\n"end
  5150. return a,e
  5151. end
  5152. local function a(...)local e={{"Buffer",u},{"CameraAngles",m},{"CollapsedCamera",f},{"CollapsedModel",x},{"CollapsedPolygon",_},{"Model",w},{"ModelGenerator",y},{"PineCamera",p},{"PineObject",g},{"Polygon",b},{"ThreeDFrame",v}}C("/src/pine3d/integrate-me",table.concat(r(e,function(n,e)local t
  5153. local n
  5154. n=e[1]t=e[2]local r,e=h(t)local t=("{\n\t"..l(l(table.concat(e,""),"\n","\n\t").."\n","\t\n","\n")).."}"local o=#r
  5155. if o==0 then
  5156. return((("export interface "..n).." ")..t).."\n"else
  5157. local e={}for n=1,o do
  5158. e[#e+1]="null"end
  5159. for n,t in pairs(r)do
  5160. e[n]=t
  5161. end
  5162. return((((("export type "..n).." = [\n\t")..table.concat(e,",\n\t")).."\n] & ")..t)..";\n"end
  5163. end),"\n"))end
  5164. a(...)return s
  5165. end,}return a("game",...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement