Advertisement
awsumben13

CC Emulator

Sep 29th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 88.84 KB | None | 0 0
  1. local files = {
  2.     ["graphics.Canvas"] = "local e=table.insert local t=table.remove local a,o=math.min,math.max local i=unpack\nclass\"Canvas\"{useSetters=true,x=0,y=0,width=0,height=0,colour=0,buffer=\nnil,cursor=nil}\nfunction Canvas:init(n,s,h,r)self.raw.x=h and n or 0\nself.raw.y=r and s or 0\nself.raw.width=h or n or select(1,term.getSize())\nself.raw.height=r or s or select(2,term.getSize())local d={}for l=1,self.raw.width*self.raw.height do\nd[l]={self.colour,1,\" \"}end self.raw.buffer=d\nself.mt.__tostring=self.tostring end function Canvas:mapPixels(n)local s=self.buffer\nfor h=1,#n do s[n[h][1]]=n[h][2]end end\nfunction Canvas:mapColour(n,s)local h=self.buffer\nlocal r={s or 0,1,\" \"}for d=1,#n do h[n[d]]=r end end\nfunction Canvas:mapStaticPixel(n,s)local h=self.buffer for r=1,#n do h[n[r]]=s end end\nfunction Canvas:drawPixels(n)local s=self.buffer\nfor h=1,#n do local r=n[h][1]if s[r]then local d,l,u=i(n[h][2])if d==0 then\nd=s[r][1]end if l==0 or u==\"\"then l=s[r][2]u=s[r][3]end\ns[r]={d,l,u}end end end\nfunction Canvas:drawColour(n,s)if s==0 then return end return self:mapColour(n,s)end\nfunction Canvas:drawStaticPixel(n,s)local h=self.buffer\nlocal r,d=s.bc==0,s.tc==0 or s.char==\"\"\nif r or d and not(r and d)then local l,u,c=i(s)for m=1,#n do local f=n[m]\nh[f]={\nr and h[f][1]or l,d and h[f][2]or u,d and h[f][3]or c}end elseif not r and not d then\nfor l=1,#n do h[n[l]]=s end end end\nfunction Canvas:clear(n)local s=self.buffer local h={n or self.colour,1,\" \"}for r=1,\nself.width*self.height do s[r]=h end end\nfunction Canvas:clone()local n=self.class(self.width,self.height)\nlocal s,h=n.buffer,self.buffer for r=1,#h do s[r]=h[r]end return n end\nfunction Canvas:cloneAs(n)local s=n(self.width,self.height)\nlocal h,r=s.buffer,self.buffer for d=1,#r do h[d]=r[d]end return s end\nfunction Canvas:drawTo(n,s,h)s=(s or 0)+self.x h=(h or 0)+self.y local r={}\nlocal d=self.buffer local l=self.width local u=n.width local c=1 local m=1\nfor f=0,self.height-1 do\nlocal w=(f+h)*u+s+1 for y=1,l do if y+s>0 and y+s<=u then r[c]={w,d[m]}c=c+1 end w=w+1\nm=m+1 end end n:drawPixels(r)end\nfunction Canvas:setWidth(n)local s,h,r=self.height,self.buffer,self.raw\nlocal d={self.colour,1,\" \"}while r.width<n do for l=1,s do e(h,(r.width+1)*l,d)end r.width=\nr.width+1 end while r.width>n do for l=s,1,-1 do\nt(h,r.width*l)end r.width=r.width-1 end end\nfunction Canvas:setHeight(n)local s,h,r=self.width,self.buffer,self.raw\nlocal d={self.colour,1,\" \"}\nwhile r.height<n do for l=1,s do h[#h+1]=d end r.height=r.height+1 end\nwhile r.height>n do for l=1,s do h[#h]=nil end r.height=r.height-1 end end function Canvas:tostring()\nreturn\"[Instance] \"..\nself.class.name..\" (\"..self.x..\n\",\"..self.y..\" \"..self.width..\n\"x\"..self.height..\")\"end";
  3.     ["graphics.TermCanvas"] = "require\"graphics.Canvas\"local e={}for a=0,15 do e[(\"%x\"):format(a):byte()]=\n2^a end local t=term.isColour()\nclass\"TermCanvas\"\nextends\"Canvas\"{colour=32768,term_bc=32768,term_tc=1,term_x=1,term_y=1,term_cb=false,isColour=t}\nfunction TermCanvas:getTermRedirect()local a={}\nfunction a.write(o)o=tostring(o)local i=\n(self.term_y-1)*self.width+self.term_x local n={}\nlocal s,h=self.term_bc,self.term_tc for r=1,math.min(#o,self.width-self.term_x+1)do\nn[#n+1]={i,{s,h,o:sub(r,r)}}i=i+1 end\nself.term_x=self.term_x+#o self:mapPixels(n)end\nfunction a.blit(o,i,n)\nif#o~=#n or#o~=#i then return error\"arguments must be the same length\"end local s={}\nlocal h=(self.term_y-1)*self.width+self.term_x for r=1,math.min(#o,self.width-self.term_x+1)do\ns[#s+1]={h,{e[n:byte(r)],e[i:byte(r)],o:sub(r,r)}}h=h+1 end self.term_x=self.term_x+\n#o self:mapPixels(s)end function a.clear()self:clear(self.term_bc)end\nfunction a.clearLine()\nlocal o={self.term_bc,1,\" \"}local i={}local n=self.width* (self.term_y-1)for s=1,self.width do i[\n#i+1]={s+n,o}end self:mapPixels(i)end function a.getCursorPos()return self.term_x,self.term_y end function a.setCursorPos(o,i)\nself.term_x=math.floor(o)self.term_y=math.floor(i)end function a.setCursorBlink(o)\nself.term_cb=o end\nfunction a.getSize()return self.width,self.height end\nfunction a.scroll(o)local i=self.buffer local n=o*self.width local o,h,r=\no<0 and self.width*self.height or 1,o<0 and 1 or self.width*self.height,\no<0 and-1 or 1 local d={}\nlocal l={self.term_bc,self.term_tc,\" \"}for s=o,h,r do d[#d+1]={s,i[s+n]or l}end\nself:mapPixels(d)end function a.isColour()return self.isColour end\nfunction a.setBackgroundColour(o)self.term_bc=o end function a.setTextColour(o)self.term_tc=o end\nfunction a.getBackgroundColour()return self.term_bc end function a.getTextColour()return self.term_tc end a.isColor=a.isColour\na.setBackgroundColor=a.setBackgroundColour a.setTextColor=a.setTextColour a.getBackgroundColor=a.getBackgroundColour\na.getTextColor=a.getTextColour return a end\nfunction TermCanvas:drawTo(a,o,i)self.super:drawTo(a,o,i)\nif self.term_cb then\na.term_cb=true a.term_x=self.term_x+ (o or 1)-1 a.term_y=self.term_y+\n(i or 1)-1 end end function TermCanvas:redirect()\nreturn term.redirect(self:getTermRedirect())end function TermCanvas:wrap(a)\nlocal o=self:redirect()a()term.redirect(o)end";
  4.     ["Event.Event"] = "\nclass\"Event\"{handled=false,name=\"\",parameters={},MOUSEDOWN=0,MOUSEUP=1,MOUSEDRAG=2,MOUSESCROLL=3,MOUSEPING=4,KEYDOWN=5,KEYUP=6,TEXT=7,PASTE=8}\nfunction Event:init(e,t)self.name=e self.parameters=t or{}end";
  5.     ["Tween"] = "\nlocal e={_VERSION='tween 2.0.0',_DESCRIPTION='tweening for lua',_URL='https://github.com/kikito/tween.lua',_LICENSE=[[\n\9\9MIT LICENSE\n\9\9Copyright (c) 2014 Enrique GarcΓ­a Cota, Yuichi Tateno, Emmanuel Oga\n\9\9Permission is hereby granted, free of charge, to any person obtaining a\n\9\9copy of this software and associated documentation files (the\n\9\9\"Software\"), to deal in the Software without restriction, including\n\9\9without limitation the rights to use, copy, modify, merge, publish,\n\9\9distribute, sublicense, and/or sell copies of the Software, and to\n\9\9permit persons to whom the Software is furnished to do so, subject to\n\9\9the following conditions:\n\9\9The above copyright notice and this permission notice shall be included\n\9\9in all copies or substantial portions of the Software.\n\9\9THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n\9\9OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\9\9MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n\9\9IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n\9\9CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n\9\9TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n\9\9SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\9]]}\nlocal t,a,o,i,n,s,h=math.pow,math.sin,math.cos,math.pi,math.sqrt,math.abs,math.asin local function r(ea,eo,ei,en)return ei*ea/en+eo end local function d(ea,eo,ei,en)return\nei*t(ea/en,2)+eo end local function l(ea,eo,ei,en)ea=ea/en return\n-ei*ea* (ea-2)+eo end\nlocal function u(ea,eo,ei,en)ea=ea/en*2 if ea<1 then return\nei/2*t(ea,2)+eo end return-ei/2*\n((ea-1)* (ea-3)-1)+eo end\nlocal function c(ea,eo,ei,en)if ea<en/2 then return l(ea*2,eo,ei/2,en)end return d((ea*2)-en,eo+\nei/2,ei/2,en)end local function m(ea,eo,ei,en)return ei*t(ea/en,3)+eo end\nlocal function f(ea,eo,ei,en)return ei* (\nt(ea/en-1,3)+1)+eo end\nlocal function w(ea,eo,ei,en)ea=ea/en*2\nif ea<1 then return ei/2*ea*ea*ea+eo end ea=ea-2 return ei/2* (ea*ea*ea+2)+eo end\nlocal function y(ea,eo,ei,en)if ea<en/2 then return f(ea*2,eo,ei/2,en)end return m((ea*2)-en,eo+\nei/2,ei/2,en)end local function p(ea,eo,ei,en)return ei*t(ea/en,4)+eo end\nlocal function v(ea,eo,ei,en)return-ei* (\nt(ea/en-1,4)-1)+eo end\nlocal function b(ea,eo,ei,en)ea=ea/en*2 if ea<1 then return ei/2*t(ea,4)+eo end return\n-ei/2* (t(ea-2,4)-2)+eo end\nlocal function g(ea,eo,ei,en)if ea<en/2 then return v(ea*2,eo,ei/2,en)end return p((ea*2)-en,eo+\nei/2,ei/2,en)end local function k(ea,eo,ei,en)return ei*t(ea/en,5)+eo end\nlocal function q(ea,eo,ei,en)return ei* (\nt(ea/en-1,5)+1)+eo end\nlocal function j(ea,eo,ei,en)ea=ea/en*2 if ea<1 then return ei/2*t(ea,5)+eo end return\nei/2* (t(ea-2,5)+2)+eo end\nlocal function x(ea,eo,ei,en)if ea<en/2 then return q(ea*2,eo,ei/2,en)end return k((ea*2)-en,eo+\nei/2,ei/2,en)end local function z(ea,eo,ei,en)\nreturn-ei*o(ea/en* (i/2))+ei+eo end local function _(ea,eo,ei,en)return\nei*a(ea/en* (i/2))+eo end local function E(ea,eo,ei,en)return-ei/2*\n(o(i*ea/en)-1)+eo end local function T(ea,eo,ei,en)if\nea<en/2 then return _(ea*2,eo,ei/2,en)end return\nz((ea*2)-en,eo+ei/2,ei/2,en)end\nlocal function A(ea,eo,ei,en)if\nea==0 then return eo end return ei*t(2,10* (ea/en-1))+eo-ei*\n0.001 end\nlocal function O(ea,eo,ei,en)if ea==en then return eo+ei end return ei*1.001*\n(-t(2,-10*ea/en)+1)+eo end\nlocal function I(ea,eo,ei,en)if ea==0 then return eo end if ea==en then return eo+ei end ea=ea/en*2 if ea<1 then\nreturn\nei/2*t(2,10* (ea-1))+eo-ei*0.0005 end return ei/2*1.0005*\n(-t(2,-10* (ea-1))+2)+eo end\nlocal function N(ea,eo,ei,en)if ea<en/2 then return O(ea*2,eo,ei/2,en)end return A((ea*2)-en,eo+\nei/2,ei/2,en)end local function S(ea,eo,ei,en)return\n(-ei* (n(1-t(ea/en,2))-1)+eo)end\nlocal function H(ea,eo,ei,en)return(ei*\nn(1-t(ea/en-1,2))+eo)end\nlocal function R(ea,eo,ei,en)ea=ea/en*2 if ea<1 then\nreturn-ei/2* (n(1-ea*ea)-1)+eo end ea=ea-2 return\nei/2* (n(1-ea*ea)+1)+eo end\nlocal function D(ea,eo,ei,en)if ea<en/2 then return H(ea*2,eo,ei/2,en)end return S((ea*2)-en,eo+\nei/2,ei/2,en)end\nlocal function L(ea,eo,ei,en)ea,eo=ea or en*0.3,eo or 0 if eo<s(ei)then return ea,ei,ea/4 end return ea,\neo,ea/ (2*i)*h(ei/eo)end\nlocal function U(ea,eo,ei,en,es,eh)local er if ea==0 then return eo end ea=ea/en if ea==1 then return eo+ei end\neh,es,er=L(eh,es,ei,en)ea=ea-1 return\n- (es*t(2,10*ea)*\na((ea*en-er)* (2*i)/eh))+eo end\nlocal function C(ea,eo,ei,en,es,eh)local er if ea==0 then return eo end ea=ea/en if ea==1 then return eo+ei end\neh,es,er=L(eh,es,ei,en)return\nes*t(2,-10*ea)*a((ea*en-er)* (2*i)/eh)+ei+eo end\nlocal function M(ea,eo,ei,en,es,eh)local er if ea==0 then return eo end ea=ea/en*2 if ea==2 then return eo+ei end\neh,es,er=L(eh,es,ei,en)ea=ea-1 if ea<0 then return\n-0.5* (es*t(2,10*ea)*\na((ea*en-er)* (2*i)/eh))+eo end\nreturn\nes*\nt(2,-10*ea)*a((ea*en-er)* (2*i)/eh)*0.5+ei+eo end\nlocal function F(ea,eo,ei,en,es,eh)if ea<en/2 then return C(ea*2,eo,ei/2,en,es,eh)end return U(\n(ea*2)-en,eo+ei/2,ei/2,en,es,eh)end\nlocal function W(ea,eo,ei,en,es)es=es or 1.70158 ea=ea/en return\nei*ea*ea* ((es+1)*ea-es)+eo end local function Y(ea,eo,ei,en,es)es=es or 1.70158 ea=ea/en-1\nreturn ei* (\nea*ea* ((es+1)*ea+es)+1)+eo end\nlocal function P(ea,eo,ei,en,es)\nes=(es or 1.70158)*1.525 ea=ea/en*2 if ea<1 then return\nei/2* (ea*ea* ((es+1)*ea-es))+eo end ea=ea-2 return\n\nei/2* (ea*ea* ((es+1)*ea+es)+2)+eo end\nlocal function V(ea,eo,ei,en,es)if ea<en/2 then return Y(ea*2,eo,ei/2,en,es)end return W((ea*2)-en,\neo+ei/2,ei/2,en,es)end\nlocal function B(ea,eo,ei,en)ea=ea/en if ea<1/2.75 then\nreturn ei* (7.5625*ea*ea)+eo end\nif ea<2/2.75 then ea=ea- (1.5/2.75)return ei* (\n7.5625*ea*ea+0.75)+eo elseif ea<2.5/\n2.75 then ea=ea- (2.25/2.75)return ei*\n(7.5625*ea*ea+0.9375)+eo end ea=ea- (2.625/2.75)return ei*\n(7.5625*ea*ea+0.984375)+eo end\nlocal function G(ea,eo,ei,en)return ei-B(en-ea,0,ei,en)+eo end local function K(ea,eo,ei,en)\nif ea<en/2 then return G(ea*2,0,ei,en)*0.5+eo end\nreturn B(ea*2-en,0,ei,en)*0.5+ei*.5+eo end local function Q(ea,eo,ei,en)if ea<en/2 then return B(ea*2,eo,ei/\n2,en)end return\nG((ea*2)-en,eo+ei/2,ei/2,en)end\ne.easing={linear=r,inQuad=d,outQuad=l,inOutQuad=u,outInQuad=c,inCubic=m,outCubic=f,inOutCubic=w,outInCubic=y,inQuart=p,outQuart=v,inOutQuart=b,outInQuart=g,inQuint=k,outQuint=q,inOutQuint=j,outInQuint=x,inSine=z,outSine=_,inOutSine=E,outInSine=T,inExpo=A,outExpo=O,inOutExpo=I,outInExpo=N,inCirc=S,outCirc=H,inOutCirc=R,outInCirc=D,inElastic=U,outElastic=C,inOutElastic=M,outInElastic=F,inBack=W,outBack=Y,inOutBack=P,outInBack=V,inBounce=G,outBounce=B,inOutBounce=K,outInBounce=Q}\nlocal function J(ea,eo,ei)ei=ei or eo local en=getmetatable(eo)if\nen and getmetatable(ea)==nil then setmetatable(ea,en)end for es,eh in pairs(eo)do\nif\ntype(eh)=='table'then ea[es]=J({},eh,ei[es])else ea[es]=ei[es]end end return ea end\nlocal function X(ea,eo,ei)ei=ei or{}local en,es\nfor eh,er in pairs(eo)do en,es=type(er),J({},ei)\ntable.insert(es,tostring(eh))\nif en=='number'then\nassert(type(ea[eh])=='number',\"Parameter '\"..table.concat(es,'/')..\n\"' is missing from subject or isn't a number\")elseif en=='table'then X(ea[eh],er,es)else\nassert(en=='number',\"Parameter '\"..table.concat(es,'/')..\n\"' must be a number or table of numbers\")end end end\nlocal function Z(ea,eo,ei,en)\nassert(type(ea)=='number'and ea>0,\"duration must be a positive number. Was \"..tostring(ea))local es=type(eo)\nassert(es=='table'or es=='userdata',\n\"subject must be a table or userdata. Was \"..tostring(eo))\nassert(type(ei)=='table',\"target must be a table. Was \"..tostring(ei))\nassert(type(en)=='function',\"easing must be a function. Was \"..tostring(en))X(eo,ei)end\nlocal function ee(ea)ea=ea or\"linear\"\nif type(ea)=='string'then local eo=ea ea=e.easing[eo]if type(ea)~=\n'function'then\nerror(\"The easing function name '\"..eo..\"' is invalid\")end end return ea end\nlocal function et(ea,eo,ei,en,es,eh,er)local ed,el,eu,ec\nfor em,ef in pairs(eo)do\nif type(ef)=='table'then\net(ea[em],ef,ei[em],en,es,eh,er)else ed,el,eu,ec=en,ei[em],ef-ei[em],es\nea[em]=er and\nmath.floor(eh(ed,el,eu,ec)+.5)or eh(ed,el,eu,ec)end end end\nclass\"Tween\"{duration=0,subject=0,target=0,easing=0,initial=0,clock=0,round=false,DEFAULT_EASING=\"inOutSine\",DEFAULT_DURATION=.3}\nfunction Tween:init(ea,eo,ei,en)en=en or self.DEFAULT_EASING\nei=ei or self.DEFAULT_DURATION en=ee(en)Z(ei,ea,eo,en)self.duration=ei self.subject=ea\nself.target=eo self.easing=en self.initial=J({},eo,ea)end\nfunction Tween:set(ea)self.clock=ea\nif self.clock<=0 then self.clock=0\nJ(self.subject,self.initial)elseif self.clock>=self.duration then self.clock=self.duration\nJ(self.subject,self.target)else\net(self.subject,self.target,self.initial,self.clock,self.duration,self.easing,self.round)end return self.clock>=self.duration end function Tween:reset()return self:set(0)end function Tween:update(ea)return\nself:set(self.clock+ea)end";
  6.     ["Timer"] = "class\"Timer\"local e,t,a=0,{},nil\nlocal function o(s)local n=os.clock()+s for r=1,#t do if t[r].timeout==n then return\nt[r]end end\nlocal h={timeout=n,timer=os.startTimer(s)}t[#t+1]=h return h end\nlocal function i(n)\nfor s=#t,1,-1 do if t[s].timer==n then for h=1,#t[s]do t[s][h]()end\ntable.remove(t,s)return true end end return false end function Timer.step()e=os.clock()end function Timer.getDelta()\nreturn os.clock()-e end function Timer.getFPS()return fps end\nfunction Timer.setFPS(n)fps=n a=a or(n and os.startTimer(\n1/n))end function Timer.queue(s,h)local n=o(s)n[#n+1]=h return n.timer end\nfunction Timer.sleep(s)\nlocal n=o(s).timer repeat local h,r=coroutine.yield\"timer\"until r==n end\nfunction Timer.update(n,s)if n==\"timer\"then\nif s==a then\na=fps and os.startTimer(1/fps)or nil os.queueEvent\"update\"return true else return i(s)end end end";
  7.     ["UIAnimationHandler"] = "require\"Tween\"require\"Timer\"local function e(t)local a=os.clock()\nt.updateTimer=t.updateTimer or Timer.queue(.05,function()t:update(\nos.clock()-a)end)end\nclass\"UIAnimationHandler\"{tweens={}}function UIAnimationHandler:init()self.tweens={}end function UIAnimationHandler:killTween(t)\nlocal a=self.tweens\nfor o=1,#a do if a[o].label==t then table.remove(a,o)break end end end\nfunction UIAnimationHandler:createTween(t,a,o,i,n)\nself:killTween(t)e(self)local s=Tween(a,o,i,n)s.label=t\nself.tweens[#self.tweens+1]=s return s end\nfunction UIAnimationHandler:createRoundedTween(t,a,o,i,n)self:killTween(t)e(self)\nlocal s=Tween(a,o,i,n)s.round=true s.label=t\nself.tweens[#self.tweens+1]=s return s end\nfunction UIAnimationHandler:update(t)self.updateTimer=nil local a=self.tweens\nfor o=#a,1,-1 do if\na[o]:update(t)then if a[o].onFinish then a[o]:onFinish()end\ntable.remove(a,o)end end if#a>0 then e(self)end end";
  8.     ["Event.MouseEvent"] = "require\"Event.Event\"class\"MouseEvent\"\nextends\"Event\"{useSetters=true,x=0,y=0,button=1,parent=nil,within=true,BUTTONLEFT=1,BUTTONRIGHT=2,BUTTONMIDDLE=3}\nfunction MouseEvent:init(e,t,a,o,i,n)self.x=t self.y=a self.button=o self.within=i\nself.super:init(e,n)self.mt.__tostring=self.tostring end\nfunction MouseEvent:clone(e,t,a)\nlocal o=MouseEvent(self.name,self.x-e,self.y-t,self.button,self.within and a,self.parameters)o.parent=self o.handled=self.handled if self.name==Event.MOUSEPING then\no.elements=self.elements end return o end function MouseEvent:isInArea(e,t,a,o)local i,n=self.x,self.y\nreturn self.within and i>=e and n>=t and i<e+\na and n<t+o end\nfunction MouseEvent:setHandled(e)\nself.handled=e if e and self.parent then self.parent.handled=true end end function MouseEvent:tostring()\nreturn\"[Instance] MouseEvent[\"..self.button..\n\"] @\"..self.x..\",\"..self.y end";
  9.     ["Event.KeyboardEvent"] = "require\"Event.Event\"class\"KeyboardEvent\"\nextends\"Event\"{key=0,modifiers={}}function KeyboardEvent:init(e,t,a,o)self.key=keys.getName(t)self.modifiers=a\nself.super:init(e,o)end\nfunction KeyboardEvent:matchesHotkey(e)\nfor t in(\ne:match\"^(.+)%-\"or\"\"):gmatch\"[^%-]+\"do\nif\nt==\"ctrl\"and not\nself.modifiers.leftCtrl and not self.modifiers.rightCtrl then return false elseif t==\"shift\"and not self.modifiers.leftShift and not\nself.modifiers.rightShift then return false elseif t~=\"ctrl\"and\nt~=\"shift\"and not self.modifiers[t]then return false end end return self.key==e:gsub(\".+%-\",\"\")end";
  10.     ["Event.TextEvent"] = "require\"Event.Event\"class\"TextEvent\"\nextends\"Event\"{text=\"\"}\nfunction TextEvent:init(e,t,a)self.text=t self.super:init(e,a)end";
  11.     ["graphics.DrawingCanvas"] = "require\"graphics.Canvas\"\nlocal e,t,a,o=math.max,math.min,math.floor,math.abs local function i(f)\nreturn{f.colour or 0,f.textColour or 0,f.character or\"\"}end local function n(f)return\nf.textColour==nil and f.character==nil end\nlocal function s(f,w,p,v,b,g)local y=false local k=f for q=1,f do\nlocal j=p[q]\nif\n((j<b and p[k]>=b)or(p[k]<b and j>=b))then if w[q]+g[q]* (b-j)<v then y=not y end end k=q end return y end\nlocal function h(f,y)if y<=0 then return\"\",#f>1 and f:sub(2)end\nfor w=1,y+1 do if\nf:sub(w,w)==\"\\n\"then return f:sub(1,w-1),f:sub(w+1)end end if#f<=y then return f end for w=y+1,1,-1 do\nif f:sub(w,w):find\"%s\"then return f:sub(1,w-1)..\nf:match(\"%s+\",w),f:match(\"%S.+$\",w+1)end end return f:sub(1,y)end\nlocal function r(f,y,p)local w,v={}while f do v,f=h(f,y)w[#w+1]=v end while\np and#w>math.max(p,1)do w[#w]=nil end return w end\nlocal function d(f,w,y)if n(y)then f:mapColour(w,y.colour or 1)else\nf:mapStaticPixel(w,i(y))end end\nlocal function l(f,w,p,v,b,g)local y={}local k,q=f.width,f.height local j=g.weight or 1 local x=1 for z=0,j-1 do\nlocal _=(p+z)*k+w+1 local E=(p+b-z-1)*k+w+1\nfor T=1,v do if w+T<=k and w+T>0 then y[x]=_\ny[x+1]=E x=x+2 end _=_+1 E=E+1 end end\nfor z=j,b-j-1\ndo local _=(p+z)*k+w\nfor E=0,j-1 do\nif w+E<k and w+E>0 then y[x]=_+E+1 x=x+1 end if w+v-E<k and w+v-E>0 then y[x]=_+v-E x=x+1 end end end d(f,y,g)end\nlocal function u(f,w,p,v,b,g)local y={}local k,q=f.width,f.height local j=1 if w<0 then v=v+w w=0 end\nif w+v>=k then v=k-w end\nfor x=1,b do local z=p*k+w+1 p=p+1 for x=1,v do y[j]=z j=j+1 z=z+1 end end d(f,y,g)end\nlocal function c(f,w,p,v,b)local y={}local g=f.width local k=b.weight or 1 local q=1 local j=v*v\nfor x=0,v do local z=a((j-x^2)^.5*\nf.correction+.5)local _=\n(p-x)*g+w-z+1 local E=(p+x)*g+w-z+1 local T=\n(p-x)*g+w+z+1 local A=(p+x)*g+w+z+1\nfor O=0,k do y[q]=_ y[q+1]=E y[q+\n2]=T y[q+3]=A _=_+1 E=E+1 T=T-1 A=A-1 q=q+4 end end d(f,y,b)end\nlocal function m(f,w,p,v,b)local y={}local g=f.width local k=1 local q=v*v\nfor z=1,v do\nlocal _=a((q-z^2)^.5*f.correction+.5)local E=(p-z)*g+e(0,w-_)+1\nlocal T=(p+z)*g+e(0,w-_)+1\nfor A=e(0,w-_),t(g-1,w+_)do y[k]=E y[k+1]=T E=E+1 T=T+1 k=k+2 end end local j=a(v*f.correction+.5)\nlocal x=p*g+e(0,w-j)+1 for z=e(0,w-j),t(g-1,w+j)do y[k]=x x=x+1 k=k+1 end d(f,y,b)end class\"DrawingCanvas\"\nextends\"Canvas\"{correction=cclite and 1.5 or 1.67}\nfunction DrawingCanvas:drawPoint(f,w,y)local p=y.weight or 1 if p==1 then\nself.buffer[w*self.width+f+1]=i(y)else\nself:drawCircle(f,w,p-1,{colour=colour,textColour=textColour,character=character,filled=true})end end\nfunction DrawingCanvas:drawRectangle(f,w,y,p,v)if v.filled or v.outline==false then\nu(self,f,w,y,p,v)else l(self,f,w,y,p,v)end end\nfunction DrawingCanvas:drawCircle(f,w,y,p)if p.filled or p.outline==false then m(self,f,w,y,p)else\nc(self,f,w,y,p)end end\nfunction DrawingCanvas:drawLine(f,w,y,p,v)local b,g=y-f,p-w\nif o(b)<.0001 then return\nself:drawVerticalLine(f,t(w,p),o(p-w)+1,v)elseif o(g)<.0001 then return\nself:drawHorizontalLine(t(f,y),w,o(y-f)+1,v)end local k=g/b local q=w-k*f+.5 local j=t(1,1/o(k))for z=t(f,y),e(f,y),j do\nlocal x=a(k*z+q)end end\nfunction DrawingCanvas:drawHorizontalLine(f,w,y,p)local v=p.weight or 1 local b=self.width local g={}local k=math.floor(\nv/2-.5)local q=k*k local j=1\nfor x=0,k do local z=k-a(\n(q-x^2)^.5*self.correction+.5)local _=\n(w+x)*b+f+z+1 local E=(w-x)*b+f+z+1 for T=f+z,\nf+y-z-1 do g[j]=_ g[j+1]=E _=_+1 E=E+1 j=j+2 end end d(self,g,p)end\nfunction DrawingCanvas:drawVerticalLine(f,w,y,p)local v=p.weight or 1 local b=self.width local g={}local k=math.floor(v/2-\n.5)local q=k*k local j=1 for x=0,y-1 do\nif x<k then elseif x>=y-k then else\nlocal z=(w+x)*b+f-k+1 for E=1,v do g[j]=z z=z+1 j=j+1 end end end d(self,g,p)end function DrawingCanvas:drawTriangle()end\nfunction DrawingCanvas:drawTopLeftTriangle()end function DrawingCanvas:drawTopRightTriangle()end\nfunction DrawingCanvas:drawBottomLeftTriangle()end function DrawingCanvas:drawBottomRightTriangle()end\nfunction DrawingCanvas:drawText(f,w,y)\nlocal p=y.colour or 0 local v=y.textColour or 0 local b={}local g=self.width local k=w*g+f for q=math.max(1,1-f),\n#y.text do if f+q>g then break end\nb[#b+1]={k+q,{p,v,y.text:sub(q,q)}}end\nself:drawPixels(b)end\nfunction DrawingCanvas:drawWrappedText(f,w,y,p,v)local b=v.colour or 0 local g=v.textColour or 0\nlocal k={}local q=v.alignment local j=v.verticalAlignment local x=r(v.text,y,p)\nlocal z=self.width\nlocal _=\n(\n(j==\"centre\"and math.floor(p/2-#x/2+.5)or(j==\"bottom\"and p-#\nx)or 0)+w)*z+f local E=1\nfor T=1,#x do\nlocal A=\n(q==\"centre\"and math.floor(y/2-#x[T]/2+.5))or(q==\"right\"and y-#x[T])or\n0\nfor O=1,#x[T]do k[E]={_+O+A,{b,g,x[T]:sub(O,O)}}E=E+1 end _=_+z end self:drawPixels(k)end\nfunction DrawingCanvas:drawPreformattedText(f,w,y,p,v)local b={}local g=v.verticalAlignment\nlocal k=v.selectedColour or colours.blue local q=v.selectedTextColour or 1 local j=v.text local x=self.width\nlocal z=\n(\n(\n(\ng==\"centre\"and math.floor(p/2-#j/2+.5))or(g==\"bottom\"and p-#j)or 0)+w)*x+f local _=1\nfor E=1,#j do local T=j[E]\nlocal A=\n\n(T.alignment==\"centre\"and math.floor(y/2-#T/2+.5))or(T.alignment==\"right\"and y-#T)or 0\nfor O=1,#T do if O+f+A>=0 and O+f+A<=x then\nif T[O][3]~=\"\\n\"then if T[O].selected then\nb[_]={z+O+A,{k,q,T[O][3]}}else b[_]={z+O+A,T[O]}end _=_+1 end end end z=z+x end self:drawPixels(b)end";
  12.     ["UIElement"] = "require\"UIAnimationHandler\"require\"Event.MouseEvent\"\nrequire\"Event.KeyboardEvent\"require\"Event.TextEvent\"require\"graphics.DrawingCanvas\"local function e(a)return\n{unpack(a)}end\nclass\"UIElement\"{useSetters=true,id=\"NOID\",tags={},x=0,y=0,width=0,height=0,ox=0,oy=0,children={},parent=nil,handlesMouse=true,handlesKeyboard=false,handlesText=false,canvas=nil,animationHandler=nil,changed=true,transitionTime=.3}\nfunction UIElement:init(t,a,o,i)self.tags={}self.children={}self.raw.x=t\nself.raw.y=a self.raw.width=o self.raw.height=i\nself.animationHandler=UIAnimationHandler()self.canvas=DrawingCanvas(0,0,o,i)\nself.mt.__tostring=self.tostring end\nfunction UIElement:getChildById(t,a)\nfor o=#self.children,1,-1 do local i=self.children[o]if i.id==t then return i elseif a then\ni=i:getChildById(t,true)if i then return i end end end end UIElement.getElementById=UIElement.getChildById\nfunction UIElement:getChildrenByTag(t,a)\nlocal o={}\nfor n=1,#self.children do local i=self.children[n]for s=1,#i.tags do if i.tags[s]==t then\no[#o+1]=i break end end if a then\nlocal s=i:getChildrenByTag(t,true)for h=1,#s do o[#o+1]=s[h]end end end return o end\nfunction UIElement:childrenWithTag(t,a)local o=self:getChildrenByTag(t,a)local n=0 return function()n=n+1\nreturn o[n]end end\nfunction UIElement:getChildrenAt(t,a)\nlocal o=MouseEvent(Event.MOUSEPING,t+self.ox,a+self.oy)o.elements={}for n=#self.children,1,-1 do\nself.children[n]:handle(o)end return unpack(o.elements)end\nfunction UIElement:childrenAt(t,a)local o={self:getChildrenAt(t,a)}local n=0 return function()\nn=n+1 return o[n]end end\nfunction UIElement:addTag(t)self.tags[#self.tags+1]=t end\nfunction UIElement:removeTag(t)for a=#self.tags,1,-1 do if self.tags[a]==t then\ntable.remove(self.tags,a)end end end function UIElement:hasTag(t)\nfor a=#self.tags,1,-1 do if self.tags[a]==t then return true end end return false end\nfunction UIElement:addChild(t)if\nt.parent then t.parent:removeChild(t)end self.children[#\nself.children+1]=t t.raw.parent=self\nt:onParentChanged()self.changed=true return t end\nfunction UIElement:removeChild(t)\nfor a=#self.children,1,-1 do\nif self.children[a]==t then\ntable.remove(self.children,a)t.raw.parent=nil t:onParentChanged()self.changed=true break end end return t end\nfunction UIElement:setParent(t)if t then t:addChild(self)elseif self.parent then\nself.parent:removeChild(self)end end function UIElement:remove()\nif self.parent then self.parent:removeChild(self)end end\nfunction UIElement:transitionInLeft(t)\nself.x=-self.width return\nself.animationHandler:createRoundedTween(\"x\",self,{x=0},self.transitionTime,t)end\nfunction UIElement:transitionInLeftFrom(t,a)self.x=t return\nself.animationHandler:createRoundedTween(\"x\",self,{x=0},self.transitionTime,a)end\nfunction UIElement:transitionInRight(t)self.x=self.parent.width return\nself.animationHandler:createRoundedTween(\"x\",self,{x=\nself.parent.width-self.width},self.transitionTime,t)end\nfunction UIElement:transitionInRightFrom(t,a)self.x=t return\nself.animationHandler:createRoundedTween(\"x\",self,{x=\nself.parent.width-self.width},self.transitionTime,a)end\nfunction UIElement:transitionInTop(t)self.y=-self.height return\nself.animationHandler:createRoundedTween(\"y\",self,{y=0},self.transitionTime,t)end\nfunction UIElement:transitionInTopFrom(t,a)self.y=t return\nself.animationHandler:createRoundedTween(\"y\",self,{y=0},self.transitionTime,a)end\nfunction UIElement:transitionInBottom(t)self.y=self.parent.height return\nself.animationHandler:createRoundedTween(\"y\",self,{y=\nself.parent.height-self.height},self.transitionTime,t)end\nfunction UIElement:transitionInBottomFrom(t,a)self.y=t return\nself.animationHandler:createRoundedTween(\"y\",self,{y=\nself.parent.height-self.height},self.transitionTime,a)end\nfunction UIElement:transitionOutLeft(t)\nlocal a=self.animationHandler:createRoundedTween(\"x\",self,{x=-self.width},self.transitionTime,t)function a.onFinish()self:remove()end end\nfunction UIElement:transitionOutLeftTo(t,a)\nlocal o=self.animationHandler:createRoundedTween(\"x\",self,{x=t},self.transitionTime,a)function o.onFinish()self:remove()end end\nfunction UIElement:transitionOutRight(t)\nlocal a=self.animationHandler:createRoundedTween(\"x\",self,{x=self.parent.width},self.transitionTime,t)function a.onFinish()self:remove()end end\nfunction UIElement:transitionOutRightTo(t,a)\nlocal o=self.animationHandler:createRoundedTween(\"x\",self,{x=t},self.transitionTime,a)function o.onFinish()self:remove()end end\nfunction UIElement:transitionOutTop(t)\nlocal a=self.animationHandler:createRoundedTween(\"y\",self,{y=-self.height},self.transitionTime,t)function a.onFinish()self:remove()end end\nfunction UIElement:transitionOutTopTo(t,a)\nlocal o=self.animationHandler:createRoundedTween(\"y\",self,{y=t},self.transitionTime,a)function o.onFinish()self:remove()end end\nfunction UIElement:transitionOutBottom(t)\nlocal a=self.animationHandler:createRoundedTween(\"y\",self,{y=self.parent.height},self.transitionTime,t)function a.onFinish()self:remove()end end\nfunction UIElement:transitionOutBottomTo(t,a)\nlocal o=self.animationHandler:createRoundedTween(\"y\",self,{y=t},self.transitionTime,a)function o.onFinish()self:remove()end end\nfunction UIElement:bringToFront()\nif self.parent and\nself.parent.children[#self.parent.children]~=self then\nfor t=#\nself.parent.children,1,-1 do if self.parent.children[t]==self then\ntable.remove(self.parent.children,t)end end\nself.parent.children[#self.parent.children+1]=self self.parent.changed=true end end\nfunction UIElement:setChanged(t)self.changed=t if t and self.parent then\nself.parent.changed=true end end function UIElement:setX(t)self.raw.x=t\nif self.parent then self.parent.changed=true end end\nfunction UIElement:setAnimatedX(t)return\nself.animationHandler:createRoundedTween(\"x\",self,{x=t},self.transitionTime)end function UIElement:setY(t)self.raw.y=t\nif self.parent then self.parent.changed=true end end\nfunction UIElement:setAnimatedY(t)return\nself.animationHandler:createRoundedTween(\"y\",self,{y=t},self.transitionTime)end\nfunction UIElement:setOx(t)self.raw.ox=t self.changed=true end\nfunction UIElement:setAnimatedOX(t)return\nself.animationHandler:createRoundedTween(\"ox\",self,{ox=t},self.transitionTime)end\nfunction UIElement:setOy(t)self.raw.oy=t self.changed=true end\nfunction UIElement:setAnimatedOY(t)return\nself.animationHandler:createRoundedTween(\"oy\",self,{oy=t},self.transitionTime)end\nfunction UIElement:setWidth(t)self.raw.width=t for a=1,#self.children do\nself.children[a]:onParentResized()end self.canvas.width=t\nself.changed=true end\nfunction UIElement:setAnimatedWidth(t)return\nself.animationHandler:createRoundedTween(\"width\",self,{width=t},self.transitionTime)end\nfunction UIElement:setHeight(t)self.raw.height=t for a=1,#self.children do\nself.children[a]:onParentResized()end self.canvas.height=t\nself.changed=true end\nfunction UIElement:setAnimatedHeight(t)return\nself.animationHandler:createRoundedTween(\"height\",self,{height=t},self.transitionTime)end\nfunction UIElement:update(t)self:onUpdate(t)for a=1,#self.children do\nself.children[a]:update(t)end end\nfunction UIElement:draw()if not self.changed then return end self.changed=false\nlocal t=self.canvas t.cursor=nil self:onDraw()\nfor a=1,#self.children do\nlocal o=self.children[a]o:draw()\no.canvas:drawTo(t,o.x+self.ox,o.y+self.oy)if o.canvas.cursor then\nt.cursor={x=o.canvas.cursor.x+o.x+self.ox,y=\no.canvas.cursor.y+o.y+self.oy,colour=o.canvas.cursor.colour}end end end\nfunction UIElement:handle(t)local a={}\nfor o=1,#self.children do a[o]=self.children[o]end\nif t:typeOf(MouseEvent)then\nlocal o=t:isInArea(0,0,self.width,self.height)for n=#a,1,-1 do local i=a[n]\ni:handle(t:clone(i.x+self.ox,i.y+self.oy,o))end else\nfor o=#a,1,-1 do a[o]:handle(t)end end\nif t:typeOf(MouseEvent)and self.handlesMouse then if\nt.name==Event.MOUSEPING and t:isInArea(0,0,self.width,self.height)then\nlocal o=t.elements o[#o+1]=self end\nself:onMouseEvent(t)elseif t:typeOf(KeyboardEvent)and self.handlesKeyboard then\nself:onKeyboardEvent(t)elseif t:typeOf(TextEvent)and self.handlesText then\nself:onTextEvent(t)end end function UIElement:onUpdate(t)end function UIElement:onDraw()end\nfunction UIElement:onMouseEvent(t)end function UIElement:onKeyboardEvent(t)end function UIElement:onTextEvent(t)end function UIElement:onParentChanged()\nend function UIElement:onParentResized()end\nfunction UIElement:tostring()\nreturn\n\"[Instance] \"..\nself.class.name..\" \"..\ntostring(self.id)..\" (\"..self.x..\n\",\"..self.y..\" \"..self.width..\n\"x\"..self.height..\")\"end";
  13.     ["UITerminal"] = "require\"graphics.TermCanvas\"require\"Event.Event\"\nrequire\"UIElement\"class\"UITerminal\"\nextends\"UIElement\"{handlesKeyboard=true,handlesText=true,holding=false}\nfunction UITerminal:init(e,t,a,o)self.super:init(e,t,a,o)\nself.canvas=TermCanvas(a,o)self.term=self.canvas:getTermRedirect()end\nfunction UITerminal:wrap()return term.redirect(self.term)end\nfunction UITerminal:onMouseEvent(e)\nif e.handled or not self.onEvent then return end\nif\ne.name==Event.MOUSEDOWN and e:isInArea(0,0,self.width,self.height)then self.holding=true\nself:onEvent(\"mouse_click\",e.button,e.x+1,e.y+1)e.handled=true self.changed=true elseif e.name==Event.MOUSESCROLL and\ne:isInArea(0,0,self.width,self.height)then\nself:onEvent(\"mouse_scroll\",e.button,e.x+1,e.y+1)e.handled=true self.changed=true elseif\ne.name==Event.MOUSEUP and self.holding then self.holding=false\nself:onEvent(\"mouse_up\",e.button,e.x+1,e.y+1)e.handled=true self.changed=true elseif\ne.name==Event.MOUSEDRAG and self.holding then\nself:onEvent(\"mouse_drag\",e.button,e.x+1,e.y+1)e.handled=true self.changed=true end end\nfunction UITerminal:onKeyboardEvent(e)\nif e.handled or not self.onEvent then return end\nif e.name==Event.KEYUP then\nself:onEvent(\"key_up\",keys[e.key])e.handled=true self.changed=true elseif e.name==Event.KEYDOWN then\nself:onEvent(\"key\",keys[e.key],e.parameters.isRepeat)e.handled=true self.changed=true end end\nfunction UITerminal:onTextEvent(e)\nif e.handled or not self.onEvent then return end\nif e.name==Event.TEXT then self:onEvent(\"char\",e.text)\ne.handled=true self.changed=true elseif e.name==Event.PASTE then\nself:onEvent(\"paste\",e.text)e.handled=true self.changed=true end end\nfunction UITerminal:setWidth(e)self.super:setWidth(e)if self.onEvent then\nself:onEvent\"term_resize\"end end\nfunction UITerminal:setHeight(e)self.super:setHeight(e)if self.onEvent then\nself:onEvent\"term_resize\"end end\nfunction UITerminal:handle(e)if e.class==Event and self.onEvent then\nself:onEvent(e.name,unpack(e.parameters))self.changed=true end\nUIElement.handle(self,e)end\nfunction UITerminal:onDraw()if self.canvas.term_cb then\nself.canvas.cursor={x=self.canvas.term_x-1,y=\nself.canvas.term_y-1,colour=self.canvas.term_tc}end end";
  14.     ["clipboard"] = "local e={{\"empty\"}}local t={}function t.put(a)e=a end\nfunction t.clear()e={{\"empty\"}}end function t.get(a)\nfor o=1,#e do if e[o][1]==a then return e[o][2]end end end return t";
  15.     ["util.UIEventHelpers"] = "require\"Event.Event\"local e=require\"clipboard\"local t={}t.clicking={}\nt.scrollbar={}t.scrollbar.mixin={}t.textSelection={}\nfunction t.clicking:handleMouseEvent(a)\nif a.handled then return end\nif\na.name==Event.MOUSEDOWN and a:isInArea(0,0,self.width,self.height)then self.clicking={button=a.button,moved=false}a.handled=true return\"down\"elseif\na.name==Event.MOUSEDRAG and self.clicking then\nif not a.handled and\na:isInArea(0,0,self.width,self.height)then a.handled=true end self.clicking.moved=true elseif\na.name==Event.MOUSEUP and self.clicking then\nif a.button==self.clicking.button then a.handled=true if\na:isInArea(0,0,self.width,self.height)and not self.clicking.moved then\nself.clicking=nil return\"click\"end\nself.clicking=nil return\"up\"end end end\nfunction t.scrollbar:active()\nlocal a,o=self:getContentWidth(),self:getContentHeight()local i,n=self:getDisplayWidth(),self:getDisplayHeight()if\na>i or o>n then return o>n-1,a>i-1 end return false,false end\nfunction t.scrollbar:getBarInfo(a,o,i)\nlocal n=\na==\"bottom\"and self.width- (o and 1 or 0)or self.height- (i and 1 or 0)local s=a==\"bottom\"and self:getContentWidth()or\nself:getContentHeight()local h=n/s\nlocal r=(\n\na==\"bottom\"and self:getDisplayWidth()- (o and 1 or 0)or self:getDisplayHeight()- (i and 1 or 0))\nlocal d=(a==\"bottom\"and self:getHorizontalOffset()or\nself:getVerticalOffset())return s==0 and 0 or math.floor(d*h+.5),s==0 and 0 or\nmath.floor(r*h+.5)end\nfunction t.scrollbar:updateScrollbarPosition(a,o,i,n)\nlocal s=\na==\"bottom\"and self.width- (i and 1 or 0)or self.height- (n and 1 or 0)local h=a==\"bottom\"and self:getContentWidth()or\nself:getContentHeight()\nlocal r=(\n\na==\"bottom\"and self:getDisplayWidth()- (i and 1 or 0)or self:getDisplayHeight()- (n and 1 or 0))local d=math.floor(\n(o-self.scrollbar_mounted)/s*h+.5)if\na==\"right\"then\nself:setVerticalOffset(math.max(0,math.min(h-r,d)))else\nself:setHorizontalOffset(math.max(0,math.min(h-r,d)))end end\nfunction t.scrollbar:handleMouseEvent(a)if a.handled then return end local o,i=a.x,a.y\nlocal n,s=t.scrollbar.active(self)\nif\na.name==Event.MOUSEDOWN and a:isInArea(0,0,self.width,self.height)then\nif n and o==self.width-1 then\nlocal h,r=t.scrollbar.getBarInfo(self,\"right\",n,s)\nif i<=h then self.scrollbar_mounted=0 self.scrollbar_mounted_side=\"right\"elseif i>=h+r then self.scrollbar_mounted=\nr-1 self.scrollbar_mounted_side=\"right\"else\nself.scrollbar_mounted=i-h self.scrollbar_mounted_side=\"right\"end self.scrollbar_scrollright=n self.scrollbar_scrollbottom=s\nt.scrollbar.updateScrollbarPosition(self,\"right\",i,n,s)a.handled=true elseif s and i==self.height-1 then\nlocal h,r=t.scrollbar.getBarInfo(self,\"bottom\",n,s)\nif o<h then self.scrollbar_mounted=0 self.scrollbar_mounted_side=\"bottom\"elseif o>=h+r then self.scrollbar_mounted=\nr-1 self.scrollbar_mounted_side=\"bottom\"else\nself.scrollbar_mounted=o-h self.scrollbar_mounted_side=\"bottom\"end self.scrollbar_scrollright=n self.scrollbar_scrollbottom=s\nt.scrollbar.updateScrollbarPosition(self,\"bottom\",o,n,s)a.handled=true end elseif a.name==Event.MOUSEDRAG and self.scrollbar_mounted then\nlocal h=self.scrollbar_mounted_side\nt.scrollbar.updateScrollbarPosition(self,h,h==\"right\"and i or o,self.scrollbar_scrollright,self.scrollbar_scrollbottom)a.handled=true elseif a.name==Event.MOUSEUP and self.scrollbar_mounted then self.scrollbar_mounted=\nnil self.scrollbar_mounted_side=nil a.handled=true\nself.changed=true end end\nfunction t.scrollbar:handleMouseScroll(a)\nif\n\nnot a.handled and a.name==Event.MOUSESCROLL and a:isInArea(0,0,self.width,self.height)then local o,i=t.scrollbar.active(self)\nlocal n=self:getContentHeight()-\nself.height+ (i and 1 or 0)\nif a.button==1 and self:getVerticalOffset()<n then\nself:setVerticalOffset(math.max(0,math.min(n,\nself:getVerticalOffset()+1)))a.handled=true elseif\na.button==-1 and self:getVerticalOffset()>0 then\nself:setVerticalOffset(math.max(0,math.min(n,self:getVerticalOffset()-1)))a.handled=true end end end\nfunction t.scrollbar.mixin:getDisplayWidth()return self.width end\nfunction t.scrollbar.mixin:getDisplayHeight()return self.height end function t.scrollbar.mixin:getContentWidth()return 0 end function t.scrollbar.mixin:getContentHeight()return\n0 end function t.scrollbar.mixin:getHorizontalOffset()\nreturn-self.ox end function t.scrollbar.mixin:getVerticalOffset()\nreturn-self.oy end function t.scrollbar.mixin:setHorizontalOffset(a)\nself.ox=-a end function t.scrollbar.mixin:setVerticalOffset(a)\nself.oy=-a end\nfunction t.textSelection:getCharacter(a,o,i,n,s,h)\nlocal r=math.max(1,math.min(#i,1+o-\n(\n(\nn==\"centre\"and math.floor(h/2-#i/2+.5))or(n==\"bottom\"and h-#i)or 0)))if not i[r]then return nil end local d=0 for c=1,r-1 do d=d+#i[c]end\nlocal l=i[r].alignment\nlocal u=math.max(1,math.min(1+a- (\n(l==\"centre\"and math.floor(s/2-#i[r]/2+.5))or(l==\"right\"and s-#i[r])or\n0),\n#i[r]))return d+u,r,u end\nfunction t.textSelection:deselectAll(a)for o=1,#a do local i=a[o]\nfor n=1,#i do i[n].pixel.selected=false end end end\nfunction t.textSelection:selectRange(a,o,i,n,s)\nif o>n then o,n=n,o i,s=s,i elseif o==n and i>s then i,s=s,i end\nfor h=1,#a do local r=a[h]\nfor d=1,#r do\nif h<o or h>n then r[d].pixel.selected=false elseif o==n then r[d].pixel.selected=\nd>=i and d<=s elseif h==o then r[d].pixel.selected=d>=i elseif h==n then r[d].pixel.selected=\nd<=s else r[d].pixel.selected=true end end end end\nfunction t.textSelection:getCharacterLink(a,o,i,n,s,h)\nlocal r=math.max(1,math.min(#i,1+o- (\n(n==\"centre\"and\nmath.floor(h/2-#i/2+.5))or(n==\"bottom\"and h-#i)or 0)))if not i[r]then return nil end local d=0 for c=1,r-1 do d=d+#i[c]end\nlocal l=i[r].alignment local u=1+a- (\n(l==\"centre\"and math.floor(s/2-#i[r]/2+.5))or(l==\"right\"and s-#i[r])or\n0),\n#i[r]if i[r][u]then\nreturn i[r][u].link end end\nfunction t.textSelection:handleMouseEvent(a,o,i,n,s)\nif a.name==Event.MOUSEDOWN then\nt.textSelection.deselectAll(self,o)\nif\na.handled or not a:isInArea(0,0,self.width,self.height)then self.selection=nil else\nlocal h,r,d=t.textSelection.getCharacter(self,a.x-self.ox,a.y-self.oy,o,i,n,s)if h then\nself.selection={line1=r,char1=d,pos1=h,line2=r,char2=d,pos2=h,holding=true,button=a.button,initialised=false}end a.handled=true end self.changed=true elseif\nnot a.handled and a.name==Event.MOUSEUP and\nself.selection and a.button==self.selection.button then self.selection.holding=false\nif not self.selection.initialised then\nif\nself.onLinkPressed then\nlocal h=t.textSelection.getCharacterLink(self,a.x-self.ox,a.y-self.oy,o,i,n,s)if h then self:onLinkPressed(h)end end self.selection=nil end a.handled=true elseif\nnot a.handled and a.name==Event.MOUSEDRAG and\nself.selection and self.selection.holding then\nlocal h,r,d=t.textSelection.getCharacter(self,a.x-self.ox,a.y-self.oy,o,i,n,s)self.selection.pos2=h self.selection.char2=d\nself.selection.line2=r self.selection.initialised=true\nt.textSelection.selectRange(self,o,self.selection.line1,self.selection.char1,r,d)self.changed=true end end\nfunction t.textSelection:handleKeyboardEvent(a,o)\nif\n\nnot a.handled and a.name==Event.KEYDOWN and self.selection and self.selection.initialised then\nif a:matchesHotkey\"ctrl-c\"or a:matchesHotkey\"ctrl-x\"then local i=\"\"\nlocal n={}local s,h=self.selection.pos1,self.selection.pos2\nfor r=math.min(s,h),math.max(s,h)\ndo i=i..o[r].pixel[3]n[#n+1]=o[r].pixel end e.put{{\"plaintext\",i},{\"text\",n}}\na.handled=true end end end return t";
  16.     ["util.UIDrawingHelpers"] = "local e=require\"util.UIEventHelpers\"local t={}t.scrollbar={}\nfunction t.scrollbar:drawScrollbars()\nlocal a,o=e.scrollbar.active(self)local i,n=e.scrollbar.getBarInfo(self,\"right\",a,o,x,y)\nlocal s,h=e.scrollbar.getBarInfo(self,\"bottom\",a,o,x,y)\nif a then\nself.canvas:drawVerticalLine(self.width-1,0,o and self.height-1 or self.height,{colour=colours.grey})\nself.canvas:drawVerticalLine(self.width-1,i,n,{colour=self.scrollbar_mounted_side==\"right\"and\ncolours.lightBlue or colours.lightGrey})end\nif o then\nself.canvas:drawHorizontalLine(0,self.height-1,a and self.width-1 or self.width,{colour=colours.grey})\nself.canvas:drawHorizontalLine(s,self.height-1,h,{colour=\nself.scrollbar_mounted_side==\"bottom\"and colours.lightBlue or colours.lightGrey})end if a and o then\nself.canvas:drawPoint(self.width-1,self.height-1,{colour=colours.grey})end end return t";
  17.     ["UIContainer"] = "require\"UIElement\"require\"Event.MouseEvent\"\nlocal e=require\"util.UIDrawingHelpers\"local t=require\"util.UIEventHelpers\"class\"UIContainer\"\nextends\"UIElement\"{colour=1,scrollbars=true}UIContainer:mixin(t.scrollbar.mixin)\nfunction UIContainer:draw()if\nnot self.changed then return end local a=self.canvas\na:clear(self.colour)self.super:draw()if self.scrollbars then\ne.scrollbar.drawScrollbars(self)end end\nfunction UIContainer:onMouseEvent(a)if a:isInArea(0,0,self.width,self.height)then\nt.scrollbar.handleMouseScroll(self,a)end end\nfunction UIContainer:handle(a)if a:typeOf(MouseEvent)and self.scrollbars then\nt.scrollbar.handleMouseEvent(self,a)end\nreturn UIElement.handle(self,a)end\nfunction UIContainer:getContentWidth()local a=0 for o=1,#self.children do\na=math.max(a,self.children[o].x+\nself.children[o].width)end return a end\nfunction UIContainer:getContentHeight()local a=0 for o=1,#self.children do\na=math.max(a,self.children[o].y+\nself.children[o].height)end return a end\nfunction UIContainer:setWidth(a)self.super:setWidth(a)\nif\nself:getContentWidth()+self.ox<self.width then self.ox=math.min(0,self.width-\nself:getContentWidth())end end\nfunction UIContainer:setHeight(a)self.super:setHeight(a)\nif\nself:getContentHeight()+self.oy<self.height then self.oy=math.min(0,self.height-\nself:getContentHeight())end end\nfunction UIContainer:setColour(a)self.raw.colour=a self.changed=true end\nfunction UIContainer:setScrollbars(a)self.raw.scrollbars=a self.changed=true end";
  18.     ["UIWindow"] = "require\"UIElement\"require\"UIContainer\"require\"Event.MouseEvent\"\nlocal e=require\"util.UIDrawingHelpers\"local t=require\"util.UIEventHelpers\"class\"UIWindow\"\nextends\"UIElement\"{minWidth=15,minHeight=6,maxWidth=term.getSize(),maxHeight=select(2,term.getSize()),title=\"Window\",titleColour=colours.cyan,titleTextColour=colours.white,shadowColour=colours.grey,closeable=true,resizeable=true,moveable=true,content=\nnil}UIWindow:mixin(t.scrollbar.mixin)function UIWindow:init(a,o,i,n)\nself.super:init(a,o,i,n)\nself.content=self:addChild(UIContainer(0,1,i-1,n-2))end\nfunction UIWindow:onMouseEvent(a)if\na.handled then return end\nif a.name==Event.MOUSEDOWN and\na:isInArea(0,0,self.width,self.height)then\nif\na.y==0 and a.x==self.width-2 and self.closeable then\nif self.onClose then self:onClose()end self:remove()elseif\na.x==self.width-1 and a.y==self.height-1 and self.resizeable then\nself.dragging={button=a.button,mode=\"resize\"}elseif a.y==0 and a.x<self.width-1 and self.moveable then\nself.dragging={x=a.x,y=a.y,button=a.button,mode=\"move\"}end a.handled=true elseif a.name==Event.MOUSEDRAG and self.dragging and\nself.dragging.mode==\"move\"then self.x=self.x+a.x-\nself.dragging.x\nself.y=self.y+a.y-self.dragging.y if self.onMove then self:onMove()end elseif\na.name==Event.MOUSEDRAG and\nself.dragging and self.dragging.mode==\"resize\"then self.width=a.x+1 self.height=a.y+1\nif self.onResize then self:onResize()end elseif a.name==Event.MOUSEUP and self.dragging then if\na.button==self.dragging.button then a.handled=true self.dragging=nil end end end\nfunction UIWindow:onDraw()self.canvas:clear()\nself.canvas:drawVerticalLine(self.width-\n1,1,self.height-1,{colour=self.shadowColour})\nself.canvas:drawHorizontalLine(1,self.height-1,self.width-1,{colour=self.shadowColour})\nself.canvas:drawHorizontalLine(0,0,self.width-1,{colour=self.titleColour})\nself.canvas:drawText(0,0,{text=self.title,textColour=self.titleTextColour})if self.closeable then\nself.canvas:drawPoint(self.width-2,0,{character=\"x\",colour=colours.red,textColour=colours.white})end end\nfunction UIWindow:handle(a)\nif\nnot a.handled and a:typeOf(MouseEvent)and\na.name==Event.MOUSEDOWN and a:isInArea(0,0,self.width,self.height)then local o=self.parent if\no and o.children[#o.children]~=self then o:addChild(self)end end return UIElement.handle(self,a)end\nfunction UIWindow:setWidth(a)\nself.super:setWidth(math.max(math.min(a,self.maxWidth),self.minWidth))self.content.width=self.width-1 end\nfunction UIWindow:setHeight(a)\nself.super:setHeight(math.max(math.min(a,self.maxHeight),self.minHeight))self.content.height=self.height-2 end\nfunction UIWindow:setTitle(a)self.raw.title=tostring(a)self.changed=true end\nfunction UIWindow:setTitleColour(a)self.raw.titleColour=a self.changed=true end\nfunction UIWindow:setTitleTextColour(a)self.raw.titleTextColour=a self.changed=true end\nfunction UIWindow:setCloseable(a)self.raw.closeable=a self.changed=true end\nfunction UIWindow:setShadowColour(a)self.raw.shadowColour=a self.changed=true end function UIWindow:setMinWidth(a)if a>self.width then self.width=a end\nself.raw.minWidth=a end\nfunction UIWindow:setMaxWidth(a)if a<self.width then\nself.width=a end self.raw.maxWidth=a end function UIWindow:setMinHeight(a)if a>self.height then self.height=a end\nself.raw.minHeight=a end\nfunction UIWindow:setMaxHeight(a)if\na<self.height then self.height=a end self.raw.maxHeight=a end";
  19.     ["graphics.shader"] = "local e={}\ne.darken={[colours.white]=colours.lightGrey,[colours.orange]=colours.brown,[colours.magenta]=colours.purple,[colours.lightBlue]=colours.cyan,[colours.yellow]=colours.orange,[colours.lime]=colours.green,[colours.pink]=colours.magenta,[colours.grey]=colours.black,[colours.lightGrey]=colours.grey,[colours.cyan]=colours.blue,[colours.purple]=colours.grey,[colours.blue]=colours.grey,[colours.brown]=colours.black,[colours.green]=colours.grey,[colours.red]=colours.brown,[colours.black]=colours.black}\ne.lighten={[colours.white]=colours.white,[colours.orange]=colours.yellow,[colours.magenta]=colours.pink,[colours.lightBlue]=colours.white,[colours.yellow]=colours.white,[colours.lime]=colours.white,[colours.pink]=colours.white,[colours.grey]=colours.lightGrey,[colours.lightGrey]=colours.white,[colours.cyan]=colours.lightBlue,[colours.purple]=colours.magenta,[colours.blue]=colours.cyan,[colours.brown]=colours.red,[colours.green]=colours.lime,[colours.red]=colours.orange,[colours.black]=colours.grey}\ne.greyscale={[colours.white]=1,[colours.orange]=256,[colours.magenta]=256,[colours.lightBlue]=256,[colours.yellow]=1,[colours.lime]=256,[colours.pink]=1,[colours.grey]=128,[colours.lightGrey]=256,[colours.cyan]=128,[colours.purple]=128,[colours.blue]=32768,[colours.brown]=32768,[colours.green]=128,[colours.red]=128,[colours.black]=32768}\ne.sepia={[colours.white]=1,[colours.orange]=2,[colours.magenta]=2,[colours.lightBlue]=2,[colours.yellow]=1,[colours.lime]=2,[colours.pink]=1,[colours.grey]=2,[colours.lightGrey]=2,[colours.cyan]=16,[colours.purple]=16,[colours.blue]=4096,[colours.brown]=4096,[colours.green]=16,[colours.red]=16,[colours.black]=4096}return e";
  20.     ["ComputerWindow"] = "require\"UITerminal\"require\"UIWindow\"local e=require\"graphics.shader\"\nlocal function t(a)\nlocal o=a.width\nfor i=0,a.width-1 do for n=0,a.height-1 do local s=a.buffer[n*o+i+1]s[1]=\ne.greyscale[s[1]]or s[1]\ns[2]=e.greyscale[s[2]]or s[2]end end end class\"ComputerWindow\"\nextends\"UIWindow\"{COMPUTER_WIDTH=51,COMPUTER_HEIGHT=19,POCKET_WIDTH=26,POCKET_HEIGHT=20,TURTLE_WIDTH=39,TURTLE_HEIGHT=17,isAdvanced=false}\nfunction ComputerWindow:init(a,o,i,n)\nif o==\"default\"then\nself.super:init(0,0,self.COMPUTER_WIDTH+1,\nself.COMPUTER_HEIGHT+2)elseif o==\"turtle\"then\nself.super:init(0,0,self.TURTLE_WIDTH+1,self.TURTLE_HEIGHT+2)elseif o==\"pocket\"then\nself.super:init(0,0,self.POCKET_WIDTH+1,self.POCKET_HEIGHT+2)else self.super:init(0,0,20,10)end self.title=a\nself.titleColour=i and colours.yellow or colours.lightGrey self.titleTextColour=colours.black self.resizeable=n function self:onResize()\nself.title=a..\n\" (\"..\nself.content.width..\"x\"..self.content.height..\")\"end\nself.screen=self.content:addChild(UITerminal(0,0,self.content.width,self.content.height))self.screen.canvas.isColour=i self.isAdvanced=i end function ComputerWindow:setWidth(a)self.super:setWidth(a)\nself.screen.width=self.content.width end\nfunction ComputerWindow:setHeight(a)\nself.super:setHeight(a)self.screen.height=self.content.height end\nfunction ComputerWindow:draw()if not self.changed then return end self.changed=false\nlocal a=self.canvas a.cursor=nil self:onDraw()local o=self.content o:draw()if\nnot self.isAdvanced then t(o.canvas)end\no.canvas:drawTo(a,o.x+self.ox,o.y+self.oy)if o.canvas.cursor then\na.cursor={x=o.canvas.cursor.x+o.x+self.ox,y=\no.canvas.cursor.y+o.y+self.oy,colour=o.canvas.cursor.colour}end end";
  21.     ["newFilesystemRedirect"] = "\nlocal function e(t)if t==\"..\"then return\"\"end return\nt:gsub(\"//+\",\"/\"):gsub(\"/.-/%.%./\",\"/\"):gsub(\"^.-/%.%./\",\"\"):gsub(\"^%.%./\",\"\"):gsub(\"/%./\",\"/\"):gsub(\"^/+\",\"\"):gsub(\"/+$\",\"\")end\nfunction newFilesystemRedirect(t)t=e(t)if t==\"\"then return fs end if not fs.isDir(t)then\nfs.makeDir(t)end local a={}\nlocal o={\"combine\",\"getName\",\"getDir\",\"getDrive\"}for n=1,#o do a[o[n]]=fs[o[n]]end\nlocal i={\"exists\",\"isDir\",\"makeDir\",\"delete\",\"isReadOnly\",\"getFreeSpace\",\"getSize\",\"open\"}for n=1,#i do\na[i[n]]=function(s,...)s=e(s)\nif s:sub(1,4)==\"rom/\"or s==\"rom\"then return\nfs[i[n]](s,...)else return fs[i[n]](t..\"/\"..s,...)end end end\nfunction a.list(n)\nn=e(n)\nif n:sub(1,4)==\"rom/\"or n==\"rom\"then return fs.list(n)end if n==\"\"then local s=fs.list(t)s[#s+1]=\"rom\"return s end return fs.list(\nt..\"/\"..n)end\nfunction a.copy(n,s)n=e(n)s=e(s)\nn=n:sub(1,4)==\"rom/\"and n or t..\"/\"..n\ns=s:sub(1,4)==\"rom/\"and s or t..\"/\"..s return fs.copy(n,s)end\nfunction a.move(n,s)n=e(n)s=e(s)\nn=n:sub(1,4)==\"rom/\"and n or t..\"/\"..n\ns=s:sub(1,4)==\"rom/\"and s or t..\"/\"..s return fs.move(n,s)end\nfunction a.complete(n,s,h,r)local d={}h=(h~=false)r=(r~=false)local l=s local u=1\nlocal c=string.find(n,\"[/\\\\]\",u)if c==1 then l=\"\"u=2 end local m\nwhile not m do local c=string.find(n,\"[/\\\\]\",u)if c then local f=string.sub(n,u,\nc-1)l=fs.combine(l,f)u=c+1 else\nm=string.sub(n,u)end end\nif fs.isDir(t..\"/\"..l)then local f={}\nif r and n==\"\"then table.insert(f,\".\")end if l~=\"\"then\nif n==\"\"then table.insert(f,(r and\"..\")or\"../\")elseif\nn==\".\"then table.insert(f,(r and\".\")or\"./\")end end\nlocal w=fs.list(t..\"/\"..l)\nfor y=1,#w do local p=w[y]\nif#p>=#m and string.sub(p,1,#m)==m then local v=fs.isDir(t..\"/\"..\nfs.combine(l,p))\nlocal b=string.sub(p,#m+1)\nif v then table.insert(f,b..\"/\")\nif r and#b>0 then table.insert(f,b)end else if h and#b>0 then table.insert(f,b)end end end end return f end return d end\nfunction a.find(n)n=e(n)\nlocal function s(n,h)\nlocal r=\"^\"..\n(n:match\"^(.-)/\"or n):gsub(\"%*\",\"%.*\")..\"$\"local d=fs.list(t..\"/\"..h)\nfor l in n:gmatch\"[^/]+\"do for u=#d,1,-1 do if not d[u]:find(r)then\ntable.remove(d,u)end end end for l=1,#d do d[l]=h..\"/\"..d[l]end if n:find\"/\"then local l={}\nfor u=1,#d do for c,t in\nipairs(s(n:match\"/(.+)$\",d[u]))do l[#l+1]=t end end return l else return d end end return s(n,\"\")end return a end";
  22.     ["newComputerEnvironment"] = "local e=0 require\"newFilesystemRedirect\"\nfunction newComputerEnvironment(t)\nlocal a=setmetatable({},{__index=_G})a._G=a local o=newFilesystemRedirect(t.filesystemRoot)a.fs=o a.pocket=\nt.mode==\"pocket\"or nil\nfunction a.load(l,u,c,m)return load(l,u,c,m or a)end function a.loadstring(l,u)return load(l,u,nil,a)end\nfunction a.loadfile(l)\nlocal u=o.open(l,\"r\")if u then local c,m=load(u.readAll(),o.getName(l),nil,a)\nu.close()return c,m end return false,\"File not found\"end\nfunction a.dofile(l)local u=o.open(l,\"r\")if u then\nlocal c,m=load(u.readAll(),o.getName(l),nil,\ngetfenv and getfenv(2)or a)u.close()return c()end return\nerror\"File not found\"end a.os={}a.io={}a.os.version=os.version a.os.setAlarm=os.setAlarm\na.os.cancelAlarm=os.cancelAlarm a.os.time=os.time a.os.day=os.day a.os.clock=os.clock\na.os.pullEvent=os.pullEvent a.os.pullEventRaw=os.pullEventRaw a.os.sleep=sleep function a.os.getComputerLabel()\nreturn t.name end function a.os.computerLabel()return t.name end function a.os.setComputerLabel(l)\nt.name=tostring(l)t.window.title=tostring(l)end function a.os.getComputerID()return\nt.ID end function a.os.computerID()return t.ID end\nfunction a.os.run(l,u,...)\nlocal c=o.open(u,\"r\")\nif c then\nlocal m,f=load(c.readAll(),o.getName(u),nil,setmetatable(l,{__index=a}))c.close()local w,f=pcall(m,...)if w then return true end if f and f~=\"\"then\nprintError(f)end return false end printError\"File not found\"return false end local i={}\nfunction a.os.loadAPI(l)local u=o.getName(l)if i[u]then\nprintError(\"API \"..u..\" is already being loaded\")return false end i[u]=true\nlocal c=o.open(l,\"r\")\nif c then local m=setmetatable({},{__index=a})\nlocal w,y=load(c.readAll(),o.getName(l),nil,m)c.close()w()local p={}for f,b in pairs(m)do p[f]=b end a[u]=p i[u]=nil return true end i[u]=nil printError\"File not found\"return false end function a.os.unloadAPI(l)\nif l~=\"_G\"and type(a[l])==\"table\"then a[l]=nil end end\nfunction a.os.shutdown()t:close()end function a.os.reboot()t:close()end\nfunction a.os.queueEvent(...)t:resume(...)end local n={}function a.os.startTimer(l)return os.startTimer(l)end function a.os.cancelTimer(l)\nn[l]=true end\nlocal s={bFileHandle=true,bClosed=false,close=function(l)end,read=function(l,u)if u and u~=\"*l\"then\nerror(\"Unsupported format\")end return a.read()end,lines=function(l)return function()return\na.read()end end}\nlocal h={bFileHandle=true,bClosed=false,close=function(l)end,write=function(l,u)a.write(u)end,flush=function(l)end}local r=s local d=h function a.io.close(l) (l or d):close()end function a.io.flush()\nd:flush()end\nfunction a.io.input(l)\nif a.type(l)==\"string\"then r=a.io.open(l,\"r\")elseif\na.type(l)==\"table\"then r=l elseif a.type(l)==\"nil\"then return r else\nerror(\"Expected file name or file handle\")end end\nfunction a.io.lines(l)if l then return a.io.open(l,\"r\"):lines()else\nreturn r:lines()end end\nfunction a.io.open(l,u)local c=u or\"r\"local m=o.open(l,c)if not m then return nil end\nif c==\"r\"then\nreturn\n{bFileHandle=true,bClosed=false,close=function(f)\nm.close()f.bClosed=true end,read=function(f,w)local y=w or\"*l\"\nif y==\"*l\"then return m.readLine()elseif\ny==\"*a\"then return m.readAll()else error(\"Unsupported format\")end return nil end,lines=function(f)return\nfunction()\nlocal w=m.readLine()if w==nil then m.close()f.bClosed=true end return w end end}elseif c==\"w\"or c==\"a\"then return\n{bFileHandle=true,bClosed=false,close=function(f)m.close()f.bClosed=true end,write=function(f,w)\nm.write(w)end,flush=function(f)m.flush()end}elseif c==\n\"rb\"then return\n{bFileHandle=true,bClosed=false,close=function(f)m.close()f.bClosed=true end,read=function(f)return m.read()end}elseif\nc==\"wb\"or c==\"ab\"then return\n{bFileHandle=true,bClosed=false,close=function(f)m.close()f.bClosed=true end,write=function(f,w)m.write(w)end,flush=function(f)\nm.flush()end}else\nm.close()error(\"Unsupported mode\")end end\nfunction a.io.output(l)\nif _G.type(l)==\"string\"then d=a.io.open(l,\"w\")elseif\n_G.type(l)==\"table\"then d=l elseif _G.type(l)==\"nil\"then return d else\nerror(\"Expected file name or file handle\")end end\nfunction a.io.read(...)return a.io.input():read(...)end\nfunction a.io.type(l)\nif _G.type(l)==\"table\"and l.bFileHandle==true then if l.bClosed then return\n\"closed file\"else return\"file\"end end return nil end\nfunction a.io.write(...)return a.io.output():write(...)end return a end";
  23.     ["Computer"] = "require\"ComputerWindow\"require\"newComputerEnvironment\"\nlocal e=fs.open(\"rom/programs/shell\",\"r\")local t=e.readAll()e.close()\nclass\"Computer\"{manager=nil,ID=0,name=\"Computer\",mode=\"default\",isAdvanced=false,filesystemRoot=nil,window=nil,screen=nil,coroutine=nil,filter=nil,environment=nil,filesystem=nil,queue={}}\nfunction Computer:init(a,o,i)self.manager=a self.ID=o self.name=\ni.name==\"\"and\"Emulated Computer\"or i.name self.mode=i.mode\nself.isAdvanced=i.isAdvanced self.filesystemRoot=i.filesystemRoot\nself.window=a.content:addChild(ComputerWindow(self.name,self.mode,i.isAdvanced,i.resizeable))self.screen=self.window.screen\nself.environment=newComputerEnvironment(self)self.filesystem=self.environment.fs function self.window.onClose()\nself:close()end\nlocal n,s=load(t,\"shell\",nil,self.environment)if not n then return self:showError(s)end function self.screen.onEvent(h,...)\nself:resume(...)end\nself.coroutine=coroutine.create(n)self.queue={}end\nfunction Computer:showError(a)\nself.window.content:addChild(UIText(0,0,self.window.content.width,self.window.content.height,a)).textColour=colours.red end\nfunction Computer:resume(a,...)self.queue[#self.queue+1]={a,...}if\nself.running then return end self.running=true\nwhile self.queue[1]do\nlocal a=self.queue[1][1]\nif self.filter and a~=self.filter then\ntable.remove(self.queue,1)else local o=self.screen:wrap()\nlocal i,n=coroutine.resume(self.coroutine,unpack(table.remove(self.queue,1)))term.redirect(o)if i then self.filter=n else self:showError(n)\nself.screen:remove()break end\nif\ncoroutine.status(self.coroutine)==\"dead\"then self:close()break end end end self.running=false end\nfunction Computer:close()self.manager:close(self.ID)end";
  24.     ["UIButton"] = "require\"UIElement\"local e=require\"graphics.shader\"\nlocal t=require\"util.UIEventHelpers\"class\"UIButton\"\nextends\"UIElement\"{colour=1,textColour=colours.grey,text=\"\",holding=false,noAlign=false}\nfunction UIButton:init(a,o,i,n,s)self.super:init(a,o,i,n)self.text=s end\nfunction UIButton:onMouseEvent(a)local o=t.clicking.handleMouseEvent(self,a)\nif\no==\"down\"or o==\"up\"then self.holding=o==\"down\"elseif o==\"click\"then\nself.holding=false if self.onClick then self:onClick(a.button)end end end\nfunction UIButton:onDraw()\nif self.holding then local a=e.lighten[self.colour]\nself.canvas:clear(a==\nself.colour and e.darken[a]or a)else self.canvas:clear(self.colour)end\nself.canvas:drawWrappedText(0,0,self.width,self.height,{text=self.text,alignment=self.noAlign and\"left\"or\"centre\",verticalAlignment=\nself.noAlign and\"top\"or\"centre\",textColour=self.textColour})end\nfunction UIButton:setHolding(a)self.raw.holding=a self.changed=true end function UIButton:setText(a)\nself.raw.text=a==nil and\"\"or tostring(a)self.changed=true end function UIButton:setColour(a)\nself.raw.colour=a self.changed=true end function UIButton:setTextColour(a)\nself.raw.textColour=a self.changed=true end";
  25.     ["UICheckbox"] = "require\"UIElement\"local e=require\"util.UIEventHelpers\"\nclass\"UICheckbox\"\nextends\"UIElement\"{colour=colours.lightGrey,checkColour=colours.black,check=\"x\",toggled=false}\nfunction UICheckbox:init(t,a)self.super:init(t,a,1,1)end function UICheckbox:onLabelPressed()self.toggled=not self.toggled if self.onToggle then\nself:onToggle()end end\nfunction UICheckbox:onMouseEvent(t)\nif\ne.clicking.handleMouseEvent(self,t)==\"click\"then self.toggled=not self.toggled if self.onToggle then\nself:onToggle()end end end\nfunction UICheckbox:onDraw()self.canvas:clear(self.colour)\nself.canvas:drawPoint(0,0,{colour=self.colour})if self.toggled then\nself.canvas:drawText(0,0,{textColour=self.checkColour,text=self.check})end end function UICheckbox:setWidth()end function UICheckbox:setHeight()end function UICheckbox:setHolding(t)\nself.raw.holding=t self.changed=true end function UICheckbox:setColour(t)\nself.raw.colour=t self.changed=true end function UICheckbox:setCheckColour(t)\nself.raw.checkColour=t self.changed=trur end function UICheckbox:setCheck(t)\nself.raw.check=tostring(t)self.changed=true end function UICheckbox:setToggled(t)\nself.raw.toggled=t self.changed=true end";
  26.     ["UILabel"] = "require\"UIElement\"local e=require\"util.UIEventHelpers\"class\"UILabel\"\nextends\"UIElement\"{link=\nnil,textColour=colours.lightGrey,text=\"\"}function UILabel:init(t,a,o,i)self.super:init(t,a,#o,1)self.raw.text=o\nself.raw.link=i end\nfunction UILabel:onMouseEvent(t)\nlocal a=e.clicking.handleMouseEvent(self,t)\nif a==\"click\"then if self.link and self.link.onLabelPressed then\nself.link:onLabelPressed()end end end function UILabel:onDraw()\nself.canvas:drawText(0,0,{text=self.text:sub(1,self.width),textColour=self.textColour})end function UILabel:setText(t)self.width=\n#tostring(t)self.raw.text=tostring(t)\nself.changed=true end function UILabel:setTextColour(t)\nself.raw.textColour=t self.changed=true end";
  27.     ["UIRadioButton"] = "require\"UIElement\"local e=require\"util.UIEventHelpers\"local t={[0]={}}\nclass\"UIRadioButton\"\nextends\"UIElement\"{colour=colours.lightGrey,checkColour=colours.black,check=\"@\",group=0,toggled=false}function UIRadioButton:init(a,o)self.super:init(a,o,1,1)t[0]=t[0]or{}t[0][\n#t[0]+1]=self end function UIRadioButton:onLabelPressed()self.toggled=\nnot self.toggled end\nfunction UIRadioButton:onMouseEvent(a)if\ne.clicking.handleMouseEvent(self,a)==\"click\"then self.holding=false\nself.toggled=not self.toggled end end\nfunction UIRadioButton:onDraw()self.canvas:clear(self.colour)\nself.canvas:drawPoint(0,0,{colour=self.colour})if self.toggled then\nself.canvas:drawText(0,0,{textColour=self.checkColour,text=self.check})end end function UIRadioButton:setWidth()end function UIRadioButton:setHeight()end function UIRadioButton:setHolding(a)\nself.raw.holding=a self.changed=true end function UIRadioButton:setColour(a)\nself.raw.colour=a self.changed=true end function UIRadioButton:setCheckColour(a)\nself.raw.checkColour=a self.changed=trur end function UIRadioButton:setCheck(a)\nself.raw.check=a self.changed=true end\nfunction UIRadioButton:setToggled(a)if a then\nfor n=1,#\nt[self.group]do t[self.group][n].toggled=false end end local o=self.toggled\nself.raw.toggled=a if a~=o and self.onToggle then self:onToggle()end\nself.changed=true end\nfunction UIRadioButton:setGroup(a)for o=#t[self.group],1,-1 do\nif\nt[self.group][o]==self then table.remove(t[self.group],o)end end if\n#t[self.group]==0 then t[self.group]=nil end t[a]=t[a]or{}\nt[a][#t[a]+1]=self self.raw.group=a end";
  28.     ["util.markup"] = "local e={}for n=0,15 do e[(\"%x\"):format(n)]=2^n e[(\"%X\"):format(n)]=\n2^n end e[\" \"]=0\nlocal function t(n,s,h,r)local d={}local l=1\nlocal u,c=\"left\",nil local m=1\nwhile m<=#n do\nif n:sub(m,m)==\"@\"and r then m=m+1 local f=n:sub(m,m)\nif f==\"b\"then\ns=e[n:sub(m+1,m+1)]m=m+2 elseif f==\"t\"then h=e[n:sub(m+1,m+1)]m=m+2 elseif f==\"a\"then\nlocal w=n:sub(m+1,m+1)u=(w==\"c\"and\"centre\")or(w==\"r\"and\"right\")or\n\"left\"m=m+2 elseif f==\"m\"then\nif n:sub(m+1,m+1)==\n\"-\"then c=nil m=m+2 else local w=n:match(\"m%((.-)%)\",m)if w then c=w m=m+3+#w else\nd[l]={pixel={s,h,\"m\"},tag=c,alignment=u}l=l+1 m=m+1 end end elseif f==\"l\"then local w,y=n:match(\"l%[(.-)%]%((.-)%)\",m)\nif w then m=m+5+#w+#y for p=1,#w\ndo d[l]={pixel={s,h,w:sub(p,p)},tag=c,alignment=u,link=y}l=l+\n1 end else\nd[l]={pixel={s,h,\"l\"},tag=c,alignment=u}l=l+1 m=m+1 end else d[l]={pixel={s,h,n:sub(m,m)},tag=c,alignment=u}l=l+1\nm=m+1 end else d[l]={pixel={s,h,n:sub(m,m)},tag=c,alignment=u}l=l+1\nm=m+1 end end return d end\nlocal function a(n,s,h)for r=s,s+math.min(h or#n-s,#n-s)do\nif n[r].pixel[3]==\"\\n\"then return r end end\nif not h or#n-s+1 <=h then return#n end\nfor r=s+h,s,-1 do if n[r].pixel[3]:find\"%s\"then while\nn[r+1].pixel[3]:find\"%s\"do r=r+1 end return r end end return s+h-1 end\nlocal function o(n,s,h)local r,l={},1\nwhile l<=#n do local d=a(n,l,s)r[#r+1]={l,d}l=d+1 end local u,c={},{}if h then error(h)end\nfor d=1,math.min(h or#r,#r)do\nlocal m=n[r[d][1]].alignment u[d]={alignment=m}c[d]={alignment=m}local f=1 for w=r[d][1],r[d][2]do u[d][f]=n[w]\nc[d][f]=n[w].pixel f=f+1 end end return u,c,n end local i={}function i.parse(n,s,h,r,d,l)return o(t(n,s,h,l),r,d)end return i";
  29.     ["UIText"] = "require\"UIElement\"local e=require\"util.markup\"\nlocal t=require\"util.UIDrawingHelpers\"local a=require\"util.UIEventHelpers\"class\"UIText\"\nextends\"UIElement\"{colour=1,textColour=colours.grey,text=\"\",selectedColour=colours.blue,selectedTextColour=colours.white,alignment=\"top\",wrap=true,selectable=true,internalWidth=\nnil,internalHeight=nil,formattedText=nil,formattedTextInfo=nil,handlesKeyboard=true}UIText:mixin(a.scrollbar.mixin)function UIText:init(o,i,n,s,h)\nself.super:init(o,i,n,s)self.text=h end\nfunction UIText:onMouseEvent(o)\na.scrollbar.handleMouseEvent(self,o)a.scrollbar.handleMouseScroll(self,o)\nif self.selectable then\na.textSelection.handleMouseEvent(self,o,self.formattedTextInfo,self.alignment,math.max(self:getContentWidth(),\nself.internalWidth or self.width),math.max(self:getContentHeight(),\nself.internalHeight or self.height))end end\nfunction UIText:onKeyboardEvent(o)if self.selectable then\na.textSelection.handleKeyboardEvent(self,o,self.stream)end end\nfunction UIText:onDraw()self.canvas:clear(self.colour)\nself.canvas:drawPreformattedText(self.ox,self.oy,math.max(self:getContentWidth(),\nself.internalWidth or self.width),math.max(self:getContentHeight(),\nself.internalHeight or self.height),{text=self.formattedText,verticalAlignment=self.alignment,selectedColour=self.selectedColour,selectedTextColour=self.selectedTextColour})t.scrollbar.drawScrollbars(self)end\nfunction UIText:updateText()\nlocal o,i,n=e.parse(self.text,self.colour,self.textColour,self.wrap and\n(self.internalWidth or self.width),self.wrap and self.internalHeight,true)self.formattedTextInfo,self.formattedText,self.stream=o,i,n\nself.changed=true end\nfunction UIText:getContentWidth()local o=0 for n=1,#self.formattedText do\no=math.max(\n#self.formattedText[n]-\n(\nself.formattedText[n][#self.formattedText[n]][3]==\"\\n\"and 1 or 0),o)end return o end\nfunction UIText:getContentHeight()return#self.formattedText end\nfunction UIText:setText(o)self.raw.text=tostring(o)self:updateText()end\nfunction UIText:setColour(o)self.raw.colour=o self:updateText()end\nfunction UIText:setTextColour(o)self.raw.textColour=o self:updateText()end\nfunction UIText:setWrap(o)self.raw.wrap=o self:updateText()end\nfunction UIText:setInternalWidth(o)self.raw.internalWidth=o self:updateText()end\nfunction UIText:setInternalHeight(o)self.raw.internalHeight=o self:updateText()end\nfunction UIText:setWidth(o)self.super:setWidth(o)\nself:updateText()if self:getContentWidth()+self.ox<self.width then\nself.ox=math.min(0,\nself.width-self:getContentWidth())end end\nfunction UIText:setHeight(o)self.super:setHeight(o)\nself:updateText()if self:getContentHeight()+self.oy<self.height then\nself.oy=math.min(0,\nself.height-self:getContentHeight())end end\nfunction UIText:setAlignment(o)self.raw.alignment=o self.changed=true end\nfunction UIText:setSelectedColour(o)self.raw.selectedColour=o self.changed=true end\nfunction UIText:setSelectedTextColour(o)self.raw.selectedTextColour=o self.changed=true end";
  30.     ["UITextInput"] = "require\"UIElement\"local e=require\"clipboard\"class\"UITextInput\"\nextends\"UIElement\"{text=\"\",mask=\nnil,colour=colours.lightGrey,textColour=colours.grey,focussedColour=colours.white,focussedTextColour=colours.grey,selectedColour=colours.blue,selectedTextColour=colours.white,cursor=0,selection=nil,focussed=false,handlesKeyboard=true,handlesText=true}\nfunction UITextInput:init(t,a,o)self.super:init(t,a,o,1)end\nfunction UITextInput:write(t)\nif self.selection then\nself.raw.text=\nself.text:sub(1,math.min(self.selection,self.cursor))..t..\nself.text:sub(math.max(self.selection,self.cursor)+2)\nself.cursor=math.min(self.selection,self.cursor)+#t self.selection=nil else\nself.raw.text=self.text:sub(1,self.cursor)..t..self.text:sub(\nself.cursor+1)self.cursor=self.cursor+#t end end\nfunction UITextInput:focusOn()if#self.text>0 then self.selection=0 end self.cursor=\n#self.text self.focussed=true self.changed=true end function UITextInput:onLabelPressed()self:focusOn()end\nfunction UITextInput:setCursor(t)self.raw.cursor=math.max(math.min(t,\n#self.text),0)if self.cursor+\nself.ox<1 then self.ox=math.min(-self.cursor,0)elseif\nself.cursor+self.ox>=self.width-1 then\nself.ox=self.width-1-self.cursor end end\nfunction UITextInput:onMouseEvent(t)\nif t.name==Event.MOUSEDOWN and t.handled then if self.onUnFocus then\nself:onUnFocus()end self.focussed=false self.changed=true end if t.handled then return end\nif t.name==Event.MOUSEDOWN then\nif\nt:isInArea(0,0,self.width,self.height)then self.focussed=true self.cursor=t.x-self.ox t.handled=true else if self.onUnFocus then\nself:onUnFocus()end self.focussed=false end self.selection=nil self.changed=true elseif\nt.name==Event.MOUSEDRAG and self.focussed then\nif not self.selection then self.selection=self.cursor end t.handled=true\nself.cursor=math.max(0,math.min(t.x-self.ox,#self.text))self.changed=true end end\nfunction UITextInput:onKeyboardEvent(t)\nif not t.handled and self.focussed and\nt.name==Event.KEYDOWN then\nif t:matchesHotkey\"shift-left\"then self.selection=self.selection or\nself.cursor self.cursor=self.cursor-1\nself.changed=true t.handled=true elseif t:matchesHotkey\"shift-right\"then\nself.selection=self.selection or self.cursor self.cursor=self.cursor+1 self.changed=true t.handled=true elseif\nt:matchesHotkey\"ctrl-a\"then self.cursor=#self.text self.selection=0 self.changed=true\nt.handled=true elseif t:matchesHotkey\"ctrl-c\"then\nif self.selection then\ne.put{{\"plaintext\",self.text:sub(\nmath.min(self.cursor,self.selection)+1,math.max(self.cursor,self.selection)+1)}}else e.put{{\"plaintext\",self.text}}end t.handled=true elseif t:matchesHotkey\"ctrl-x\"then\nif self.selection then\ne.put{{\"plaintext\",self.text:sub(\nmath.min(self.cursor,self.selection)+1,math.max(self.cursor,self.selection)+1)}}self:write\"\"else\ne.put{{\"plaintext\",self.text}}self.text=\"\"end self.changed=true t.handled=true elseif t:matchesHotkey\"ctrl-b\"then local a=e.get\"plaintext\"if\na then self:write(a)self.changed=true end t.handled=true elseif\nt:matchesHotkey\"left\"then\nif self.selection then\nself.cursor=math.min(self.cursor,self.selection)self.selection=nil else self.cursor=self.cursor-1 end self.changed=true t.handled=true elseif t:matchesHotkey\"right\"then\nif self.selection then\nself.cursor=math.max(self.cursor,self.selection)self.selection=nil else self.cursor=self.cursor+1 end self.changed=true t.handled=true elseif t:matchesHotkey\"backspace\"then\nif self.selection then\nself:write\"\"self.changed=true elseif self.cursor>0 then self.cursor=self.cursor-1\nself.text=\nself.text:sub(1,self.cursor)..self.text:sub(self.cursor+2)end t.handled=true elseif t:matchesHotkey\"shift-home\"then self.selection=self.cursor\nself.cursor=0 self.changed=true t.handled=true elseif t:matchesHotkey\"shift-end\"then\nself.selection=self.cursor self.cursor=#self.text self.changed=true t.handled=true elseif\nt:matchesHotkey\"home\"then self.cursor=0 self.selection=nil self.changed=true t.handled=true elseif\nt:matchesHotkey\"end\"then self.cursor=#self.text self.selection=nil self.changed=true\nt.handled=true elseif t:matchesHotkey\"delete\"then\nself.text=self.text:sub(1,self.cursor)..self.text:sub(\nself.cursor+2)t.handled=true elseif t:matchesHotkey\"enter\"then self.focussed=false self.changed=true if\nself.onEnter then self:onEnter()end t.handled=true elseif t:matchesHotkey\"tab\"then\nself.focussed=false self.changed=true if self.onTab then self:onTab()end\nt.handled=true end end end function UITextInput:onTextEvent(t)\nif not t.handled and self.focussed then\nself:write(t.text)self.changed=true t.handled=true end end\nfunction UITextInput:onDraw()\nself.canvas:clear(\nself.focussed and self.focussedColour or self.colour)\nif self.selection then\nlocal t,a=math.min(self.selection,self.cursor),math.max(self.selection,self.cursor)\nself.canvas:drawHorizontalLine(self.ox+t,0,\nmath.abs(self.selection-self.cursor)+1,{colour=self.selectedColour})\nself.canvas:drawText(self.ox,0,{text=(\nself.mask and self.mask:rep(#self.text)or self.text):sub(1,t),textColour=\nself.focussed and self.focussedTextColour or self.textColour})\nself.canvas:drawText(self.ox+t,0,{text=(\nself.mask and self.mask:rep(#self.text)or self.text):sub(\nt+1,a+1),textColour=self.selectedTextColour})\nself.canvas:drawText(self.ox+a+1,0,{text=(self.mask and\nself.mask:rep(#self.text)or self.text):sub(\na+2),textColour=\nself.focussed and self.focussedTextColour or self.textColour})else\nself.canvas:drawText(self.ox,0,{text=\nself.mask and self.mask:rep(#self.text)or self.text,textColour=self.focussed and self.focussedTextColour or\nself.textColour})end if self.focussed then\nself.canvas.cursor={x=self.cursor+self.ox,y=0,colour=self.focussedTextColour}end end\nfunction UITextInput:setText(t)self.raw.text=tostring(t)if#t<self.cursor then self.cursor=#\ntostring(t)end self.changed=true end\nfunction UITextInput:setMask(t)self.raw.mask=t self.changed=true end\nfunction UITextInput:setFocussedColour(t)self.raw.focussedColour=t self.changed=true end\nfunction UITextInput:setFocussedTextColour(t)self.raw.focussedTextColour=t self.changed=true end\nfunction UITextInput:setColour(t)self.raw.colour=t self.changed=true end\nfunction UITextInput:setTextColour(t)self.raw.textColour=t self.changed=true end\nfunction UITextInput:setSelectedColour(t)self.raw.selectedColour=t self.changed=true end\nfunction UITextInput:setSelectedTextColour(t)self.raw.selectedTextColour=t self.changed=true end\nfunction UITextInput:setFocussed(t)self.raw.focussed=t self.changed=true end function UITextInput:setHeight()end";
  31.     ["ComputerManager"] = "require\"Computer\"require\"UIButton\"require\"UICheckbox\"\nrequire\"UIContainer\"require\"UILabel\"require\"UIRadioButton\"require\"UIText\"\nrequire\"UITextInput\"local e=26 local t=16\nlocal a=math.floor(application.view.width/2-e/2)\nlocal o=math.floor(application.view.height/2-t/2)\nlocal i=[[\nYou can give your computer a custom root.\nThis means you can give the emulated computer a custom startup, custom files, etc.\nJust type in a path to a folder that you want it to treat as /.\n\nYou can also leave this blank and the normal filesystem will be used (this avoids bugs).\n]]\nlocal function n()\nlocal s=application.view:addChild(UIWindow(a,o,e,t))s.title=\"Filesystem Root Help\"s.resizeable=false\ns.content:addChild(UIText(0,0,s.content.width,s.content.height,i))end\nclass\"ComputerManager\"{sessionName=nil,opened={},display=nil}\nfunction ComputerManager:init(s)self.sessionName=s self.opened={}\nself.display=application.view:addChild(UIContainer(0,0,application.view.width,application.view.height))self.display.scrollbars=false\nself.content=self.display:addChild(UIContainer(0,0,self.display.width,self.display.height))\nlocal h=self.content:addChild(UIButton(1,1,7,3,\"New\"))h.colour=colours.cyan h.textColour=colours.white\nlocal r=self.content:addChild(UIButton(9,1,7,3,\"Close\"))r.colour=colours.cyan r.textColour=colours.white function h.onClick()\nself:showOpenDialogue()end function r.onClick()\nself.display:transitionOutLeft()newSession()end end\nfunction ComputerManager:open(s,h,...)local r=Computer(self,s,h)\nself.opened[#self.opened+1]=r r:resume(...)self:saveSession()end function ComputerManager:openNoID(s,...)\nself:open(self:getFreeID(),s,...)end\nfunction ComputerManager:close(s)for h=#self.opened,1,-1 do\nif\nself.opened[h].ID==s then\nself.opened[h].window:remove()table.remove(self.opened,h)self:saveSession()break end end end\nfunction ComputerManager:getFreeID()local s=-1 local h=true while h do h=false s=s+1\nfor r=1,#self.opened do if\nself.opened[r].ID==s then h=true break end end end return s end function ComputerManager:saveSession()end\nfunction ComputerManager:showOpenDialogue()\nlocal s=self.display:addChild(UIContainer(\n-26,0,26,self.display.height))s:transitionInLeft()\nlocal h=s:addChild(UIText(0,0,s.width-1,3,\"@ac@t0New Computer\"))h.colour=colours.grey h.alignment=\"centre\"\nlocal r=s:addChild(UIButton(s.width-2,0,1,1,\"x\"))r.colour=colours.grey r.textColour=colours.red function r:onClick()\ns:transitionOutLeft()end\nlocal d=s:addChild(UILabel(1,5,\"Computer Name\"))\nlocal l=s:addChild(UITextInput(1,6,s.width-3,1))\nlocal u=s:addChild(UILabel(1,8,\"Filesystem Root\"))\nlocal c=s:addChild(UIButton(s.width-3,8,1,1,\"i\"))\nlocal m=s:addChild(UITextInput(1,9,s.width-3,1))local f=s:addChild(UICheckbox(1,11))\nlocal w=s:addChild(UILabel(3,11,\"Colour Computer\",f))\nlocal y=s:addChild(UILabel(1,13,\"Computer Type\"))local p=s:addChild(UIRadioButton(2,14))\nlocal v=s:addChild(UILabel(4,14,\"Default Computer\",p))local b=s:addChild(UIRadioButton(2,15))\nlocal g=s:addChild(UILabel(4,15,\"Pocket Computer\",b))local k=s:addChild(UIRadioButton(2,16))\nlocal q=s:addChild(UILabel(4,16,\"Turtle\",k))local j=s:addChild(UICheckbox(1,18))\nlocal x=s:addChild(UILabel(3,18,\"Resizeable Window\",j))\nlocal z=s:addChild(UIButton(1,20,s.width-3,3,\"Create\"))l.focussedColour=colours.lightGrey c.textColour=colours.lightBlue\nm.focussedColour=colours.lightGrey f.toggled=true p.group=\"computer-types\"b.group=\"computer-types\"\nk.group=\"computer-types\"z.colour=colours.cyan z.textColour=colours.white\nfunction c:onClick()n()end\nfunction z.onClick()\nself:openNoID{name=l.text,mode=(k.toggled and\"turtle\")or\n(b.toggled and\"pocket\")or\"default\",isAdvanced=f.toggled,filesystemRoot=m.text,resizeable=j.toggled}s:transitionOutLeft()z.onClick=function()end end end";
  32.     ["init"] = "require\"ComputerManager\"\nfunction newSession()\nlocal t=application.view:addChild(UIContainer(application.view.width,0,application.view.width,application.view.height))\nt:addChild(UIText(0,1,t.width,1,\"@acNew Session\"))application:stop()end local e=ComputerManager()";
  33.     ["class"] = "local e,t,a,o=type,string.sub,string.upper,unpack\nlocal i=setmetatable({},{__index=function(l,u)\nif e(u)~=\"string\"then return end local c=\"set\"..a(t(u,1,1))..t(u,2)l[u]=c return c end})\nlocal n=setmetatable({},{__index=function(l,u)if e(u)~=\"string\"then return end\nlocal c=\"get\"..a(t(u,1,1))..t(u,2)l[u]=c return c end})local s local h={}local function r(l)return\"[Class] \"..l.name end\nlocal function d(l,u)local c={}if u.super then\nc.super=d(l,u.super)end\nsetmetatable(c,{__index=function(c,m)\nif e(u[m])==\"function\"then return\nfunction(f,...)if f==c then f=l end\nl.super=c.super local w={u[m](f,...)}l.super=c return o(w)end else return u[m]end end,__newindex=u,__tostring=function(m)\nreturn\n\"[Super] \"..tostring(u)..\" of \"..tostring(l)end})return c end\nfunction h:new(l)local u={}u.__index=self u.__type=l u.__isClass=true u.__tostring=r local c={}\nc.name=l c.mt=u function u:__call(...)return self:new(...)end\nfunction c:new(...)\nlocal m=t(tostring{},8)local f,c={},self local w=self.useGetters or self.useSetters local y=w and\nsetmetatable({},{__index=c})or f f.raw=y\nf.class=self if self.super then f.super=d(f,self.super)end f.mt={}\nf.mt.__isInstance=true function f.mt:__tostring()\nreturn\"[Instance] \"..self.class.name..\" \"..m end for p,b in pairs(self.mt)do\nif p~=\"__isClass\"and(\np~=\"__tostring\"or b~=r)then f.mt[p]=b end end\nif self.useGetters then local p={}\nif e(c.get)==\n\"function\"then local v=c.get\nfunction f.mt:__index(b)\nif not p[b]then local g=n[b]\nif\ng and e(c[g])==\"function\"then p[b]=true local j=c[g](self)p[b]=nil return j end p[b]=true local k,q=v(self,b)p[b]=nil if k then return q end end return y[b]end else\nfunction f.mt:__index(v)\nif not p[v]then local b=n[v]if b and e(c[b])==\"function\"then p[v]=true\nlocal g=c[b](self)p[v]=nil return g end end return y[v]end end else f.mt.__index=w and y or self end\nif self.useSetters then local p={}\nif e(c.set)==\"function\"then local v=c.set\nfunction f.mt:__newindex(b,g)\nif not p[b]then local k=i[b]\nif k and\ne(c[k])==\"function\"then p[b]=true c[k](self,g)p[b]=nil return end p[b]=true local q=v(self,b,g)p[b]=nil if q then return end end y[b]=g end else\nfunction f.mt:__newindex(b,g)\nif not p[b]then local v=i[b]if v and e(c[v])==\"function\"then p[b]=true\nc[v](self,g)p[b]=nil return end end y[b]=g end end end\nfor p,b in pairs(self.mt)do if\n\np~=\"__isClass\"and p~=\"__call\"and p~=\"__index\"and(p~=\"__tostring\"or b~=r)then f.mt[p]=b end end setmetatable(f,f.mt)\nif e(f.init)==\"function\"then f:init(...)end return f end setmetatable(c,u)getfenv(2)[l]=c s=c return function(m)\nfor f,w in pairs(m)do c[f]=w end end end\nfunction h:typeOf(l)if e(self)~=\"table\"then return false end if self.class then return\nself.class:typeOf(l)end if self==l then return true end if self.super then return\nself.super:typeOf(l)end return false end function h:type()local l=e(self)\npcall(function()\nl=getmetatable(self).__type or l end)return l end function h:can(l)return\ne(self[l])==\"function\"end\nfunction h:has(l,u)for c,m in pairs(l)do\nif\n(not u and self[c]~=m)or e(self[c])~=e(m)then return false end end return true end function h:mixin(l)for u,c in pairs(l)do self[u]=c end end\nfunction h:extends(h)\nself.super=h\nfor l,u in pairs(h.mt)do if\n\nl~=\"__index\"and l~=\"__type\"and l~=\"__tostring\"and l~=\"__call\"and l~=\"__isClass\"then self.mt[l]=u end end self.mt.__index=h end function h:isClass()\nreturn pcall(function()\nif not getmetatable(self).__isClass then error\"\"end end),nil end\nfunction h.last()return s end\nsetmetatable(h,{__call=function(l,...)return l:new(...)end})return h";
  34.     ["UIView"] = "require\"UIElement\"class\"UIView\"\nextends\"UIElement\"{shortcuts={}}\nfunction UIView:init(...)self.shortcuts={}return self.super:init(...)end\nfunction UIView:createShortcut(e,t,a)if self:shortcutExists(e)then self:setShortcut(e,t)\nself:setShortcutAction(e,a)else\nself.shortcuts[#self.shortcuts+1]={e,t,a}end end\nfunction UIView:shortcutExists(e)for t=1,#self.shortcuts do if self.shortcuts[t][1]==e then\nreturn true end end return false end function UIView:deleteShortcut(e)\nfor t=1,#self.shortcuts do if self.shortcuts[t][1]==e then\ntable.remove(self.shortcuts,t)return true end end end function UIView:getShortcuts()\nlocal e={}\nfor t=1,#self.shortcuts do e[t]=self.shortcuts[t][1]end return e end\nfunction UIView:setShortcut(e,t)\nfor a=1,#\nself.shortcuts do if self.shortcuts[a][1]==e then\nself.shortcuts[a][2]=shortcut return true end end return false end function UIView:getShortcut(e)\nfor t=1,#self.shortcuts do if self.shortcuts[t][1]==e then return\nself.shortcuts[t][2]end end end\nfunction UIView:setShortcutAction(e,t)\nfor a=1,\n#self.shortcuts do if self.shortcuts[a][1]==e then\nself.shortcuts[a][3]=t return true end end return false end function UIView:getShortcutAction(e)\nfor t=1,#self.shortcuts do if self.shortcuts[t][1]==e then return\nself.shortcuts[t][3]end end end\nfunction UIView:handle(e)\nif\ne.name==Event.KEYDOWN then local t,a=nil,-1\nfor o=1,#self.shortcuts do\nif#\nself.shortcuts[o][2]>a and\ne:matchesHotkey(self.shortcuts[o][2])then t,a=self.shortcuts[o][3],#\nself.shortcuts[o][2]end end if t then e.handled=true t()end end return UIElement.handle(self,e)end";
  35.     ["graphics.ScreenCanvas"] = "require\"graphics.Canvas\"local e={}\nfor h=0,15 do e[2^h]=(\"%x\"):format(h)end local t=table.concat local a=table.insert local o=table.remove\nlocal i,n=math.min,math.max local s=unpack class\"ScreenCanvas\"\nextends\"Canvas\"{colour=1,last=nil}\nfunction ScreenCanvas:init(...)self.super:init(...)self.last={}for h=1,self.width*\nself.height do self.last[h]={}end end\nfunction ScreenCanvas:setWidth(h)local r,d,l=self.height,self.buffer,self.raw local u=self.last\nlocal c={0,1,\" \"}\nwhile l.width<h do for m=1,r do a(u,(l.width+1)*m,{})\na(d,(l.width+1)*m,c)end l.width=l.width+1 end while l.width>h do\nfor m=r,1,-1 do o(u,l.width*m)o(d,l.width*m)end l.width=l.width-1 end end\nfunction ScreenCanvas:setHeight(h)local r,d,l=self.width,self.buffer,self.raw local u=self.last\nlocal c={0,1,\" \"}local c={0,1,\" \"}while l.height<h do for m=1,r do u[#u+1]={}d[#d+1]=c end l.height=\nl.height+1 end\nwhile l.height>h do for m=1,r do\nu[#u]=nil d[#d]=nil end l.height=l.height-1 end end\nfunction ScreenCanvas:drawToTerminal(h,r,d)r=(r or 0)+self.x\nd=(d or 0)+self.y local l=1 local u=self.width local c=self.buffer local m=self.last\nlocal f,w=h.blit,h.setCursorPos\nfor p=1,self.height do local y local v,b,g={},{},{}\nfor k=1,u do local q=c[l]local j=m[l]\nif\nq[1]~=j[1]or q[2]~=j[2]or q[3]~=j[3]then if not y then y=k tx=k w(r+k,p+d)end\nb[#b+1]=e[q[1]]g[#g+1]=e[q[2]]\nv[#v+1]=#q[3]==0 and\" \"or q[3]m[l]=c[l]elseif y then f(t(v),t(g),t(b))y=nil v={}g={}b={}end l=l+1 end f(t(v),t(g),t(b))end end\nfunction ScreenCanvas:drawToScreen(h,r)return self:drawToTerminal(term,h,r)end";
  36. }
  37. local loader = "local e,t=...\nif type(e)~=\"table\"or type(t)~=\"string\"then\nif shell and\nshell.getRunningProgram()==\"Flare/run.lua\"then return\nprintError\"Use Flare/bin/debug to run a Flare project\"else\nreturn error(\"expected table files, string path, got \"..\ntype(e)..\", \"..type(t))end end local a=\"Flare/lib;Flare/lib/elements\"\nlocal o=setmetatable({},{__index=_ENV or getfenv()})local i,n={},{}local s\nlocal function h(j)if not s.isClass(o[j])then\nreturn error(j..\" is not a class\")end local x=s.last()x:extends(o[j])return function(z)\nx:mixin(z)end end\nlocal function r(j,x)local z,_=load(j,x,nil,o)if not z then return error(_,0)end return z end\nlocal function d(j,x)local z=fs.open(j,\"r\")local _=z.readAll()z.close()return r(_,x)end\nlocal function l(j)if i[j]then return n[j]end i[j]=true\nif e[j]then local x,z=pcall(r(e[j],j),j)if not x then return\nerror(z,0)end n[j]=z return z else\nfor x in a:gmatch\"[^;]+\"do local z,_=x..\n\"/\"..j:gsub(\"%.\",\"/\"),nil\nif fs.exists(z..\".lua\")and not\nfs.isDir(z..\".lua\")then _=z..\".lua\"elseif\nfs.exists(z..\"/init.lua\")and not fs.isDir(z..\"/init.lua\")then _=z..\n\"/init.lua\"end if _ then local E,T=pcall(d(_,j),j)if not E then return error(T,0)end n[j]=T\nreturn T end end return error(\"file not found: '\"..j..\"'\")end end s=l\"class\"o.require=l o.class=s o.extends=h local u,c local m=true local f={}l\"UIView\"\nl\"Timer\"l\"graphics.ScreenCanvas\"l\"Event.Event\"l\"Event.MouseEvent\"\nl\"Event.KeyboardEvent\"l\"Event.TextEvent\"l\"Timer\"local w=o.Timer local y=o.Event local p=o.MouseEvent\nlocal v=o.KeyboardEvent local b=o.TextEvent\nlocal g={view=o.UIView(0,0,term.getSize()),terminateable=true}function g:stop()m=false end\ng.view.canvas=g.view.canvas:cloneAs(o.ScreenCanvas)u=g.view.canvas c=g.view\nlocal function k(j)\nif j[1]==\"key\"then\nf[keys.getName(j[2])or j[2]]=true return v(y.KEYDOWN,j[2],f,{isRepeat=j[3]})elseif j[1]==\"key_up\"then f[\nkeys.getName(j[2])or j[2]]=nil\nreturn v(y.KEYUP,j[2],f,{})elseif j[1]==\"mouse_click\"then\nreturn p(y.MOUSEDOWN,j[3]-1,j[4]-1,j[2],true,{})elseif j[1]==\"mouse_up\"then\nreturn p(y.MOUSEUP,j[3]-1,j[4]-1,j[2],true,{})elseif j[1]==\"mouse_scroll\"then\nreturn p(y.MOUSESCROLL,j[3]-1,j[4]-1,j[2],true,{})elseif j[1]==\"mouse_drag\"then\nreturn p(y.MOUSEDRAG,j[3]-1,j[4]-1,j[2],true,{})elseif j[1]==\"char\"then return b(y.TEXT,j[2],{})elseif j[1]==\"paste\"then\nreturn b(y.PASTE,j[2],{})else return y(j[1],{unpack(j,2)})end end\nlocal function q()\nif c.changed then u:clear()c:draw()u:drawToScreen()\nif u.cursor then local j=u.cursor term.setCursorPos(\nj.x+1,j.y+1)\nterm.setTextColour(j.colour)term.setCursorBlink(true)else\nterm.setCursorBlink(false)end end end o.application=g l\"init\"if type(g.load)==\"function\"then\ng:load(select(3,...))end\nwhile m do w.step()q()\nlocal j={coroutine.yield()}\nif j[1]==\"term_resize\"then c.width,c.height=term.getSize()elseif j[1]==\"terminate\"and\ng.terminateable then m=false elseif\nj[1]~=\"timer\"or not w.update(j[1],j[2])then c:handle(k(j))end c:update(w.getDelta())end"
  38. local f, err = load( loader, "Flare", nil, _ENV or getfenv() )
  39. if not f then
  40.     error( "there was a problem with Flare!: " .. err, 0 )
  41. end
  42. f( files, "init", ... )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement