Advertisement
maca134

CC: CREATE Depot Manager

Apr 12th, 2023 (edited)
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 38.60 KB | None | 0 0
  1. local a,b,c,d=(function(e)local f={[{}]=true}local g;local h={}local require;local i={}g=function(j,k)if not h[j]then h[j]=k end end;require=function(j)local l=i[j]if l then if l==f then return nil end else if not h[j]then if not e then local m=type(j)=='string'and'\"'..j..'\"'or tostring(j)error('Tried to require '..m..', but no such module has been registered')else return e(j)end end;i[j]=f;l=h[j](require,i,g,h)i[j]=l end;return l end;return require,i,g,h end)(require)c("__root",function(require,n,c,d)local o=[[
  2. -----------------------------------------------------------------------------------------------------
  3. CREATE depot manager for CC: Tweaked - https://pastebin.com/t8gPXNwT
  4.  
  5. To install run the follow in a CC: Tweaked computer:
  6.      pastebin get t8gPXNwT startup
  7.      reboot
  8. -----------------------------------------------------------------------------------------------------
  9. ]]local p=require("lib.luact")local q=require("lib.utils")local r={text={colors.white,0xffffff},background={colors.black,0x191a19},primary={colors.blue,0xB88E44},secondary={colors.lightBlue,0x794D20},focus={colors.cyan,0xC5A454},border={colors.purple,0x413C27},shadow={colors.gray,0x454342},disabled={colors.lightGray,0x585F69},success={colors.green,0x4A632A},error={colors.red,0x890725},warn={colors.yellow,0xf6aa1a},sidebar={colors.magenta,0x2a2a2a}}local s=p.getMonitor()q.setTheme(s,r)s.setTextColor(colors.white)s.setBackgroundColor(colors.black)s.clear()p.run(require("depot.App")())s.clear()end)c("depot.App",function(require,n,c,d)local p=require("lib.luact")local t=require("components.Object")local u=require("components.Window")local v=require("components.Label")local w=require("components.Button")local x=require("components.Button3D")local y=require("components.Tabs")local z=require("depot.configdb")local A={{id='top',label='Top'},{id='bottom',label='Bottom'},{id='front',label='Front'},{id='back',label='Back'},{id='left',label='Left'},{id='right',label='Right'}}local function B(C,D)for o,E in ipairs(C)do if E==D then return true end end;return false end;local F=p.createComponent(function(G)local H=G.skip or{}local function I()local J=G.value;repeat J=J-1;if J<1 then J=#A end until not B(H,J)G.setValue(J)end;local function K()local J=G.value;repeat J=J+1;if J>#A then J=1 end until not B(H,J)G.setValue(J)end;local L=peripheral.isPresent(A[G.value].id)local j='-'local M=false;if L then local N=peripheral.wrap(A[G.value].id)j=peripheral.getType(N)M=peripheral.hasType(N,'inventory')end;return t(v({text=G.name..(L and' ('..j..')'or''),x=0,y=0,align='center',color=M and colors.success or colors.error}),t({x='parent.w / 2 - self.w / 2',h=3,y=1,w=18,background=colors.primary},w({text='<',w=3,click=I}),v({text=A[G.value].label,align='center',valign='middle',color=colors.text}),w({x='parent.w - 3',text='>',w=3,click=K})))end)local O=p.createComponent(function()local P,Q=p.useState(z.get('inputSide',1))local R,S=p.useState(z.get('processSide',2))local T,U=p.useState(z.get('outputSide',3))return t({background=colors.black},t({y=1,h=3},F({name='Input Side',skip={T,R},value=P,setValue=function(D)z.set('inputSide',D)Q(D)end})),t({y=6,h=3},F({name='Process Side',skip={P,T},value=R,setValue=function(D)z.set('processSide',D)S(D)end})),t({y=11,h=3},F({name='Output Side',skip={P,R},value=T,setValue=function(D)z.set('outputSide',D)U(D)end})))end)local function V(W,X)X=X or 0.5;local P=z.get('inputSide',-1)local R=z.get('processSide',-1)local T=z.get('outputSide',-1)if P==-1 or R==-1 or T==-1 then return false,'Please configure all sides'end;if not peripheral.isPresent(A[P].id)then return false,'Input side is not present'end;if not peripheral.isPresent(A[R].id)then return false,'Process side is not present'end;if not peripheral.isPresent(A[T].id)then return false,'Output side is not present'end;local Y=peripheral.wrap(A[P].id)local Z=peripheral.wrap(A[R].id)local _=peripheral.wrap(A[T].id)if not peripheral.hasType(Y,'inventory')then return false,'Input side is not an inventory'end;if not peripheral.hasType(Z,'inventory')then return false,'Process side is not an inventory'end;if not peripheral.hasType(_,'inventory')then return false,'Output side is not an inventory'end;local function a0(a1)local a2={}for a3,a4 in pairs(a1.list())do table.insert(a2,{slot=a3,item=a4})end;return a2 end;local a5=a0(Z)if#a5>0 then Z.pushItems(peripheral.getName(_),1,1)end;while true do W('Waiting for items')os.sleep(X)local a2=a0(Y)if#a2>0 then local a4=a2[1].item;local a3=a2[1].slot;Y.pushItems(peripheral.getName(Z),a3,1)W('Processing '..a4.name)while true do os.sleep(X)local a5=a0(Z)if#a5==0 then break end;if a5[1].item.name~=a4.name then break end end;Z.pushItems(peripheral.getName(_),1,1)end end end;local a6=p.createComponent(function()local a7,a8=p.useState(z.get('enabled',false))local a9,aa=p.useState()local error,ab=p.useState()p.useSchedule(function()if not a7 then return end;local ac,ad=V(aa)if not ac then ab(ad)a8(false)z.set('enabled',false)end end,{a7})return t({background=colors.black},error and v({text=error,align='center',color=colors.error,y=1})or a7 and t({y=1},a9 and t({h=2},v({text='[Status]',align='center',color=colors.gray}),v({text=a9,align='center',color=colors.text,y=1}))or v({text='Waiting for item...',align='center',color=colors.text}))or t({y=1},v({text='Disabled',align='center',color=colors.shadow})),t({x='parent.w / 2 - self.w / 2',y='parent.h - 4',w='parent.w / 2',h=3},x({text=a7 and'Disable'or'Enable',background=a7 and colors.error or colors.success,click=function()ab()z.set('enabled',not a7)a8(not a7)end})))end)return p.createComponent(function()return u({title='Depot Manager'},y({selected=1},t({title='Main'},a6()),t({title='Config'},O())))end)end)c("depot.configdb",function(require,n,c,d)local ae='config.json'local z={}local function af()local ag=fs.open(ae,'w')ag.write(textutils.serialiseJSON(z))ag.close()end;if fs.exists(ae)then local ag=fs.open(ae,'r')local ah=ag.readAll()ag.close()z=textutils.unserialiseJSON(ah)end;return{get=function(ai,aj)return z[ai]or aj end,set=function(ai,E)z[ai]=E;af()end}end)c("components.Tabs",function(require,n,c,d)local p=require("lib.luact")local q=require("lib.utils")local t=require("components.Object")local v=require("components.Label")return p.createComponent(function(G)local ak,al=p.useState(G.selected or 1)local am=p.useRef()local an,ao=p.useState(0)local ap=G.children;p.useEffect(function()ao(am.current.props.w)end,{})return t({background=colors.background},t({x=0,y=0,w=13,h='parent.h'},t({ref=am,x=0,y=0,w='parent.w',h='parent.h',background=colors.sidebar},q.map(ap,function(C,aq)local ar=aq==ak;return t({x=0,y=(aq-1)*3,h=3,w=an,background=ar and colors.background or colors.sidebar,onClick=function()al(aq)end,onTouch=function()al(aq)end},t({w='parent.w - 1',click=false},v({text=ar and C.props.title..' '..string.char(26)or C.props.title,color=colors.focus,align='right',valign='middle'})))end))),t({x=13,y=0,w='parent.w - 13',h='parent.h - 1',background=colors.background},G.children[ak]))end)end)c("components.Label",function(require,n,c,d)local p=require("lib.luact")local t=require("components.Object")return p.createComponent(function(G)G.text=G.text or''local as=G.align or'left'local at=G.x or 0;if as=='center'then at='parent.w * 0.5 - self.w * 0.5'elseif as=='right'then at='parent.w - self.w'end;local au=G.valign or'top'local av=G.y or 0;if au=='middle'then av='parent.h * 0.5 - self.h * 0.5'elseif au=='bottom'then av='parent.h - self.h'end;return t({color=G.color or colors.text,text=G.text,x=at or 0,y=av or 0,w=string.len(G.text),h=1,click=false})end)end)c("components.Object",function(require,n,c,d)local p=require("lib.luact")return p.createComponent('object',{x=0,y=0,w='parent.w',h='parent.h',onClick=function()end,onTouch=function()end})end)c("lib.luact",function(require,n,c,d)local a,b,c,d=(function(e)local f={[{}]=true}local g;local h={}local aw;local i={}g=function(j,k)if not h[j]then h[j]=k end end;require=function(j)local l=i[j]if l then if l==f then return nil end else if not h[j]then if not e then local m=type(j)=='string'and'\"'..j..'\"'or tostring(j)error('Tried to _require '..m..', but no such module has been registered')else return e(j)end end;i[j]=f;l=h[j](require,i,g,h)i[j]=l end;return l end;return require,i,g,h end)(require)c("__root",function(aw,n,c,d)local ax=aw("misc.debugger")local ay=aw("render.screen")local az=aw("ui.events")()local aA=aw("render.mouse")(az)local aB=aw("render.renderer")(az,aA)local aC=aw("ui.luact")(az)local aD=aw("ui.hooks")(az,aC)local aE=aw("cc.schedule")(az,aD)return{events=az,Fragment=aC.Fragment,createComponent=aC.createComponent,init=function(aF)return aC.init(aF,aB)end,update=aC.update,useReducer=aD.useReducer,useState=aD.useState,useEffect=aD.useEffect,useMemo=aD.useMemo,useRef=aD.useRef,useCallback=aD.useCallback,createContext=aD.createContext,useContext=aD.useContext,useSchedule=aE.useSchedule,getMonitor=function()return ay.currentScreen end,run=function(aF)aC.init(aF,aB)while true do local aG={os.pullEvent()}local aH=aG[1]table.remove(aG,1)if LUACT_DEBUG_ENABLED then local aI=ax.timer(function()az.emit(aH,table.unpack(aG))end)ax.log('event: '..aH..'. time: '..aI..'ms.')ax.log()else az.emit(aH,table.unpack(aG))end;if aH=='app_exit'then break end end end}end)c("cc.schedule",function(aw,n,c,d)local q=aw("misc.utils")return function(az,aD)local aJ={}local function aK(...)if#aJ==0 then return end;local aL={}for aM=1,#aJ do if aJ[aM]~=nil then if coroutine.status(aJ[aM])=="suspended"then local aN,aO=coroutine.resume(aJ[aM],...)if not aN then error(aO)end else table.insert(aL,aM)end end end;for aM=1,#aL do table.remove(aJ,aL[aM]-(aM-1))end end;az.on('timer',function(...)aK('timer',...)end)az.on('task_complete',function(...)aK('task_complete',...)end)local function aE(aP)return function(...)local aQ=coroutine.create(function(...)os.sleep(0)return aP(...)end)local aN,aO=coroutine.resume(aQ,...)if not aN then error(aO)end;table.insert(aJ,aQ)return function()aJ=q.filter(aJ,function(aR)return aR~=aQ end)end end end;local function aS(aT,aU)return aD.useEffect(aE(aT),aU)end;return{schedule=aE,useSchedule=aS}end end)c("misc.utils",function(aw,n,c,d)local q={}q.exclude=function(aV,aW)local _={}for aX,aY in pairs(aV)do if not aW[aX]then _[aX]=aY end end;return _ end;q.filter=function(aZ,aP)local _={}for o,aY in ipairs(aZ)do if aP(aY)then table.insert(_,aY)end end;return _ end;q.isArray=function(aV)local aq=0;for o in pairs(aV)do aq=aq+1;if aV[aq]==nil then return false end end;return true end;q.merge=function(...)local _={}for o,aV in ipairs({...})do if aV then for aX,aY in pairs(aV)do _[aX]=aY end end end;return _ end;q.parseArgs=function(...)local aU={...}local a_;local G=nil;if aU[1]~=nil then if aU[1]._type=='_component'then a_=aU elseif aU[2]and q.isArray(aU[2])then G=aU[1]a_=aU[2]elseif q.isArray(aU[1])then a_=aU[1]else G=aU[1]table.remove(aU,1)a_=aU end end;if a_ then a_=q.filter(a_,function(b0)return type(b0)=='table'end)end;return G,a_ end;return q end)c("ui.hooks",function(aw,n,c,d)local q=aw("misc.utils")return function(az,aC)local b1,b2,b3=nil,0,0;az.on('update-fiber',function(b4)b1=b4;b2=0;if b4.hooks~=nil then b4.hooks._effects={}end end)az.on('commit-fiber',function(b4)if b4.hooks~=nil then for o,b5 in pairs(b4.hooks._effects)do if b5.cleanup then b5.cleanup()end;b5.cleanup=b5.value()end;b4.hooks._effects={}end end)az.on('destroy-fiber',function(b4)if b4.hooks~=nil then for o,b5 in pairs(b4.hooks._list)do if b5.cleanup then b5.cleanup()end end end end)local function b6(b7,aP)if type(aP)=='function'then return aP(b7)else return aP end end;local function b8(b9,ba)for aq,E in ipairs(ba)do if E~=b9[aq]then return false end end;return true end;local function bb(b9,ba)return ba==nil or b9==nil or#b9~=#ba or not b8(b9,ba)end;local function bc(bd)local aD=b1.hooks;if b1.prev~=nil and b1.prev.hooks~=nil then aD=b1.prev.hooks end;if aD==nil then aD={_list={},_effects={}}end;b1.hooks=aD;if aD._list[bd]==nil then aD._list[bd]={}end;return aD._list[bd]end;local function be(bf,bg,bh)b2=b2+1;local bi=bc(b2)bi.reducer=bf;if bi.action==nil then if bh==nil then bi.value=b6(nil,bg)else bi.value=bh(bg)end;bi.action=function(bj)local bk=bi.value;local bl=bi.reducer(bk,bj)if bl~=bk then bi.value=bl;aC.update()end end end;return bi.value,bi.action end;local function bm(aP,bn)b2=b2+1;local bi=bc(b2)if bb(bi.deps,bn)then bi.deps=bn;bi.value=aP;table.insert(b1.hooks._effects,bi)end end;local function bo(bg)return be(b6,bg)end;local function bp(bq,bn)b2=b2+1;local bi=bc(b2)if bb(bi.deps,bn)then bi.deps=bn;bi.value=bq()end;return bi.value end;local function br(bs)return bp(function()return{current=bs}end,{})end;local function bt(aT,aU)return bp(function()return aT end,aU)end;local function bu(bv)b3=b3+1;local bw=b3;return{id=bw,defaultValue=bv,Provider=function(...)local G,a_=q.parseArgs(...)local bx=aC.Fragment(a_)bx.ctx={id=bw,value=G and G.value or bv}return bx end}end;local function by(bz)local bA;local bx=b1;while bx do if bx.ctx and bx.ctx.id==bz.id then bA=bx;break end;bx=bx.parent end;if bA==nil then return bz.defaultValue end;return bA.ctx.value end;return{useReducer=be,useState=bo,useEffect=bm,useMemo=bp,useRef=br,useCallback=bt,createContext=bu,useContext=by}end end)c("ui.luact",function(aw,n,c,d)local q=aw("misc.utils")return function(az)local bB,aB;local bC='fragment'local function bD(bE,bF)bF=bF or{}assert(type(bE)=='function'or type(bE)=='string','component must be a function or string')return function(...)local G,a_=q.parseArgs(...)G=G or{}local bG={}local am;for aX,aY in pairs(G)do if aX=='ref'then am=aY elseif aX=='children'then if a_==nil then a_=aY end else bG[aX]=aY end end;bG.children=a_;return{_type='_component',type=bE,ref=am,props=q.merge(bF,bG)}end end;local function bH(b4,bI)if b4.child then bH(b4.child,true)end;if bI and b4.sibling then bH(b4.sibling,true)end;if b4.type~='root'and b4.type~=bC and b4.element and type(b4.type)~='function'then aB.destroy(b4)end;az.emit('destroy-fiber',b4)end;local function bJ(b4,bK)local bd=1;local bL=b4.prev and b4.prev.child;local bM;while bd<=#bK or bL do local aF=bK[bd]local bN=nil;local bO=bL and aF and aF.type==bL.type;if bO then bN={type=bL.type,ref=bL.ref,ctx=aF.ctx,props=aF.props,parent=b4,element=bL.element,prev=bL,effectTag="UPDATE"}bL.prev=nil end;if aF and not bO then bN={type=aF.type,props=aF.props,ref=aF.ref,ctx=aF.ctx,parent=b4,effectTag="PLACEMENT"}end;if bL and not bO then bH(bL)end;if bL then bL=bL.sibling end;if bd==1 then b4.child=bN elseif aF then bM.sibling=bN end;bM=bN;bd=bd+1 end end;local function bP(b4)if b4.type==bC or type(b4.type)=="function"then local bQ=b4.parent;while not bQ.element and bQ.parent do bQ=bQ.parent end;b4.element=bQ.element end;if type(b4.type)=="function"then az.emit('update-fiber',b4)bJ(b4,{b4.type(b4.props)})else if b4.type~=bC and not b4.element then b4.element=aB.create(b4)end;if b4.ref then b4.ref.current=b4.element end;bJ(b4,b4.props.children)end;if b4.child then return bP(b4.child)end;local bR=b4;while bR do if bR.sibling then return bP(bR.sibling)end;bR=bR.parent end end;local function bS(b4)if b4==nil then return end;local bT=b4.type=='root'if b4.effectTag=="UPDATE"and not bT and type(b4.type)~="function"and b4.type~=bC then aB.update(b4)end;bS(b4.child)bS(b4.sibling)az.emit('commit-fiber',b4)if bT then bB=b4;return end end;local bU=(function()local bV=0;return function()if not bB then return end;if bV>0 then bV=2;return end;local aq=0;repeat bV=1;local b4={type=bB.type,element=bB.element,props=bB.props,prev=bB}bP(b4)bS(b4)aq=aq+1;if aq>20 then error('infinite loop detected. aborting.')break end until bV==1;bV=0;aB.render(bB)end end)()local function bh(aF,bW)bB={type='root',props={children={aF}}}aB=bW;bU()return bB.element end;az.on('update',bU)return{Fragment=bD(bC),createComponent=bD,update=bU,init=bh}end end)c("render.renderer",function(aw,n,c,d)local ax=aw("misc.debugger")local q=aw("misc.utils")local bX=aw("render.expressions")local ay=aw("render.screen")local function bY(aF)if not aF.props.w then aF.props.w='parent.w'end;if not aF.props.h then aF.props.h='parent.h'end;if not aF.props.x then aF.props.x=0 end;if not aF.props.y then aF.props.y=0 end;local bZ,b_=ay.getSize()local c0={['screen.w']=bZ,['screen.h']=b_}if aF.props.position=='absolute'then c0['parent.x']=0;c0['parent.y']=0;c0['parent.w']=bZ;c0['parent.h']=b_ elseif aF.parent then c0['parent.x']=aF.parent.props.x;c0['parent.y']=aF.parent.props.y;c0['parent.w']=aF.parent.props.w;c0['parent.h']=aF.parent.props.h end;if aF.prev then c0['prev.x']=aF.prev.props.x;c0['prev.y']=aF.prev.props.y;c0['prev.w']=aF.prev.props.w;c0['prev.h']=aF.prev.props.h else c0['prev.x']=0;c0['prev.y']=0;c0['prev.w']=0;c0['prev.h']=0 end;if aF.props.w and type(aF.props.w)=='string'then aF.props.w=math.ceil(bX(aF.props.w,c0))end;if aF.props.h and type(aF.props.h)=='string'then aF.props.h=math.ceil(bX(aF.props.h,c0))end;c0['self.w']=aF.props.w;c0['self.h']=aF.props.h;if aF.parent then c0['center.x']=aF.parent.props.w/2-aF.props.w/2;c0['center.y']=aF.parent.props.h/2-aF.props.h/2 end;if aF.props.x and type(aF.props.x)=='string'then aF.props.x=math.floor(bX(aF.props.x,c0))end;if aF.props.y and type(aF.props.y)=='string'then aF.props.y=math.floor(bX(aF.props.y,c0))end;if aF.props.position~='absolute'then aF.props.x=aF.props.x+c0['parent.x']aF.props.y=aF.props.y+c0['parent.y']end end;local function c1(b4)local aF={type=b4.type,props=q.exclude(b4.props,{children=true}),children={},parent=b4.parent and b4.parent.element}if b4.parent then local c2=b4.parent.element.children;if#c2>0 then local c3=c2[#c2]aF.prev=c3 end;table.insert(b4.parent.element.children,aF)else aF.props.w='screen.w'aF.props.h='screen.h'aF.props.x=0;aF.props.y=0;aF.props.position='absolute'aF.props.background=colors.black end;bY(aF)return aF end;local function bU(b4)b4.element.props=q.exclude(b4.props,{children=true})bY(b4.element)ay.draw(b4.element)end;local function c4(b4)if b4.parent then b4.parent.element.children=q.filter(b4.parent.element.children,function(b0)return b0~=b4.element end)for aq,b0 in ipairs(b4.parent.element.children)do if aq==1 then b0.prev=nil else b0.prev=b4.parent.element.children[aq-1]end end end end;local function c5(c6)local bK={}local c7=0;local function c8(aF)if aF.props.hidden then return end;table.insert(bK,aF)if aF.props.z then local c9=c7;c7=aF.props.z+1;for o,b0 in ipairs(aF.children)do c8(b0)end;c7=c9 else aF.props.z=c7;c7=c7+1;for o,b0 in ipairs(aF.children)do c8(b0)end end end;c8(c6)table.sort(bK,function(ca,cb)return ca.props.z<cb.props.z end)return bK end;return function(az,aA)az.on('monitor_resize',function()az.emit('update')end)local function bW(c6)local bK=c5(c6.element)ax.dumpTree(c6.element)aA.clear()for aq=1,#bK,1 do ay.draw(bK[aq])aA.register(bK[#bK+1-aq])end;ay.update()end;return{render=bW,create=c1,update=bU,destroy=c4}end end)c("render.screen",function(aw,n,c,d)local cc={}local cd={}local ce={}local cf=peripheral.find('monitor')if cf~=nil then cf.setTextScale(0.5)else cf=term end;local function cg()return cf.getSize()end;local ch,ci=cg()local function cj()for av=1,ci do cc[av]=string.rep(" ",ch)ce[av]=string.rep(colors.toBlit(colors.black),ch)cd[av]=string.rep(colors.toBlit(colors.black),ch)end end;local function ck(at,av,cl)if av>=1 and av<=ci then local cm=cc[av]local cn=#cl;if at+cn-1>=1 then if at<1 then cl=string.sub(cl,2-at)at=1 end;if at+cn-1>ch then cl=string.sub(cl,1,ch-at+1)end;cc[av]=string.sub(cm,1,at-1)..cl..string.sub(cm,at+cn)end end end;local function co(at,av,cp)if av>=1 and av<=ci then local cm=cd[av]local cn=#cp;if at+cn-1>=1 then if at<1 then cp=string.sub(cp,2-at)at=1 end;if at+cn-1>ch then cp=string.sub(cp,1,ch-at+1)end;cd[av]=string.sub(cm,1,at-1)..cp..string.sub(cm,at+cn)end end end;local function cq(at,av,cp)if av>=1 and av<=ci then local cm=ce[av]local cn=#cp;if at+cn-1>=1 then if at<1 then cp=string.sub(cp,2-at)at=1 end;if at+cn-1>ch then cp=string.sub(cp,1,ch-at+1)end;ce[av]=string.sub(cm,1,at-1)..cp..string.sub(cm,at+cn)end end end;local function cr(at,av,cs,ct,cu)for aM=1,ct do co(at,av+aM-1,string.rep(colors.toBlit(cu),cs))ck(at,av+aM-1,string.rep(' ',cs))end end;local function cv(at,av,cl,cw)ck(at,av,cl)if cw then cq(at,av,string.rep(colors.toBlit(cw),#cl))end end;local function cx(aF)if aF.props.background then local at=aF.props.x;local av=aF.props.y;local cs=aF.props.w;local ct=aF.props.h;if at<0 then cs=cs+at;at=0 end;if av<0 then ct=ct+av;av=0 end;if at+cs>ch then cs=ch-at end;if av+ct>ci then ct=ci-av end;cr(at+1,av+1,cs,ct,aF.props.background)end;if aF.props.text then if string.len(aF.props.text)>aF.parent.props.w then aF.props.text=string.sub(aF.props.text,1,aF.parent.props.w)end;cv(aF.props.x+1,aF.props.y+1,aF.props.text,aF.props.color or colors.white)end end;local function bU()ch,ci=cg()local cy,cz=cf.getCursorPos()for aM=1,ci do cf.setCursorPos(1,aM)cf.blit(cc[aM],ce[aM],cd[aM])end;cf.setCursorPos(cy,cz)cf.setBackgroundColor(colors.black)cj()end;cj()return{draw=cx,update=bU,getSize=function()return ch,ci end,clear=cj,currentScreen=cf,setCurrentScreen=function(ay)cf=ay end}end)c("render.expressions",function(aw,n,c,d)local cA=aw("render.pg")local function cB(cC)return cA.string(cC):skip(cA.optWhitespace)end;local cD=cA.createLanguage({expression=function(cE)return cA.alt(cE.uExpression,cE.bExpression)end,uExpression=function(cE)return cA.seq(cE.unop,cE.expression):map(function(E)local aO={E[1]}for o,aY in ipairs(E[2])do table.insert(aO,aY)end;return aO end)end,bExpression=function(cE)return cA.seq(cE.value,cA.optional(cA.seq(cE.binop,cE.expression))):map(function(E)local aO={}if E[1].type=='brackets'then table.insert(aO,{type='open_bracket'})for o,aY in ipairs(E[1].value)do table.insert(aO,aY)end;table.insert(aO,{type='close_bracket'})else table.insert(aO,E[1])end;if E[2]~=nil then table.insert(aO,E[2][1])for o,aY in ipairs(E[2][2])do table.insert(aO,aY)end end;return aO end)end,value=function(cE)return cA.alt(cE.number,cE.variable,cA.seq(cA.skip(cB('(')),cE.expression,cA.skip(cB(')'))):map(function(E)return{type='brackets',value=E[1]}end))end,number=function()return cA.alt(cA.seq(cA.regex('[0-9]*'),cA.string('.'),cA.regex('[0-9]*')):concat(),cA.regex('[0-9]+')):skip(cA.optWhitespace):map(function(E)return{type='number',value=tonumber(E)}end)end,variable=function()return cA.seq(cA.regex('[a-zA-Z]+'),cA.seq(cA.skip(cA.string('.')),cA.regex('[a-zA-Z]+')):concat():many()):skip(cA.optWhitespace):map(function(E)return{type='variable',value=table.concat({E[1],table.unpack(E[2])},'.')}end)end,binop=function()return cA.alt(cB("+"),cB("-"),cB("*"),cB("/")):map(function(E)return{type='binop',value=E}end)end,unop=function()return cA.alt(cB("-")):map(function(E)return{type='unop',value=E}end)end})local function cF(cG)if cG=='*'or cG=='/'then return 2 elseif cG=='+'or cG=='-'then return 1 else return 0 end end;local function cH(cI)local cJ={}local aO={}for o,aY in ipairs(cI)do if aY.type=='number'or aY.type=='variable'then if#cJ>0 and cJ[#cJ].type=='unop'then table.remove(cJ)aY.value=-aY.value end;table.insert(aO,aY)elseif aY.type=='binop'then while#cJ>0 and cJ[#cJ].type=='binop'and cF(cJ[#cJ].value)>=cF(aY.value)do table.insert(aO,table.remove(cJ))end;table.insert(cJ,aY)elseif aY.type=='unop'then table.insert(cJ,aY)elseif aY.type=='open_bracket'then table.insert(cJ,aY)elseif aY.type=='close_bracket'then while#cJ>0 and cJ[#cJ].type~='open_bracket'do table.insert(aO,table.remove(cJ))end;table.remove(cJ)end end;while#cJ>0 do table.insert(aO,table.remove(cJ))end;return aO end;local function cK(cI,cL)cL=cL or{}local cJ={}for o,aY in ipairs(cI)do if aY.type=='number'then table.insert(cJ,aY.value)elseif aY.type=='variable'then if cL[aY.value]==nil then error('Variable "'..aY.value..'" is not defined')end;table.insert(cJ,cL[aY.value])elseif aY.type=='binop'then local cb=table.remove(cJ)local ca=table.remove(cJ)if aY.value=='+'then table.insert(cJ,ca+cb)elseif aY.value=='-'then table.insert(cJ,ca-cb)elseif aY.value=='*'then table.insert(cJ,ca*cb)elseif aY.value=='/'then table.insert(cJ,ca/cb)end end end;return cJ[1]end;local cM={}return function(cI,cL)if cM[cI]==nil then cM[cI]=cD.expression:map(cH):parse(cI)end;return cK(cM[cI],cL)end end)c("render.pg",function(aw,n,c,d)local function cN(...)local aO={}for o,aV in ipairs({...})do for o,aY in pairs(aV)do table.insert(aO,aY)end end;return aO end;local function ac(bd,E)return{success=true,index=bd,value=E,furthest=-1,expected={}}end;local function cO(bd,cP)if type(cP)=='string'then cP={cP}end;return{success=false,index=-1,furthest=bd,expected=cP}end;local function cQ(aO,cR)if cR==nil then return aO end;if aO.furthest>cR.furthest then return aO end;local cP=aO.furthest==cR.furthest and cN(aO.expected,cR.expected)or cR.expected;return{success=aO.success,index=aO.index,value=aO.value,furthest=cR.furthest,expected=cP}end;local function cS(Y,aO)local cT=string.sub(Y,aO.furthest-20,aO.furthest-1)..'['..string.sub(Y,aO.furthest,aO.furthest)..']'..string.sub(Y,aO.furthest+1,aO.furthest+20)if#aO.expected==1 then return string.format('Expected: %s at position %d\n%s',aO.expected[1],aO.furthest,cT)else local cP=table.concat(aO.expected,', ')return string.format('Expected one of the following: [%s] at position %d\n%s',cP,aO.furthest,cT)end end;local cU={}cU.__index=cU;function cU:new(cV)local cW={parser=cV}setmetatable(cW,self)cW.__index=self;return cW end;local function cX(...)local cY={...}return cU:new(function(Y,bd)local aO=nil;for o,cD in ipairs(cY)do aO=cQ(cD.parser(Y,bd),aO)if aO.success then return aO end end;return aO end)end;local function cC(E)local cP='"'..E..'"'return cU:new(function(Y,bd)local cZ=bd+string.len(E)local c_=string.sub(Y,bd,cZ-1)if c_==E then return ac(cZ,c_)else return cO(bd,cP)end end)end;local function d0(d1,d2)d2=d2 or 0;local cP='/'..d1 ..'/'return cU:new(function(Y,bd)local aO={string.find(Y,'^('..d1 ..')',bd)}if aO[1]~=nil then return ac(aO[2]+1,aO[d2+3])else return cO(bd,cP)end end)end;local function d3(...)local cY={...}return cU:new(function(Y,bd)local aO={}local d4={}for o,cD in ipairs(cY)do aO=cD.parser(Y,bd)if not aO.success then return aO end;table.insert(d4,aO.value)bd=aO.index end;return cQ(ac(bd,d4),aO)end)end;local function d5(cD)return cU:new(function(Y,bd)local aO=cD.parser(Y,bd)if not aO.success then return ac(bd,nil)end;return aO end)end;local function H(cD)return cD:map(function()return nil end)end;local function d6(cD)return cU:new(function(Y,bd)local aO=nil;local d4={}while true do aO=cQ(cD.parser(Y,bd),aO)if aO.success then if bd==aO.index then error('infinite loop detected in .many() parser')end;bd=aO.index;table.insert(d4,aO.value)end;if not aO.success then break end end;return cQ(ac(bd,d4),aO)end)end;local function d7(cD,d8)return cD:map(function(aO)assert(type(aO)=='table','Expected table, got '..type(aO))return table.concat(aO,d8)end)end;local function d9(aP)local cD=nil;return cU:new(function(Y,bd)if cD==nil then cD=aP()end;return cD.parser(Y,bd)end)end;local da=cU:new(function(cC,bd)if bd>#cC then return ac(bd,nil)end;return cO(bd,'end of input')end)local function db(cY)local dc={}for j,aP in pairs(cY)do dc[j]=d9(function()return aP(dc)end)end;return dc end;local function dd(cD,aP)return cU:new(function(Y,bd)local aO=cD.parser(Y,bd)if aO.success then return ac(aO.index,aP(aO.value))end;return aO end)end;function cU:map(aP)return dd(self,aP)end;function cU:skip(de)return d3(self,H(de)):map(function(aO)return aO[1]end)end;function cU:concat(d8)return d7(self,d8)end;function cU:many()return d6(self)end;function cU:parse(E)local aO=self:skip(da).parser(E,1)if aO.success then return aO.value end;error(cS(E,aO))end;return{alt=cX,string=cC,regex=d0,seq=d3,optional=d5,skip=H,createLanguage=db,optWhitespace=d0('%s*')}end)c("misc.debugger",function(aw,n,c,d)local df=aw("misc.inspect")local ax;if LUACT_DEBUG_ENABLED and periphemu then periphemu.create('top','debugger')ax=peripheral.wrap('top')end;local dg=ccemux and ccemux.nanoTime or function()return os.epoch('local')*1000 end;local function dh(...)if not LUACT_DEBUG_ENABLED then return end;local di='[LUACT] '..table.concat({...},' ')if ax then ax.print(di)elseif ccemux then ccemux.echo(di)end end;local function dj(...)if ax then ax.print(df(...))elseif ccemux then ccemux.echo('\n'..df(...))end end;local function dk(dl,dm)local dn=dg()for o=1,dm do dl()end;local dp=dg()return(dp-dn)/1000000/dm end;local function dq(dl)local dn=dg()dl()local dp=dg()return(dp-dn)/1000000 end;local function dr(ds)if not LUACT_DEBUG_XML then return end;local aO={}local function dt(bx,du)local G=''if bx.props then for aX,aY in pairs(bx.props)do local D=aY;if type(aY)=='boolean'then D=aY and'true'or'false'elseif type(aY)=='number'then D=tostring(aY)elseif type(aY)=='string'then D='"'..aY..'"'else D='['..type(D)..']'end;G=G..' '..aX..'='..D end end;if bx.children and#bx.children>0 then table.insert(aO,string.rep('\t',du)..'<'..bx.type..G..'>')for o,b0 in ipairs(bx.children)do dt(b0,du+1)end;table.insert(aO,string.rep('\t',du)..'</'..bx.type..'>')else table.insert(aO,string.rep('\t',du)..'<'..bx.type..G..' />')end end;dt(ds,0)dh(table.concat(aO,'\n'))end;return{log=dh,dump=dj,measure=dk,nanoTime=dg,timer=dq,dumpTree=dr}end)c("misc.inspect",function(aw,n,c,d)local dv;if(tonumber((_VERSION or''):match('[%d.]*$'))or 0)<5.3 then local dw,dx=pcall(aw,'compat53.module')if dw then dv=dx end end;local math=dv and dv.math or math;local string=dv and dv.string or string;local table=dv and dv.table or table;local df={Options={}}df.KEY=setmetatable({},{__tostring=function()return'inspect.KEY'end})df.METATABLE=setmetatable({},{__tostring=function()return'inspect.METATABLE'end})local tostring=tostring;local dy=string.rep;local dz=string.match;local dA=string.char;local dB=string.gsub;local dC=string.format;local function dD(aV)return next,aV,nil end;local function dE(cC)if dz(cC,'"')and not dz(cC,"'")then return"'"..cC.."'"end;return'"'..dB(cC,'"','\\"')..'"'end;local dF={["\a"]="\\a",["\b"]="\\b",["\f"]="\\f",["\n"]="\\n",["\r"]="\\r",["\t"]="\\t",["\v"]="\\v",["\127"]="\\127"}local dG={["\127"]="\127"}for aq=0,31 do local dH=dA(aq)if not dF[dH]then dF[dH]="\\"..aq;dG[dH]=dC("\\%03d",aq)end end;local function dI(cC)return dB(dB(dB(cC,"\\","\\\\"),"(%c)%f[0-9]",dG),"%c",dF)end;local function dJ(cC)return type(cC)=="string"and not not cC:match("^[_%a][_%a%d]*$")end;local dK=math.floor;local function dL(aX,dM)return type(aX)=="number"and dK(aX)==aX and 1<=aX and aX<=dM end;local dN={['number']=1,['boolean']=2,['string']=3,['table']=4,['function']=5,['userdata']=6,['thread']=7}local function dO(ca,cb)local dP,dQ=type(ca),type(cb)if dP==dQ and(dP=='string'or dP=='number')then return ca<cb end;local dR=dN[dP]or 100;local dS=dN[dQ]or 100;return dR==dS and dP<dQ or dR<dS end;local function dT(aV)local dU=1;while rawget(aV,dU)~=nil do dU=dU+1 end;dU=dU-1;local aW,dV={},0;for aX in dD(aV)do if not dL(aX,dU)then dV=dV+1;aW[dV]=aX end end;table.sort(aW,dO)return aW,dV,dU end;local function dW(at,dX)if type(at)=="table"then if dX[at]then dX[at]=dX[at]+1 else dX[at]=1;for aX,aY in dD(at)do dW(aX,dX)dW(aY,dX)end;dW(getmetatable(at),dX)end end end;local function dY(dZ,ca,cb)local d_={}local e0=#dZ;for aq=1,e0 do d_[aq]=dZ[aq]end;d_[e0+1]=ca;d_[e0+2]=cb;return d_ end;local function e1(e2,a4,dZ,e3)if a4==nil then return nil end;if e3[a4]then return e3[a4]end;local e4=e2(a4,dZ)if type(e4)=="table"then local e5={}e3[a4]=e5;local e6;for aX,aY in dD(e4)do e6=e1(e2,aX,dY(dZ,aX,df.KEY),e3)if e6~=nil then e5[e6]=e1(e2,aY,dY(dZ,e6),e3)end end;local e7=e1(e2,getmetatable(e4),dY(dZ,df.METATABLE),e3)if type(e7)~='table'then e7=nil end;setmetatable(e5,e7)e4=e5 end;return e4 end;local function e8(e9,cC)e9.n=e9.n+1;e9[e9.n]=cC end;local ea={}local eb={__index=ea}local function ec(ed)e8(ed.buf,ed.newline..dy(ed.indent,ed.level))end;function ea:getId(aY)local bw=self.ids[aY]local ee=self.ids;if not bw then local ef=type(aY)bw=(ee[ef]or 0)+1;ee[aY],ee[ef]=bw,bw end;return tostring(bw)end;function ea:putValue(aY)local e9=self.buf;local ef=type(aY)if ef=='string'then e8(e9,dE(dI(aY)))elseif ef=='number'or ef=='boolean'or ef=='nil'or ef=='cdata'or ef=='ctype'then e8(e9,tostring(aY))elseif ef=='table'and not self.ids[aY]then local aV=aY;if aV==df.KEY or aV==df.METATABLE then e8(e9,tostring(aV))elseif self.level>=self.depth then e8(e9,'{...}')else if self.cycles[aV]>1 then e8(e9,dC('<%d>',self:getId(aV)))end;local aW,dV,dU=dT(aV)e8(e9,'{')self.level=self.level+1;for aq=1,dU+dV do if aq>1 then e8(e9,',')end;if aq<=dU then e8(e9,' ')self:putValue(aV[aq])else local aX=aW[aq-dU]ec(self)if dJ(aX)then e8(e9,aX)else e8(e9,"[")self:putValue(aX)e8(e9,"]")end;e8(e9,' = ')self:putValue(aV[aX])end end;local e7=getmetatable(aV)if type(e7)=='table'then if dU+dV>0 then e8(e9,',')end;ec(self)e8(e9,'<metatable> = ')self:putValue(e7)end;self.level=self.level-1;if dV>0 or type(e7)=='table'then ec(self)elseif dU>0 then e8(e9,' ')end;e8(e9,'}')end else e8(e9,dC('<%s %d>',ef,self:getId(aY)))end end;function df.inspect(c6,eg)eg=eg or{}local eh=eg.depth or math.huge;local ei=eg.newline or'\n'local ej=eg.indent or'  'local e2=eg.process;if e2 then c6=e1(e2,c6,{},{})end;local dX={}dW(c6,dX)local ed=setmetatable({buf={n=0},ids={},cycles=dX,depth=eh,level=0,newline=ei,indent=ej},eb)ed:putValue(c6)return table.concat(ed.buf)end;setmetatable(df,{__call=function(o,c6,eg)return df.inspect(c6,eg)end})return df end)c("render.mouse",function(aw,n,c,d)local function ek(at,av,aF)return aF.props.x<=at and aF.props.y<=av and aF.props.x+aF.props.w>at and aF.props.y+aF.props.h>av end;return function(az)local bK={}local function el(em)return function(...)local aH={...}local at,av=aH[2]-1,aH[3]-1;for o,aF in ipairs(bK)do if ek(at,av,aF)then if aF.props[em]and aF.props[em](...)then return true end end end;return false end end;az.on('mouse_click',el('onClick'))az.on('monitor_touch',el('onTouch'))az.on('mouse_up',el('onMouseUp'))az.on('mouse_scroll',el('onScroll'))return{register=function(aF)table.insert(bK,aF)end,clear=function()bK={}end}end end)c("ui.events",function(aw,n,c,d)return function()local az={}local function en(eo,aT)if type(eo)=='function'then aT=eo;eo='_all_'end;az[eo]=az[eo]or{}table.insert(az[eo],aT)end;local function ep(eo,aT)if type(eo)=='function'then aT=eo;eo='_all_'end;if az[eo]then for aq,aY in ipairs(az[eo])do if aY==aT then table.remove(az[eo],aq)break end end end end;local function eq(aH,...)if az[aH]then for aq=#az[aH],1,-1 do if az[aH][aq](...)then break end end end;if az['_all_']then for aq=#az['_all_'],1,-1 do if az['_all_'][aq](aH,...)then break end end end end;local function er(eo,aT)if type(eo)=='function'then aT=eo;eo='_all_'end;local function es(aH)aT(aH)ep(eo,es)end;en(eo,es)end;local function cj(eo)if eo==nil then eo='_all_'end;az[eo]=nil end;return{on=en,off=ep,emit=eq,clear=cj,once=er}end end)return a("__root")end)c("lib.utils",function(require,n,c,d)local q={}q.tableToList=function(aZ)local et={}for o,a4 in pairs(aZ)do table.insert(et,a4)end;return et end;q.filter=function(aZ,aP)local _={}for o,aY in ipairs(aZ)do if aP(aY)then table.insert(_,aY)end end;return _ end;q.map=function(aZ,aP)local _={}for aq,aY in ipairs(aZ)do table.insert(_,aP(aY,aq,aZ))end;return _ end;q.reduce=function(aZ,aP,bv)local aO=bv;for aq,aY in ipairs(aZ)do aO=aP(aO,aY,aq)end;return aO end;q.split=function(cC,eu)local _={}for dz in(cC..eu):gmatch('(.-)'..eu)do table.insert(_,dz)end;return _ end;q.splitByChunk=function(cl,ev)local aR={}for aq=1,#cl,ev do aR[#aR+1]=cl:sub(aq,aq+ev-1)end;return aR end;q.trim=function(aR)return aR:gsub("^%s*(.-)%s*$","%1")end;q.wrapText=function(cl,an,ew,as)local aO={}cl=q.trim(cl)if cl==nil or cl==''or an==0 or ew==0 then return aO end;as=as or'left'local ex=q.map(q.split(cl,'\n'),function(ey)local ez=q.split(ey,' ')ez=q.filter(ez,function(eA)return string.len(eA)>0 end)ez=q.reduce(ez,function(eB,eA)if#eA>an then local eC=q.map(q.splitByChunk(eA,an-1),function(eD,aq,eC)return eD..(#eC>aq and'-'or'')end)for o,eD in ipairs(eC)do table.insert(eB,eD)end else table.insert(eB,eA)end;return eB end,{})return ez end)for o,ey in ipairs(ex)do local eE=''for o,eA in ipairs(ey)do if#eE+#eA+1>an and#eE>0 then table.insert(aO,eE)eE=eA elseif#eE+#eA+1>an then table.insert(aO,eA)eE=''elseif#eE>0 then eE=eE..' '..eA else eE=eA end end;table.insert(aO,eE)end;aO=q.slice(aO,1,ew)if as=='center'then aO=q.map(aO,function(ey)local eF=math.floor((an-#ey)/2)return string.rep(' ',eF)..ey end)elseif as=='right'then aO=q.map(aO,function(ey)local eF=an-#ey;return string.rep(' ',eF)..ey end)end;return aO end;q.slice=function(aZ,dn,eG)local _={}local eH=eG and dn+eG-1 or#aZ-dn;for aq=dn,eH do table.insert(_,aZ[aq])end;return _ end;q.recipeInputSummary=function(eI)local eJ={}for aq=1,#eI do local Y=eI[aq]if not eJ[Y['name']]then eJ[Y['name']]={['name']=Y['name'],['displayName']=Y['displayName'],['count']=1}else eJ[Y['name']]['count']=eJ[Y['name']]['count']+1 end end;local eK=q.tableToList(eJ)table.sort(eK,function(ca,cb)return ca['count']>cb['count']end)return eK end;q.setTheme=function(eL,r)for aX,aY in pairs(r)do if eL.setPaletteColour then eL.setPaletteColour(aY[1],aY[2])end;colors[aX]=aY[1]end end;return q end)c("components.Button3D",function(require,n,c,d)local p=require("lib.luact")local v=require("components.Label")local t=require("components.Object")return p.createComponent(function(G)local eM=G.focus or colors.focus;local eN=G.background or colors.primary;local eO,eP=p.useState(false)p.useSchedule(function()if not eO then return end;os.sleep(0.2)eP(false)if G.click then G.click()end end,{eO})local cs=(G.w or'parent.w')..' - 1'local ct=G.h or'parent.h'local eQ=eN;if G.disabled then eQ=colors.disabled elseif eO then eQ=eM end;return p.Fragment(t({x=(G.x or 0)..' + 1',y=(G.y or 0)..' + 1',w=cs,h=ct,background=colors.shadow}),t({onClick=function()if not G.disabled then eP(true)end end,onTouch=function()if not G.disabled then eP(true)end end,x=eO and(G.x or 0)..' + 1'or(G.x or 0),y=eO and(G.y or 0)..' + 1'or(G.y or 0),w=cs,h=ct,background=eQ},v({text=G.text,align='center',valign='middle',color=G.color or colors.text})))end)end)c("components.Button",function(require,n,c,d)local p=require("lib.luact")local v=require("components.Label")local t=require("components.Object")return p.createComponent(function(G)local eM=G.focus or colors.focus;local eN=G.background or colors.primary;local eO,eP=p.useState(false)p.useSchedule(function()if not eO then return end;os.sleep(0.2)eP(false)if G.click then G.click()end end,{eO})local eQ=eN;if G.disabled then eQ=colors.disabled elseif eO then eQ=eM end;return p.Fragment(t({onClick=function()if not G.disabled then eP(true)end end,onTouch=function()if not G.disabled then eP(true)end end,x=G.x or 0,y=G.y or 0,w=G.w or'parent.w',h=G.h or'parent.h',hidden=G.hidden,background=eQ},v({text=G.text,align='center',valign='middle',color=G.color or colors.text})))end)end)c("components.Window",function(require,n,c,d)local p=require("lib.luact")local t=require("components.Object")local v=require("components.Label")return p.createComponent(function(G)return t({background=colors.background},t({h=1,background=colors.primary},t({x='parent.w - 1',y=0,w=1,h=1,text=string.char(215),onClick=function()os.queueEvent('app_exit')end,onTouch=function()os.queueEvent('app_exit')end}),v({text=string.char(17)..' '..G.title..' '..string.char(16),x=0,y=0,align='center',color=colors.text,background=colors.primary})),t({x=0,y=1,w='parent.w',h='parent.h - 1',background=colors.background},G.children))end)end)return a("__root")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement