Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function find(waldo)
- w = component.findComponent(waldo)[1]
- if w then
- return component.proxy(w)
- else
- return nil
- end
- end
- local panel = find("big_control_panel")
- local panel2 = find("small_control_panel")
- local colors = {
- red = { 255, 0, 0 },
- green = { 0, 255, 0 },
- blue = { 0, 0, 255 },
- yellow = { 255, 255, 0 },
- purple = { 255, 0, 255 },
- teal = { 0, 255, 255 },
- white = { 255, 255, 255 },
- black = { 0, 0, 0 }
- }
- local function loc(x,y,pane)
- return panel:getModule(x,y,pane)
- end
- local function setColor(light, color, isLit)
- if type(color) == "table" then
- light:setColor(color[1], color[2], color[3], isLit)
- elseif type(color) == "string" then
- light:setColor(colors[color][1],colors[color][2],colors[color][3], isLit)
- end
- end
- local function isPowerOn(switch)
- return switch.isSwitchOn
- end
- local indicators = {
- extractor = { dirt = loc(0,8,0), bog = loc(1,8,0), peat = loc(2,8,0) },
- groups = { extractor = loc(0,3,0), dirt = loc(1,3,0), bog = loc(2,3,0), peat = loc(3,3,0) },
- water = { water = loc(3,8,0) },
- dirt = { wheat = loc(7, 8, 0) , carrot = loc(8, 8, 0) , potato = loc(9, 8, 0) , corn = loc(10, 8, 0) },
- bog = { pumpkin = loc(7, 5, 0), cotton = loc(8, 5, 0), yosse = loc(9, 5, 0), mycelium = loc(10, 5, 0) },
- peat = { apple = loc(8, 2, 0), banana = loc(9, 2, 0) }
- }
- local panel_swiches = {
- extractor = { dirt = loc(0,7,0), bog = loc(1,7,0), peat = loc(2,7,0) },
- groups = { extractor = loc(0,1,0), dirt = loc(1,1,0), bog = loc(2,1,0), peat = loc(3,1,0) },
- water = { water = loc(3,7,0) },
- dirt = { wheat = loc(7, 7, 0) , carrot = loc(8, 7, 0) , potato = loc(9, 7, 0) , corn = loc(10, 7, 0) },
- bog = { pumpkin = loc(7, 4, 0), cotton = loc(8, 4, 0), yosse = loc(9, 4, 0), mycelium = loc(10, 4, 0) },
- peat = { apple = loc(8, 1, 0), banana = loc(9, 1, 0) }
- }
- local power_switches = {
- extractor = { dirt = { find("dirt_cutoff_1"), find("dirt_cutoff_2") }, bog = { find("bog_cutoff_1"), find("bog_cutoff_2") }, peat = find("peat_cutoff") },
- water = { water = find("water_cutoff") },
- dirt = { wheat = find("wheat_cutoff"), carrot = find("carrot_cutoff"), potato = find("potato_cutoff"), corn = find("corn_cutoff") },
- bog = { pumpkin = find("pumpkin_cutoff"), cotton = find("cotton_cutoff"), yosse = find("yosse_cutoff"), mycelium = find("mycelium_cutoff") },
- peat = { apple = find("apple_cutoff"), banana = find("banana_cutoff") }
- }
- local valves = {
- water_extracters = { find("water_valve_1"), find("water_valve_2"), find("water_valve_3"), find("water_valve_4"),
- find("water_valve_5"), find("water_valve_6"), find("water_valve_7"), find("water_valve_8") },
- farms = { wheat = find("wheat_valve"), carrot = find("carrot_valve"), potato = find("potato_valve"), corn = find("corn_valve"),
- pumpkin = find("pumpkin_valve"), cotton = find("cotton_valve"), yosse = find("yosse_valve"), mycelium = find("mycelium_valve"),
- apple = find("apple_valve"), banana = find("banana_valve")
- }}
- local gauges = {
- water_extracters = { loc(0,8,1), loc(1,8,1), loc(2,8,1), loc(3,8,1), loc(4,8,1), loc(5,8,1), loc(6,8,1), loc(7,8,1) },
- farms = { wheat = loc(0,2,1), carrot = loc(1,2,1), potato = loc(2,2,1), corn = loc(3,2,1),
- pumpkin = loc(4,2,1), cotton = loc(5,2,1), yosse = loc(6,2,1), mycelium = loc(7,2,1),
- apple = loc(8,2,1), banana = loc(9,2,1)
- },
- groups = { total_water_in = loc(0, 1, 2), total_water_out = loc(2, 1, 2), dirt = loc(4, 1, 2), bog = loc(6, 1, 2), peat = loc(8, 1, 2) }
- }
- local mini_displays = {
- water_extracters = { loc(0,7,1), loc(1,7,1), loc(2,7,1), loc(3,7,1), loc(4,7,1), loc(5,7,1), loc(6,7,1), loc(7,7,1) },
- farms = { wheat = loc(0,1,1), carrot = loc(1,1,1), potato = loc(2,1,1), corn = loc(3,1,1),
- pumpkin = loc(4,1,1), cotton = loc(5,1,1), yosse = loc(6,1,1), mycelium = loc(7,1,1),
- apple = loc(8,1,1), banana = loc(9,1,1)
- }
- }
- local ptn = {
- water_extracters = { loc(0,6,1), loc(1,6,1), loc(2,6,1), loc(3,6,1), loc(4,6,1), loc(5,6,1), loc(6,6,1), loc(7,6,1) },
- farms = { wheat = loc(0,0,1), carrot = loc(1,0,1), potato = loc(2,0,1), corn = loc(3,0,1),
- pumpkin = loc(4,0,1), cotton = loc(5,0,1), yosse = loc(6,0,1), mycelium = loc(7,0,1),
- apple = loc(8,0,1), banana = loc(9,0,1)
- }
- }
- local displays = {
- groups = { total_water_in = loc(0, 0, 2), total_water_out = loc(2, 0, 2), dirt = loc(4, 0, 2), bog = loc(6, 0, 2), peat = loc(8, 0, 2) },
- power = { total = loc(0, 4, 2), extractors = loc(2, 4, 2), dirt = loc(4, 4, 2), bog = loc(6, 4, 2), peat = loc(8, 4, 2) }
- --big_power = { main = loc(4, 7, 2) }
- }
- local e_stop = loc(4, 3, 0):getSubModule()
- local resume = loc(4, 0, 0):getSubModule()
- local mappings = {}
- local flows = {}
- local groupFlows = {}
- function handle3Switch(event, sender, p1, p2)
- h = mappings[sender.Hash]
- state = false
- if p1 == 0 then
- setColor(h.light, "red", 0)
- state = false
- elseif p1 == 1 then
- setColor(h.light, "green", 0)
- state = true
- elseif p1 == 2 then
- setColor(h.light, "blue", 0)
- state = h.parent.state
- end
- if type(h.power) == "table" then
- for _, v in pairs(h.power) do
- v:setIsSwitchOn(state)
- end
- else
- h.power:setIsSwitchOn(state)
- end
- end
- function handle2Switch(event, sender, p1, p2)
- h = mappings[sender.Hash]
- if p1 == false then
- setColor(mappings[sender.Hash].light, "red", 0)
- elseif p1 == true then
- setColor(mappings[sender.Hash].light, "green", 0)
- end
- if type(h.power) == "table" then
- for _, v in pairs(h.power) do
- v:setIsSwitchOn(p1)
- end
- else
- h.power:setIsSwitchOn(p1)
- end
- end
- function handle2SwitchParent(event, sender, p1, p2)
- h = mappings[sender.Hash]
- if p1 == false then
- setColor(h.light, "red", 0)
- elseif p1 == true then
- setColor(h.light, "green", 0)
- end
- for k,v in pairs(h.children) do
- if v.state == 2 and mappings[v.Hash].power then
- if type(mappings[v.Hash].power) == "table" then
- for _, w in pairs(mappings[v.Hash].power) do
- w:setIsSwitchOn(p1)
- end
- else
- mappings[v.Hash].power:setIsSwitchOn(p1)
- end
- end
- end
- end
- function handleFlowGroup(event, sender, p1, p2)
- h = mappings[sender.Hash]
- h.valve.userFlowLimit = p1 / 60.0
- h.gauge.limit = p1 / 600.0
- end
- function handleEStop(event, sender, p1, p2)
- for _, v in pairs(mappings) do
- if v.power then
- if type(v.power) == "table" then
- for _, w in pairs(v.power) do
- w:setIsSwitchOn(false)
- end
- else
- v.power:setIsSwitchOn(false)
- end
- print(v.btn)
- setColor(v.btn, "red")
- setColor(v.light, "red")
- end
- end
- for _, v in pairs(mini_displays) do
- for _, w in pairs(v) do
- setColor(w, "red")
- end
- end
- for _, v in pairs(displays) do
- for _, w in pairs(v) do
- setColor(w, "red")
- end
- end
- for _, v in pairs(indicators.groups) do
- setColor(v, "red")
- end
- end
- function handleResume(event, sender, p1, p2)
- for _, v in pairs(mappings) do
- if v.btn then
- v.action("resume", v.btn, v.btn.state, nil)
- if v.btn.setColor ~= nil then
- setColor(v.btn, "black")
- end
- end
- end
- for _, v in pairs(mini_displays) do
- for _, w in pairs(v) do
- setColor(w, "green")
- end
- end
- for _, v in pairs(displays) do
- for _, w in pairs(v) do
- setColor(w, "green")
- end
- end
- for _, v in pairs(indicators.groups) do
- setColor(v, "green")
- end
- end
- local function registerSwitch(btn, action, light)
- event.listen(btn)
- mappings[btn.Hash] = { btn = btn, action = action, light = light }
- end
- local function registerSwitchPower(btn, action, light, power_switch)
- event.listen(btn)
- mappings[btn.Hash] = { btn = btn, action = action, light = light, power = power_switch }
- end
- local function registerParentSwitch(btn, action, light, children)
- event.listen(btn)
- mappings[btn.Hash] = { btn = btn, action = action, light = light, children = children }
- end
- local function registerSubSwitch(btn, action, light, power_switch, parent)
- event.listen(btn)
- mappings[btn.Hash] = { btn = btn, action = action, light = light, power = power_switch, parent = parent }
- end
- local function registerFlow(gauge, display, ptn, valve, action)
- event.listen(ptn)
- ptn.max = 600
- gauge.limit = ptn.value / 600
- mappings[ptn.Hash] = { action = action, gauge = gauge, display = display, valve = valve }
- flows[valve] = { gauge = gauge, display = display }
- end
- local function registerFlowGroup(gauge, display, valves)
- table.insert(groupFlows, { gauge = gauge, display = display, valves = valves } )
- gauge.limit = 1.0
- end
- local function registerMushButton(btn, action, color)
- event.listen(btn)
- mappings[btn.Hash] = { action = action }
- setColor(btn, color)
- end
- registerSwitchPower(panel_swiches.water.water, handle2Switch, indicators.water.water, power_switches.water.water)
- registerParentSwitch(panel_swiches.groups.extractor, handle2SwitchParent, indicators.groups.extractor, panel_swiches.extractor)
- registerSubSwitch(panel_swiches.extractor.dirt, handle3Switch, indicators.extractor.dirt, power_switches.extractor.dirt, panel_swiches.groups.extractor)
- registerSubSwitch(panel_swiches.extractor.bog, handle3Switch, indicators.extractor.bog, power_switches.extractor.bog, panel_swiches.groups.extractor)
- registerSubSwitch(panel_swiches.extractor.peat, handle3Switch, indicators.extractor.peat, power_switches.extractor.peat, panel_swiches.groups.extractor)
- registerParentSwitch(panel_swiches.groups.dirt, handle2SwitchParent, indicators.groups.dirt, panel_swiches.dirt)
- registerSubSwitch(panel_swiches.dirt.wheat, handle3Switch, indicators.dirt.wheat, power_switches.dirt.wheat, panel_swiches.groups.dirt)
- registerSubSwitch(panel_swiches.dirt.carrot, handle3Switch, indicators.dirt.carrot, power_switches.dirt.carrot, panel_swiches.groups.dirt)
- registerSubSwitch(panel_swiches.dirt.potato, handle3Switch, indicators.dirt.potato, power_switches.dirt.potato, panel_swiches.groups.dirt)
- registerSubSwitch(panel_swiches.dirt.corn, handle3Switch, indicators.dirt.corn, power_switches.dirt.corn, panel_swiches.groups.dirt)
- registerParentSwitch(panel_swiches.groups.bog, handle2SwitchParent, indicators.groups.bog, panel_swiches.bog)
- registerSubSwitch(panel_swiches.bog.pumpkin, handle3Switch, indicators.bog.pumpkin, power_switches.bog.pumpkin, panel_swiches.groups.bog)
- registerSubSwitch(panel_swiches.bog.cotton, handle3Switch, indicators.bog.cotton, power_switches.bog.cotton, panel_swiches.groups.bog)
- registerSubSwitch(panel_swiches.bog.yosse, handle3Switch, indicators.bog.yosse, power_switches.bog.yosse, panel_swiches.groups.bog)
- registerSubSwitch(panel_swiches.bog.mycelium, handle3Switch, indicators.bog.mycelium, power_switches.bog.mycelium, panel_swiches.groups.bog)
- registerParentSwitch(panel_swiches.groups.peat, handle2SwitchParent, indicators.groups.peat, panel_swiches.peat)
- registerSubSwitch(panel_swiches.peat.apple, handle3Switch, indicators.peat.apple, power_switches.peat.apple, panel_swiches.groups.peat)
- registerSubSwitch(panel_swiches.peat.banana, handle3Switch, indicators.peat.banana, power_switches.peat.banana, panel_swiches.groups.peat)
- registerFlow(gauges.water_extracters[1], mini_displays.water_extracters[1], ptn.water_extracters[1], valves.water_extracters[1], handleFlowGroup)
- registerFlow(gauges.water_extracters[2], mini_displays.water_extracters[2], ptn.water_extracters[2], valves.water_extracters[2], handleFlowGroup)
- registerFlow(gauges.water_extracters[3], mini_displays.water_extracters[3], ptn.water_extracters[3], valves.water_extracters[3], handleFlowGroup)
- registerFlow(gauges.water_extracters[4], mini_displays.water_extracters[4], ptn.water_extracters[4], valves.water_extracters[4], handleFlowGroup)
- registerFlow(gauges.water_extracters[5], mini_displays.water_extracters[5], ptn.water_extracters[5], valves.water_extracters[5], handleFlowGroup)
- registerFlow(gauges.water_extracters[6], mini_displays.water_extracters[6], ptn.water_extracters[6], valves.water_extracters[6], handleFlowGroup)
- registerFlow(gauges.water_extracters[7], mini_displays.water_extracters[7], ptn.water_extracters[7], valves.water_extracters[7], handleFlowGroup)
- registerFlow(gauges.water_extracters[8], mini_displays.water_extracters[8], ptn.water_extracters[8], valves.water_extracters[8], handleFlowGroup)
- registerFlow(gauges.farms.wheat, mini_displays.farms.wheat, ptn.farms.wheat, valves.farms.wheat, handleFlowGroup)
- registerFlow(gauges.farms.carrot, mini_displays.farms.carrot, ptn.farms.carrot, valves.farms.carrot, handleFlowGroup)
- registerFlow(gauges.farms.potato, mini_displays.farms.potato, ptn.farms.potato, valves.farms.potato, handleFlowGroup)
- registerFlow(gauges.farms.corn, mini_displays.farms.corn, ptn.farms.corn, valves.farms.corn, handleFlowGroup)
- registerFlow(gauges.farms.pumpkin, mini_displays.farms.pumpkin, ptn.farms.pumpkin, valves.farms.pumpkin, handleFlowGroup)
- registerFlow(gauges.farms.cotton, mini_displays.farms.cotton, ptn.farms.cotton, valves.farms.cotton, handleFlowGroup)
- registerFlow(gauges.farms.yosse, mini_displays.farms.yosse, ptn.farms.yosse, valves.farms.yosse, handleFlowGroup)
- registerFlow(gauges.farms.mycelium, mini_displays.farms.mycelium, ptn.farms.mycelium, valves.farms.mycelium, handleFlowGroup)
- registerFlow(gauges.farms.apple, mini_displays.farms.apple, ptn.farms.apple, valves.farms.apple, handleFlowGroup)
- registerFlow(gauges.farms.banana, mini_displays.farms.banana, ptn.farms.banana, valves.farms.banana, handleFlowGroup)
- registerFlowGroup(gauges.groups.total_water_in, displays.groups.total_water_in, valves.water_extracters)
- registerFlowGroup(gauges.groups.total_water_out, displays.groups.total_water_out, valves.farms)
- registerFlowGroup(gauges.groups.dirt, displays.groups.dirt, { valves.farms.wheat, valves.farms.carrot, valves.farms.potato, valves.farms.corn })
- registerFlowGroup(gauges.groups.bog, displays.groups.bog, { valves.farms.pumpkin, valves.farms.cotton, valves.farms.yosse, valves.farms.mycelium })
- registerFlowGroup(gauges.groups.peat, displays.groups.peat, { valves.farms.apple, valves.farms.banana })
- registerMushButton(e_stop, handleEStop, "red")
- registerMushButton(resume, handleResume, "green")
- while true do --main loop
- local e, s, p1, p2, type, data = event.pull(0.1)
- if e then
- mappings[s.Hash].action(e, s, p1, p2)
- end
- for k, v in pairs(flows) do
- v.gauge.percent = k.flowPct
- v.display:setText(math.floor(k.flow * 60))
- end
- for _, v in pairs(groupFlows) do
- flowPctTotal = 0
- flowTotal = 0
- count = 0
- for _, w in pairs(v.valves) do
- flowPctTotal = flowPctTotal + w.flowPct
- flowTotal = flowTotal + w.flow
- count = count + 1
- end
- if count == 0 then count = 1 end
- v.gauge.percent = flowPctTotal / count
- v.display:setText(math.floor(flowTotal * 60))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement