Advertisement
bobmarley12345

CC BigReactor controller

Nov 23rd, 2023 (edited)
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 53.00 KB | None | 0 0
  1. -- By TheRareCarrot/REghZy >:)
  2. -- This is minified/obfuscated purely to reduce file size! Tool used (+ my own editing): https://mothereff.in/lua-minifier
  3. -- The source code can be found here: https://pastebin.com/R9niGHQw
  4. -- If you wanna know more about how this works then feel free to ask :D
  5.  
  6. local a=true;local b={}local c=0;local d=10;local e=1/d;local f=true;local g=0;local h;local i=true;local j=false;local k=0;local l=false;local m=true;local n=false;local o=nil;local p=false;local q=nil;local r={}local s={}local t={}local u=term;local v=0;local w=0;local x=0;local y=0;local z=nil;local A=nil;local B=nil;local C=1;local D=1;local E=2;local F=3;local G=4;local H=1;local I=2;local J=3;local K=20;local L=40;local M=100;local N=false;local O={}local P={}local Q={[D]={},[E]={},[F]={},[G]={}}local R={}local S={}function DefineType(T,U)local V={}V.__index=V;if T~=nil then setmetatable(V,T)V.__TheBaseType__=T end;V.ActualTypeString=U or"<no typename>"if T~=nil and T.SetupDerivedType~=nil then T.SetupDerivedType(T,V)end;return V end;function NewTypeInstance(W,U)local T=W.__TheBaseType__;local X;if T==nil or T.new==nil then X={}else X=T.new()end;setmetatable(X,W)X.TypeName=U or W.ActualTypeString;X.__TheType__=W;X.__TheBaseType__=T;return X end;local Y=DefineType(nil,"BaseRZObject")_DO=DefineType(Y,"_DO")_DO.PropTable={}_DO.PropTable.TotalEntries=0;function _DO:SetupDerivedType(Z)Z.PropTable={}Z.PropTable.TotalEntries=0 end;local _={}function _DO.new()local X=NewTypeInstance(_DO,"_DO")X.PropValueTable={}return X end;function _DO:RegProp(a0,W,a1,...)if self.PropTable==nil then error("Not a _DO: "..(self.TypeName or"<unknown type>"))end;if self.PropTable[a0]~=nil then error("Property already exists: "..a0 ..". Self = "..self.ActualTypeString)end;if self.__TheType__~=nil then error("Properties must be registered on the object type table, not the instance")end;local a2={Name=a0,ValueType=W,DefaultValue=a1,Flags={},ChangeHandlers={}}if arg~=nil then for a3=1,arg.n do a2.Flags[arg[a3]]=true end end;self.PropTable[a0]=a2;self.PropTable.TotalEntries=self.PropTable.TotalEntries+1;return a2 end;function _DO:FindProperty(a4)if type(a4)=="string"then local X=self;local a2;while true do a2=X.PropTable[a4]if a2~=nil then return a2 end;X=X.__TheBaseType__;if X==nil then break end end;error("No such property: "..a4)elseif a4==nil then error("Property (or name) cannot be null")elseif a4.Name==nil then error("Invalid property object")end;return a4 end;function _DO:AddPropertyHandler(a5,a6)local a7=self.PropTable[a5]if a7==nil then error("No such property: "..a5)end;table.insert(a7.ChangeHandlers,a6)end;function _DO:GetPropValue(a8)local a2=self:FindProperty(a8)local a9=self.PropValueTable[a2]if a9==nil then return a2.DefaultValue elseif a9==_ then return nil else return a9 end end;function _DO:SetPropValue(a8,aa)local a2=self:FindProperty(a8)local ab=self.PropValueTable[a2]if ab==nil then ab=a2.DefaultValue end;if ab==aa then return end;self.PropValueTable[a2]=aa or _;self:InternalOnPropValueChanged(a2,ab,aa,false)end;function _DO:ClearPropValue(a8)local a2=self:FindProperty(a8)local ab=self.PropValueTable[a2]if ab==nil then return end;if ab==_ then ab=nil end;self.PropValueTable[a2]=nil;self:InternalOnPropValueChanged(a2,ab,nil,true)end;function _DO:InternalOnPropValueChanged(a2,ab,aa,ac)end;local function ad(ae,af)return(af-1)*x+ae end;function r.setBackgroundColour(ag)if ag~=nil then u.setBackgroundColour(ag)end end;function r.setTextColour(ah)if ah~=nil then u.setTextColour(ah)end end;function r.clear()u.setBackgroundColour(colours.black)u.setTextColour(colours.white)u.clear()u.setCursorPos(1,1)end;function r.writeTextAt(ae,af,ai)u.setCursorPos(ae+v,af+w)u.write(ai)end;function r.fill(ae,af,aj,ak,al)r.setBackgroundColour(al)local ai=string.rep(" ",aj)for a3=0,ak-1 do r.writeTextAt(ae,af+a3,ai)end end;function r.drawText(ae,af,ai,am,al)r.setTextColour(am)r.setBackgroundColour(al)r.writeTextAt(ae,af,ai)end;function r.drawTextCentered(ae,af,aj,ak,ai,am,al)local an=math.floor(aj/2-#ai/2)local ao=math.floor(ak/2)r.drawText(ae+an,af+ao,ai,am,al)end;function r.drawLineH(ae,af,ap,aq)r.setBackgroundColour(aq)r.writeTextAt(ae,af,string.rep(" ",ap))end;function r.drawLineV(ae,af,ak,aq)ae=ae+v;af=af+w;r.setBackgroundColour(aq)for a3=1,ak,1 do u.setCursorPos(ae,af+a3)u.write(" ")end end;local function ar(ap,as,at,a9)return math.floor(s.clamp(a9,as,at)/(at-as)*ap)end;function r.drawProgressBarH(ae,af,ap,as,at,a9,al,au,av)local aw=ar(ap,as,at,a9)r.drawLineH(aw+1,af,ap-aw,al)if av==true then r.drawLineH(ae+ap-aw,af,aw,au)else r.drawLineH(ae,af,aw,au)end end;function r.drawProgressBarV(ae,af,ak,as,at,a9,al,au,ax)r.drawLineV(ae,af,ak,al)local aw=ar(ak,as,at,a9)if ax~=nil and ax==true then r.drawLineV(ae,af+ak-aw,aw,au)else r.drawLineV(ae,af,aw,au)end end;function PushFunction(ay,...)if a then table.insert(b,{FunctionName=ay,Args={...}})end end;function PushFunctionAndInvoke(ay,az,...)PushFunction(ay)return PopFunction(az(...))end;function PopFunction(...)if a and#b>0 then table.remove(b,#b)end;if...~=nil then return...end end;function PrintStackTrace()for a3=1,#b,1 do local aA=b[a3]local ai=aA.FunctionName;if#aA.Args>0 then local aB={}for aC,a9 in pairs(aA.Args)do if type(aC)=="number"then table.insert(aB,tostring(a9))else table.insert(aB,tostring(aC).."="..tostring(a9))end end;ai=ai..": "..table.concat(aB,", ")end;print(ai)PrintDebug(ai)end end;function PrintDebug(aD,...)if l and o~=nil then local aE={...}if aE~=nil and#aE>0 then for a3=1,#aE do local aF=aE[a3]if aF==nil then aE[a3]="nil"else local aG=type(aF)if aG=="boolean"or aG=="function"or aG=="table"then aE[a3]=tostring(aF)end end end;aD=string.format(aD,unpack(aE))end;o.writeLine(aD)end end;function s.min(...)local as=0;for a3=1,arg.n,1 do as=math.min(#arg[a3],as)end;return as end;function s.max(...)local at=0;for a3=1,arg.n,1 do at=math.max(#arg[a3],at)end;return at end;function s.clamp(a9,as,at)if a9<as then return as end;if a9>at then return at end;return a9 end;function s.isNaN(aH)return aH~=aH end;function UpdateCachedIndices(aI)for aJ,X in pairs(aI)do X.IndexInParent=aJ end end;function ClearTable(V)for a3=#V,1,-1 do table.remove(V,a3)end end;local aK=DefineType(Y,"DispatcherOperation")function aK.new(aL,...)local aM=C;C=aM+1;local aN=NewTypeInstance(aK)aN.Id=aM;aN.IsCompleted=false;aN.Method=aL;aN.Args={...}return aN end;function InvokeAsync(aL,aO,...)local aN=aK.new(aL,...)if aO==nil then aO=G end;table.insert(Q[aO],aN)if g==0 then g=os.startTimer(0)end;return aN end;function InvokeAsyncWithDelay(aL,aP,...)local aN=aK.new(aL,...)aN.TimeUntilExecution=os.clock()+aP;table.insert(R,aN)end;UIComponent=DefineType(_DO,"UIComponent")UIComponent.MarginLProperty=_DO.RegProp(UIComponent,"MarginL","number",0,"AffectsArrange")UIComponent.MarginTProperty=_DO.RegProp(UIComponent,"MarginT","number",0,"AffectsArrange")UIComponent.MarginRProperty=_DO.RegProp(UIComponent,"MarginR","number",0,"AffectsArrange")UIComponent.MarginBProperty=_DO.RegProp(UIComponent,"MarginB","number",0,"AffectsArrange")UIComponent.HorizontalAlignmentProperty=_DO.RegProp(UIComponent,"HorizontalAlignment","string","left","AffectsArrange")UIComponent.VerticalAlignmentProperty=_DO.RegProp(UIComponent,"VerticalAlignment","string","top","AffectsArrange")UIComponent.WidthProperty=_DO.RegProp(UIComponent,"Width","number",nil,"AffectsMeasure")UIComponent.HeightProperty=_DO.RegProp(UIComponent,"Height","number",nil,"AffectsMeasure")UIComponent.MinWidthProperty=_DO.RegProp(UIComponent,"MinWidth","number",0,"AffectsMeasure")UIComponent.MinHeightProperty=_DO.RegProp(UIComponent,"MinHeight","number",0,"AffectsMeasure")UIComponent.MaxWidthProperty=_DO.RegProp(UIComponent,"MaxWidth","number",math.huge,"AffectsMeasure")UIComponent.MaxHeightProperty=_DO.RegProp(UIComponent,"MaxHeight","number",math.huge,"AffectsMeasure")UIComponent.IsFocusableProperty=_DO.RegProp(UIComponent,"IsFocusable","boolean",false)UIComponent.IsFocusedProperty=_DO.RegProp(UIComponent,"IsFocused","boolean",false)UIComponent.BackgroundProperty=_DO.RegProp(UIComponent,"Background","number",nil,"AffectsRender")Button=DefineType(UIComponent,"Button")Button.TextProperty=_DO.RegProp(Button,"Text","string","Text","AffectsMeasure","AffectsRender")Button.PressedBackgroundProperty=_DO.RegProp(Button,"PressedBackground","number",colours.lightBlue,"AffectsRender")TextBlock=DefineType(UIComponent,"TextBlock")TextBlock.TextProperty=_DO.RegProp(TextBlock,"Text","string","Text","AffectsMeasure","AffectsRender")TextBlock.TextColourProperty=_DO.RegProp(TextBlock,"TextColour","string",colours.white,"AffectsRender")UniformPanel=DefineType(UIComponent,"UniformPanel")UniformPanel.OrientationProperty=_DO.RegProp(UniformPanel,"Orientation","string","horizontal")UniformPanel.SpacingProperty=_DO.RegProp(UniformPanel,"Spacing","number",0)HorizontalStackPanel=DefineType(UIComponent,"HorizontalStackPanel")VerticalStackPanel=DefineType(UIComponent,"VerticalStackPanel")DockPanel=DefineType(UIComponent,"DockPanel")ContentPresenter=DefineType(UIComponent,"ContentPresenter")local aQ=DefineType(UIComponent,"TabControl")ProgressBar=DefineType(UIComponent,"ProgressBar")ProgressBar.ValueColourProperty=_DO.RegProp(ProgressBar,"ValueColour","number",colours.lightBlue,"AffectsRender")ProgressBar.ValueProperty=_DO.RegProp(ProgressBar,"Value","number",0,"AffectsRender")ProgressBar.MinimumProperty=_DO.RegProp(ProgressBar,"Minimum","number",0,"AffectsRender")ProgressBar.MaximumProperty=_DO.RegProp(ProgressBar,"Maximum","number",1,"AffectsRender")local aR=DefineType(UIComponent,"DualColourTextBlock")local aS=DefineType(UIComponent,"BasePageComponent")local aT=DefineType(aS,"HomePageComponent")local aU=DefineType(aS,"RodsPageComponent")local aV=DefineType(aS,"AutoPageComponent")local aW=DefineType(aS,"InfoPageComponent")function UIComponent:AddEventHandler(type,aX)PushFunction("AddEventHandler",self.TypeName)local aY=self.EventHandlers[type]if aY==nil then aY={}self.EventHandlers[type]=aY end;table.insert(aY,aX)PopFunction()end;function UIComponent:RaiseEvent(type,aZ,aE)PushFunction("RaiseEvent",self.TypeName)local a_=self.EventHandlers[type]if a_~=nil then if aZ==nil then aZ=os.clock()end;for a3,aX in ipairs(a_)do if aX(self,aZ,aE)==true then aE.handled=true end end end;return PopFunction(aE.handled)end;function UIComponent:InternalOnPropValueChanged(a2,ab,aa,ac)if a2.Flags["AffectsMeasure"]==true then self:InvalidateMeasure()end;if a2.Flags["AffectsArrange"]==true then self:InvalidateArrange()end;if a2.Flags["AffectsRender"]==true then self:InvalidateVisual()end;_DO.InternalOnPropValueChanged(self,a2,ab,aa,ac)local aZ=os.clock()local aE={OldValue=ab,NewValue=aa,Property=a2}for a3,aX in ipairs(a2.ChangeHandlers)do aX(self,aZ,aE)end;self:RaiseEvent(M,aZ,aE)end;function UIComponent.new()local X=NewTypeInstance(UIComponent,"UIComponent")X.DesiredWidth=0;X.DesiredHeight=0;X.RenderPosX=0;X.RenderPosY=0;X.RenderWidth=0;X.RenderHeight=0;X._internal_Visibility="visible"X._internal_FinalVisibility="visible"X.IsVisualDirty=false;X.IsMeasureDirty=false;X.IsArrangeDirty=false;X._NM=true;X.NeverArranged=true;X.MeasureInProgress=false;X.ArrangeInProgress=false;X.MeasureDuringArrange=false;X._LMW=0;X._LMH=0;X.LastArrangeFinalX=0;X.LastArrangeFinalY=0;X.LastArrangeFinalW=0;X.LastArrangeFinalH=0;X.IsVisualPositionValid=false;X.Children={}X.IndexInParent=-1;X.Parent=nil;X.IdToChildTable={}X.EventHandlers={}return X end;function UIComponent:SetVisibility(b0)self._internal_Visibility=b0;self:UpdateVisibility()self:InvalidateLayoutAndVisual()end;function UIComponent:GetVisibility(b1)if b1==true then return self._internal_Visibility else return self._internal_FinalVisibility end end;function UIComponent:UpdateVisibility()if self.Parent==nil then self._internal_FinalVisibility=self._internal_Visibility else local b2=self.Parent._internal_FinalVisibility;if b2=="visible"then self._internal_FinalVisibility=self._internal_Visibility else self._internal_FinalVisibility=b2 end end;for a3,b3 in ipairs(self.Children)do b3:UpdateVisibility()end end;function UIComponent:SetMargin(b4,b5,b6,b7)if b4~=nil then _DO.SetPropValue(self,UIComponent.MarginLProperty,b4)end;if b5~=nil then _DO.SetPropValue(self,UIComponent.MarginTProperty,b5)end;if b6~=nil then _DO.SetPropValue(self,UIComponent.MarginRProperty,b6)end;if b7~=nil then _DO.SetPropValue(self,UIComponent.MarginBProperty,b7)end;return self end;function UIComponent:SetAlignment(b8,b9)if b8~=nil then _DO.SetPropValue(self,UIComponent.HorizontalAlignmentProperty,b8)end;if b9~=nil then _DO.SetPropValue(self,UIComponent.VerticalAlignmentProperty,b9)end;return self end;function UIComponent:SetSize(aj,ak)if aj~=nil then _DO.SetPropValue(self,UIComponent.WidthProperty,aj)end;if ak~=nil then _DO.SetPropValue(self,UIComponent.HeightProperty,ak)end;return self end;function UniformPanel.new()local X=NewTypeInstance(UniformPanel,"UniformPanel")return X end;function HorizontalStackPanel.new()return NewTypeInstance(HorizontalStackPanel,"HorizontalStackPanel")end;function VerticalStackPanel.new()return NewTypeInstance(VerticalStackPanel,"VerticalStackPanel")end;function ProgressBar.new(as,at,aH,al,au)local ba=NewTypeInstance(ProgressBar,"ProgressBar")ba:SetPropValue(ProgressBar.MinimumProperty,as or 0)ba:SetPropValue(ProgressBar.MaximumProperty,at or 1)ba:SetPropValue(ProgressBar.ValueProperty,aH or 0)_DO.SetPropValue(ba,UIComponent.BackgroundProperty,al or colours.grey)_DO.SetPropValue(ba,ProgressBar.ValueColourProperty,au or colours.lightBlue)ba:SetSize(nil,1)return ba end;function ProgressBar:SetValue(bb,au)if au~=nil then self:SetPropValue(ProgressBar.ValueColourProperty,au)end;self:SetPropValue(ProgressBar.ValueProperty,bb)end;function ProgressBar:OnRender()local as=self:GetPropValue(ProgressBar.MinimumProperty)or 0;local at=self:GetPropValue(ProgressBar.MaximumProperty)or 1;local a9=self:GetPropValue(ProgressBar.ValueProperty)or 0;r.drawProgressBarH(1,1,self.RenderWidth,as,at,a9,self:GetPropValue(UIComponent.BackgroundProperty),self:GetPropValue(ProgressBar.ValueColourProperty))end;function DockPanel.new()local X=NewTypeInstance(DockPanel,"DockPanel")X.LastChildFill=true;return X end;function ContentPresenter.new()local X=NewTypeInstance(ContentPresenter,"ContentPresenter")return X end;function aQ:SetActiveTabItem(bc)if bc~=nil and bc.IsActive==true then return end;local bd=self.MyContentPresenter;local be=aQ.ActiveTabItem;if be~=nil then be:SetPropValue(UIComponent.BackgroundProperty,be.BackgroundBeforeNotActive)be.BackgroundBeforeNotActive=nil;be.IsActive=false;if be.PageContent~=nil then be.PageContent:SetVisibility("collapsed")end;be:InvalidateLayoutAndVisual()aQ.ActiveTabItem=nil end;if bc~=nil then bc.BackgroundBeforeNotActive=bc:GetPropValue(UIComponent.BackgroundProperty)bc:SetPropValue(UIComponent.BackgroundProperty,colours.lightBlue)bc.IsActive=true;bc:InvalidateLayoutAndVisual()aQ.ActiveTabItem=bc;if bc.PageContent~=nil then bd:ClearChildren()bd:InsertChild(bc.PageContent)bc.PageContent:SetVisibility("visible")end;bc:RaiseEvent(L,os.clock(),{})end;self:InvalidateLayoutAndVisual()end;function OnTabItemClicked(self,aZ,aE)local bf=self.Parent;if bf==nil then return end;local bg=bf.Parent;if bg==nil then return end;bg:SetActiveTabItem(self)end;function Button.new(U,bh)local X=NewTypeInstance(Button,U or"Button")X.IsPressed=false;X.IsToggleButton=false;X:SetPropValue(Button.TextProperty,bh)X:SetPropValue(UIComponent.IsFocusableProperty,true)X:SetPropValue(UIComponent.BackgroundProperty,colours.grey)X:SetPropValue(Button.PressedBackgroundProperty,colours.green)X.DoNotProcessButtonClickLogic=false;UIComponent.AddEventHandler(X,I,Button.OnMouseDown)return X end;function NewTabItem(ai,bi)local bj=Button.new("TabItem:"..ai,ai)bj:SetPropValue(UIComponent.HorizontalAlignmentProperty,"stretch")bj:AddEventHandler(K,OnTabItemClicked)bj:SetPropValue(UIComponent.BackgroundProperty,colours.blue)bj.PageContent=bi;bj.DoNotProcessButtonClickLogic=true;return bj end;function Button:SetPressed(bk)if self.IsPressed==bk then return end;self.IsPressed=bk;self:InvalidateVisual()end;function TextBlock.new(ai,am,al)local X=NewTypeInstance(TextBlock,"TextBlock")X:SetPropValue(TextBlock.TextProperty,ai)if am~=nil then X:SetPropValue(TextBlock.TextColourProperty,am)end;if al~=nil then X:SetPropValue(UIComponent.BackgroundProperty,al)end;return X end;function TextBlock:MeasureOverride(bl,bm)local ai=self:GetPropValue(TextBlock.TextProperty)if ai~=nil then local bn=#ai;if bn<=bl then return bn,1 else return bl,math.ceil(bn/bl)end else return 0,1 end end;function TextBlock:_AO(aj,ak)local ai=self:GetPropValue(TextBlock.TextProperty)if ai==nil then self.InternalLines=nil;return aj,ak end;local bo={}local bp=1;local aJ=aj;local bq=0;while true do bq=bq+1;if bq>ak then break end;table.insert(bo,string.sub(ai,bp,aJ))bp=aJ+1;aJ=aJ+aj end;self.InternalLines=bo;return aj,ak end;function TextBlock:OnRender()UIComponent.OnRender(self)if self.InternalLines~=nil then local br=self:GetPropValue(TextBlock.TextColourProperty)or colours.white;for a3,bs in ipairs(self.InternalLines)do r.drawText(1,a3,bs,br,nil)end end end;function UIComponent:GetMinMax()local bt,bu=self:GetPropValue(UIComponent.MinWidthProperty),self:GetPropValue(UIComponent.MaxWidthProperty)local bv,bw=self:GetPropValue(UIComponent.MinHeightProperty),self:GetPropValue(UIComponent.MaxHeightProperty)local bx,by=self:GetPropValue(UIComponent.WidthProperty),self:GetPropValue(UIComponent.HeightProperty)bu=math.max(math.min(bx or math.huge,bu),bt)bt=math.max(math.min(bu,bx or 0),bt)bw=math.max(math.min(by or math.huge,bw),bv)bv=math.max(math.min(bw,by or 0),bv)return bt,bu,bv,bw end;function UIComponent:GetRenderPositon()PushFunction("GetRenderPositon",self.TypeName)if self.IsVisualPositionValid then return PopFunction(self.AbsVisualPosX or 1,self.AbsVisualPosY or 1)end;if self.IsArrangeDirty then error("Arrangement is dirty; cannot get absolute position")end;local bz={}local bA=self;while bA~=nil do table.insert(bz,1,bA)bA=bA.Parent end;local ae,af=0,0;for a3,bB in ipairs(bz)do ae=ae+bB.RenderPosX;af=af+bB.RenderPosY end;self.AbsVisualPosX=ae;self.AbsVisualPosY=af;self.IsVisualPositionValid=true;return PopFunction(ae,af)end;function UIComponent:OnRender()local bC=self:GetPropValue(UIComponent.BackgroundProperty)if bC~=nil then r.fill(1,1,self.RenderWidth,self.RenderHeight,bC)end end;function UIComponent:Measure(bl,bm)if bl==nil then error("Cannot measure with nil width")end;if bm==nil then error("Cannot measure with nil height")end;if self:GetVisibility()=="collapsed"then self._LMW=bl;self._LMH=bm;if l then PrintDebug("Skipping measure for %s as it is collapsed",self.TypeName)end else local bD=bl==self._LMW and bm==self._LMH;if self.IsMeasureDirty or self._NM or not bD then if l then PrintDebug("Begin Measure '%s' (forced = %s, dirty = %s, _NM = %s, similar = %s)",self.TypeName,N,self.IsMeasureDirty,self._NM,bD)end;self._NM=false;self._LMW=bl;self._LMH=bm;self.MeasureInProgress=true;local bx,by=self:MeasureCore(bl,bm)self.MeasureInProgress=false;if bx==nil then error("MeasureCore returned null width")end;if by==nil then error("MeasureCore returned null height")end;self.DesiredWidth=bx;self.DesiredHeight=by;self.IsMeasureDirty=false;if l then PrintDebug("End Measure '%s' (%f x %f)",self.TypeName,bx,by)end else if l then PrintDebug("Skipping measure for %s",self.TypeName)end end end;return self.DesiredWidth,self.DesiredHeight end;function UIComponent:MeasureCore(bl,bm)local bE=self:GetPropValue(UIComponent.MarginLProperty)+self:GetPropValue(UIComponent.MarginRProperty)local bF=self:GetPropValue(UIComponent.MarginTProperty)+self:GetPropValue(UIComponent.MarginBProperty)local bG,bH,bI,bJ=self:GetMinMax()local bK=s.clamp(math.max(bl-bE,0),bG,bH)local bL=s.clamp(math.max(bm-bF,0),bI,bJ)bK,bL=self:MeasureOverride(bK,bL)bK,bL=math.max(bK,bG),math.max(bL,bI)local bM,bN=bK,bL;local bO=false;if bK>bH then bK=bH;bO=true end;if bL>bJ then bL=bJ;bO=true end;local bP,bQ=bK+bE,bL+bF;if bP>bl then bP=bl;bO=true end;if bQ>bm then bQ=bm;bO=true end;local bR=self.UnclippedDesiredSize;if bO or bP<0 or bQ<0 then if bR==nil then bR={}self.UnclippedDesiredSize=bR end;bR.w=bM;bR.h=bN elseif bR~=nil then self.UnclippedDesiredSize=nil end;bP=math.max(bP,0)bQ=math.max(bQ,0)return bP,bQ end;function UIComponent:MeasureOverride(bl,bm)local bx,by=0,0;for a3,b3 in ipairs(self.Children)do local bS,bT=b3:Measure(bl,bm)if bS>bx then bx=bS end;if bT>by then by=bT end end;return bx,by end;function UIComponent:SetLastArrangeRect(bU,bV,bW,bX)self.LastArrangeFinalX=bU;self.LastArrangeFinalY=bV;self.LastArrangeFinalW=bW;self.LastArrangeFinalH=bX end;function UIComponent:Arrange(bY,bZ,b_,c0)if self:GetVisibility()=="collapsed"then if l then PrintDebug("Skipping arrange for %s as it is collapsed",self.TypeName)end;self:SetLastArrangeRect(bY,bZ,b_,c0)return end;if self.IsMeasureDirty or self._NM then if l then PrintDebug("Measuring %s during arrange (Dirty = %s, _NM = %s)",self.TypeName,self.IsMeasureDirty,self._NM)end;self.MeasureDuringArrange=true;if self._NM then self:Measure(b_,c0)else self:Measure(self._LMW,self._LMH)end;self.MeasureDuringArrange=false end;local c1=self.LastArrangeFinalX==bY and self.LastArrangeFinalY==bZ and self.LastArrangeFinalW==b_ and self.LastArrangeFinalH==c0;if N or self.IsArrangeDirty or self.NeverArranged or not c1 then if l then PrintDebug("Begin Arrange '%s' (forced = %s, dirty = %s, NeverArranged = %s, similar = %s)",self.TypeName,N,self.IsArrangeDirty,self.NeverArranged,c1)end;self.IsVisualPositionValid=false;self.NeverArranged=false;self.ArrangeInProgress=true;self:ArrangeCore(bY,bZ,b_,c0)self.ArrangeInProgress=false;self:SetLastArrangeRect(bY,bZ,b_,c0)self.IsArrangeDirty=false;if l then PrintDebug("End Arrange '%s' at %f,%f (%f x %f)",self.TypeName,self.RenderPosX,self.RenderPosY,self.RenderWidth,self.RenderHeight)end else if l then PrintDebug("Skipping arrange for %s",self.TypeName)end end end;function UIComponent:ArrangeCore(bY,bZ,c2,c3)local c4,c5,c6,c7=self:GetPropValue(UIComponent.MarginLProperty),self:GetPropValue(UIComponent.MarginTProperty),self:GetPropValue(UIComponent.MarginRProperty),self:GetPropValue(UIComponent.MarginBProperty)c2=math.max(c2-(c4+c6),0)c3=math.max(c3-(c5+c7),0)local c8,c9=c2,c3;local ca,cb;if self.UnclippedDesiredSize==nil then ca=math.max(self.DesiredWidth-(c4+c6),0)cb=math.max(self.DesiredHeight-(c5+c7),0)else ca=self.UnclippedDesiredSize.w;cb=self.UnclippedDesiredSize.h end;self.NeedClipBounds=false;if ca>c2 then c2=ca;self.NeedClipBounds=true end;if cb>c3 then c3=cb;self.NeedClipBounds=true end;local cc=_DO.GetPropValue(self,UIComponent.HorizontalAlignmentProperty)local cd=_DO.GetPropValue(self,UIComponent.VerticalAlignmentProperty)if cc~="stretch"then c2=ca end;if cd~="stretch"then c3=cb end;local ce,bH,ce,bJ=self:GetMinMax()local cf=math.max(ca,bH)if c2>cf then c2=cf;self.NeedClipBounds=true end;local cg=math.max(cb,bJ)if c3>cg then c3=cg;self.NeedClipBounds=true end;local ch,ci=self:_AO(c2,c3)if ch==nil then error("_AO Width cannot be null")end;if ci==nil then error("_AO Height cannot be null")end;self.RenderWidth=ch;self.RenderHeight=ci;local cj,ck=math.min(ch,bH),math.min(ci,bJ)if not self.NeedClipBounds and(cj<ch or ck<ci)then self.NeedClipBounds=true end;if not self.NeedClipBounds and(c8<cj or c9<ck)then self.NeedClipBounds=true end;if cj>c8 then cc="left"end;if ck>c9 then cd="top"end;local cl,cm=0,0;if cc=="center"or cc=="stretch"then cl=(c8-cj)/2 elseif cc=="right"then cl=c8-cj end;if cd=="center"or cd=="stretch"then cm=(c9-ck)/2 elseif cd=="bottom"then cm=c9-ck end;self.RenderPosX=cl+bY+c4;self.RenderPosY=cm+bZ+c5 end;function UIComponent:_AO(aj,ak)for a3,b3 in ipairs(self.Children)do b3:Arrange(0,0,aj,ak)if b3.IsArrangeDirty then error("Child arrange was dirty after Arrange() call")end end;return aj,ak end;function UIComponent:IsMousePointOver(ae,af)if ae<0 or ae>=self.RenderWidth then return false end;if af<0 or af>=self.RenderHeight then return false end;return true end;function t.RenderComponent(bB)local an,ao=bB:GetRenderPositon()v=an;w=ao;z=bB;bB:OnRender()bB.IsVisualDirty=false end;function t.RenderComponentTreeInternal(bB)if bB:GetVisibility()~="visible"then return end;if bB.IsArrangeDirty then error("Component's arrangement is dirty; cannot render")end;t.RenderComponent(bB)for a3,b3 in ipairs(bB.Children)do t.RenderComponentTreeInternal(b3)end end;function t.RenderComponentTree(bB)PushFunction("DoRenderComponent",bB.TypeName)if m then t.RenderComponentTreeInternal(bB)z=nil;v=0;w=0 end;PopFunction()end;function t.GetComponentDepth(bB,cn)if cn==nil then cn=0 end;while bB~=nil do cn=cn+1;bB=bB.Parent end;return cn end;function t.FindHighestComponentForRender(co)if#co<1 then return nil end;local cp,cq=t.GetComponentDepth(co[1]),co[1]for a3=2,#co,1 do local X=co[a3]local cn=t.GetComponentDepth(X)if cn<cp then cp=cn;cq=X end end;return cq end;function ThrowForDirtyArrangeWhenUnexpected(bB)PushFunction("ThrowForDirtyArrangeWhenUnexpected: "..bB.TypeName)if bB:GetVisibility()~="collapsed"and bB.IsArrangeDirty then error("Child arrange was dirty after Arrange() call")end;for a3,b3 in ipairs(bB.Children)do ThrowForDirtyArrangeWhenUnexpected(b3)end;PopFunction()end;function t.InternalCanProcessItem(bB,cr)if cr then return bB.IsMeasureDirty else return bB.IsArrangeDirty end end;function t.DoLayoutUpdate()PushFunction("DoLayoutUpdate")if l then PrintDebug("Doing layout update: %d measures and %d arranges",#P,#O)end;N=true;if#P>0 then for a3,bB in ipairs(P)do local cs=nil;local ct=bB.Parent;while ct~=nil do if ct.IsMeasureDirty then cs=ct end;ct=ct.Parent end;local cu;if cs~=nil then cu=cs else cu=bB end;local bx,by;if not cu._NM then bx=cu._LMW;by=cu._LMH elseif cu.Parent==nil then bx,by=t.GetCompositionRenderSize()else local cv=cu.Parent;bx=cv._LMW;by=cv._LMH end;local cw,cx=bB.DesiredWidth,bB.DesiredHeight;bB:Measure(bx,by)if cw~=bB.DesiredWidth or cx~=bB.DesiredHeight then bB:InvalidateArrange()end end;ClearTable(P)end;if#O>0 then for a3,bB in ipairs(O)do local cs=nil;local ct=bB.Parent;while ct~=nil do if ct.IsArrangeDirty then cs=ct end;ct=ct.Parent end;local cy;if cs~=nil then cy=cs else cy=bB end;local ae,af,bx,by;if not cy.NeverArranged then ae,af,bx,by=cy.LastArrangeFinalX,cy.LastArrangeFinalY,cy.LastArrangeFinalW,cy.LastArrangeFinalH elseif cy.Parent==nil then ae,af,bx,by=0,0,t.GetCompositionRenderSize()else local cv=cy.Parent;ae,af,bx,by=cv.LastArrangeFinalX,cv.LastArrangeFinalY,cv.LastArrangeFinalW,cv.LastArrangeFinalH end;local cz,cA=cy.LastArrangeFinalX,cy.LastArrangeFinalY;local cB,cC=cy.LastArrangeFinalW,cy.LastArrangeFinalH;cy:Arrange(ae,af,bx,by)bB.IsVisualPositionValid=false;local cD=cy.LastArrangeFinalX~=cz or cy.LastArrangeFinalY~=cA;local cE=cy.LastArrangeFinalW~=cB or cy.LastArrangeFinalH~=cC;if cD or cE then UIComponent.InvalidateVisual(cy)end end;ClearTable(O)end;N=false;if n then n=false;if not j then t.RenderComponentTree(h)end end;PopFunction()end;function t.TryScheduleLayoutUpdate()if q==nil or q.IsCompleted then q=InvokeAsync(t.DoLayoutUpdate,E)end end;function UIComponent:InvalidateArrange()if self.IsArrangeDirty or self.ArrangeInProgress then return end;if l then PrintDebug("Arrange invalidated for '%s'",self.TypeName)end;if not self.NeverArranged then table.insert(O,self)end;self.IsArrangeDirty=true;t.TryScheduleLayoutUpdate()end;function UIComponent:InvalidateMeasure()if self.IsMeasureDirty or self.MeasureInProgress then return end;if l then PrintDebug("Measure invalidated for '%s'",self.TypeName)end;if not self._NM then table.insert(P,self)end;self.IsMeasureDirty=true;t.TryScheduleLayoutUpdate()end;function UIComponent:InvalidateVisual()t.TryScheduleLayoutUpdate()if not self.IsVisualDirty then self.IsVisualDirty=true;n=true;if l then PrintDebug("Visual invalidated for '%s'",self.TypeName)end end end;function UIComponent:InvalidateLayoutAndVisual()self:InvalidateMeasure()self:InvalidateArrange()self:InvalidateVisual()end;function UIComponent:InsertChild(b3,aM)PushFunction("InsertChild")assert(b3~=nil,"Child cannot be null")if b3.IndexInParent~=-1 then error("Child component already added to another component: "..b3.IndexInParent)end;if self==b3 then error("Cannot add self as a child")end;b3.Parent=self;table.insert(self.Children,b3)if aM~=nil then b3.IdInParent=aM;self.IdToChildTable[aM]=b3 end;UpdateCachedIndices(self.Children)b3:UpdateVisibility()self:InvalidateLayoutAndVisual()return PopFunction(b3)end;function UIComponent:RemoveChild(b3,cF)if b3.IndexInParent==-1 or b3.Parent~=self then return end;self:RemoveChildAt(b3.IndexInParent,cF)end;function UIComponent:GetChildById(aM)return self.IdToChildTable[aM]end;function UIComponent:RemoveChildAt(cG,cF)PushFunction("RemoveChildAt",cG,cF)local b3=self.Children[cG]b3.Parent=nil;b3.IndexInParent=-1;table.remove(self.Children,cG)if b3.IdInParent~=nil then self.IdToChildTable[b3.IdInParent]=nil end;if cF~=true then UpdateCachedIndices(self.Children)end;b3:UpdateVisibility()PopFunction()end;function UIComponent:RemoveFromParent()if self.IndexInParent==-1 or self.Parent==nil then return end;self.Parent:RemoveChildAt(self.IndexInParent)end;function UIComponent:ClearChildren()PushFunction("ClearChildren")for a3=#self.Children,1,-1 do self:RemoveChildAt(a3,true)end;self.IdToChildTable={}UpdateCachedIndices(self.Children)PopFunction()end;function UIComponent:OnGotFocus()end;function UIComponent:OnLostFocus()end;function UniformPanel:CountVisibleChildren()local cH=0;for a3,b3 in ipairs(self.Children)do if b3:GetVisibility()~="collapsed"then cH=cH+1 end end;return cH end;function UniformPanel:GetTotalGap(cI,cJ)if cI>1 then return(cI-1)*cJ end;return 0 end;function UniformPanel:GetSlotPerElement(aj,ak,cH)local cK=self:GetTotalGap(cH,self:GetPropValue(UniformPanel.SpacingProperty))if self:GetPropValue(UniformPanel.OrientationProperty)=="vertical"then return aj,math.ceil((ak-cK)/cH)else return math.ceil((aj-cK)/cH),ak end end;function UniformPanel:MeasureOverride(bu,bw)local cH=self:CountVisibleChildren()local cL,cM=self:GetSlotPerElement(bu,bw,cH)local cN,cO=0,0;for a3,b3 in ipairs(self.Children)do b3:Measure(cL,cM)if cN<b3.DesiredWidth then cN=b3.DesiredWidth end;if cO<b3.DesiredHeight then cO=b3.DesiredHeight end end;return cN,cO end;function UniformPanel:_AO(cP,cQ)local cR,cS=0,0;local cH=self:CountVisibleChildren()local cT=self:GetPropValue(UniformPanel.OrientationProperty)local cJ=self:GetPropValue(UniformPanel.SpacingProperty)local cN,cO=self:GetSlotPerElement(cP,cQ,cH)for a3,b3 in ipairs(self.Children)do b3:Arrange(cR,cS,cN,cO)if b3:GetVisibility()~="collapsed"then if cT=="vertical"then cS=cS+cO+cJ else cR=cR+cN+cJ end end end;return cP,cQ end;function HorizontalStackPanel:MeasureOverride(bu,bw)local cU,cV=0,0;for a3,b3 in ipairs(self.Children)do local cW,cX=b3:Measure(bu,bw)cU=cU+cW;if cV<cX then cV=cX end end;return cU,cV end;function HorizontalStackPanel:_AO(cP,cQ)local cR=0;for a3,b3 in ipairs(self.Children)do b3:Arrange(cR,0,b3.DesiredWidth,cQ)cR=cR+b3.DesiredWidth end;return cP,cQ end;function VerticalStackPanel:MeasureOverride(bu,bw)local cU,cV=0,0;for a3,b3 in ipairs(self.Children)do local cW,cX=b3:Measure(bu,bw)cV=cV+cX;if cU<cW then cU=cW end end;return cU,cV end;function VerticalStackPanel:_AO(cP,cQ)local cS=0;for a3,b3 in ipairs(self.Children)do b3:Arrange(0,cS,cP,b3.DesiredHeight)cS=cS+b3.DesiredHeight end;return cP,cQ end;function DockPanel:MeasureOverride(bu,bw)local cY,cZ,c_,d0=0,0,0,0;for a3,b3 in ipairs(self.Children)do b3:Measure(math.max(0,bu-c_),math.max(0,bw-d0))local d1=b3.DockValue or"left"if d1=="left"or d1=="right"then cZ=math.max(cZ,d0+b3.DesiredHeight)c_=c_+b3.DesiredWidth elseif d1=="top"or d1=="bottom"then cY=math.max(cY,c_+b3.DesiredWidth)d0=d0+b3.DesiredHeight end end;return math.max(cY,c_),math.max(cZ,d0)end;function DockPanel:_AO(d2,d3)local d4=#self.Children;if self.LastChildFill then d4=d4-1 end;local ae,af,c_,d0=0,0,0,0;for a3,b3 in ipairs(self.Children)do local d5,d6=ae,af;local d7,d8=math.max(0,d2-(ae+c_)),math.max(0,d3-(af+d0))local d1=b3.DockValue or"left"if a3-1<d4 then if d1=="left"then ae=ae+b3.DesiredWidth;d7=b3.DesiredWidth elseif d1=="top"then af=af+b3.DesiredHeight;d8=b3.DesiredHeight elseif d1=="right"then c_=c_+b3.DesiredWidth;d5=math.max(0,d2-c_)d7=b3.DesiredWidth elseif d1=="bottom"then d0=d0+b3.DesiredHeight;d6=math.max(0,d3-d0)d8=b3.DesiredHeight end end;b3:Arrange(d5,d6,d7,d8)end;return d2,d3 end;function Button.OnMouseDown(self,aZ,aE)aE.handled=true;if not self.DoNotProcessButtonClickLogic then if self.IsToggleButton then self.IsPressed=not self.IsPressed;self:InvalidateVisual()elseif not self.IsPressed then self.IsPressed=true;self:InvalidateVisual()InvokeAsyncWithDelay(function()self.IsPressed=false;self:InvalidateVisual()end,0.5)end end;self:RaiseEvent(K,aZ,aE)end;function Button:MeasureOverride(bu,bw)local bx,by=UIComponent.MeasureOverride(self,bu,bw)local ai=self:GetPropValue(Button.TextProperty)if ai~=nil and#ai>bx then bx=#ai end;if by<1 then by=1 end;return bx,by end;function Button:OnRender()local al;if self.IsPressed then al=self:GetPropValue(Button.PressedBackgroundProperty)else al=self:GetPropValue(UIComponent.BackgroundProperty)end;r.fill(1,1,self.RenderWidth,self.RenderHeight,al)r.drawTextCentered(1,1,self.RenderWidth,self.RenderHeight,self:GetPropValue(Button.TextProperty)or"",colours.white,nil)end;function t.FocusComponent(bB)PushFunction("FocusComponent",bB)if bB~=nil and not bB:GetPropValue(UIComponent.IsFocusableProperty)then PopFunction()return end;if A~=nil and A:GetPropValue(UIComponent.IsFocusedProperty)then A:SetPropValue(UIComponent.IsFocusedProperty,false)A:OnLostFocus()end;A=bB;if bB~=nil then bB:SetPropValue(UIComponent.IsFocusedProperty,true)bB:OnGotFocus()end;PopFunction()end;function t.SetComponsitionTarget(d9)u=d9;if d9==nil then x=0;y=0 else x,y=d9.getSize()end end;function t.GetCompositionRenderSize()return x,y end;function UIComponent:DoMouseClick_Tunnel(aZ,da,ae,af)PushFunction("DoMouseClick_Tunnel",self.TypeName,da,ae,af)if self:IsMousePointOver(ae,af)then local aE={btn=da,x=ae,y=af,handled=false}self:RaiseEvent(H,aZ,aE)if not aE.handled then for a3=#self.Children,1,-1 do local b3=self.Children[a3]local bY,bZ=ae-b3.RenderPosX,af-b3.RenderPosY;local db=b3:DoMouseClick_Tunnel(aZ,da,bY,bZ)if db~=nil then return PopFunction(db,bY,bZ)end end end;if aE.handled or self:GetPropValue(UIComponent.IsFocusableProperty)or self:GetPropValue(UIComponent.BackgroundProperty)~=nil then return PopFunction(self,ae,af)end end;return PopFunction(nil,nil,nil)end;function UIComponent:DoMouseClick_Bubble(aZ,da,ae,af)PushFunction("DoMouseClick_Bubble",self.TypeName,da,ae,af)local dc={btn=da,x=ae,y=af,handled=false}if self:RaiseEvent(I,aZ,dc)then return PopFunction(self)end;if self.Parent~=nil then ae=ae+self.RenderPosX;af=af+self.RenderPosY;return PopFunction(self.Parent:DoMouseClick_Bubble(aZ,da,ae,af))end;return PopFunction(nil)end;function t.OnWakeDisplay(aZ)k=aZ;if j then j=false;if h~=nil then h:InvalidateVisual()end;return true else return false end end;function t.OnTickDisplaySleep(aZ)if i and not j and aZ-k>300 then j=true;r.clear()local bx,by=t.GetCompositionRenderSize()r.drawTextCentered(1,1,bx,by,"Display is asleep. Click to wake",colours.grey,colours.black)end end;function t.OnMouseClick(aZ,bj,an,ao)if h==nil then return end;PushFunction("OnMouseClick",bj,an,ao)local db,ae,af=h:DoMouseClick_Tunnel(aZ,bj,an,ao)if db==nil then t.FocusComponent(nil)else local dd=db:DoMouseClick_Bubble(aZ,bj,ae,af)if dd~=nil then t.FocusComponent(dd)else t.FocusComponent(db)end end;PopFunction()end;function t.OnMouseDrag(aZ,bj,an,ao)PushFunction("OnMouseDrag",bj,an,ao)if A~=nil and A.CanHandleDrag and not A.IsArrangeDirty then local de,df=A:GetRenderPositon()local dc={btn=bj,x=an-de,y=ao-df,absX=an,absY=ao,handled=false}A:RaiseEvent(J,aZ,dc)end;return PopFunction()end;function SetupTimer(dg)c=os.startTimer(dg)end;local function dh(aZ,di,dj,dk,dl,dm,dn)PushFunction("OnApplicationEvent",di,dj,dk,dl,dm,dn)if di=="timer"then if dj==c then SetupTimer(e)if#R>0 then local dp={}local dq={}for a3,aN in ipairs(R)do if l then PrintDebug(tostring(aZ).." >= "..aN.TimeUntilExecution..": "..tostring(aZ>=aN.TimeUntilExecution))end;if aZ>=aN.TimeUntilExecution then table.insert(dp,aN)table.insert(dq,a3)end end;for a3=#dq,1,-1 do table.remove(R,dq[a3])end;for a3,aN in ipairs(dp)do aN.Method(unpack(aN.Args))end end;t.OnTickDisplaySleep(aZ)elseif dj==g then g=0;local dr={}for a3,ds in ipairs(Q)do for bp=1,#ds do table.insert(dr,ds[bp])end;ClearTable(ds)end;if#dr>0 then p=true;for a3=1,#dr do local aN=dr[a3]aN.Method(unpack(aN.Args))aN.IsCompleted=true end;p=false end end else if di=="mouse_click"then if t.OnWakeDisplay(aZ)then return end;t.OnMouseClick(aZ,dj,dk-1,dl-1)elseif di=="monitor_touch"then if t.OnWakeDisplay(aZ)then return end;t.OnMouseClick(aZ,1,dk-1,dl-1)elseif di=="mouse_drag"then if t.OnWakeDisplay(aZ)then return end;t.OnMouseDrag(aZ,dj,dk-1,dl-1)elseif di=="key"then elseif di=="char"then else return end end;PopFunction()end;function aR.new(dt,du,dv,dw,al)local X=NewTypeInstance(aR,"DualColourTextBlock")X.LeftText=dt or""X.RightText=du or""X.LeftColour=dv or colours.white;X.RightColour=dw or colours.white;_DO.SetPropValue(X,UIComponent.BackgroundProperty,al or colours.black)return X end;function aR:MeasureOverride(bu,bw)local bx,by=UIComponent.MeasureOverride(self,bu,bw)local dx=0;if self.LeftText~=nil then dx=dx+#self.LeftText end;if self.RightText~=nil then dx=dx+#self.RightText end;if bx<dx then bx=dx end;if by<1 then by=1 end;return bx,by end;function aR:OnRender()UIComponent.OnRender(self)r.drawText(1,1,self.LeftText,self.LeftColour,nil)r.drawText(1+#self.LeftText,1,self.RightText,self.RightColour,nil)end;function aR:SetRightText(dy,dz)if dy==nil then dy=""elseif type(dy)~="string"then dy=tostring(dy)end;self.RightText=dy;self.RightColour=dz;self:InvalidateMeasure()self:InvalidateVisual()end;local dA;local dB;local dC;local dD={Handle=nil,IsOnline=false,PowerLevel=0,MaxFuelAmount=0,CurFuelAmount=0,FuelTemp=0,CaseTemp=0,EnergyProducedLastTick=0,EnergyStored=0,AvgRodInsertion=0,TotalControlRodCount=0,Automation={Minimum=40,Maximum=60,IsEnabled=false},UI={HomePage={},RodsPage={},AutoPage={}}}function t.LoadConfig()local dE=fs.open("config","r")if dE==nil then return end;while true do local dF=dE.readLine()if dF==nil then break end;for aC,a9 in string.gmatch(dF,"([^=]+)=([^=]+)")do S[aC]=a9 end end;dE.close()dD.Automation.Minimum=tonumber(S["Automation_Minimum"])or 30;dD.Automation.Maximum=tonumber(S["Automation_Maximum"])or 70;local dG=S["Automation_IsEnabled"]=="true"or false;i=S["CanDisplayAutoSleep"]=="true"or false;SetAutomationState(dG)end;function t.SaveConfig()local dE=fs.open("config","w")if dE==nil then return end;S["Automation_Minimum"]=tostring(dD.Automation.Minimum)S["Automation_Maximum"]=tostring(dD.Automation.Maximum)S["Automation_IsEnabled"]=tostring(dD.Automation.IsEnabled)S["CanDisplayAutoSleep"]=tostring(i)for aC,a9 in pairs(S)do dE.writeLine(aC.."="..a9)end;dE.close()end;function dD.SetRodInsertion(dH)if dD.Handle~=nil then dD.Handle.setAllControlRodLevels(dH)end;dD.AvgRodInsertion=dH end;function GetColourForReactorTemp(dI)if dI<500 then return colors.lime elseif dI<1000 then return colors.yellow elseif dI<1500 then return colors.orange else return colors.red end end;function SetAutomationState(dJ)if dD.Automation.IsEnabled==dJ then return false end;dD.Automation.IsEnabled=dJ;t.SaveConfig()local aA=dD.Automation;local dK=dD.UI.HomePage;if aA.IsEnabled then dK.ControlBtn_On:SetPropValue(Button.PressedBackgroundProperty,colours.cyan)dK.ControlBtn_Off:SetPropValue(Button.PressedBackgroundProperty,colours.cyan)dK.ControlBtn_Auto.IsPressed=true else dK.ControlBtn_On:SetPropValue(Button.PressedBackgroundProperty,colours.green)dK.ControlBtn_Off:SetPropValue(Button.PressedBackgroundProperty,colours.green)dK.ControlBtn_Auto.IsPressed=false end;DoReactorTick(false)return true end;local dL=1;function DoReactorTick(dM)PushFunction("DoReactorTick::"..tostring(dM))local dN=dD.Handle;if dN~=nil then dD.IsOnline=dN.getActive()dD.PowerLevel=dN.getEnergyStored()dD.MaxFuelAmount=dN.getFuelAmountMax()dD.CurFuelAmount=dN.getFuelAmount()dD.FuelTemp=dN.getFuelTemperature()dD.CaseTemp=dN.getCasingTemperature()dD.EnergyProducedLastTick=dN.getEnergyProducedLastTick()dD.EnergyStored=dN.getEnergyStored()dD.AvgRodInsertion=dN.getControlRodLevel(0)dD.TotalControlRodCount=dN.getNumberOfControlRods()local dO=dD.Automation;if dO.IsEnabled then local dP=math.floor(dD.EnergyStored/10000000*100)if dO.Minimum==dO.Maximum then if dP<dO.Minimum then dN.setActive(true)elseif dP>dO.Minimum then dN.setActive(false)end else if dP<=dO.Minimum then dN.setActive(true)elseif dP>=dO.Maximum then dN.setActive(false)end end end end;if dA.IsActive then local dK=dD.UI.HomePage;if dD.IsOnline then dK.PowerLabel:SetRightText("ONLINE",colours.green)else dK.PowerLabel:SetRightText("OFFLINE",colours.red)end;local dQ=math.floor(dD.CurFuelAmount/dD.MaxFuelAmount*100)dK.FuelLevelLabel:SetRightText(tostring(dQ).."%",colours.white)dK.FuelLevelProgBar:SetValue(dQ,colours.lime)local dI=dD.FuelTemp;dK.FuelTempLabel:SetRightText(tostring(math.floor(dI)).."/4000",colours.white)dK.FuelTempProgBar:SetValue(dI,GetColourForReactorTemp(dI))local dR=dD.CaseTemp;dK.CasingTempLabel:SetRightText(tostring(math.floor(dR)).."/4000",colours.white)dK.CasingTempProgBar:SetValue(dR,GetColourForReactorTemp(dR))dK.EnergyLabel:SetRightText(tostring(math.floor(dD.EnergyProducedLastTick)).." RF/t",colours.white)dK.StoredLabel:SetRightText(tostring(math.floor(dD.EnergyStored/10000000*100)).."% ("..tostring(math.floor(dD.EnergyStored)).." RF)",colours.white)dK.StoredProgBar:SetValue(dD.EnergyStored)dK.ControlRodsLabel:SetRightText(dD.AvgRodInsertion.."%",colours.white)dK.ControlBtn_On:SetPressed(dD.IsOnline)dK.ControlBtn_Off:SetPressed(not dD.IsOnline)dK.ControlBtn_Auto:SetPressed(dD.Automation.IsEnabled)elseif dB.IsActive then local dK=dD.UI.RodsPage;dK.InsertionTextBlock:SetRightText(tostring(dD.AvgRodInsertion).."%",colours.lightBlue)dK.InsertionProgBar:SetValue(dD.AvgRodInsertion)dK.TotalControlRodLabel:SetRightText(tostring(dD.TotalControlRodCount))elseif dC.IsActive then local dK=dD.UI.AutoPage;UpdateReactorAutomationLabels()end;if dM==nil or dM==true then InvokeAsyncWithDelay(DoReactorTick,0.4,true)end;PopFunction()end;function CreateBasicPage(dS,dT)local dK=NewTypeInstance(dS,"BasicPage")_DO.SetPropValue(dK,UIComponent.BackgroundProperty,colours.black)dK:SetPropValue(UIComponent.HorizontalAlignmentProperty,"stretch")dK:SetPropValue(UIComponent.VerticalAlignmentProperty,"stretch")local dU=TextBlock.new(dT,colours.white,colours.blue)dU:SetPropValue(UIComponent.HorizontalAlignmentProperty,"center")local dV=UIComponent.new()_DO.SetPropValue(dV,UIComponent.BackgroundProperty,colours.blue)dV:SetPropValue(UIComponent.HorizontalAlignmentProperty,"stretch")dV:SetPropValue(UIComponent.VerticalAlignmentProperty,"bottom")dV:InsertChild(dU)dK:InsertChild(dV)return dK end;function CreateHomePage()local dW=CreateBasicPage(aT,"Info about your reactor")local dX=dW:InsertChild(VerticalStackPanel.new():SetMargin(1,1,1,2))dX:SetPropValue(UIComponent.HorizontalAlignmentProperty,"stretch")dW.PowerLabel=dX:InsertChild(aR.new("Power:        ","OFFLINE",colours.yellow,colours.red))dX:InsertChild(UIComponent.new():SetSize(0,1))dW.FuelLevelLabel=dX:InsertChild(aR.new("Fuel Level:   ","0",colours.yellow,colours.white))dW.FuelLevelProgBar=dX:InsertChild(ProgressBar.new(0,100,0):SetAlignment("stretch","top"))dX:InsertChild(UIComponent.new():SetSize(0,1))dW.FuelTempLabel=dX:InsertChild(aR.new("Fuel Temp:    ","0",colours.yellow,colours.white))dW.FuelTempProgBar=dX:InsertChild(ProgressBar.new(0,4000,0):SetAlignment("stretch","top"))dX:InsertChild(UIComponent.new():SetSize(0,1))dW.CasingTempLabel=dX:InsertChild(aR.new("Casing Temp:  ","0",colours.yellow,colours.white))dW.CasingTempProgBar=dX:InsertChild(ProgressBar.new(0,4000,0):SetAlignment("stretch","top"))dX:InsertChild(UIComponent.new():SetSize(0,1))local dY=dX:InsertChild(DockPanel.new():SetAlignment("stretch"))local dZ=dY:InsertChild(HorizontalStackPanel.new())dZ.DockValue="right"local d_=dY:InsertChild(VerticalStackPanel.new():SetMargin(0,0,1,0))d_:SetPropValue(UIComponent.HorizontalAlignmentProperty,"stretch")dW.EnergyLabel=d_:InsertChild(aR.new("Energy: ","0 RF/t",colours.yellow,colours.white))dW.StoredLabel=d_:InsertChild(aR.new("Stored: ","0 RF",colours.yellow,colours.white))dW.StoredProgBar=d_:InsertChild(ProgressBar.new(0,10000000,0,colours.grey,colours.red):SetAlignment("stretch"))dW.ControlRodsLabel=d_:InsertChild(aR.new("Control Rods: ","0%",colours.yellow,colours.white))local e0=Button.new("Button:Automatic")dW.ControlBtn_Auto=e0;e0.IsToggleButton=true;e0:SetPropValue(Button.TextProperty,"Automatic")e0:SetSize(11,3)e0:AddEventHandler(K,function(self,aZ,e1)if not SetAutomationState(self.IsPressed)then return end;self:InvalidateVisual()end)local e2=Button.new("Button:ON")dW.ControlBtn_On=e2;e2.DoNotProcessButtonClickLogic=true;e2:SetPropValue(Button.TextProperty,"ON")e2:SetSize(6,3)e2:AddEventHandler(K,function(self,aZ,e1)if dD.Handle~=nil then dD.Handle.setActive(true)end;SetAutomationState(false)self:InvalidateVisual()end)local e3=Button.new("Button:OFF")dW.ControlBtn_Off=e3;e3.DoNotProcessButtonClickLogic=true;e3:SetPropValue(Button.TextProperty,"OFF")e3:SetSize(7,3)e3:AddEventHandler(K,function(self,aZ,e1)if dD.Handle~=nil then dD.Handle.setActive(false)end;SetAutomationState(false)self:InvalidateVisual()end)dZ:InsertChild(e0)dZ:InsertChild(e2)dZ:InsertChild(e3)return dW end;function AddToRodInsertion(e4)dD.AvgRodInsertion=dD.AvgRodInsertion+e4;dD.SetRodInsertion(s.clamp(dD.AvgRodInsertion,0,100))local dK=dD.UI.RodsPage;dK.InsertionTextBlock:SetRightText(tostring(dD.AvgRodInsertion).."%",colours.lightBlue)dK.InsertionProgBar:SetValue(dD.AvgRodInsertion)end;function CreateRodsPage()local dK=CreateBasicPage(aU,"Modify control rods here")local dX=dK:InsertChild(VerticalStackPanel.new():SetMargin(1,1,1,2):SetAlignment("stretch"))_DO.SetPropValue(dX,UIComponent.BackgroundProperty,colours.black)dK.InsertionTextBlock=dX:InsertChild(aR.new("Inserted: ","0%",colours.white,colours.lightBlue,colours.black):SetAlignment("center"))dX:InsertChild(UIComponent.SetSize(UIComponent.new(),0,1))dK.InsertionProgBar=dX:InsertChild(ProgressBar.new(0,100,0,colours.grey,colours.lightBlue):SetAlignment("stretch"))dX:InsertChild(UIComponent.SetSize(UIComponent.new(),0,1))local e5=dX:InsertChild(UIComponent.new():SetAlignment("stretch"))local e6=e5:InsertChild(HorizontalStackPanel.new():SetAlignment("left"))local e7=e6:InsertChild(Button.new("DecrBigButton","<<"):SetSize(4,1))local e8=e6:InsertChild(Button.new("DecrSmallButton","<"):SetSize(3,1):SetMargin(1))local e9=e5:InsertChild(HorizontalStackPanel.new():SetAlignment("right"))local ea=e9:InsertChild(Button.new("IncrSmallButton",">"):SetSize(3,1))local eb=e9:InsertChild(Button.new("IncrBigButton",">>"):SetSize(4,1):SetMargin(1))e7:AddEventHandler(K,function(self,aZ,e1)AddToRodInsertion(-10)end)e8:AddEventHandler(K,function(self,aZ,e1)AddToRodInsertion(-1)end)eb:AddEventHandler(K,function(self,aZ,e1)AddToRodInsertion(10)end)ea:AddEventHandler(K,function(self,aZ,e1)AddToRodInsertion(1)end)dK.TotalControlRodLabel=dK:InsertChild(aR.new("Total control rods: ","0",colours.white,colours.green))dK.TotalControlRodLabel:SetMargin(1,0,1,2):SetAlignment("left","bottom")dX:InsertChild(UIComponent.SetSize(UIComponent.new(),0,1))return dK end;function UpdateReactorAutomationLabels()local aA=dD.Automation;local dK=dD.UI.AutoPage;dK.StorageOnTextBlock:SetPropValue(TextBlock.TextProperty,tostring(aA.Minimum).."% RF")dK.StorageOffTextBlock:SetPropValue(TextBlock.TextProperty,tostring(aA.Maximum).."% RF")end;function AddToReactorAutomation(e4,ec)local aA=dD.Automation;if ec then aA.Minimum=s.clamp(aA.Minimum+e4,0,aA.Maximum)else aA.Maximum=s.clamp(aA.Maximum+e4,aA.Minimum,100)end;UpdateReactorAutomationLabels()t.SaveConfig()end;function CreateAutoPage()local dK=CreateBasicPage(aV,"Modify automation parameters")local dX=dK:InsertChild(VerticalStackPanel.new():SetMargin(1,1,1,2))dX:SetPropValue(UIComponent.HorizontalAlignmentProperty,"stretch")_DO.SetPropValue(dX,UIComponent.BackgroundProperty,colours.black)dX:InsertChild(TextBlock.new("Configure automatic ON/OFF data"))dX:InsertChild(TextBlock.new("You can enable this by clicking 'Automatic' button in the home screen"))dX:InsertChild(UIComponent.SetSize(UIComponent.new(),0,1))dX:InsertChild(TextBlock.new("Turn ON when storage drops below:",colours.white,colours.black))local ed=dX:InsertChild(HorizontalStackPanel.new())local ee=ed:InsertChild(Button.new("ON_Decr_Button_b","--"):SetSize(4):SetMargin(0,0,0,0))local ef=ed:InsertChild(Button.new("ON_Decr_Button_s","-"):SetSize(3):SetMargin(1,0,0,0))dK.StorageOnTextBlock=ed:InsertChild(TextBlock.new("0% RF",colours.white,colours.black):SetSize(7):SetMargin(1,0,1))local eg=ed:InsertChild(Button.new("ON_Incr_Button_s","+"):SetSize(3):SetMargin(0,0,0,0))local eh=ed:InsertChild(Button.new("ON_Incr_Button_b","++"):SetSize(4):SetMargin(1,0,0,0))dX:InsertChild(UIComponent.SetSize(UIComponent.new(),0,1))dX:InsertChild(TextBlock.new("Turn OFF when storage exceeds:",colours.white,colours.black))local ei=dX:InsertChild(HorizontalStackPanel.new())local ej=ei:InsertChild(Button.new("OFF_Decr_Button_b","--"):SetSize(4):SetMargin(0,0,0,0))local ek=ei:InsertChild(Button.new("OFF_Decr_Button_s","-"):SetSize(3):SetMargin(1,0,0,0))dK.StorageOffTextBlock=ei:InsertChild(TextBlock.new("100% RF",colours.white,colours.black):SetSize(7):SetMargin(1,0,1))local el=ei:InsertChild(Button.new("OFF_Incr_Button_s","+"):SetSize(3):SetMargin(0,0,0,0))local em=ei:InsertChild(Button.new("OFF_Incr_Button_b","++"):SetSize(4):SetMargin(1,0,0,0))ef:AddEventHandler(K,function(self,aZ,e1)AddToReactorAutomation(-1,true)end)ee:AddEventHandler(K,function(self,aZ,e1)AddToReactorAutomation(-10,true)end)eg:AddEventHandler(K,function(self,aZ,e1)AddToReactorAutomation(1,true)end)eh:AddEventHandler(K,function(self,aZ,e1)AddToReactorAutomation(10,true)end)ek:AddEventHandler(K,function(self,aZ,e1)AddToReactorAutomation(-1,false)end)ej:AddEventHandler(K,function(self,aZ,e1)AddToReactorAutomation(-10,false)end)el:AddEventHandler(K,function(self,aZ,e1)AddToReactorAutomation(1,false)end)em:AddEventHandler(K,function(self,aZ,e1)AddToReactorAutomation(10,false)end)return dK end;function CreateInfoPage()local dK=CreateBasicPage(aW,"About the program")local dX=dK:InsertChild(VerticalStackPanel.new():SetMargin(1,1,1,2))_DO.SetPropValue(dX,UIComponent.BackgroundProperty,colours.black)dX:InsertChild(TextBlock.new("Made by TheRareCarrot :D",colours.white))dX:InsertChild(TextBlock.new("BigReactor controller program v1.0"))dX:InsertChild(TextBlock.new("using Lua Presentation Framework (LPF) v1.1"))dX:InsertChild(UIComponent.new():SetSize(0,1))dX:InsertChild(TextBlock.new("The 'Z' button (bottom right) toggles auto-sleep after 5 minutes"))dX:InsertChild(TextBlock.new("The 'Automatic' button toggles reactor activation automation (configurable in the Auto tab)"))dX:InsertChild(UIComponent.new():SetSize(0,1))dX:InsertChild(TextBlock.new("This works best in the computer itself, or a 5x3 monitor, though the monitor can be bigger if you wish",colours.yellow))return dK end;function CreateMainContent(en)PushFunction("CreateMainContent",en.TypeName)local eo=NewTypeInstance(aQ,"TabControl")eo:SetPropValue(UIComponent.HorizontalAlignmentProperty,"stretch")eo:SetPropValue(UIComponent.VerticalAlignmentProperty,"stretch")local bf=eo:InsertChild(UniformPanel.new())bf:SetPropValue(UIComponent.HorizontalAlignmentProperty,"stretch")bf:SetPropValue(UIComponent.VerticalAlignmentProperty,"stretch")local dW=CreateHomePage()local ep=CreateRodsPage()local eq=CreateAutoPage()local er=CreateInfoPage()dD.UI.HomePage=dW;dD.UI.RodsPage=ep;dD.UI.AutoPage=eq;dA=bf:InsertChild(NewTabItem("Home",dW))dB=bf:InsertChild(NewTabItem("Rods",ep))dC=bf:InsertChild(NewTabItem("Auto",eq))TabItem_Info=bf:InsertChild(NewTabItem("Info",er))local es=ContentPresenter.new()es:SetPropValue(UIComponent.HorizontalAlignmentProperty,"stretch")es:SetPropValue(UIComponent.VerticalAlignmentProperty,"stretch")es:SetPropValue(UIComponent.MarginTProperty,1)eo:InsertChild(es)eo.MyContentPresenter=es;eo:SetActiveTabItem(dA)en:InsertChild(eo)local et=function(self,aZ,e1)PushFunctionAndInvoke("DoReactorTick::tabChangedHandler",DoReactorTick,false)end;dA:AddEventHandler(L,et)dB:AddEventHandler(L,et)dC:AddEventHandler(L,et)PopFunction()end;function FindPeripheralByType(W)local eu=peripheral.getNames()for a3,a0 in ipairs(eu)do if peripheral.getType(a0)==W then return peripheral.wrap(a0)end end;return nil end;function FindReactor()return FindPeripheralByType("BigReactors-Reactor")end;local ev;function LoadReactorAndDoShit()dD.Handle=FindReactor()t.LoadConfig()ev.IsPressed=i;ev:InvalidateVisual()PushFunctionAndInvoke("DoReactorTick::LoadReactorAndDoShit",DoReactorTick,true)end;function OnAppStartup()if h==nil then error("No root component")end;CreateMainContent(h)ev=h:InsertChild(Button.new("AutoSleepButton","Z"):SetAlignment("right","bottom"))ev.IsToggleButton=true;ev:AddEventHandler(K,function(self,aZ,e1)i=self.IsPressed;t.SaveConfig()end)h:InvalidateLayoutAndVisual()InvokeAsync(LoadReactorAndDoShit,G)end;local function ew()h:SetAlignment("stretch","stretch")h.TypeName="RootPanel"local bx,by=t.GetCompositionRenderSize()h:SetSize(bx,by)h:UpdateVisibility()h:Arrange(0,0,bx,by)h:InvalidateLayoutAndVisual()t.DoLayoutUpdate()end;local function ex()PushFunction("AppMain")k=os.clock()t.SetComponsitionTarget(FindPeripheralByType("monitor")or term)r.clear()h=UIComponent.new()ew()InvokeAsync(OnAppStartup,G)SetupTimer(e)while f do local ey,dj,dk,dl,dm,dn=os.pullEventRaw()if ey=="terminate"then break end;dh(os.clock(),ey,dj,dk,dl,dm,dn)end;PopFunction()end;local function ez()o=fs.open("debug.log","w")local eA,eB=pcall(ex)t.SetComponsitionTarget(term)r.setBackgroundColour(colours.black)r.setTextColour(colours.white)if not eA then PrintStackTrace()print("The app has crashed! "..eB)PrintDebug(tostring(eB))end;o.close()if eA then print("Application has exited without error")end end;ez()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement