Advertisement
ComputerMan123

Sheets by Exerro

Feb 4th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 83.14 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.     local env = setmetatable( {}, { __index = _ENV } )
  138.     local function f()
  139.         local _ENV = env
  140.         if setfenv then
  141.             setfenv( 1, env )
  142.         end
  143.  
  144.  
  145. event = {
  146.     mouse_down = 0;
  147.     mouse_up = 1;
  148.     mouse_click = 2;
  149.     mouse_hold = 3;
  150.     mouse_drag = 4;
  151.     mouse_scroll = 5;
  152.     mouse_ping = 6;
  153.     key_down = 7;
  154.     key_up = 8;
  155.     text = 9;
  156.     voice = 10;
  157.     paste = 11;
  158. }
  159.  
  160. alignment = {
  161.     left = 0;
  162.     centre = 1;
  163.     center = 1;
  164.     right = 2;
  165.     top = 3;
  166.     bottom = 4;
  167. }
  168.  
  169. area = {
  170.     box = 0;
  171.     circle = 1;
  172.     line = 2;
  173.     vline = 3;
  174.     hline = 4;
  175.     fill = 5;
  176.     point = 6;
  177.     ccircle = 7;
  178. }
  179.  
  180. colour = {
  181.     transparent = 0;
  182.     white = 1;
  183.     orange = 2;
  184.     magenta = 4;
  185.     lightBlue = 8;
  186.     yellow = 16;
  187.     lime = 32;
  188.     pink = 64;
  189.     grey = 128;
  190.     lightGrey = 256;
  191.     cyan = 512;
  192.     purple = 1024;
  193.     blue = 2048;
  194.     brown = 4096;
  195.     green = 8192;
  196.     red = 16384;
  197.     black = 32768;
  198. }
  199.  
  200. token = {
  201.     eof = TOKEN_EOF;
  202.     string = TOKEN_STRING;
  203.     float = TOKEN_FLOAT;
  204.     int = TOKEN_INT;
  205.     ident = TOKEN_IDENT;
  206.     newline = TOKEN_NEWLINE;
  207.     symbol = TOKEN_SYMBOL;
  208.     operator = TOKEN_OPERATOR;
  209. }
  210.  
  211. local __f,__err=load("class={}local e=setmetatable({},{__index=class})local t={}local a={}\
  212. local o\
  213. local i={__add=true,__sub=true,__mul=true,__div=true,__mod=true,__pow=true,__unm=true,__len=true,__eq=true,__lt=true,__lte=true,__tostring=true,__concat=true}local function n(d)return\"[Class] \"..d:type()end local function s(d,l)return tostring(d)..\
  214. tostring(l)end\
  215. local function h(d)if not o then\
  216. return error\"no class to define\"end for l,u in pairs(d)do o[l]=u end o=nil end\
  217. local function r(d,l)local u={}if l.super then u.super=r(d,l.super)end\
  218. setmetatable(u,{__index=function(c,m)\
  219. if type(l[m])==\
  220. \"function\"then\
  221. return function(f,...)if f==u then f=d end d.super=u.super local w={l[m](f,...)}\
  222. d.super=u return unpack(w)end else return l[m]end end,__newindex=l,__tostring=function(c)\
  223. return\
  224. \"[Super] \"..tostring(l)..\" of \"..tostring(d)end})return u end\
  225. function e:new(...)local d={__index=self,__INSTANCE=true}\
  226. local l=setmetatable({class=self,meta=d},d)if self.super then l.super=r(l,self.super)end for c,m in\
  227. pairs(self.meta)do if i[c]then d[c]=m end end if d.__tostring==n then function d:__tostring()return\
  228. self:tostring()end end function l:type()return\
  229. self.class:type()end function l:typeOf(c)\
  230. return self.class:typeOf(c)end\
  231. if not self.tostring then function l:tostring()return\
  232. \"[Instance] \"..self:type()end end local u=self while u do\
  233. if u[u.meta.__type]then u[u.meta.__type](l,...)break end u=u.super end return l end function e:extends(d)self.super=d self.meta.__index=d end function e:type()return\
  234. tostring(self.meta.__type)end function e:typeOf(d)return\
  235. d==self or(self.super and\
  236. self.super:typeOf(d))or false end\
  237. function class:new(d)\
  238. if type(\
  239. d or self)~=\"string\"then return\
  240. error(\"expected string class name, got \"..type(d or self))end\
  241. local l={__index=e,__CLASS=true,__tostring=n,__concat=s,__call=e.new,__type=d or self}local u=setmetatable({meta=l},l)t[d]=u o=u _ENV[d]=u return\
  242. function(c)if not o then return\
  243. error\"no class to define\"end for m,f in pairs(c)do o[m]=f end o=nil end end\
  244. function class.type(d)local l=type(d)if l==\"table\"then\
  245. pcall(function()local u=getmetatable(d)\
  246. l=(\
  247. (u.__CLASS or u.__INSTANCE)and d:type())or l end)end return l end\
  248. function class.typeOf(d,l)\
  249. if type(d)==\"table\"then\
  250. local u,c=pcall(function()\
  251. return getmetatable(d).__CLASS or\
  252. getmetatable(d).__INSTANCE or error()end)return u and d:typeOf(l)end return false end function class.isClass(d)\
  253. return pcall(function()\
  254. if not getmetatable(d).__CLASS then error()end end),nil end\
  255. function class.isInstance(d)return\
  256. pcall(function()if not\
  257. getmetatable(d).__INSTANCE then error()end end),nil end setmetatable(class,{__call=class.new})\
  258. function extends(d)\
  259. if not o then return\
  260. error\"no class to extend\"elseif not t[d]then return\
  261. error(\"no such class '\"..tostring(d)..\"'\")end o:extends(t[d])return h end\
  262. function interface(d)a[d]={}_ENV[d]=a[d]\
  263. return function(l)if type(l)~=\"table\"then return\
  264. error(\"expected table t, got \"..class.type(l))end\
  265. _ENV[d]=l a[d]=l end end\
  266. function implements(d)\
  267. if not o then return error\"no class to modify\"elseif not a[d]then return error(\"no interface by name '\"..\
  268. tostring(d)..\"'\")end for l,u in pairs(a[d])do o[l]=u end return h end","lib.class",nil,_ENV)if not __f then error(__err,0)end __f()
  269. local __f,__err=load("timer={}local e={}local a=0 local o,i=os.clock()\
  270. function timer.new(t)\
  271. parameters.check(1,\"n\",\"number\",t)local n,s=o+t,false\
  272. for h=1,#e do if e[h].time==n then s=e[h].ID break end end return s or os.startTimer(t)end\
  273. function timer.queue(t,n)\
  274. parameters.check(2,\"n\",\"number\",t,\"response\",\"function\",n)local s,h=o+t,false\
  275. for r=1,#e do if e[r].time==s then h=e[r].ID break end end local a=h or os.startTimer(t)\
  276. e[#e+1]={time=s,response=n,ID=a}return a end\
  277. function timer.cancel(t)parameters.check(1,\"ID\",\"number\",t)for n=#e,1,-1 do\
  278. if\
  279. e[n].ID==t then return table.remove(e,n).time-o end end return 0 end function timer.step()i=o o=os.clock()end\
  280. function timer.getDelta()return o-i end function timer.update(a)local t=false for n=#e,1,-1 do if e[n].ID==a then\
  281. table.remove(e,n).response()t=true end end\
  282. return t end\
  283. timer.step()","lib.timer",nil,_ENV)if not __f then error(__err,0)end __f()
  284. local __f,__err=load("local e={}clipboard={}function clipboard.put(t)\
  285. parameters.check(1,\"modes\",\"table\",t)e=t end function clipboard.get(t)\
  286. parameters.check(1,\"mode\",\"string\",t)return e[t]end\
  287. function clipboard.clear()e={}end","lib.clipboard",nil,_ENV)if not __f then error(__err,0)end __f()
  288. local __f,__err=load("parameters={}\
  289. function parameters.checkConstructor(e,t,...)local a={...}\
  290. for o=1,t*3,3 do local i=a[o]local n=a[o+1]\
  291. local s=a[o+2]\
  292. if type(n)==\"string\"then if type(s)~=n then\
  293. Exception.throw(IncorrectConstructorException,e:type()..\" expects \"..n..\
  294. \" \"..i..\
  295. \" when created, got \"..class.type(s),4)end else\
  296. if not\
  297. class.typeOf(s,n)then\
  298. Exception.throw(IncorrectConstructorException,e:type()..\" expects \"..\
  299. n:type()..\" \"..i..\" when created, got \"..\
  300. class.type(s),4)end end end end\
  301. function parameters.check(e,...)local t={...}\
  302. for a=1,e*3,3 do local o=t[a]local i=t[a+1]local n=t[a+2]\
  303. if\
  304. type(i)==\"string\"then if type(n)~=i then\
  305. Exception.throw(IncorrectParameterException,\"expected \"..i..\" \"..\
  306. o..\", got \"..class.type(n),3)end else if not\
  307. class.typeOf(n,i)then\
  308. Exception.throw(IncorrectParameterException,\"expected \"..i:type()..\" \"..o..\
  309. \", got \"..class.type(n),3)end end end end","lib.parameters",nil,_ENV)if not __f then error(__err,0)end __f()
  310.  
  311. local __f,__err=load("local e={}\
  312. for t=0,15 do e[2^t]=(\"%x\"):format(t)e[(\"%x\"):format(t)]=\
  313. 2^t e[(\"%X\"):format(t)]=2^t end image={}\
  314. function image.decodePaintutils(t,a)local o={}\
  315. for i in t:gmatch\"[^\\n]+\"do local n={}for s=1,#i do\
  316. n[s]={e[i:sub(s,s)]or 0,1,\" \"}end o[#o+1]=n end return o end function image.encodePaintutils(t)end\
  317. function image.apply(t,a)local o,i={},{}local s=1\
  318. for n=0,\
  319. math.min(#t,a.height)-1 do local h=n*a.width for r=1,math.min(#t[n+1],a.width)do\
  320. o[s]=t[n+1][r]i[s]=h+r s=s+1 end end a:mapPixels(i,o)end","graphics.image",nil,_ENV)if not __f then error(__err,0)end __f()
  321.  
  322. local e={[1]=256,[2]=16384,[4]=1024,[8]=512,[16]=2,[32]=8192,[64]=4,[128]=32768,[256]=128,[512]=2048,[1024]=128,[2048]=128,[4096]=32768,[8192]=128,[16384]=4096,[32768]=32768}
  323. local t={[1]=1,[2]=16,[4]=64,[8]=1,[16]=1,[32]=1,[64]=1,[128]=256,[256]=1,[512]=8,[1024]=4,[2048]=512,[4096]=16384,[8192]=32,[16384]=2,[32768]=128}
  324. local a={[1]=1,[2]=256,[4]=256,[8]=256,[16]=1,[32]=256,[64]=1,[128]=128,[256]=256,[512]=128,[1024]=128,[2048]=128,[4096]=32768,[8192]=128,[16384]=128,[32768]=32768}
  325. local o={[1]=32768,[2]=2048,[4]=8192,[8]=4096,[16]=2048,[32]=1024,[64]=8192,[128]=256,[256]=128,[512]=16384,[1024]=8192,[2048]=16,[4096]=8,[8192]=1024,[16384]=512,[32768]=1}shader={}function shader.darken(i,...)return e[i]or i,...end function shader.lighten(i,...)return t[i]or
  326. i,...end
  327. function shader.greyscale(i,...)return a[i]or i,...end function shader.inverse(i,...)return o[i]or i,...end
  328. local __f,__err=load("\
  329. local e,t=load(\"local function e(l,u,m,f)local d=l>m and l or m\\\
  330. local c=(l+u<m+f and l+u or m+f)-d return d,c end local t,a,o,i local function n(d)return\\\
  331. setmetatable(d,{__add=t,__sub=a,__mod=o,__tostring=i})end\\\
  332. function t(d,l)\\\
  333. local u,m,f=1,1,0 local w={}\\\
  334. while d[u]or l[m]do\\\
  335. if\\\
  336. d[u]and(not l[m]or d[u]<=l[m])then if w[f]~=d[u]then f=f+1 w[f]=d[u]end u=u+1 elseif l[m]and\\\
  337. (not d[u]or d[u]>l[m])then if w[f]~=l[m]then f=f+1 w[f]=l[m]end m=m+1 end end return n(w)end\\\
  338. function a(d,l)local u,m,f=1,1,1 local w={}\\\
  339. while d[u]do while l[m]and l[m]<d[u]do m=m+1 end if\\\
  340. d[u]~=l[m]then w[f]=d[u]f=f+1 end u=u+1 end return n(w)end\\\
  341. function o(d,l)local u,m,f=1,1,1 local w={}\\\
  342. while d[u]do while l[m]and l[m]<d[u]do m=m+1 end if\\\
  343. d[u]==l[m]then w[f]=d[u]f=f+1 end u=u+1 end return n(w)end\\\
  344. function i(d)return\\\"Area of \\\"..#d..\\\" coordinates\\\"end local s,h=term.getSize()local r={}function r.setDimensions(d,l)s,h=d,l end function r.new(d)\\\
  345. return n(d)end function r.blank()return n{}end function r.fill()local d={}for l=1,s*h do d[l]=l end return\\\
  346. n(d)end\\\
  347. function r.point(d,l)if\\\
  348. d>=0 and d<s and l>=0 and l<h then return n{l*s+d+1}end return n{}end\\\
  349. function r.box(d,l,u,c)d,u=e(0,s,d,u)l,c=e(0,h,l,c)local m=l*s+d local f,w={},1 for y=1,c do\\\
  350. for d=1,u do f[w]=m+d w=w+1 end m=m+s end return n(f)end\\\
  351. function r.circle(d,l,u)local c=u*u local m={}local f=1\\\
  352. for w=math.floor(l-u),math.ceil(l+u)do\\\
  353. if w>0 and w<h then local y=l-w local p=(\\\
  354. c-y*y)^.5 local v=w*s+1 local g=math.floor(d-p+.5)local k,q=e(0,s,g,math.ceil(\\\
  355. d+p-.5)-g+1)for b=k,k+\\\
  356. q-1 do m[f]=v+b f=f+1 end end end return n(m)end\\\
  357. function r.correctedCircle(d,l,u)local c=u*u local m={}local f=1\\\
  358. for w=math.floor(l-u+1),math.ceil(l+u-1)do\\\
  359. if\\\
  360. w>=0 and w<h then local y=l-w local p=(c-y*y)^.5*1.5 local v=w*s+1\\\
  361. local g=math.floor(d-p+.5)\\\
  362. local k,q=e(0,s,g,math.ceil(d+p-.5)-g+1)for b=k,k+q-1 do m[f]=v+b f=f+1 end end end return n(m)end\\\
  363. function r.hLine(d,l,u)if l>=0 and l<h then d,u=e(0,s,d,u)local c=l*s+d local m={}for f=1,u do m[f]=c+f end\\\
  364. return n(m)end return n{}end\\\
  365. function r.vLine(d,l,u)if d>=0 and d<s then l,u=e(0,h,l,u)local c=l*s+d+1 local m={}\\\
  366. for f=1,u do m[f]=c c=c+s end return n(m)end return n{}end\\\
  367. function r.line(d,l,u,c)if d>u then d,u=u,d l,c=c,l end local f,w=u-d,c-l\\\
  368. if f==0 then if w==0 then\\\
  369. return newPointArea(d,l,s,h)end return newVLineArea(d,l,w,s,h)elseif w==0 then return\\\
  370. newHLineArea(d,l,f,s,h)end local y={}\\\
  371. if d>=0 and d<s and l>=0 and l<h then\\\
  372. y[1]=\\\
  373. math.floor(l+.5)*s+math.floor(d+.5)+1\\\
  374. if u>=0 and u<s and c>=0 and c<h then y[2]=math.floor(c+.5)*s+math.floor(\\\
  375. u+.5)+1 end elseif u>=0 and u<s and c>=0 and c<h then y[1]=math.floor(c+.5)*s+math.floor(\\\
  376. u+.5)+1 end local p=w/f local v=l-p*d local b=math.min(1/math.abs(p),1)local g=\\\
  377. #y+1 for m=math.max(d,0),math.min(u,s-1),b do\\\
  378. local k=math.floor(p*m+v+.5)\\\
  379. if k>0 and k<h then y[g]=k*s+math.floor(m+.5)+1 g=g+1 end end return n(y)end return r\",\"area\",\
  380. nil,_ENV)if not e then error(t,0)end local a=e()\
  381. local function o(l,u,m,f)local d=l>m and l or m local c=(\
  382. l+u<m+f and l+u or m+f)-d return d,c end local i,n=table.insert,table.remove local s,h=math.min,math.max\
  383. local r=math.floor\
  384. class\"Canvas\"{width=0,height=0,colour=1,pixels={}}\
  385. function Canvas:Canvas(d,l)d=d or 0 l=l or 0\
  386. if type(d)~=\"number\"then return\
  387. error(\"element attribute #1 'width' not a number (\"..\
  388. class.type(d)..\")\",2)end\
  389. if type(l)~=\"number\"then return\
  390. error(\"element attribute #2 'height' not a number (\"..class.type(l)..\")\",2)end self.width=d self.height=l self.pixels={}local u={1,1,\" \"}for c=1,d*l do\
  391. self.pixels[c]=u end end\
  392. function Canvas:setWidth(d)if type(d)~=\"number\"then return\
  393. error(\"expected number width, got \"..class.type(d))end\
  394. d=math.floor(d)local l,u=self.height,self.pixels local c=self.width\
  395. local m={self.colour,1,\" \"}while c<d do for f=1,l do i(u,(c+1)*f,m)end c=c+1 end while\
  396. c>d do for f=l,1,-1 do n(u,c*f)end c=c-1 end self.width=c end\
  397. function Canvas:setHeight(d)if type(d)~=\"number\"then return\
  398. error(\"expected number height, got \"..class.type(d))end\
  399. d=math.floor(d)local l,u=self.width,self.pixels local c=self.height\
  400. local m={self.colour,1,\" \"}while c<d do for f=1,l do u[#u+1]=m end c=c+1 end while c>d do\
  401. for f=1,l do u[#u]=nil end c=c-1 end self.height=c end\
  402. function Canvas:getPixel(d,l)local u=self.width\
  403. if\
  404. d>=0 and d<u and l>=0 and l<self.height then local c=self.pixels[l*u+d+1]return c[1],c[2],c[3]end end\
  405. function Canvas:mapColour(d,l)if type(d)~=\"table\"then return\
  406. error(\"expected table coords, got \"..class.type(d))end if\
  407. type(l)~=\"number\"then return\
  408. error(\"expected number colour, got \"..class.type(l))end\
  409. local u={l,1,\" \"}local c=self.pixels for m=1,#d do c[d[m]]=u end end\
  410. function Canvas:mapColours(d,l)if type(d)~=\"table\"then return\
  411. error(\"expected table coords, got \"..class.type(d))end if\
  412. type(l)~=\"table\"then return\
  413. error(\"expected table colours, got \"..class.type(l))end\
  414. local u=self.pixels local c=#l\
  415. for m=1,#d do u[d[m]]={l[(m-1)%c+1],1,\" \"}end end\
  416. function Canvas:mapPixel(d,l)if type(d)~=\"table\"then return\
  417. error(\"expected table coords, got \"..class.type(d))end if\
  418. type(l)~=\"table\"then return\
  419. error(\"expected table pixel, got \"..class.type(l))end\
  420. local u=self.pixels for c=1,#d do u[d[c]]=l end end\
  421. function Canvas:mapPixels(d,l)if type(d)~=\"table\"then return\
  422. error(\"expected table coords, got \"..class.type(d))end if\
  423. type(l)~=\"table\"then return\
  424. error(\"expected table pixels, got \"..class.type(l))end\
  425. local u=self.pixels for c=1,#d do u[d[c]]=l[c]end end\
  426. function Canvas:mapShader(d,l)if type(d)~=\"table\"then return\
  427. error(\"expected table coords, got \"..class.type(d))end\
  428. if\
  429. type(l)~=\"function\"then return\
  430. error(\"expected function shader, got \"..class.type(l))end local u=self.pixels local c=self.width local m={}\
  431. for f=1,#d do local w=d[f]local y=u[w]\
  432. local p=(w-1)%c local v,b,g=l(y[1],y[2],y[3],p,(w-1-p)/c)\
  433. m[f]=\
  434. (v or b or g)and{v or y[1],b or y[2],g or y[3]}end for f=1,#d do local w=m[f]if w then u[d[f]]=w end end end\
  435. function Canvas:shift(a,d,l,u)local c=self.width if type(a)==\"number\"then d,l,u=a,d,l a={}for w=1,c*self.height do\
  436. a[w]=w end end local m=l*c+d\
  437. local f=self.pixels for w=1,#a do f[w]=f[w+m]or u end end\
  438. function Canvas:drawColour(d,l)if type(d)~=\"table\"then return\
  439. error(\"expected table coords, got \"..class.type(d))end if\
  440. type(l)~=\"number\"then return\
  441. error(\"expected number colour, got \"..class.type(l))end if\
  442. l==0 then return end local u={l,1,\" \"}local c=self.pixels for m=1,#d do c[d[m]]=u end end\
  443. function Canvas:drawColours(d,l)if type(d)~=\"table\"then return\
  444. error(\"expected table coords, got \"..class.type(d))end if\
  445. type(l)~=\"table\"then return\
  446. error(\"expected table colours, got \"..class.type(l))end\
  447. local u=#l local c=self.pixels for m=1,#d do if l[m]~=0 then\
  448. c[d[m]]={l[(m-1)%u+1],1,\" \"}end end end\
  449. function Canvas:drawPixel(d,l)if type(d)~=\"table\"then return\
  450. error(\"expected table coords, got \"..class.type(d))end if\
  451. type(l)~=\"table\"then return\
  452. error(\"expected table pixel, got \"..class.type(l))end\
  453. local u=self.pixels\
  454. if l[1]==0 and(l[2]==0 or l[3]==\"\")then return elseif\
  455. l[1]==0 or l[2]==0 or l[3]==\"\"then local c,m,f=l[1],l[2],l[3]\
  456. for w=1,#d do local y=d[w]local p,v,b,g if c==0 then p=u[y]\
  457. v=p[1]end\
  458. if m==0 or f==\"\"then p=p or u[y]b=p[2]g=p[3]end u[y]={v or c,b or m,g or f}end else for c=1,#d do u[d[c]]=l end end end\
  459. function Canvas:drawPixels(d,l)if type(d)~=\"table\"then return\
  460. error(\"expected table coords, got \"..class.type(d))end if\
  461. type(l)~=\"table\"then return\
  462. error(\"expected table pixels, got \"..class.type(l))end\
  463. local u=#l local c=self.pixels local m=u<#d\
  464. for f=1,#d do\
  465. local w=m and l[(f-1)%u+1]or l[f]local y,p,v=w[1],w[2],w[3]local b if y==0 then b=c[d[f]]y=b[1]end if\
  466. p==0 or v==\"\"then b=b or c[d[f]]p=b[2]v=b[3]end\
  467. c[d[f]]={y,p,v}end end\
  468. function Canvas:clear(d)\
  469. if d and type(d)~=\"number\"then return\
  470. error(\"expected number colour, got \"..class.type(d))end local l={d or self.colour,d and 1 or 0,\" \"}for u=1,self.width*\
  471. self.height do self.pixels[u]=l end end\
  472. function Canvas:clone(d)if d and not class.isClass(d)then\
  473. return error(\"expected Class class, got \"..\
  474. class.type(d))end\
  475. local l=(d or self.class)(self.width,self.height)l.pixels=self.pixels return l end\
  476. function Canvas:copy(d)if d and not class.isClass(d)then\
  477. return error(\"expected Class class, got \"..\
  478. class.type(d))end\
  479. local l=(d or self.class)(self.width,self.height)local u,c=l.pixels,self.pixels for m=1,#c do u[m]=c[m]end return l end\
  480. function Canvas:drawTo(d,l,u)l,u=l or 0,u or 0 if not class.typeOf(d,Canvas)then\
  481. return error(\
  482. \"expected Canvas canvas, got \"..class.type(d))end if type(l)~=\"number\"then\
  483. return error(\
  484. \"expected number offsetX, got \"..class.type(l))end if type(u)~=\"number\"then\
  485. return error(\
  486. \"expected number offsetY, got \"..class.type(u))end local c,m=self.width,self.height\
  487. local f,w=d.width,d.height local y={}local p={}local v=1 local g=self.pixels local k,q=o(0,f,l,c)k=k-l+1 q=k+q-1 for b=0,m-1 do\
  488. local j=b+u\
  489. if j>=0 and j<w then local x=b*c local z=j*f+l for _=k,q do\
  490. if g[x+_]then p[v]=g[x+_]y[v]=z+_ v=v+1 end end end end\
  491. d:drawPixels(y,p)end\
  492. function Canvas:getArea(l,u,m,f,w)a.setDimensions(self.width,self.height)\
  493. if l==5 then return\
  494. a.fill()elseif l==0 then if type(u)~=\"number\"then return\
  495. error(\"expected number x, got \"..class.type(u))end if type(m)~=\
  496. \"number\"then return\
  497. error(\"expected number y, got \"..class.type(m))end if type(f)~=\
  498. \"number\"then return\
  499. error(\"expected number width, got \"..class.type(f))end if\
  500. type(w)~=\"number\"then return\
  501. error(\"expected number height, got \"..class.type(w))end return\
  502. a.box(u,m,f,w)elseif l==6 then if type(u)~=\"number\"then return\
  503. error(\"expected number x, got \"..class.type(u))end if type(m)~=\
  504. \"number\"then return\
  505. error(\"expected number y, got \"..class.type(m))end return\
  506. a.point(u,m)elseif l==4 then if type(u)~=\"number\"then return\
  507. error(\"expected number x, got \"..class.type(u))end if type(m)~=\
  508. \"number\"then return\
  509. error(\"expected number y, got \"..class.type(m))end if type(f)~=\
  510. \"number\"then return\
  511. error(\"expected number width, got \"..class.type(f))end return\
  512. a.hLine(u,m,f)elseif l==3 then if type(u)~=\"number\"then return\
  513. error(\"expected number x, got \"..class.type(u))end if type(m)~=\
  514. \"number\"then return\
  515. error(\"expected number y, got \"..class.type(m))end if type(f)~=\
  516. \"number\"then return\
  517. error(\"expected number height, got \"..class.type(f))end return\
  518. a.vLine(u,m,f)elseif l==2 then if type(u)~=\"number\"then return\
  519. error(\"expected number x1, got \"..class.type(u))end if type(m)~=\
  520. \"number\"then return\
  521. error(\"expected number y1, got \"..class.type(m))end if\
  522. type(f)~=\"number\"then return\
  523. error(\"expected number x2, got \"..class.type(f))end if type(w)~=\
  524. \"number\"then return\
  525. error(\"expected number y2, got \"..class.type(w))end return\
  526. a.line(u,m,f,w)elseif l==1 then if type(u)~=\"number\"then return\
  527. error(\"expected number x, got \"..class.type(u))end if type(m)~=\
  528. \"number\"then return\
  529. error(\"expected number y, got \"..class.type(m))end if type(f)~=\
  530. \"number\"then return\
  531. error(\"expected number radius, got \"..class.type(f))end return\
  532. a.circle(u,m,f)elseif l==7 then if type(u)~=\"number\"then return\
  533. error(\"expected number x, got \"..class.type(u))end if type(m)~=\
  534. \"number\"then return\
  535. error(\"expected number y, got \"..class.type(m))end if type(f)~=\
  536. \"number\"then return\
  537. error(\"expected number radius, got \"..class.type(f))end return\
  538. a.correctedCircle(u,m,f)else\
  539. return error(\"unexpected mode: \"..tostring(l))end end","graphics.Canvas",nil,_ENV)if not __f then error(__err,0)end __f()
  540. local __f,__err=load("class\"DrawingCanvas\"extends\"Canvas\"{}\
  541. function DrawingCanvas:drawPoint(e,t,a)if\
  542. type(e)~=\"number\"then return\
  543. error(\"expected number x, got \"..class.type(e))end if type(t)~=\
  544. \"number\"then return\
  545. error(\"expected number y, got \"..class.type(t))end if type(a)~=\
  546. \"table\"then return\
  547. error(\"expected table options, got \"..class.type(a))end local o=\
  548. a.colour or 0 local i=a.textColour or 1 local n=a.character or\" \"if\
  549. type(o)~=\"number\"then return\
  550. error(\"expected number colour, got \"..class.type(o))end\
  551. if\
  552. type(i)~=\"number\"then return\
  553. error(\"expected number textColour, got \"..class.type(i))end\
  554. if type(n)~=\"string\"then return\
  555. error(\"expected string character, got \"..class.type(n))end if\
  556. e>=0 and t>=0 and e<self.width and t<self.height then\
  557. self:drawPixel({t*self.width+e+1},{o,i,n})end end\
  558. function DrawingCanvas:drawBox(e,t,a,o,i)if type(e)~=\"number\"then return\
  559. error(\"expected number x, got \"..class.type(e))end if type(t)~=\
  560. \"number\"then return\
  561. error(\"expected number y, got \"..class.type(t))end if type(a)~=\
  562. \"number\"then return\
  563. error(\"expected number width, got \"..class.type(a))end if\
  564. type(o)~=\"number\"then return\
  565. error(\"expected number height, got \"..class.type(o))end if\
  566. type(i)~=\"table\"then return\
  567. error(\"expected table options, got \"..class.type(i))end local n=\
  568. i.colour or 0 local s=i.textColour or 1 local h=i.character or\" \"if\
  569. type(n)~=\"number\"then return\
  570. error(\"expected number colour, got \"..class.type(n))end\
  571. if\
  572. type(s)~=\"number\"then return\
  573. error(\"expected number textColour, got \"..class.type(s))end\
  574. if type(h)~=\"string\"then return\
  575. error(\"expected string character, got \"..class.type(h))end if h==\" \"then\
  576. self:drawColour(self:getArea(0,e,t,a,o),n)else\
  577. self:drawPixel(self:getArea(0,e,t,a,o),{n,s,h})end end\
  578. function DrawingCanvas:drawCircle(e,t,a,o)if type(e)~=\"number\"then return\
  579. error(\"expected number x, got \"..class.type(e))end if type(t)~=\
  580. \"number\"then return\
  581. error(\"expected number y, got \"..class.type(t))end if type(a)~=\
  582. \"number\"then return\
  583. error(\"expected number radius, got \"..class.type(a))end if\
  584. type(o)~=\"table\"then return\
  585. error(\"expected table options, got \"..class.type(o))end local i=\
  586. o.colour or 0 local n=o.textColour or 1 local s=o.character or\" \"local h=\
  587. o.corrected or false if type(i)~=\"number\"then\
  588. return error(\"expected number colour, got \"..\
  589. class.type(i))end if type(n)~=\"number\"then\
  590. return error(\
  591. \"expected number textColour, got \"..class.type(n))end if type(s)~=\"string\"then\
  592. return error(\
  593. \"expected string character, got \"..class.type(s))end if s==\" \"then\
  594. self:drawColour(self:getArea(h and 7 or 1,e,t,a),i)else\
  595. self:drawPixel(self:getArea(h and 7 or 1,e,t,a),{i,n,s})end end\
  596. function DrawingCanvas:drawLine(e,t,a,o,i)if type(e)~=\"number\"then return\
  597. error(\"expected number x1, got \"..class.type(e))end if type(t)~=\
  598. \"number\"then return\
  599. error(\"expected number y1, got \"..class.type(t))end if\
  600. type(a)~=\"number\"then return\
  601. error(\"expected number x2, got \"..class.type(a))end if type(o)~=\
  602. \"number\"then return\
  603. error(\"expected number y2, got \"..class.type(o))end if\
  604. type(i)~=\"table\"then return\
  605. error(\"expected table options, got \"..class.type(i))end local n=\
  606. i.colour or 0 local s=i.textColour or 1 local h=i.character or\" \"if\
  607. type(n)~=\"number\"then return\
  608. error(\"expected number colour, got \"..class.type(n))end\
  609. if\
  610. type(s)~=\"number\"then return\
  611. error(\"expected number textColour, got \"..class.type(s))end\
  612. if type(h)~=\"string\"then return\
  613. error(\"expected string character, got \"..class.type(h))end if h==\" \"then\
  614. self:drawColour(self:getArea(2,e,t,a,o),n)else\
  615. self:drawPixel(self:getArea(2,e,t,a,o),{n,s,h})end end\
  616. function DrawingCanvas:drawHorizontalLine(e,t,a,o)if type(e)~=\"number\"then return\
  617. error(\"expected number x, got \"..class.type(e))end if type(t)~=\
  618. \"number\"then return\
  619. error(\"expected number y, got \"..class.type(t))end if type(a)~=\
  620. \"number\"then return\
  621. error(\"expected number width, got \"..class.type(a))end if\
  622. type(o)~=\"table\"then return\
  623. error(\"expected table options, got \"..class.type(o))end local i=\
  624. o.colour or 0 local n=o.textColour or 1 local s=o.character or\" \"if\
  625. type(i)~=\"number\"then return\
  626. error(\"expected number colour, got \"..class.type(i))end\
  627. if\
  628. type(n)~=\"number\"then return\
  629. error(\"expected number textColour, got \"..class.type(n))end\
  630. if type(s)~=\"string\"then return\
  631. error(\"expected string character, got \"..class.type(s))end if s==\" \"then\
  632. self:drawColour(self:getArea(4,e,t,a),i)else\
  633. self:drawPixel(self:getArea(4,e,t,a),{i,n,s})end end\
  634. function DrawingCanvas:drawVerticalLine(e,t,a,o)if type(e)~=\"number\"then return\
  635. error(\"expected number x, got \"..class.type(e))end if type(t)~=\
  636. \"number\"then return\
  637. error(\"expected number y, got \"..class.type(t))end if type(a)~=\
  638. \"number\"then return\
  639. error(\"expected number height, got \"..class.type(a))end if\
  640. type(o)~=\"table\"then return\
  641. error(\"expected table options, got \"..class.type(o))end local i=\
  642. o.colour or 0 local n=o.textColour or 1 local s=o.character or\" \"if\
  643. type(i)~=\"number\"then return\
  644. error(\"expected number colour, got \"..class.type(i))end\
  645. if\
  646. type(n)~=\"number\"then return\
  647. error(\"expected number textColour, got \"..class.type(n))end\
  648. if type(s)~=\"string\"then return\
  649. error(\"expected string character, got \"..class.type(s))end if s==\" \"then\
  650. self:drawColour(self:getArea(3,e,t,a),i)else\
  651. self:drawPixel(self:getArea(3,e,t,a),{i,n,s})end end\
  652. function DrawingCanvas:drawText(e,t,a,o)if type(e)~=\"number\"then return\
  653. error(\"expected number x, got \"..class.type(e))end if type(t)~=\
  654. \"number\"then return\
  655. error(\"expected number y, got \"..class.type(t))end if type(a)~=\
  656. \"string\"then return\
  657. error(\"expected string text, got \"..class.type(a))end if\
  658. type(o)~=\"table\"then return\
  659. error(\"expected table options, got \"..class.type(o))end local i=\
  660. o.colour or 0 local n=o.textColour or 1 if type(i)~=\"number\"then\
  661. return error(\
  662. \"expected number colour, got \"..class.type(i))end if type(n)~=\"number\"then\
  663. return error(\
  664. \"expected number textColour, got \"..class.type(n))end if t<0 or t>=self.height then\
  665. return end local s=self.width\
  666. local h=t*s+ (e>0 and e or 0)local r=e>=0 and 0 or-e local d,l={},{}\
  667. local u,c=s- (e>0 and e or 0),#a-r\
  668. for m=1,u<c and u or c do d[m]={i,n,a:sub(m+r,m+r)}l[m]=h+m end self:drawPixels(l,d)end","graphics.DrawingCanvas",nil,_ENV)if not __f then error(__err,0)end __f()
  669. local __f,__err=load("local e=term.redirect local t={}\
  670. for a=0,15 do t[2^a]=(\"%x\"):format(a)end class\"ScreenCanvas\"extends\"Canvas\"{last={}}\
  671. function ScreenCanvas:ScreenCanvas(a,o)a=\
  672. a or 0 o=o or 0\
  673. if type(a)~=\"number\"then return\
  674. error(\"element attribute #1 'width' not a number (\"..class.type(a)..\
  675. \")\",2)end\
  676. if type(o)~=\"number\"then return\
  677. error(\"element attribute #2 'height' not a number (\"..class.type(o)..\")\",2)end local i={}self.last={}for n=1,a*o do self.last[n]=i end return\
  678. self:Canvas(a,o)end function ScreenCanvas:reset()local a={}\
  679. for o=1,self.width*self.height do self.last[o]=a end end\
  680. function ScreenCanvas:drawToTerminals(a,o,i)\
  681. o=o or 0 i=i or 0 if type(a)~=\"table\"then return\
  682. error(\"expected table terminals, got \"..class.type(a))end if\
  683. type(o)~=\"number\"then return\
  684. error(\"expected number x, got \"..class.type(o))end if type(i)~=\
  685. \"number\"then return\
  686. error(\"expected number y, got \"..class.type(i))end local n=1\
  687. local s,h=self.pixels,self.last local r=self.width\
  688. for d=1,self.height do local l=false for u=1,r do local c=s[n]local m=h[n]if\
  689. c[1]~=m[1]or c[2]~=m[2]or c[3]~=m[3]then l=true h[n]=c end\
  690. n=n+1 end\
  691. if l then local u,c,m={},{},{}n=n-r for f=1,r do\
  692. local w=s[n]u[f]=t[w[1]]or\"0\"c[f]=t[w[2]]or\"0\"\
  693. m[f]=w[3]==\"\"and\" \"or w[3]n=n+1 end for n=1,#a do\
  694. a[n].setCursorPos(o+1,i+d)\
  695. a[n].blit(table.concat(m),table.concat(c),table.concat(u))end end end end\
  696. function ScreenCanvas:drawToTerminal(a,o,i)return self:drawToTerminals({a},o,i)end\
  697. function ScreenCanvas:drawToScreen(a,o)return self:drawToTerminal(term,a,o)end","graphics.ScreenCanvas",nil,_ENV)if not __f then error(__err,0)end __f()
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705. local __f,__err=load("local e\
  706. local function t(a)\
  707. for o=1,#a do if\
  708. a[o].catch==e.name or a[o].default or a[o].catch==e.class then return a[o].handler(e)end end return Exception.throw(e)end\
  709. class\"Exception\"{name=\"undefined\",data=\"undefined\",trace={}}\
  710. function Exception:Exception(a,o,i)self.name=a self.data=o self.trace={}i=(i or 1)+2 if\
  711. i>2 then\
  712. for n=1,5 do\
  713. local s=select(2,pcall(error,\"\",i+n)):gsub(\": $\",\"\")if s==\"pcall\"or s==\"\"then break else self.trace[n]=s end end end end\
  714. function Exception:getTraceback(a,o)a=a or\"\"o=o or\"\\n\"\
  715. parameters.check(2,\"initial\",\"string\",a,\"delimiter\",\"string\",o)if#self.trace==0 then return\"\"end return\
  716. a..table.concat(self.trace,o)end\
  717. function Exception:getData()\
  718. if\
  719. type(self.data)==\"string\"or class.isClass(self.data)or class.isInstance(self.data)then return\
  720. tostring(self.data)else return textutils.serialize(seld.data)end end\
  721. function Exception:getDataAndTraceback(a)\
  722. parameters.check(1,\"indent\",\"number\",a or 1)\
  723. return self:getData()..\
  724. self:getTraceback(\"\\n\".. (\" \"):rep(a or 1)..\"in \",\
  725. \"\\n\".. (\" \"):rep(a or 1)..\"in \")end\
  726. function Exception:tostring()return tostring(self.name)..\
  727. \" exception:\\n  \"..self:getDataAndTraceback(4)end function Exception.thrown()return e end\
  728. function Exception.throw(a,o,i)\
  729. if class.isClass(a)then a=a(o,\
  730. (i or 1)+1)elseif type(a)==\"string\"then\
  731. a=Exception(a,o,(i or 1)+1)elseif not class.typeOf(a,Exception)then return\
  732. Exception.throw(\"IncorrectParameterException\",\
  733. \"expected class, string, or Exception e, got \"..class.type(a))end e=a\
  734. error(\"SHEETS_EXCEPTION\\nPut code in a try block to catch the exception.\",0)end\
  735. function Exception.try(a)local o,i=pcall(a)\
  736. if not o and\
  737. i==\"SHEETS_EXCEPTION\\nPut code in a try block to catch the exception.\"then return t end return error(i,0)end function Exception.catch(a)\
  738. return function(t)return{catch=a,handler=t}end end function Exception.default(t)\
  739. return{default=true,handler=t}end","exceptions.Exception",nil,_ENV)if not __f then error(__err,0)end __f()
  740. local __f,__err=load("class\"IncorrectParameterException\"extends\"Exception\"\
  741. function IncorrectParameterException:IncorrectParameterException(e,t)return\
  742. self:Exception(\"IncorrectParameterException\",e,t)end","exceptions.IncorrectParameterException",nil,_ENV)if not __f then error(__err,0)end __f()
  743. local __f,__err=load("class\"IncorrectConstructorException\"extends\"Exception\"\
  744. function IncorrectConstructorException:IncorrectConstructorException(e,t)return\
  745. self:Exception(\"IncorrectConstructorException\",e,t)end","exceptions.IncorrectConstructorException",nil,_ENV)if not __f then error(__err,0)end __f()
  746. local __f,__err=load("class\"ResourceLoadException\"extends\"Exception\"\
  747. function ResourceLoadException:ResourceLoadException(e,t)return\
  748. self:Exception(\"ResourceLoadException\",e,t)end","exceptions.ResourceLoadException",nil,_ENV)if not __f then error(__err,0)end __f()
  749. local __f,__err=load("class\"ThreadRuntimeException\"extends\"Exception\"\
  750. function ThreadRuntimeException:ThreadRuntimeException(e,t)return\
  751. self:Exception(\"ThreadRuntimeException\",e,t)end","exceptions.ThreadRuntimeException",nil,_ENV)if not __f then error(__err,0)end __f()
  752.  
  753. local __f,__err=load("interface\"IAnimation\"{}\
  754. function IAnimation:IAnimation()self.animations={}end\
  755. function IAnimation:addAnimation(e,t,a)\
  756. parameters.check(3,\"label\",\"string\",e,\"setter\",\"function\",t,\"animation\",Animation,a)self.animations[e]={setter=t,animation=a}if a.value then\
  757. t(self,a.value)end return a end\
  758. function IAnimation:stopAnimation(e)\
  759. parameters.check(1,\"label\",\"string\",e)local t=self.animations[e]self.animations[e]=nil return t end\
  760. function IAnimation:updateAnimations(e)parameters.check(1,\"dt\",\"number\",e)\
  761. local t={}local a=self.animations local o,i=next(a)while a[o]do local n=i.animation n:update(e)if n.value then\
  762. i.setter(self,n.value)end if n:finished()then t[#t+1]=o end\
  763. o,i=next(a,o)end for n=1,#t do self.animations[t[n]]=\
  764. nil end end","interfaces.IAnimation",nil,_ENV)if not __f then error(__err,0)end __f()
  765. local __f,__err=load("\
  766. local function e(a,o,i,n,s,h,r)r=r or\"transition\"\
  767. parameters.check(3,\"to\",\"number\",s,\"time\",\"number\",h or 0,\"easing\",\
  768. type(r)==\"string\"and\"string\"or\"function\",r)\
  769. local d=Animation():setRounded():addKeyFrame(n,s,h or.3,r)a:addAnimation(o,i,d)return d end\
  770. local function t(a,o,i,n,s,h)if not a.parent then return end\
  771. local r=Animation():setRounded():addKeyFrame(n,s,h,\
  772. o==\"in\"and\"entrance\"or\"exit\")if i then a:addAnimation(\"y\",a.setY,r)else\
  773. a:addAnimation(\"x\",a.setX,r)end if o==\"exit\"then\
  774. function r.onFinish()a:remove()end end return r end interface\"IAttributeAnimator\"{}\
  775. function IAttributeAnimator:animateValue(a,o,i,n,s,h)s=\
  776. s or\"transition\"\
  777. parameters.check(5,\"value\",\"string\",a,\"from\",\"number\",o,\"to\",\"number\",i,\"time\",\"number\",n or 0,\"easing\",\
  778. type(s)==\"string\"and\"string\"or\"function\",s)\
  779. local r=(h and Animation():setRounded()or Animation()):addKeyFrame(o,i,n,s)\
  780. local d=self[\"set\"..a:sub(1,1):upper()..a:sub(2)]return self:addAnimation(a,d,r)end function IAttributeAnimator:animateX(a,o,i)\
  781. return e(self,\"x\",self.setX,self.x,a,o,i)end function IAttributeAnimator:animateY(a,o,i)return\
  782. e(self,\"y\",self.setY,self.y,a,o,i)end function IAttributeAnimator:animateZ(a,o,i)return\
  783. e(self,\"z\",self.setZ,self.z,a,o,i)end\
  784. function IAttributeAnimator:animateWidth(a,o,i)return\
  785. e(self,\"width\",self.setWidth,self.width,a,o,i)end function IAttributeAnimator:animateHeight(a,o,i)\
  786. return e(self,\"height\",self.setHeight,self.height,a,o,i)end\
  787. function IAttributeAnimator:animateIn(a,o,i)a=\
  788. a or\"top\"i=i or.3\
  789. parameters.check(3,\"side\",\"string\",a,\"to\",\"number\",o or 0,\"time\",\"number\",i)\
  790. if a==\"top\"then return t(self,\"in\",true,self.y,o or 0,i)elseif a==\"left\"then return t(self,\"in\",false,self.x,\
  791. o or 0,i)elseif a==\"right\"then\
  792. return t(self,\"in\",false,self.x,o or\
  793. self.parent.width-self.width,i)elseif a==\"bottom\"then return\
  794. t(self,\"in\",true,self.y,o or self.parent.height-self.height,i)else\
  795. Exception.throw(IncorrectParameterException,\"invalid side '\"..a..\"'\",2)end end\
  796. function IAttributeAnimator:animateOut(a,o,i)a=a or\"top\"i=i or.3\
  797. parameters.check(3,\"side\",\"string\",a,\"to\",\"number\",o or 0,\"time\",\"number\",i)\
  798. if a==\"top\"then\
  799. return t(self,\"out\",true,self.y,o or-self.height,i)elseif a==\"left\"then\
  800. return t(self,\"out\",false,self.x,o or-self.width,i)elseif a==\"right\"then\
  801. return t(self,\"out\",false,self.x,o or self.parent.width,i)elseif a==\"bottom\"then return\
  802. t(self,\"out\",true,self.y,o or self.parent.height,i)else\
  803. Exception.throw(IncorrectParameterException,\"invalid side '\"..a..\"'\",2)end end","interfaces.IAttributeAnimator",nil,_ENV)if not __f then error(__err,0)end __f()
  804. local __f,__err=load("interface\"IChildContainer\"{children={}}\
  805. function IChildContainer:IChildContainer()\
  806. self.children={}self.meta.__add=self.addChild function self.meta:__concat(e)\
  807. self:addChild(e)return self end end\
  808. function IChildContainer:addChild(e)parameters.check(1,\"child\",Sheet,e)\
  809. local t=self.children if e.parent then e.parent:removeChild(e)end\
  810. e.parent=self self:setChanged()for a=1,#t do\
  811. if t[a].z>e.z then table.insert(t,a,e)return e end end t[#t+1]=e return e end\
  812. function IChildContainer:removeChild(e)\
  813. for t=1,#self.children do if self.children[t]==e then\
  814. e.parent=nil self:setChanged()\
  815. return table.remove(self.children,t)end end end function IChildContainer:getChildren()local e={}local t=self.children for a=1,#t do e[a]=t[a]end\
  816. return e end\
  817. function IChildContainer:getChildById(e)\
  818. parameters.check(1,\"id\",\"string\",e)\
  819. for t=#self.children,1,-1 do\
  820. local a=self.children[t]:getChildById(e)\
  821. if a then return a elseif self.children[t].id==e then return self.children[t]end end end\
  822. function IChildContainer:getChildrenById(e)\
  823. parameters.check(1,\"id\",\"string\",e)local a={}\
  824. for t=#self.children,1,-1 do\
  825. local o=self.children[t]:getChildrenById(e)for t=1,#o do a[#a+1]=o[t]end if self.children[t].id==e then\
  826. a[#a+1]=self.children[t]end end return a end\
  827. function IChildContainer:getChildrenAt(e,t)\
  828. parameters.check(2,\"x\",\"number\",e,\"y\",\"number\",t)local a=self:getChildren()local o={}for n=#a,1,-1 do\
  829. a[n]:handle(MouseEvent(EVENT_MOUSE_PING,e-a[n].x,t-\
  830. a[n].y,o,true))end return o end\
  831. function IChildContainer:isChildVisible(e)\
  832. parameters.check(1,\"child\",Sheet,e)\
  833. return\
  834. e.x+e.width>0 and e.y+e.height>0 and e.x<self.width and e.y<self.height end\
  835. function IChildContainer:repositionChildZIndex(e)local t=self.children\
  836. for a=1,#t do\
  837. if t[a]==e then while t[a-1]and\
  838. t[a-1].z>e.z do t[a-1],t[a]=e,t[a-1]a=a-1 end\
  839. while\
  840. t[a+1]and t[a+1].z<e.z do t[a+1],t[a]=e,t[a+1]a=a+1 end self:setChanged()break end end end","interfaces.IChildContainer",nil,_ENV)if not __f then error(__err,0)end __f()
  841. local __f,__err=load("interface\"ISize\"{width=0,height=0}\
  842. function ISize:setWidth(e)\
  843. parameters.check(1,\"width\",\"number\",e)\
  844. if self.width~=e then self.width=e self.canvas:setWidth(e)\
  845. self:setChanged()for t=1,#self.children do\
  846. self.children[t]:onParentResized()end end return self end\
  847. function ISize:setHeight(e)parameters.check(1,\"height\",\"number\",e)\
  848. if\
  849. self.height~=e then self.height=e self.canvas:setHeight(e)\
  850. self:setChanged()for t=1,#self.children do\
  851. self.children[t]:onParentResized()end end return self end","interfaces.ISize",nil,_ENV)if not __f then error(__err,0)end __f()
  852.  
  853. local __f,__err=load("class\"Event\"{event=\"Event\"}function Event:is(e)\
  854. return self.event==e end\
  855. function Event:handle(e)self.handled=true self.handler=e end","events.Event",nil,_ENV)if not __f then error(__err,0)end __f()
  856. local __f,__err=load("class\"KeyboardEvent\"\
  857. extends\"Event\"{event=\"KeyboardEvent\",key=0,held={}}\
  858. function KeyboardEvent:KeyboardEvent(e,t,a)self.event=e self.key=t self.held=a end\
  859. function KeyboardEvent:matches(e)local a for t in e:gmatch\"(.*)%-\"do if not self.held[t]or\
  860. (a and self.held[t]<a)then return false end\
  861. a=self.held[t]end return self.key==\
  862. keys[e:gsub(\".+%-\",\"\")]end function KeyboardEvent:isHeld(e)\
  863. return self.key==keys[e]or self.held[e]end","events.KeyboardEvent",nil,_ENV)if not __f then error(__err,0)end __f()
  864. local __f,__err=load("class\"MiscEvent\"\
  865. extends\"Event\"{event=\"MiscEvent\",parameters={}}\
  866. function MiscEvent:MiscEvent(e,...)self.event=e self.parameters={...}end","events.MiscEvent",nil,_ENV)if not __f then error(__err,0)end __f()
  867. local __f,__err=load("class\"MouseEvent\"\
  868. extends\"Event\"{event=\"MouseEvent\",x=0,y=0,button=0,within=true}function MouseEvent:MouseEvent(e,t,a,o,i)self.event=e self.x=t self.y=a self.button=o\
  869. self.within=i end\
  870. function MouseEvent:isWithinArea(e,t,a,o)\
  871. parameters.check(4,\"x\",\"number\",e,\"y\",\"number\",t,\"width\",\"number\",a,\"height\",\"number\",o)return self.x>=e and self.y>=t and self.x<e+a and\
  872. self.y<t+o end\
  873. function MouseEvent:clone(e,t,a)\
  874. parameters.check(2,\"x\",\"number\",e,\"y\",\"number\",t)\
  875. local o=MouseEvent(self.event,self.x-e,self.y-t,self.button,self.within and a or false)o.handled=self.handled\
  876. function o.handle()o.handled=true self:handle()end return o end","events.MouseEvent",nil,_ENV)if not __f then error(__err,0)end __f()
  877. local __f,__err=load("class\"TextEvent\"\
  878. extends\"Event\"{event=\"TextEvent\",text=\"\"}function TextEvent:TextEvent(e,t)self.event=e self.text=t end","events.TextEvent",nil,_ENV)if not __f then error(__err,0)end __f()
  879.  
  880. local __f,__err=load("local e,t=math.sin,math.cos local a=math.pi/2 local function o(s,h,r)return s+\
  881. h* (3*r*r-2*r*r*r)end local function i(s,h,r)return\
  882. -h*t(r*a)+h+s end\
  883. local function n(s,h,r)return s+h*e(r*a)end\
  884. class\"Animation\"{frame=1,frames={},value=nil,rounded=false}function Animation:Animation()self.frames={}end function Animation:setRounded(s)self.rounded=\
  885. s~=false return self end\
  886. function Animation:addKeyFrame(s,h,r,d)r=\
  887. r or.5 d=d or o\
  888. if not d or d==\"transition\"then d=o elseif d==\"entrance\"then d=n elseif d==\"exit\"then d=i end\
  889. parameters.check(4,\"initial\",\"number\",s,\"final\",\"number\",h,\"duration\",\"number\",r,\"easing\",\"function\",d)local l={ease=true,clock=0,duration=r,initial=s,difference=h-s,easing=d}self.frames[\
  890. #self.frames+1]=l if#self.frames==1 then\
  891. self.value=s end return self end\
  892. function Animation:addPause(s)s=s or 1\
  893. parameters.check(1,\"pause\",\"number\",s)local h={clock=0,duration=s}\
  894. self.frames[#self.frames+1]=h return self end\
  895. function Animation:frameFinished()if type(self.onFrameFinished)==\"function\"then\
  896. self:onFrameFinished(self.frame)end self.frame=self.frame+1 if\
  897. not\
  898. self.frames[self.frame]and type(self.onFinish)==\"function\"then self:onFinish()end end\
  899. function Animation:update(s)parameters.check(1,\"dt\",\"number\",s)\
  900. local h=self.frames[self.frame]\
  901. if h then h.clock=math.min(h.clock+s,h.duration)\
  902. if h.ease then local r=h.easing(h.initial,h.difference,\
  903. h.clock/h.duration)if\
  904. self.rounded then r=math.floor(r+.5)end self.value=r if\
  905. h.clock>=h.duration then self:frameFinished()end end\
  906. if h.clock>=h.duration then self:frameFinished()end end end\
  907. function Animation:finished()return not self.frames[self.frame]end","core.Animation",nil,_ENV)if not __f then error(__err,0)end __f()
  908. local __f,__err=load("local function e(a)return error(tostring(a),0)end local t\
  909. class\"Application\"{name=\"UnNamed Application\",path=\"\",terminateable=true,running=true,screens={},screen=\
  910. nil,resource_loaders={},extensions={},threads={},mouse=nil,keys={},changed=false}\
  911. function Application:Application(a,o)\
  912. self.screens={Screen(self,term.getSize()):addTerminal(term)}self.screen=self.screens[1]self.name=a self.path=o or a\
  913. self.resource_loaders={}self.extensions={}self.threads={}self.keys={}end\
  914. function Application:registerResourceLoader(a,o)\
  915. parameters.check(2,\"type\",\"string\",a,\"loader\",\"function\",o)self.resource_loaders[a]=o end\
  916. function Application:unregisterResourceLoader(a)\
  917. parameters.check(1,\"type\",\"string\",a)self.resource_loaders[a]=nil end\
  918. function Application:registerFileExtension(a,o)\
  919. parameters.check(2,\"extension\",\"string\",a,\"type\",\"string\",o)self.extensions[a]=o end\
  920. function Application:unregisterFileExtension(a)\
  921. parameters.check(1,\"extension\",\"string\",a)self.extensions[a]=nil end\
  922. function Application:loadResource(a,o,...)\
  923. parameters.check(2,\"resource\",\"string\",a,\"type\",\"string\",o or\"\")if not o then\
  924. o=self.extensions[a:match(\"%.(%w+)$\")or\"txt\"]or\"text.plain\"end\
  925. if self.resource_loaders[o]then local i=\
  926. fs.open(fs.combine(self.path,a),\"r\")or fs.open(a,\"r\")\
  927. if i then\
  928. local n=i.readAll()i.close()\
  929. return self.resource_loaders[o](self,a,n,...)else\
  930. Exception.throw(ResourceLoadException,\"Failed to open file '\"..a..\
  931. \"': not found under '/'' or '\"..self.path..\"'\",2)end else\
  932. Exception.throw(ResourceLoadException,\"No loader for resource type '\"..o..\"'\",2)end end\
  933. function Application:addThread(a)parameters.check(1,\"thread\",Thread,a)self.threads[\
  934. #self.threads+1]=a return a end\
  935. function Application:isKeyPressed(a)parameters.check(1,\"key\",\"string\",a)\
  936. self.resource_loaders={}self.extensions={}return self.keys[a]~=nil end function Application:stop()self.running=false return self end\
  937. function Application:addScreen()\
  938. local a=Screen(self,term.getSize())self.screens[#self.screens+1]=a return a end\
  939. function Application:removeScreen(a)\
  940. parameters.check(1,\"screen\",Screen,a)\
  941. for o=#self.screens,1,-1 do if self.screens[o]==a then\
  942. return table.remove(self.screens,o)end end end\
  943. function Application:event(a,...)local o={...}local i={}\
  944. local function n(s)for h=#i,1,-1 do i[h]:handle(s)end end if a==\"timer\"and timer.update(...)then return end for s=1,#\
  945. self.screens do i[s]=self.screens[s]end\
  946. return t(self,n,a,o,...)end function Application:draw()\
  947. if self.changed then for a=1,#self.screens do\
  948. self.screens[a]:draw()end self.changed=false end end\
  949. function Application:update()\
  950. local a=timer.getDelta()timer.step()for o=1,#self.screens do\
  951. self.screens[o]:update(a)end\
  952. if self.onUpdate then self:onUpdate(a)end end function Application:load()self.changed=true\
  953. if self.onLoad then return self:onLoad()end end\
  954. function Application:run()\
  955. Exception.try(function()\
  956. self:load()local a=timer.new(0)\
  957. while self.running do local o={coroutine.yield()}\
  958. if\
  959. o[1]==\"timer\"and o[2]==a then a=timer.new(.05)elseif o[1]==\"terminate\"and\
  960. self.terminateable then self:stop()else self:event(unpack(o))end self:update()self:draw()end end){Exception.default(e)}end\
  961. function t(a,o,i,n,...)\
  962. if i==\"mouse_click\"then\
  963. a.mouse={x=n[2]-1,y=n[3]-1,down=true,button=n[1],timer=os.startTimer(1),time=os.clock(),moved=false}\
  964. o(MouseEvent(0,n[2]-1,n[3]-1,n[1],true))elseif i==\"mouse_up\"then\
  965. o(MouseEvent(1,n[2]-1,n[3]-1,n[1],true))a.mouse.down=false os.cancelTimer(a.mouse.timer)\
  966. if\
  967. not\
  968. a.mouse.moved and os.clock()-a.mouse.time<1 and n[1]==a.mouse.button then o(MouseEvent(2,n[2]-1,\
  969. n[3]-1,n[1],true))end elseif i==\"mouse_drag\"then\
  970. o(MouseEvent(4,n[2]-1,n[3]-1,n[1],true))a.mouse.moved=true os.cancelTimer(a.mouse.timer)elseif i==\
  971. \"mouse_scroll\"then\
  972. o(MouseEvent(5,n[2]-1,n[3]-1,n[1],true))elseif i==\"monitor_touch\"then elseif i==\"chatbox_something\"then elseif i==\"char\"then\
  973. o(TextEvent(9,n[1]))elseif i==\"paste\"then\
  974. if a.keys.leftShift or a.keys.rightShift then\
  975. o(KeyboardEvent(7,keys.v,{leftCtrl=true,rightCtrl=true}))else o(TextEvent(11,n[1]))end elseif i==\"key\"then\
  976. a.keys[keys.getName(n[1])or n[1]]=os.clock()o(KeyboardEvent(7,n[1],a.keys))elseif i==\"key_up\"then a.keys[\
  977. keys.getName(n[1])or n[1]]=nil\
  978. o(KeyboardEvent(8,n[1],a.keys))elseif i==\"term_resize\"then a.width,a.height=term.getSize()for s=1,#a.screens do\
  979. a.screens[s]:onParentResized()end elseif\
  980. i==\"timer\"and a.mouse and n[1]==a.mouse.timer then\
  981. o(MouseEvent(3,a.mouse.x,a.mouse.y,a.mouse.button,true))else local s=MiscEvent(i,...)o(s)if not s.handled then\
  982. for h=#a.threads,1,-1 do if\
  983. a.threads[h].running then a.threads[h]:resume(i,...)else\
  984. table.remove(a.threads,h)end end end end end","core.Application",nil,_ENV)if not __f then error(__err,0)end __f()
  985. local __f,__err=load("class\"Screen\"implements\"IAnimation\"implements\"IChildContainer\"\
  986. implements\"ISize\"{terminals={},monitors={},canvas=\
  987. nil,parent=nil,changed=true}\
  988. function Screen:Screen(e,t,a)self.parent=e self.terminals={}self.monitors={}\
  989. self.canvas=ScreenCanvas(t,a)self.width=t self.height=a end\
  990. function Screen:getsTermEvents()for e=1,#self.terminals do\
  991. if self.terminals[e]==term then return true end end return false end function Screen:setChanged(e)self.changed=e~=false\
  992. if e~=false then self.parent.changed=true end return self end\
  993. function Screen:addMonitor(e)\
  994. parameters.check(1,\"side\",\"string\",e)if peripheral.getType(e)~=\"monitor\"then\
  995. throw(IncorrectParameterException,\
  996. \"expected monitor on side '\"..e..\"', got \"..peripheral.getType(e),2)end\
  997. local t=peripheral.wrap(e)self.monitors[e]=t return self:addTerminal(t)end\
  998. function Screen:removeMonitor(e)parameters.check(1,\"side\",\"string\",e)\
  999. local t=self.monitors[e]\
  1000. if t then self.monitors[e]=nil self:removeTerminal(t)end return self end\
  1001. function Screen:usesMonitor(e)return self.monitors[e]~=nil end\
  1002. function Screen:addTerminal(e)parameters.check(1,\"terminal\",\"table\",e)self.terminals[\
  1003. #self.terminals+1]=e\
  1004. self.canvas:reset()return self:setChanged()end\
  1005. function Screen:removeTerminal(e)\
  1006. parameters.check(1,\"terminal\",\"table\",e)\
  1007. for t=#self.terminals,1,-1 do if self.terminals[t]==e then self:setChanged()return\
  1008. table.remove(self.terminals,t)end end return self end\
  1009. function Screen:draw()\
  1010. if self.changed then local e=self.canvas local t={}local a,o,i e:clear()for n=1,#self.children do\
  1011. t[n]=self.children[n]end\
  1012. for n=1,#t do local s=t[n]if s:isVisible()then s:draw()\
  1013. s.canvas:drawTo(e,s.x,s.y)\
  1014. if s.cursor_active then a,o,i=s.x+s.cursor_x,s.y+s.cursor_y,s.cursor_colour end end end e:drawToTerminals(self.terminals)self.changed=false\
  1015. for n=1,#\
  1016. self.terminals do\
  1017. if a then\
  1018. self.terminals[n].setCursorPos(a+1,o+1)self.terminals[n].setTextColour(i)\
  1019. self.terminals[n].setCursorBlink(true)else\
  1020. self.terminals[n].setCursorBlink(false)end end end end\
  1021. function Screen:handle(e)local t={}local a=self.children for o=1,#a do t[o]=a[o]end\
  1022. if\
  1023. e:typeOf(MouseEvent)then local o=e:isWithinArea(0,0,self.width,self.height)for n=#t,1,-1 do\
  1024. t[n]:handle(e:clone(t[n].x,t[n].y,o))end else for o=#t,1,-1 do t[o]:handle(e)end end end\
  1025. function Screen:update(e)local t={}\
  1026. for a=1,#self.children do t[a]=self.children[a]end for a=1,#t do t[a]:update(e)end end","core.Screen",nil,_ENV)if not __f then error(__err,0)end __f()
  1027. local __f,__err=load("class\"Sheet\"implements\"IAnimation\"\
  1028. implements\"IAttributeAnimator\"implements\"IChildContainer\"\
  1029. implements\"ISize\"{x=0,y=0,z=0,id=\"ID\",style=nil,parent=nil,canvas=nil,changed=true,cursor_x=0,cursor_y=0,cursor_colour=0,cursor_active=false,handlesKeyboard=false,handlesText=false}\
  1030. function Sheet:Sheet(e,t,a,o)\
  1031. parameters.checkConstructor(self.class,4,\"x\",\"number\",e,\"y\",\"number\",t,\"width\",\"number\",a,\"height\",\"number\",o)self.x=e self.y=t self.width=a self.height=o self:IAnimation()\
  1032. self:IChildContainer()self.style=Style(self)self.canvas=DrawingCanvas(a,o)\
  1033. local i=DynamicValueVendor(self)i:addAttribute(\"x\",{},self.setX)\
  1034. i:addAttribute(\"y\",{},self.setY)i:addAttribute(\"z\",{},self.setZ)\
  1035. i:addAttribute(\"width\",{},self.setWidth)i:addAttribute(\"height\",{},self.setHeight)\
  1036. i:addAttribute(\"style\",{},self.setStyle)i:addAttribute(\"parent\",{},self.setParent)\
  1037. self.dynamic=i end\
  1038. function Sheet:setX(e)parameters.check(1,\"x\",\"number\",e)if self.x~=e then\
  1039. self.x=e\
  1040. if self.parent then self.parent:setChanged(true)end end return self end\
  1041. function Sheet:setY(e)parameters.check(1,\"y\",\"number\",e)if self.y~=e then\
  1042. self.y=e\
  1043. if self.parent then self.parent:setChanged(true)end end return self end\
  1044. function Sheet:setZ(e)parameters.check(1,\"z\",\"number\",e)if self.z~=e then\
  1045. self.z=e\
  1046. if self.parent then self.parent:repositionChildZIndex(self)end end return self end function Sheet:setID(e)self.id=tostring(e)return self end\
  1047. function Sheet:setStyle(e,t)\
  1048. parameters.check(1,\"style\",Style,e)self.style=e:clone(self)\
  1049. if t and self.children then for a=1,#self.children do\
  1050. self.children[a]:setStyle(e,true)end end self:setChanged(true)return self end\
  1051. function Sheet:setParent(e)\
  1052. if e and not class.typeOf(e,Sheet)and not\
  1053. class.typeOf(e,Screen)then\
  1054. Exception.throw(IncorrectParameterException(\
  1055. \"expected Sheet or Screen parent, got \"..class.type(e),2))end if e then e:addChild(self)else self:remove()end\
  1056. return self end function Sheet:remove()\
  1057. if self.parent then return self.parent:removeChild(self)end end\
  1058. function Sheet:isVisible()return self.parent and\
  1059. self.parent:isChildVisible(self)end function Sheet:bringToFront()\
  1060. if self.parent then return self:setParent(self.parent)end return self end\
  1061. function Sheet:setChanged(e)self.changed=\
  1062. e~=false\
  1063. if\
  1064. e~=false and self.parent and not self.parent.changed then self.parent:setChanged()end return self end\
  1065. function Sheet:setCursorBlink(e,t,a)a=a or 128\
  1066. parameters.check(3,\"x\",\"number\",e,\"y\",\"number\",t,\"colour\",\"number\",a)self.cursor_active=true self.cursor_x=e self.cursor_y=t\
  1067. self.cursor_colour=a return self end\
  1068. function Sheet:resetCursorBlink()self.cursor_active=false return self end\
  1069. function Sheet:tostring()return\"[Instance] \"..\
  1070. self.class:type()..\" \"..tostring(self.id)end function Sheet:onParentResized()end\
  1071. function Sheet:update(e)local t=self:getChildren()\
  1072. self:updateAnimations(e)if self.onUpdate then self:onUpdate(e)end for a=#t,1,-1 do\
  1073. t[a]:update(e)end end\
  1074. function Sheet:draw()\
  1075. if self.changed then local e=self:getChildren()local t,a,o\
  1076. self:resetCursorBlink()if self.onPreDraw then self:onPreDraw()end\
  1077. for n=1,#e do local i=e[n]\
  1078. i:draw()i.canvas:drawTo(self.canvas,i.x,i.y)\
  1079. if i.cursor_active then t,a,o=i.x+\
  1080. i.cursor_x,i.y+i.cursor_y,i.cursor_colour end end if t then self:setCursorBlink(t,a,o)end if self.onPostDraw then\
  1081. self:onPostDraw()end self.changed=false end end\
  1082. function Sheet:handle(e)local t=self:getChildren()\
  1083. if e:typeOf(MouseEvent)then\
  1084. local a=e:isWithinArea(0,0,self.width,self.height)for o=#t,1,-1 do\
  1085. t[o]:handle(e:clone(t[o].x,t[o].y,a))end else for a=#t,1,-1 do t[a]:handle(e)end end\
  1086. if e:typeOf(MouseEvent)then\
  1087. if\
  1088. e:is(EVENT_MOUSE_PING)and\
  1089. e:isWithinArea(0,0,self.width,self.height)and e.within then e.button[#e.button+1]=self end self:onMouseEvent(e)elseif\
  1090. e:typeOf(KeyboardEvent)and self.handlesKeyboard and self.onKeyboardEvent then\
  1091. self:onKeyboardEvent(e)elseif\
  1092. e:typeOf(TextEvent)and self.handlesText and self.onTextEvent then self:onTextEvent(e)end end\
  1093. function Sheet:onMouseEvent(e)\
  1094. if\
  1095. not e.handled and e:isWithinArea(0,0,self.width,self.height)and e.within then if\
  1096. not e:is(EVENT_MOUSE_DRAG)and not e:is(EVENT_MOUSE_SCROLL)then\
  1097. e:handle(self)end end end","core.Sheet",nil,_ENV)if not __f then error(__err,0)end __f()
  1098. local __f,__err=load("\
  1099. local function e(o)if not o:find\"%.\"then return o..\".default\"end return o end\
  1100. local function t(o)return o:gsub(\"%..-$\",\"\",1)..\".default\"end local a={}class\"Style\"{fields={},object=nil}\
  1101. function Style.addToTemplate(o,i)if not\
  1102. class.isClass(o)then\
  1103. throw(IncorrectParameterException(\"expected Class class, got \"..class.type(o),2))end if type(i)~=\"table\"then\
  1104. throw(IncorrectParameterException(\
  1105. \"expected table fields, got \"..class.type(i),2))end a[o]=a[o]or{}for n,s in\
  1106. pairs(i)do a[o][e(n)]=s end end\
  1107. function Style:Style(o)if not class.isInstance(o)then\
  1108. throw(IncorrectConstructorException(\
  1109. \"Style expects Instance object when created, got \"..class.type(o),3))end a[o.class]=\
  1110. a[o.class]or{}self.fields={}self.object=o end\
  1111. function Style:clone(o)if not class.isInstance(o)then\
  1112. throw(IncorrectInitialiserException(\"expected Instance object, got \"..\
  1113. class.type(o),2))end\
  1114. local i=Style(o or self.object)for n,s in pairs(self.fields)do i.fields[n]=s end return i end\
  1115. function Style:setField(o,i)parameters.check(1,\"field\",\"string\",o)\
  1116. self.fields[e(o)]=i self.object:setChanged()return self end\
  1117. function Style:getField(o)parameters.check(1,\"field\",\"string\",o)\
  1118. o=e(o)local i=t(o)\
  1119. if self.fields[o]~=nil then return self.fields[o]elseif\
  1120. self.fields[i]~=nil then return self.fields[i]elseif\
  1121. a[self.object.class][o]~=nil then return a[self.object.class][o]end return a[self.object.class][i]end","core.Style",nil,_ENV)if not __f then error(__err,0)end __f()
  1122. local __f,__err=load("\
  1123. class\"Thread\"{running=true,f=nil,co=nil,filter=nil}\
  1124. function Thread:Thread(e,...)if type(e)==\"string\"then e=load(e)elseif type(e)~=\"function\"then\
  1125. parameters.check(1,\"f\",\"function/string\",e)end self.f=e\
  1126. self.co=coroutine.create(e)self:resume(...)end function Thread:stop()self.running=false end\
  1127. function Thread:restart()\
  1128. self.running=true self.co=coroutine.create(self.f)end\
  1129. function Thread:resume(e,...)if not self.running or\
  1130. (self.filter~=nil and e~=self.filter)then return end\
  1131. local t,a=coroutine.resume(self.co,e,...)\
  1132. if t then\
  1133. if coroutine.status(self.co)==\"dead\"then self.running=false end self.filter=a else\
  1134. if\
  1135. a==\"SHEETS_EXCEPTION\\nPut code in a try block to catch the exception.\"then return Exception.throw(Exception.thrown())end return Exception.throw(ThreadRuntimeException,a,0)end end","core.Thread",nil,_ENV)if not __f then error(__err,0)end __f()
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145. local __f,__err=load("class\"DynamicValueException\"extends\"Exception\"\
  1146. function DynamicValueException:DynamicValueException(e,t)return\
  1147. self:Exception(\"DynamicValueException\",e,t)end","exceptions.DynamicValueException",nil,_ENV)if not __f then error(__err,0)end __f()
  1148. local __f,__err=load("\
  1149. class\"DynamicValueVendor\"{instance=nil,objects={},attributes={}}\
  1150. function DynamicValueVendor:DynamicValueVendor(e)\
  1151. if not class.isInstance(e)then\
  1152. Exception.throw(IncorrectConstructorException(\
  1153. self.class:type()..\" expects Instance instance when created, got \"..class.type(e),3))end self.instance=e self.objects={}self.attributes={}end\
  1154. function DynamicValueVendor:addAttribute(e,t,a,o)\
  1155. parameters.check(4,\"attribute\",\"string\",e,\"dependencies\",t and\"table\"or\"nil\",t,\"setter\",\
  1156. a and\"function\"or\"nil\",a,\"getter\",o and\"function\"or\"nil\",o)\
  1157. if self.attributes[e]then self.attributes[e].setter=a\
  1158. self.attributes[e].getter=o else\
  1159. self.attributes[e]={setter=a,getter=o,dependencies={},linked={}}end return self:setAttributeDependencies(e,t)end\
  1160. function DynamicValueVendor:setAttributeDependencies(e,t)\
  1161. parameters.check(2,\"attribute\",\"string\",e,\"dependencies\",t and\"table\"or\"nil\",t)local o=self.attributes local i=o[e]if not i then\
  1162. Exception.throw(DynamicValueException(\"no such attribute '\"..e..\"'\",2))end for a=1,#i.dependencies do o[i.dependencies[a]].linked[e]=\
  1163. nil end i.dependencies={}\
  1164. for a=1,#t do\
  1165. if not\
  1166. o[t[a]]then\
  1167. Exception.throw(DynamicValueException(\"no such dependency attribute '\"..e..\"'\",2))elseif i.linked[t[a]]then\
  1168. Exception.throw(DynamicValueException(\"cyclic reference '\"..\
  1169. t[a]..\"' <--> '\"..e..\"'\",2))elseif t[a]==e then\
  1170. Exception.throw(DynamicValueException(\"self reference of '\"..e..\"'\",2))end i.dependencies[a]=t[a]o[t[a]].linked[e]=true end self:updateAttribute(e)end\
  1171. function DynamicValueVendor:setAttributeSetter(e,t)\
  1172. parameters.check(2,\"attribute\",\"string\",e,\"setter\",t and\"function\"or\"nil\",t)if not self.attributes[e]then\
  1173. Exception.throw(DynamicValueException(\"no such attribute '\"..e..\"'\",2))end\
  1174. self.attributes[e].setter=t self:updateAttribute(e)end\
  1175. function DynamicValueVendor:setAttributeGetter(e,t)\
  1176. parameters.check(2,\"attribute\",\"string\",e,\"getter\",t and\"function\"or\"nil\",t)if not self.attributes[e]then\
  1177. Exception.throw(DynamicValueException(\"no such attribute '\"..e..\"'\",2))end\
  1178. self.attributes[e].getter=t self:updateAttribute(e)end\
  1179. function DynamicValueVendor:removeAttribute(e)\
  1180. parameters.check(1,\"attribute\",\"string\",e)if not self.attributes[e]then return end\
  1181. local t=self.attributes[e].dependencies local a=self.attributes[e].linked for n=1,#t do self.attributes[t[n]].linked[e]=\
  1182. nil end local o,i=next(a)while o do\
  1183. self:removeAttribute(o)o,i=next(a,o)end end function DynamicValueVendor:updateAttribute(e)\
  1184. parameters.check(1,\"attribute\",\"string\",e)\
  1185. return self:setAttribute(e,self:getAttribute(e))end\
  1186. function DynamicValueVendor:setAttribute(e,t)\
  1187. parameters.check(1,\"attribute\",\"string\",e)if not self.attributes[e]then\
  1188. Exception.throw(DynamicValueException(\"no such attribute '\"..e..\"'\",2))end\
  1189. local o=self.attributes[e]\
  1190. if o.setter then o.setter(self.instance,t)else self.instance[e]=t end local i,n=next(o.linked)while i do self:updateAttribute(i)\
  1191. i,n=next(o.linked,i)end end\
  1192. function DynamicValueVendor:getAttribute(e)\
  1193. parameters.check(1,\"attribute\",\"string\",e)if not self.attributes[e]then\
  1194. Exception.throw(DynamicValueException(\"no such attribute '\"..e..\"'\",2))end\
  1195. local t=self.attributes[e]\
  1196. if t.getter then return t.getter(self.instance)else return self.instance[e]end end function DynamicValueVendor:wrapSetter(e)\
  1197. parameters.check(1,\"attribute\",\"string\",e)\
  1198. return function(t,a)return self:setAttribute(e,a)end end\
  1199. DynamicValueVendor.set=DynamicValueVendor.setAttribute DynamicValueVendor.get=DynamicValueVendor.getAttribute","dynamic.DynamicValueVendor",nil,_ENV)if not __f then error(__err,0)end __f()
  1200.  
  1201.  
  1202.  
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209.  
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215. local __f,__err=load("local e,t\
  1216. interface\"IHasText\"{text=\"\",text_lines=nil}\
  1217. function IHasText:autoHeight()\
  1218. if not self.text_lines then self:wrapText(true)end return self:setHeight(#self.text_lines)end\
  1219. function IHasText:setText(a)parameters.check(1,\"text\",\"string\",a)\
  1220. self.text=a self:wrapText()self:setChanged()return self end function IHasText:wrapText(a)\
  1221. self.text_lines=t(self.text,self.width,not a and self.height)end\
  1222. function IHasText:drawText(a)\
  1223. local o,i=0,self.text_lines a=a or\"default\"\
  1224. local n=self.style:getField(\"horizontal-alignment.\"..a)\
  1225. local s=self.style:getField(\"vertical-alignment.\"..a)if not i then self:wrapText()i=self.text_lines end if s==1 then o=math.floor(\
  1226. self.height/2-#i/2+.5)elseif s==4 then o=\
  1227. self.height-#i end\
  1228. for h=1,#i do local r=0\
  1229. if n==1 then\
  1230. r=math.floor(\
  1231. self.width/2-#i[h]/2+.5)elseif n==2 then r=self.width-#i[h]end\
  1232. self.canvas:drawText(r,o+h-1,i[h],{colour=0,textColour=self.style:getField(\"textColour.\"..a)})end end function IHasText:onPreDraw()self:drawText\"default\"end\
  1233. function e(a,o)if\
  1234. a:sub(1,o):find\"\\n\"then return a:match\"^(.-)\\n[^%S\\n]*(.*)$\"end if#a<=o then\
  1235. return a end\
  1236. for n=o+1,1,-1 do if a:sub(n,n):find\"%s\"then\
  1237. return\
  1238. a:sub(1,n-1):gsub(\"[^%S\\n]+$\",\"\"),a:sub(n+1):gsub(\"^[^%S\\n]+\",\"\")end end return a:sub(1,o),a:sub(o+1)end function t(a,o,i)local n,s={}\
  1239. while a and(not i or#n<i)do s,a=e(a,o)n[#n+1]=s end return n end","interfaces.IHasText",nil,_ENV)if not __f then error(__err,0)end __f()
  1240. local __f,__err=load("class\"Button\"extends\"Sheet\"\
  1241. implements\"IHasText\"{down=false}\
  1242. function Button:Button(e,t,a,o,i)self.text=i return self:Sheet(e,t,a,o)end\
  1243. function Button:onPreDraw()\
  1244. self.canvas:clear(\
  1245. self.down and self.style:getField\"colour.pressed\"or self.style:getField\"colour\")\
  1246. self:drawText(self.down and\"pressed\"or\"default\")end\
  1247. function Button:onMouseEvent(e)if e:is(1)and self.down then self.down=false\
  1248. self:setChanged()end if\
  1249. e.handled or not\
  1250. e:isWithinArea(0,0,self.width,self.height)or not e.within then return end\
  1251. if\
  1252. e:is(0)and not self.down then self.down=true self:setChanged()e:handle()elseif e:is(2)then if self.onClick then\
  1253. self:onClick(e.button,e.x,e.y)end e:handle()elseif e:is(3)then if self.onHold then\
  1254. self:onHold(e.button,e.x,e.y)end e:handle()end end\
  1255. Style.addToTemplate(Button,{[\"colour\"]=512,[\"colour.pressed\"]=8,[\"textColour\"]=1,[\"textColour.pressed\"]=1,[\"horizontal-alignment\"]=1,[\"horizontal-alignment.pressed\"]=1,[\"vertical-alignment\"]=1,[\"vertical-alignment.pressed\"]=1})","elements.Button",nil,_ENV)if not __f then error(__err,0)end __f()
  1256.  
  1257.  
  1258. local __f,__err=load("class\"Checkbox\"\
  1259. extends\"Sheet\"{down=false,checked=false}\
  1260. function Checkbox:Checkbox(e,t,a)self.checked=a self:Sheet(e,t,1,1)end function Checkbox:setWidth()end function Checkbox:setHeight()end\
  1261. function Checkbox:toggle()self.checked=\
  1262. not self.checked\
  1263. if self.onToggle then self:onToggle()end\
  1264. if self.checked and self.onCheck then self:onCheck()elseif not self.checked and\
  1265. self.onUnCheck then self:onUnCheck()end self:setChanged()end\
  1266. function Checkbox:onPreDraw()\
  1267. self.canvas:drawPoint(0,0,{colour=self.style:getField(\"colour.\"..\
  1268. (\
  1269. (self.down and\"pressed\")or(self.checked and\"checked\")or\"default\")),textColour=self.style:getField(\
  1270. \"checkColour.\".. (self.down and\"pressed\"or\"default\")),character=\
  1271. self.checked and\"x\"or\" \"})end\
  1272. function Checkbox:onMouseEvent(e)if e:is(1)and self.down then self.down=false\
  1273. self:setChanged()end if\
  1274. e.handled or not\
  1275. e:isWithinArea(0,0,self.width,self.height)or not e.within then return end\
  1276. if\
  1277. e:is(0)and not self.down then self.down=true self:setChanged()e:handle()elseif e:is(2)then\
  1278. self:toggle()e:handle()elseif e:is(3)then e:handle()end end\
  1279. Style.addToTemplate(Checkbox,{[\"colour\"]=256,[\"colour.checked\"]=256,[\"colour.pressed\"]=128,[\"checkColour\"]=32768,[\"checkColour.pressed\"]=256})","elements.Checkbox",nil,_ENV)if not __f then error(__err,0)end __f()
  1280.  
  1281.  
  1282. local __f,__err=load("class\"Container\"extends\"Sheet\"{}\
  1283. function Container:draw()\
  1284. if self.changed then\
  1285. local e=self.children local t,a,o self:resetCursorBlink()\
  1286. self.canvas:clear(self.style:getField\"colour\")if self.onPreDraw then self:onPreDraw()end\
  1287. for n=1,#e do local i=e[n]if\
  1288. i:isVisible()then i:draw()i.canvas:drawTo(self.canvas,i.x,i.y)\
  1289. if\
  1290. i.cursor_active then t,a,o=i.x+i.cursor_x,i.y+i.cursor_y,i.cursor_colour end end end if t then self:setCursorBlink(t,a,o)end if self.onPostDraw then\
  1291. self:onPostDraw()end self.changed=false end end Style.addToTemplate(Container,{[\"colour\"]=1})","elements.Container",nil,_ENV)if not __f then error(__err,0)end __f()
  1292.  
  1293.  
  1294. local __f,__err=load("class\"Draggable\"extends\"Sheet\"\
  1295. implements\"IHasText\"{down=false}\
  1296. function Draggable:Draggable(e,t,a,o,i)self.text=i return self:Sheet(e,t,a,o)end\
  1297. function Draggable:onPreDraw()\
  1298. self.canvas:clear(\
  1299. self.down and self.style:getField\"colour.pressed\"or self.style:getField\"colour\")\
  1300. self:drawText(self.down and\"pressed\"or\"default\")end\
  1301. function Draggable:onMouseEvent(e)\
  1302. if e:is(1)and self.down then if self.onDrop then\
  1303. self:onDrop(self.down.x,self.down.y)end self.down=false self:setChanged()elseif\
  1304. \
  1305. self.down and e:is(4)and not e.handled and e.within then self:setX(self.x+e.x-self.down.x)self:setY(\
  1306. self.y+e.y-self.down.y)if self.onDrag then\
  1307. self:onDrag()end e:handle()return end\
  1308. if\
  1309. e.handled or not e:isWithinArea(0,0,self.width,self.height)or not e.within then return end\
  1310. if e:is(0)and not self.down then\
  1311. if self.onPickUp then self:onPickUp()end self.down={x=e.x,y=e.y}self:setChanged()\
  1312. self:bringToFront()e:handle()elseif e:is(2)then if self.onClick then\
  1313. self:onClick(e.button,e.x,e.y)end e:handle()elseif e:is(3)then if self.onHold then\
  1314. self:onHold(e.button,e.x,e.y)end e:handle()end end\
  1315. Style.addToTemplate(Draggable,{[\"colour\"]=512,[\"colour.pressed\"]=8,[\"textColour\"]=1,[\"textColour.pressed\"]=1,[\"horizontal-alignment\"]=1,[\"horizontal-alignment.pressed\"]=1,[\"vertical-alignment\"]=1,[\"vertical-alignment.pressed\"]=1})","elements.Draggable",nil,_ENV)if not __f then error(__err,0)end __f()
  1316.  
  1317.  
  1318. local __f,__err=load("class\"Image\"\
  1319. extends\"Sheet\"{down=false,image=nil,fill=nil}\
  1320. function Image:Image(e,t,a)\
  1321. if type(a)==\"string\"then if fs.exists(a)then local n=fs.open(a,\"r\")if n then\
  1322. a=n.readAll()n.close()end end\
  1323. a=image.decodePaintutils(a)elseif type(a)~=\"table\"then\
  1324. parameters.checkConstructor(self.class,1,\"image\",\"string\",a)end local o,i=# (a[1]or\"\"),#a self.image=a\
  1325. return self:Sheet(e,t,o,i)end function Image:setWidth()end function Image:setHeight()end\
  1326. function Image:onPreDraw()\
  1327. local e=self.style:getField(\
  1328. \"shader.\".. (self.down and\"pressed\"or\"default\"))\
  1329. if not self.fill then self.fill=self.canvas:getArea(5)end image.apply(self.image,self.canvas)if e then\
  1330. self.canvas:mapShader(self.fill,e)end end\
  1331. function Image:onMouseEvent(e)if e:is(1)and self.down then self.down=false\
  1332. self:setChanged()end if\
  1333. e.handled or not\
  1334. e:isWithinArea(0,0,self.width,self.height)or not e.within then return end\
  1335. if\
  1336. e:is(0)and not self.down then self.down=true self:setChanged()e:handle()elseif e:is(2)then if self.onClick then\
  1337. self:onClick(e.button,e.x,e.y)end e:handle()elseif e:is(3)then if self.onHold then\
  1338. self:onHold(e.button,e.x,e.y)end e:handle()end end\
  1339. Style.addToTemplate(Image,{[\"shader\"]=false,[\"shader.pressed\"]=false})","elements.Image",nil,_ENV)if not __f then error(__err,0)end __f()
  1340.  
  1341.  
  1342. local __f,__err=load("class\"KeyHandler\"\
  1343. extends\"Sheet\"{shortcuts={},handlesKeyboard=true}\
  1344. function KeyHandler:KeyHandler()self.shortcuts={}return self:Sheet(0,0,0,0)end\
  1345. function KeyHandler:addShortcut(e,t)\
  1346. parameters.check(2,\"shortcut\",\"string\",e,\"handler\",\"function\",t)self.shortcuts[e]=t end\
  1347. function KeyHandler:removeShortcut(e)\
  1348. parameters.check(1,\"shortcut\",\"string\",e)self.shortcuts[e]=nil end\
  1349. function KeyHandler:onKeyboardEvent(e)\
  1350. if not e.handled and e:is(7)then local t=self.shortcuts\
  1351. local a,o=next(t)while a do if e:matches(a)then e:handle()o(self)return end\
  1352. a,o=next(t,a)end end end function KeyHandler:draw()end","elements.KeyHandler",nil,_ENV)if not __f then error(__err,0)end __f()
  1353.  
  1354.  
  1355. local __f,__err=load("class\"Panel\"extends\"Sheet\"{}function Panel:onPreDraw()\
  1356. self.canvas:clear(self.style:getField\"colour\")end\
  1357. Style.addToTemplate(Panel,{[\"colour\"]=256})","elements.Panel",nil,_ENV)if not __f then error(__err,0)end __f()
  1358.  
  1359.  
  1360. local __f,__err=load("class\"ScrollContainer\"\
  1361. extends\"Sheet\"{scrollX=0,scrollY=0,horizontalPadding=0,verticalPadding=0,heldScrollbar=false,down=false}\
  1362. function ScrollContainer:ScrollContainer(e,t,a,o,i)if class.typeOf(e,Sheet)then i=e\
  1363. e,t,a,o=e.x,e.y,e.width,e.height i.x,i.y=0,0 end\
  1364. parameters.checkConstructor(self.class,4,\"x\",\"number\",e,\"y\",\"number\",t,\"width\",\"number\",a,\"height\",\"number\",o,\"element\",\
  1365. i and Sheet,i)self:Sheet(e,t,a,o)if i then self:addChild(i)end end\
  1366. function ScrollContainer:setScrollX(e)\
  1367. parameters.check(1,\"scroll\",\"number\",e)self.scrollX=e return self:setChanged()end\
  1368. function ScrollContainer:setScrollY(e)\
  1369. parameters.check(1,\"scroll\",\"number\",e)self.scrollY=e return self:setChanged()end\
  1370. function ScrollContainer:getContentWidth()local e=self.horizontalPadding local t=self.children for a=1,#\
  1371. self.children do\
  1372. local o=t[a].x+t[a].width+self.horizontalPadding if o>e then e=o end end return e end\
  1373. function ScrollContainer:getContentHeight()local e=self.verticalPadding local t=self.children for a=1,#\
  1374. self.children do\
  1375. local o=t[a].y+t[a].height+self.verticalPadding if o>e then e=o end end return e end function ScrollContainer:getDisplayWidth(e,t)\
  1376. return t and self.width-1 or self.width end\
  1377. function ScrollContainer:getDisplayHeight(e,t)return e and\
  1378. self.height-1 or self.height end\
  1379. function ScrollContainer:getActiveScrollbars(e,t)if e>self.width or t>self.height then return\
  1380. e>=self.width,t>=self.height end return false,\
  1381. false end\
  1382. function ScrollContainer:getScrollbarSizes(e,t,a,o)\
  1383. return\
  1384. math.floor(self:getDisplayWidth(a,o)/e*\
  1385. self:getDisplayWidth(a,o)+.5),math.floor(\
  1386. self:getDisplayHeight(a,o)/t*self.height+.5)end\
  1387. function ScrollContainer:getScrollbarPositions(e,t,a,o)\
  1388. return math.floor(\
  1389. self.scrollX/e*self:getDisplayWidth(a,o)+.5),math.floor(self.scrollY/t*\
  1390. self.height+.5)end\
  1391. function ScrollContainer:draw()\
  1392. if self.changed then local e=self.children local t,a,o\
  1393. local i,n=self.scrollX,self.scrollY self:resetCursorBlink()\
  1394. if self.onPreDraw then self:onPreDraw()end\
  1395. for s=1,#e do local h=e[s]\
  1396. if h:isVisible()then h:draw()\
  1397. h.canvas:drawTo(self.canvas,h.x-i,h.y-n)if h.cursor_active then\
  1398. t,a,o=h.x+h.cursor_x-i,h.y+h.cursor_y-n,h.cursor_colour end end end if t then self:setCursorBlink(t,a,o)end if self.onPostDraw then\
  1399. self:onPostDraw()end self.changed=false end end\
  1400. function ScrollContainer:handle(e)local t={}local a,o=self.scrollX,self.scrollY\
  1401. local i=self.children for n=1,#i do t[n]=i[n]end\
  1402. if self.down and e:is(1)then self.down=false\
  1403. self.heldScrollbar=false self:setChanged()e:handle()elseif self.down and e:is(4)then\
  1404. local n,s=self:getContentWidth(),self:getContentHeight()local r,d=self:getActiveScrollbars(n,s)\
  1405. if self.heldScrollbar==\"h\"then\
  1406. self.scrollX=math.max(math.min(math.floor((\
  1407. e.x-self.down)/self:getDisplayWidth(r,d)*n),\
  1408. n-self:getDisplayWidth(r,d)),0)self:setChanged()e:handle()elseif self.heldScrollbar==\"v\"then\
  1409. self.scrollY=math.max(math.min(math.floor((\
  1410. e.y-self.down)/self.height*s),\
  1411. s-self:getDisplayHeight(r,d)),0)self:setChanged()e:handle()end end\
  1412. if\
  1413. e:typeOf(MouseEvent)and not e.handled and\
  1414. e:isWithinArea(0,0,self.width,self.height)and e.within then local n,s=self:getContentWidth(),self:getContentHeight()\
  1415. local r,d=self:getActiveScrollbars(n,s)\
  1416. if e:is(0)then\
  1417. if e.x==self.width-1 and d then\
  1418. local h,l=self:getScrollbarPositions(n,s,r,d)local u,c=self:getScrollbarSizes(n,s,r,d)local m=e.y\
  1419. if m<h then self.scrollY=math.floor(\
  1420. m/self.height*s)m=0 elseif m>=h+u then\
  1421. self.scrollY=math.floor((\
  1422. m-c+1)/self.height*s)m=c-1 else m=m-l end self.heldScrollbar=\"v\"self.down=m self:setChanged()\
  1423. e:handle()elseif e.y==self.height-1 and r then\
  1424. local h,l=self:getScrollbarPositions(n,s,r,d)local u,c=self:getScrollbarSizes(n,s,r,d)local m=e.x\
  1425. if m<h then\
  1426. self.scrollX=math.floor(\
  1427. m/self:getDisplayWidth(r,d)*n)m=0 elseif m>=h+u then\
  1428. self.scrollX=math.floor((m-u+1)/self:getDisplayWidth(r,d)*n)m=u-1 else m=m-h end self.heldScrollbar=\"h\"self.down=m self:setChanged()\
  1429. e:handle()end elseif e:is(5)then\
  1430. if d then\
  1431. self:setScrollY(math.max(math.min(o+e.button,s-self:getDisplayHeight(r,d)),0))elseif r then\
  1432. self:setScrollX(math.max(math.min(a+e.button,n-self:getDisplayWidth(r,d)),0))end elseif e:is(2)or e:is(3)then if e.x==self.width-1 and d or e.y==self.height-1 and r then e:handle()end end end\
  1433. if e:typeOf(MouseEvent)then\
  1434. local n=e:isWithinArea(0,0,self.width,self.height)for s=#t,1,-1 do\
  1435. t[s]:handle(e:clone(t[s].x-a,t[s].y-o,n))end else for n=#t,1,-1 do t[n]:handle(e)end end\
  1436. if e:typeOf(MouseEvent)then\
  1437. if\
  1438. e:is(EVENT_MOUSE_PING)and\
  1439. e:isWithinArea(0,0,self.width,self.height)and e.within then e.button[#e.button+1]=self end self:onMouseEvent(e)elseif\
  1440. e:typeOf(KeyboardEvent)and self.handlesKeyboard and self.onKeyboardEvent then\
  1441. self:onKeyboardEvent(e)elseif\
  1442. e:typeOf(TextEvent)and self.handlesText and self.onTextEvent then self:onTextEvent(e)end end function ScrollContainer:onPreDraw()\
  1443. self.canvas:clear(self.style:getField\"colour\")end\
  1444. function ScrollContainer:onPostDraw()\
  1445. local e,t=self:getContentWidth(),self:getContentHeight()local a,o=self:getActiveScrollbars(e,t)\
  1446. if a or o then\
  1447. local i,n=self:getScrollbarPositions(e,t,a,o)local s,h=self:getScrollbarSizes(e,t,a,o)\
  1448. if a then\
  1449. local r=self.style:getField\"horizontal-bar\"\
  1450. local d=\
  1451. self.heldScrollbar==\"h\"and self.style:getField\"horizontal-bar.active\"or self.style:getField\"horizontal-bar.bar\"\
  1452. self.canvas:mapColour(self.canvas:getArea(4,0,self.height-1,self:getDisplayWidth(a,o)),r)\
  1453. self.canvas:mapColour(self.canvas:getArea(4,i,self.height-1,s),d)end\
  1454. if o then local r=self.style:getField\"vertical-bar\"\
  1455. local d=\
  1456. self.heldScrollbar==\"v\"and self.style:getField\"vertical-bar.active\"or\
  1457. self.style:getField\"vertical-bar.bar\"\
  1458. self.canvas:mapColour(self.canvas:getArea(3,self.width-1,0,self.height),r)\
  1459. self.canvas:mapColour(self.canvas:getArea(3,self.width-1,n,h),d)end end end\
  1460. function ScrollContainer:getChildrenAt(e,t)\
  1461. parameters.check(2,\"x\",\"number\",e,\"y\",\"number\",t)local a={}local o,i=self.scrollX,self.scrollY local n=self.children\
  1462. for h=1,#n do a[h]=n[h]end local s={}for h=#a,1,-1 do\
  1463. a[h]:handle(MouseEvent(EVENT_MOUSE_PING,e-a[h].x-o,t-a[h].y-i,s,true))end return s end\
  1464. function ScrollContainer:isChildVisible(e)\
  1465. parameters.check(1,\"child\",Sheet,e)local t,a=self.scrollX,self.scrollY\
  1466. return\
  1467. e.x+e.width-t>0 and\
  1468. e.y+e.height-a>0 and e.x-t<self.width and e.y-a<self.height end\
  1469. Style.addToTemplate(ScrollContainer,{[\"colour\"]=1,[\"horizontal-bar\"]=128,[\"horizontal-bar.bar\"]=256,[\"horizontal-bar.active\"]=8,[\"vertical-bar\"]=128,[\"vertical-bar.bar\"]=256,[\"vertical-bar.active\"]=8})","elements.ScrollContainer",nil,_ENV)if not __f then error(__err,0)end __f()
  1470.  
  1471.  
  1472. local __f,__err=load("class\"Text\"extends\"Sheet\"implements\"IHasText\"{}function Text:Text(e,t,a,o,i)\
  1473. self.text=i return self:Sheet(e,t,a,o)end\
  1474. function Text:onPreDraw()\
  1475. self.canvas:clear(self.style:getField\"colour\")self:drawText\"default\"end\
  1476. Style.addToTemplate(Text,{[\"colour\"]=1,[\"textColour\"]=128,[\"horizontal-alignment\"]=0,[\"vertical-alignment\"]=3})","elements.Text",nil,_ENV)if not __f then error(__err,0)end __f()
  1477.  
  1478.  
  1479. local __f,__err=load("local function e(o)local i=\"^[^_%w%s]+\"\
  1480. if o:find\"%s\"then i=\"^%s+\"elseif o:find\"[%w_]\"then i=\"^[%w_]+\"end return i end\
  1481. local function t(o,i,n)\
  1482. local s=e(o:sub(n,n))\
  1483. if i then return# (o:match(s,n)or\"\")else local h=o:reverse()local r=\
  1484. #o-n+1 return# (h:match(s,r)or\"\")end end local function a(o,a)if a then return a:rep(#o)end return o end\
  1485. class\"TextInput\"\
  1486. extends\"Sheet\"{text=\"\",cursor=0,scroll=0,selection=false,focussed=false,handlesKeyboard=true,handlesText=true,doubleClickData=false}\
  1487. function TextInput:TextInput(o,i,n)return self:Sheet(o,i,n,1)end\
  1488. function TextInput:setText(o)self.text=tostring(o)return self:setChanged()end\
  1489. function TextInput:setScroll(o)parameters.check(1,\"scroll\",\"number\",o)\
  1490. self.scroll=o return self:setChanged()end\
  1491. function TextInput:setCursor(o)parameters.check(1,\"cursor\",\"number\",o)self.cursor=math.min(math.max(o,0),\
  1492. #self.text)if\
  1493. self.cursor==self.selection then self.selection=nil end\
  1494. if self.cursor-self.scroll<\
  1495. 1 then self.scroll=math.max(self.cursor-1,0)elseif\
  1496. self.cursor-self.scroll>self.width-1 then self.scroll=\
  1497. self.cursor-self.width+1 end return self:setChanged()end\
  1498. function TextInput:setSelection(o)\
  1499. parameters.check(1,\"position\",\"number\",o)self.selection=o return self:setChanged()end\
  1500. function TextInput:getSelectedText()\
  1501. return self.selection and\
  1502. self.text:sub(\
  1503. math.min(self.cursor,self.selection)+1,math.max(self.cursor,self.selection))end\
  1504. function TextInput:write(o)o=tostring(o)\
  1505. if self.selection then\
  1506. self.text=\
  1507. self.text:sub(1,math.min(self.cursor,self.selection))..o..\
  1508. self.text:sub(math.max(self.cursor,self.selection)+1)\
  1509. self:setCursor(math.min(self.cursor,self.selection)+#o)self.selection=false else\
  1510. self.text=self.text:sub(1,self.cursor)..o..self.text:sub(\
  1511. self.cursor+1)self:setCursor(self.cursor+#o)end return self:setChanged()end\
  1512. function TextInput:focus()\
  1513. if not self.focussed then self.focussed=true if self.onFocus then\
  1514. self:onFocus()end return self:setChanged()end return self end\
  1515. function TextInput:unfocus()\
  1516. if self.focussed then self.focussed=false if self.onUnFocus then\
  1517. self:onUnFocus()end return self:setChanged()end return self end\
  1518. function TextInput:onPreDraw()\
  1519. self.canvas:clear(self.style:getField(\"colour.\".. (\
  1520. self.focussed and\"focussed\"or\"default\")))\
  1521. local o=self.style:getField(\"mask.\"..\
  1522. (self.focussed and\"focussed\"or\"default\"))\
  1523. if self.selection then local i=math.min(self.cursor,self.selection)\
  1524. local n=math.max(self.cursor,self.selection)\
  1525. self.canvas:drawText(-self.scroll,0,a(self.text:sub(1,i),o),{textColour=self.style:getField(\
  1526. \"textColour.\".. (self.focussed and\"focussed\"or\"default\"))})\
  1527. self.canvas:drawText(i-self.scroll,0,a(self.text:sub(i+1,n),o),{colour=self.style:getField\"colour.highlighted\",textColour=self.style:getField\"textColour.highlighted\"})\
  1528. self.canvas:drawText(n-self.scroll,0,a(self.text:sub(n+1),o),{textColour=self.style:getField(\
  1529. \"textColour.\".. (self.focussed and\"focussed\"or\"default\"))})else\
  1530. self.canvas:drawText(-self.scroll,0,a(self.text,o),{textColour=self.style:getField(\"textColour.\".. (\
  1531. self.focussed and\"focussed\"or\"default\"))})end\
  1532. if not self.selection and self.focussed and\
  1533. self.cursor-self.scroll>=0 and\
  1534. self.cursor-self.scroll<self.width then\
  1535. self:setCursorBlink(self.cursor-\
  1536. self.scroll,0,self.style:getField(\"textColour.\"..\
  1537. (self.focussed and\"focussed\"or\"default\")))end end\
  1538. function TextInput:onMouseEvent(o)\
  1539. if self.down and o:is(4)then\
  1540. self.selection=self.selection or self.cursor self:setCursor(o.x+self.scroll+1)elseif self.down and\
  1541. o:is(1)then self.down=false end\
  1542. if\
  1543. o.handled or not o:isWithinArea(0,0,self.width,self.height)or not o.within then if o:is(0)then\
  1544. self:unfocus()end return end\
  1545. if o:is(0)then self:focus()self.selection=nil\
  1546. self:setCursor(o.x+self.scroll)self.down=true o:handle()elseif o:is(2)then\
  1547. if self.doubleClickData and self.doubleClickData.x==o.x+\
  1548. self.scroll then local i,n=\
  1549. o.x+self.scroll+1,o.x+self.scroll+1\
  1550. local s=e(self.text:sub(i,i))\
  1551. while self.text:sub(i-1,i-1):find(s)do i=i-1 end\
  1552. while self.text:sub(n+1,n+1):find(s)do n=n+1 end self:setCursor(n)self.selection=i-1\
  1553. timer.cancel(self.doubleClickData.timer)self.doubleClickData=false else if self.doubleClickData then\
  1554. timer.cancel(self.doubleClickData.timer)end\
  1555. local i=timer.queue(0.3,function()self.doubleClickData=false end)self.doubleClickData={x=o.x+self.scroll,timer=i}end elseif o:is(3)then o:handle()end end\
  1556. function TextInput:onKeyboardEvent(o)\
  1557. if not self.focussed or o.handled then return end\
  1558. if o:is(7)then\
  1559. if self.selection then\
  1560. if o:matches\"left\"then\
  1561. if\
  1562. o:isHeld\"leftShift\"or o:isHeld\"rightShift\"then local i=1 if o:isHeld\"rightCtrl\"or o:isHeld\"leftCtrl\"then\
  1563. i=t(self.text,false,self.cursor)end\
  1564. self:setCursor(self.cursor-i)else\
  1565. self:setCursor(math.min(self.cursor,self.selection))self.selection=nil end o:handle()elseif o:matches\"right\"then\
  1566. if\
  1567. o:isHeld\"leftShift\"or o:isHeld\"rightShift\"then local i=1 if o:isHeld\"rightCtrl\"or o:isHeld\"leftCtrl\"then\
  1568. i=t(self.text,true,self.cursor+1)end\
  1569. self:setCursor(self.cursor+i)else\
  1570. self:setCursor(math.max(self.cursor,self.selection))self.selection=nil end o:handle()elseif o:matches\"backspace\"or o:matches\"delete\"then\
  1571. self:write\"\"o:handle()end else\
  1572. if o:matches\"left\"then if o:isHeld\"leftShift\"or o:isHeld\"rightShift\"then\
  1573. self.selection=self.cursor end local i=1\
  1574. if\
  1575. o:isHeld\"rightCtrl\"or o:isHeld\"leftCtrl\"then i=t(self.text,false,self.cursor)end self:setCursor(self.cursor-i)o:handle()elseif\
  1576. o:matches\"right\"then if o:isHeld\"leftShift\"or o:isHeld\"rightShift\"then\
  1577. self.selection=self.cursor end local i=1\
  1578. if\
  1579. o:isHeld\"rightCtrl\"or o:isHeld\"leftCtrl\"then i=t(self.text,true,self.cursor+1)end self:setCursor(self.cursor+i)o:handle()elseif\
  1580. o:matches\"backspace\"and self.cursor>0 then\
  1581. self.text=\
  1582. self.text:sub(1,self.cursor-1)..self.text:sub(self.cursor+1)self:setCursor(self.cursor-1)o:handle()elseif\
  1583. o:matches\"delete\"then\
  1584. self:setText(self.text:sub(1,self.cursor)..\
  1585. self.text:sub(self.cursor+2))o:handle()end end\
  1586. if o:matches\"leftCtrl-a\"or o:matches\"rightCtrl-a\"then self.selection=self.selection or\
  1587. self.cursor if self.selection>self.cursor then\
  1588. self.selection,self.cursor=self.cursor,self.selection end\
  1589. self:addAnimation(\"selection\",self.setSelection,Animation():setRounded():addKeyFrame(self.selection,0,.15))\
  1590. self:addAnimation(\"cursor\",self.setCursor,Animation():setRounded():addKeyFrame(self.cursor,\
  1591. #self.text,.15))o:handle()elseif o:matches\"end\"then\
  1592. self:addAnimation(\"cursor\",self.setCursor,Animation():setRounded():addKeyFrame(self.cursor,\
  1593. #self.text,.15))o:handle()elseif o:matches\"home\"then\
  1594. self:addAnimation(\"cursor\",self.setCursor,Animation():setRounded():addKeyFrame(self.cursor,0,.15))o:handle()elseif o:matches\"enter\"then self:unfocus()o:handle()if self.onEnter then return\
  1595. self:onEnter()end elseif o:matches\"tab\"then self:unfocus()\
  1596. o:handle()if self.onTab then return self:onTab()end elseif o:matches\"v\"and(o:isHeld\"leftCtrl\"or\
  1597. o:isHeld\"rightCtrl\")then\
  1598. local i=clipboard.get\"plain-text\"if i then self:write(i)end elseif\
  1599. o:matches\"leftCtrl-c\"or o:matches\"rightCtrl-c\"then if self.selection then\
  1600. clipboard.put{[\"plain-text\"]=self:getSelectedText()}end elseif\
  1601. o:matches\"leftCtrl-x\"or o:matches\"rightCtrl-x\"then if self.selection then\
  1602. clipboard.put{[\"plain-text\"]=self:getSelectedText()}self:write\"\"end end o:handle()end end\
  1603. function TextInput:onTextEvent(o)if not o.handled and self.focussed then\
  1604. self:write(o.text)o:handle()end end\
  1605. Style.addToTemplate(TextInput,{[\"colour\"]=256,[\"colour.focussed\"]=256,[\"colour.highlighted\"]=2048,[\"textColour\"]=128,[\"textColour.focussed\"]=128,[\"textColour.highlighted\"]=1,[\"mask\"]=false,[\"mask.focussed\"]=false})","elements.TextInput",nil,_ENV)if not __f then error(__err,0)end __f()
  1606.  
  1607.  
  1608.  
  1609.     end
  1610.     f()
  1611.     local sheets = {}
  1612.     for k, v in pairs( env ) do
  1613.         sheets[k] = v
  1614.     end
  1615.  
  1616.  
  1617.     return sheets
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement