Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- screen_name = "Main_Screen"
- emergency_power_limit = 4500
- power_text_length = 54
- cont_text_length = 64
- line_per_page = 48
- local switch = component.proxy(component.findComponent("Switch"))
- local gen = component.proxy(component.findComponent("Generator"))
- local akw = component.proxy(component.findComponent("AKW"))
- local storage = component.proxy(component.findComponent("Storage"))
- local constructor = component.proxy(component.findComponent("Constructor"))
- local fabricator = component.proxy(component.findComponent("Fabricator"))
- local powerpole = component.proxy(component.findComponent("PowerPole"))
- local panel = component.proxy(component.findComponent("Panel"))
- local machine = component.proxy(component.findComponent("Machine"))
- local fluid = component.proxy(component.findComponent("F_Storage"))
- local bat = component.proxy(component.findComponent("Battery"))
- local pole = component.proxy(component.findComponent("Pole"))
- local maschine_stat = "Offline"
- local page = 1
- local max_page = 1
- --------------main functions-----------
- function tableConcat( t1, t2 )
- for i=1, #t2 do
- t1[#t1+1] = t2[i]
- end
- return t1
- end
- function tableHasValue( t, value )
- if t == nil or value == nil then
- return false
- end
- for _,v in pairs( t ) do
- if v == value then
- return true
- end
- end
- return false
- end
- function getComponentsByClass( class, getOne )
- local results = {}
- if ( getOne == nil ) then
- getOne = false
- end
- if type( class ) == "table" then
- for _, c in pairs( class ) do
- local proxies = getComponentsByClass( c, getOne )
- if not getOne then
- tableConcat( results, proxies )
- else
- if( proxies ~= nil ) then
- return proxies
- end
- end
- end
- elseif type( class ) == "string" then
- local ctype = classes[ class ]
- if ctype ~= nil then
- local comps = component.findComponent( ctype )
- for _, c in pairs( comps ) do
- local proxy = component.proxy( c )
- if getOne and proxy ~= nil then
- return proxy
- elseif not tableHasValue( results, proxy ) then
- table.insert( results, proxy )
- end
- end
- end
- end
- if ( getOne ) then
- return {}
- end
- return results
- end
- function getComponentsByClassAndNick( class, nickParts )
- if type( nickParts ) == 'string' then
- nickParts = { nickParts }
- end
- local classComponents = getComponentsByClass( class )
- local results = {}
- for _, component in pairs( classComponents ) do
- for _, nickPart in pairs( nickParts ) do
- if component.nick:find( nickPart, 1, true ) == nil then
- goto nextComponent
- end
- end
- table.insert( results, component )
- ::nextComponent::
- end
- return results
- end
- function settingsFromString( str, lowerKeys )
- lowerKeys = lowerKeys or false
- local results = {}
- if str == nil or type( str ) ~= "string" then return results end
- for key, value in string.gmatch( str, '(%w+)=(%b"")' ) do
- if lowerKeys then key = string.lower( key ) end
- results[ key ] = string.sub( value, 2, string.len( value ) - 1 )
- end
- return results
- end
- function settingsFromComponentNickname( proxy, lowerKeys )
- if proxy == nil then return nil end
- return settingsFromString( proxy[ "nick" ], lowerKeys )
- end
- Vector2d = {
- x = 0,
- y = 0,
- pattern = '{x=%d,y=%d}',
- }
- Vector2d.__index = Vector2d
- function Vector2d.new( x, y )
- if x == nil or type( x ) ~= "number" then return nil end
- if y == nil or type( y ) ~= "number" then return nil end
- local o = { x = math.floor( x ), y = math.floor( y ) }
- setmetatable( o, { __index = Vector2d } )
- return o
- end
- function split(s, delimiter)
- result = {};
- for match in (s..delimiter):gmatch("(.-)"..delimiter) do
- table.insert(result, match);
- end
- return result;
- end
- --------------GPU----------------------
- local gpu = computer.getPCIDevices( classes.GPU_T2_C )[1]
- if gpu == nil then
- computer.panic( "No GPU T2 found. Cannot continue." )
- end
- print(gpu)
- --------------Screen-------------------
- local computerSettings = settingsFromComponentNickname( computer.getInstance() )
- local screens = getComponentsByClassAndNick( {
- "ModuleScreen_C",
- "Build_Screen_C",
- }, computerSettings.screen or '' )
- if #screens == 0 then
- computer.panic( "No screen found. Cannot continue." )
- end
- if screen_name ~= "empty" then
- for i=1, #screens do
- screen_data = screens[i]
- screen_table_data = split(tostring(screen_data),'"')
- if screen_name == screen_table_data[2] then
- gpu:bindScreen( screens[i] )
- screenSize = gpu:getScreenSize()
- print( 'Screen resolution: ' .. screenSize.x .. 'x' .. screenSize.y )
- end
- end
- else
- gpu:bindScreen( screens[1] )
- screenSize = gpu:getScreenSize()
- print( 'Screen resolution: ' .. screenSize.x .. 'x' .. screenSize.y )
- end
- --------------line calc----------------
- function get_line(line)
- spacer = (size + 10) * line
- return spacer
- end
- --------------row calc-----------------
- function get_row(row)
- spacer = (size - 25) * row
- return spacer
- end
- ---------------------------------------
- -------------------------------------------------------------------------------------------------------------------------------------
- function draw_frame(x,y,le,dire,size_d,color_d)
- for i=0, le do
- if dire == "right" then
- gpu:drawText(Vector2d.new(get_row(x+i),get_line(y)),"_",size_d,color_d,TRUE)
- end
- if dire == "down" then
- gpu:drawText(Vector2d.new(get_row(x),get_line(y+i)),"|",size_d,color_d,TRUE)
- end
- end
- end
- function round(x)
- return math.floor(x + 0.5)
- end
- function get_max_power(n)
- connector = powerpole[n]:getPowerConnectors()[1]
- circuit = connector:getCircuit()
- return circuit.capacity
- end
- function bar(color_bar, x, y, w, h, fill,size_d,color_d)
- fillLine = round((fill * h) / 100)
- for i=1, h do
- gpu:drawText(Vector2d.new(get_row(x-1),get_line(y)),"|",size_d,color_d,TRUE)
- gpu:drawText(Vector2d.new(get_row(x+w+1),get_line(y)),"|",size_d,color_d,TRUE)
- y = y - 1
- end
- y = y + h
- for i=1, fillLine do
- for i=1, w do
- gpu:drawText(Vector2d.new(get_row(x),get_line(y)),"■",size_d,color_bar,TRUE)
- x = x + 1
- end
- x = x - w
- y = y - 1
- end
- end
- ----------Parameters------------------
- size = 48
- color_white = {1.000, 1.000, 1.000, 1.0}
- color_red = {1.000, 0.000, 0.000, 1.0}
- color_yellow = {1.000, 1.000, 0.000, 1.0}
- color_green = {0.000, 1.000, 0.000, 1.0}
- w = screenSize.x
- h = screenSize.y
- ---------------------------------------
- gpu:flush()
- gpu:drawText(Vector2d.new(get_row(50),get_line(20)),"Start Main_PC......",size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(50),get_line(21)),"Please wait......",size,color_red,TRUE)
- gpu:flush()
- ---------------Screen-Functions---------
- function bios()
- for i=1, #switch do
- print("Switch_"..i.."-ID: "..switch[i].id)
- switch[i].isSwitchOn = false
- end
- for i=1, #gen do
- print("Bio_Generator_"..i.."-ID: "..gen[i].id)
- end
- for i=1, #storage do
- print("Storage_"..i.."-ID: "..storage[i].id)
- end
- for i=1, #constructor do
- print("Constructor_"..i.."-ID: "..constructor[i].id)
- end
- for i=1, #fabricator do
- print("Fabricator_"..i.."-ID: "..fabricator[i].id)
- end
- for i=1, #fabricator do
- print("Power_Powle_"..i.."-ID: "..powerpole[i].id)
- end
- for i=1, #akw do
- print("AKW_"..i.."-ID: "..akw[i].id)
- end
- for i=1, #panel do
- print("Panel_"..i.."-ID: "..panel[i].id)
- end
- for i=1, #machine do
- print("Machine_"..i.."-ID: "..machine[i].id)
- end
- for i=1, #fluid do
- print("Fluid_Storage_"..i.."-ID: "..fluid[i].id)
- end
- for i=1, #bat do
- print("Battery_"..i.."-ID: "..bat[i].id)
- end
- for i=1, #pole do
- print("Pole_"..i.."-ID: "..pole[i].id)
- pole[i]:setcolor(1,0,0,5)
- end
- gpu:flush()
- gpu:drawText(Vector2d.new(get_row(0),get_line(0)),"caworks Modular Bios V.10",size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(0),get_line(1)),"2011 - 2013 caworks Software Inc",size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(0),get_line(18)),"Processor caCore 2,4 GHZ x4",size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(0),get_line(19)),"Memory Testing: ok 2096084K",size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(0),get_line(20)),"----------------------------------------",size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(0),get_line(21)),"IDE Channel 0: Master CW34342525 500GB",size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(0),get_line(22)),"IDE Channel 1: NONE",size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(0),get_line(50)),"Press F12 for Bios Setup",size,color_white,TRUE)
- gpu:flush()
- event.pull(5)
- gpu:flush()
- main_prog()
- end
- function main_prog()
- event.pull(3)
- for i=1, #akw do
- akw[i].standby = false
- end
- for i=1, #gen do
- gen[i].standby = true
- end
- for i=1, #machine do
- machine[i].standby = false
- maschine_stat = "Online"
- end
- for i=1, #switch do
- switch[i]:setIsSwitchOn(true)
- end
- for i=1, #pole do
- pole[i]:setcolor(0,1,0,5)
- end
- while true do
- gpu:drawText(Vector2d.new(get_row(45),get_line(0)),"caworks Control V1.0",size,color_white,TRUE)
- power = 0
- if #powerpole > 0 then
- power = get_max_power(1)
- end
- if(power < emergency_power_limit) then
- for i=1, #gen do
- gen[i].standby = false
- end
- for i=1, #machine do
- machine[i].standby = true
- maschine_stat = "Offline"
- end
- for i=1, #switch do
- switch[i]:setIsSwitchOn(false)
- end
- gpu:drawText(Vector2d.new(get_row(1),get_line(2)),"Current Max Power: "..power.." MWh",size,color_red,TRUE)
- end
- if(power > emergency_power_limit) then
- for i=1, #gen do
- gen[i].standby = true
- end
- for i=1, #switch do
- switch[i]:setIsSwitchOn(true)
- end
- for i=1, #machine do
- machine[i].standby = false
- maschine_stat = "Online"
- end
- gpu:drawText(Vector2d.new(get_row(1),get_line(2)),"Current Max Power: "..power.." MWh",size,color_white,TRUE)
- end
- lines = 0
- for i=1, #akw do
- cach = akw[i].standby
- out = "Offline"
- if cach == false then
- out = "Online"
- gpu:drawText(Vector2d.new(get_row(1+12),get_line(i+3)),out,size,color_green,TRUE)
- gpu:drawText(Vector2d.new(get_row(1),get_line(i+3)),"AKW "..i.." is ",size,color_white,TRUE)
- else
- gpu:drawText(Vector2d.new(get_row(1+12),get_line(i+3)),out,size,color_red,TRUE)
- gpu:drawText(Vector2d.new(get_row(1),get_line(i+3)),"AKW "..i.." is ",size,color_white,TRUE)
- end
- lines = i
- end
- for i=1, #gen do
- cach = gen[i].standby
- out = "Offline"
- if cach == false then
- out = "Online"
- gpu:drawText(Vector2d.new(get_row(25+20),get_line(i+3)),out,size,color_green,TRUE)
- gpu:drawText(Vector2d.new(get_row(25),get_line(i+3)),"Generator "..i.." is ",size,color_white,TRUE)
- else
- gpu:drawText(Vector2d.new(get_row(25+20),get_line(i+3)),out,size,color_red,TRUE)
- gpu:drawText(Vector2d.new(get_row(25),get_line(i+3)),"Generator "..i.." is ",size,color_white,TRUE)
- end
- if lines < i then
- lines = i
- end
- end
- draw_frame(1,1,power_text_length-2,"right",size,color_white)
- draw_frame(0,2,lines+1,"down",size,color_white)
- draw_frame(power_text_length,2,lines+1,"down",size,color_white)
- draw_frame(1,lines+3,power_text_length-2,"right",size,color_white)
- linesB = 0
- line_start = 1
- line_end = line_per_page
- max_page = math.floor(#storage / line_per_page)
- if max_page < (#storage / line_per_page) then
- max_page = max_page + 1
- end
- if page > 1 then
- line_start = line_per_page * (page-1)
- line_end = line_per_page * page
- end
- if line_end > #storage then
- line_end = #storage
- end
- for i=line_start, line_end do
- text_line = i+1
- if page > 1 then
- text_line = (i-line_per_page)+1
- end
- inv = storage[i]:getInventories()[1]
- inv:sort()
- amount = inv.itemCount
- itemName = "Empty"
- max = 0
- if amount > 1 then
- max = inv:getStack(0).count * inv.size
- itemName = inv:getStack(0).item.type.name
- end
- gpu:drawText(Vector2d.new(get_row(power_text_length+2),get_line(text_line)),"Container_"..i,size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(power_text_length+20),get_line(text_line)),itemName,size,color_white,TRUE)
- if (max/2) > amount then
- gpu:drawText(Vector2d.new(get_row(power_text_length+48),get_line(text_line)),amount.."/"..max,size,color_red,TRUE)
- elseif amount == 0 then
- gpu:drawText(Vector2d.new(get_row(power_text_length+48),get_line(text_line)),amount.."/"..max,size,color_red,TRUE)
- elseif amount == max then
- gpu:drawText(Vector2d.new(get_row(power_text_length+48),get_line(text_line)),amount.."/"..max,size,color_green,TRUE)
- elseif (max/2) < amount then
- gpu:drawText(Vector2d.new(get_row(power_text_length+48),get_line(text_line)),amount.."/"..max,size,color_yellow,TRUE)
- end
- gpu:drawText(Vector2d.new(get_row(power_text_length+55),get_line(0)),"Page: "..page,size,color_white,TRUE)
- linesB = i
- end
- draw_frame(power_text_length+1,1,cont_text_length,"right",size,color_white)
- draw_frame(power_text_length,2,linesB,"down",size,color_white)
- draw_frame(power_text_length+cont_text_length+1,2,linesB,"down",size,color_white)
- draw_frame(power_text_length+1,linesB+2,cont_text_length-1,"right",size,color_white)
- num_machine = #machine
- gpu:drawText(Vector2d.new(get_row(1),get_line(lines+5)),"Machine found: "..num_machine,size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(1),get_line(lines+6)),"Machine are ",size,color_white,TRUE)
- if maschine_stat == "Offline" then
- gpu:drawText(Vector2d.new(get_row(18),get_line(lines+6)),maschine_stat,size,color_red,TRUE)
- end
- if maschine_stat == "Online" then
- gpu:drawText(Vector2d.new(get_row(18),get_line(lines+6)),maschine_stat,size,color_green,TRUE)
- end
- draw_frame(0,lines+4,3,"down",size,color_white)
- draw_frame(power_text_length,lines+4,3,"down",size,color_white)
- draw_frame(1,lines+7,power_text_length-2,"right",size,color_white)
- linesC = 0
- for i=1, #fluid do
- itemName = "Empty"
- isF = fluid[i].fluidContent
- maxF = 0
- if isF > 1 then
- maxF = fluid[i].maxFluidContent
- itemName = fluid[i]:getFluidType().name
- end
- gpu:drawText(Vector2d.new(get_row(1),get_line(lines+8+i)),"Fluid_"..i,size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(13),get_line(lines+8+i)),itemName,size,color_white,TRUE)
- if (maxF/2) > isF then
- gpu:drawText(Vector2d.new(get_row(40),get_line(lines+8+i)),round(isF).."/"..round(maxF),size,color_RED,TRUE)
- elseif (maxF/2) < isF then
- gpu:drawText(Vector2d.new(get_row(40),get_line(lines+8+i)),round(isF).."/"..round(maxF),size,color_yellow,TRUE)
- elseif isF == 0 then
- gpu:drawText(Vector2d.new(get_row(40),get_line(lines+8+i)),round(isF).."/"..round(maxF),size,color_red,TRUE)
- elseif isF == maxF then
- gpu:drawText(Vector2d.new(get_row(40),get_line(lines+8+i)),round(isF).."/"..round(maxF),size,color_green,TRUE)
- elseif isF > maxF then
- gpu:drawText(Vector2d.new(get_row(40),get_line(lines+8+i)),round(isF).."/"..round(maxF),size,color_white,TRUE)
- end
- if itemName == "Sulfuric Acid" and isF >= maxF then
- print("flush")
- fluid[i]:flush()
- end
- if itemName == "Water" and isF >= maxF then
- print("flush")
- fluid[i]:flush()
- end
- if itemName == "Alumina Solutionw" and isF >= maxF then
- print("flush")
- fluid[i]:flush()
- end
- linesC = i
- end
- draw_frame(1,lines+9+linesC,power_text_length-2,"right",size,color_white)
- draw_frame(0,lines+8,linesC+1,"down",size,color_white)
- draw_frame(power_text_length,lines+8,linesC+1,"down",size,color_white)
- if #bat > 0 then
- maxCap = 0
- maxStored = 0
- for i=1, #bat do
- store = bat[i].powerStore
- cap = bat[i].powerCapacity
- storeMW = (store * cap) / 100
- maxCap = maxCap + cap
- maxStored = maxStored + storeMW
- end
- maxPre = (maxStored * 100) / maxCap
- gpu:drawText(Vector2d.new(get_row(120),get_line(0)),round(maxPre).."%",size,color_white,TRUE)
- gpu:drawText(Vector2d.new(get_row(120),get_line(1)),round(maxCap).."MW",size,color_white,TRUE)
- if maxPre == 100 then
- bar(color_green, 122, 49, 4, 48, maxPre,size,color_white)
- else
- bar(color_red, 122, 49, 4, 48, maxPre,size,color_white)
- end
- end
- -----------------------------------------------------------------------------------------------------------------------------------
- gpu:flush()
- if #panel ~= 0 then
- button_1 = panel[1]:getModule(0,0)
- event.listen(button_1)
- e, s = event.pull(30)
- if s == button_1 then
- computer.beep(5)
- page = page + 1
- if page > max_page then
- page = 1
- end
- end
- end
- end
- end
- ---------------------------------------
- bios()
Advertisement
Add Comment
Please, Sign In to add comment