fix stuffs
This commit is contained in:
+2
-3
@@ -63,11 +63,10 @@ function checkxy(x, y)
|
|||||||
for name, data in pairs(button) do
|
for name, data in pairs(button) do
|
||||||
if y>=data["ymin"] and y <= data["ymax"] then
|
if y>=data["ymin"] and y <= data["ymax"] then
|
||||||
if x>=data["xmin"] and x<= data["xmax"] then
|
if x>=data["xmin"] and x<= data["xmax"] then
|
||||||
|
fill(name, colors.lightGray, data)
|
||||||
data["func"](data["elem"], data["elem2"])
|
data["func"](data["elem"], data["elem2"])
|
||||||
--flash(data['name'])
|
fill(name, data["color"], data)
|
||||||
return true
|
return true
|
||||||
--data["active"] = not data["active"]
|
|
||||||
--print(name)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+47
-16
@@ -13,6 +13,7 @@ local version = 0.3
|
|||||||
|
|
||||||
local autoInputGate = 1
|
local autoInputGate = 1
|
||||||
local curInputGate = 222000
|
local curInputGate = 222000
|
||||||
|
local targetOutput
|
||||||
|
|
||||||
local mon, monitor, monX, monY
|
local mon, monitor, monX, monY
|
||||||
|
|
||||||
@@ -151,6 +152,7 @@ function save_config()
|
|||||||
sw = fs.open("reactorconfig.txt", "w")
|
sw = fs.open("reactorconfig.txt", "w")
|
||||||
sw.writeLine(autoInputGate)
|
sw.writeLine(autoInputGate)
|
||||||
sw.writeLine(curInputGate)
|
sw.writeLine(curInputGate)
|
||||||
|
sw.writeLine(targetOutput or 0)
|
||||||
sw.close()
|
sw.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -158,6 +160,7 @@ function load_config()
|
|||||||
sr = fs.open("reactorconfig.txt", "r")
|
sr = fs.open("reactorconfig.txt", "r")
|
||||||
autoInputGate = tonumber(sr.readLine())
|
autoInputGate = tonumber(sr.readLine())
|
||||||
curInputGate = tonumber(sr.readLine())
|
curInputGate = tonumber(sr.readLine())
|
||||||
|
targetOutput = tonumber(sr.readLine())
|
||||||
sr.close()
|
sr.close()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -167,6 +170,10 @@ else
|
|||||||
load_config()
|
load_config()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not targetOutput then
|
||||||
|
targetOutput = fluxgate.getSignalLowFlow()
|
||||||
|
end
|
||||||
|
|
||||||
function reset()
|
function reset()
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
@@ -247,6 +254,24 @@ function reactorControl()
|
|||||||
inputFluxgate.setSignalLowFlow(fluxval)
|
inputFluxgate.setSignalLowFlow(fluxval)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Ramp output toward target with safety checks
|
||||||
|
if ri.status == "running" then
|
||||||
|
local currentFlow = fluxgate.getSignalLowFlow()
|
||||||
|
if currentFlow ~= targetOutput then
|
||||||
|
local diff = targetOutput - currentFlow
|
||||||
|
local absDiff = math.abs(diff)
|
||||||
|
local step = math.min(absDiff, math.max(5000, absDiff / 20))
|
||||||
|
if diff > 0 then
|
||||||
|
local fieldPercent = math.ceil(ri.fieldStrength / ri.maxFieldStrength * 10000) * 0.01
|
||||||
|
if fieldPercent >= 20 then
|
||||||
|
fluxgate.setSignalLowFlow(currentFlow + step)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
fluxgate.setSignalLowFlow(currentFlow - step)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Emergency Safeguards
|
-- Emergency Safeguards
|
||||||
checkReactorSafety(ri)
|
checkReactorSafety(ri)
|
||||||
|
|
||||||
@@ -343,15 +368,13 @@ function buttonControls()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function changeOutputValue(num, val)
|
function changeOutputValue(num, val)
|
||||||
local cFlow = fluxgate.getSignalLowFlow()
|
|
||||||
|
|
||||||
if val == 1 then
|
if val == 1 then
|
||||||
cFlow = cFlow+num
|
targetOutput = math.min(targetOutput + num, 2000000000)
|
||||||
else
|
else
|
||||||
cFlow = cFlow-num
|
targetOutput = math.max(targetOutput - num, 0)
|
||||||
end
|
end
|
||||||
fluxgate.setSignalLowFlow(cFlow)
|
|
||||||
updateReactorInfo()
|
updateReactorInfo()
|
||||||
|
save_config()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -450,36 +473,44 @@ function updateReactorInfo()
|
|||||||
|
|
||||||
if not ri then return end
|
if not ri then return end
|
||||||
|
|
||||||
-- Update only when values change
|
drawUpdatedText(4, 4, "Status:", reactorStatus(ri.status)[1], reactorStatus(ri.status)[2], colors.white)
|
||||||
drawUpdatedText(4, 4, "Status:", reactorStatus(ri.status)[1], reactorStatus(ri.status)[2])
|
drawUpdatedText(4, 5, "Generation:", f.format_int(ri.generationRate).." rf/t", colors.lime, colors.yellow)
|
||||||
drawUpdatedText(4, 5, "Generation:", f.format_int(ri.generationRate).." rf/t", colors.lime)
|
|
||||||
|
|
||||||
local tempColor = getTempColor(ri.temperature)
|
local tempColor = getTempColor(ri.temperature)
|
||||||
drawUpdatedText(4, 7, "Temperature:", f.format_int(ri.temperature).."C", tempColor)
|
drawUpdatedText(4, 7, "Temperature:", f.format_int(ri.temperature).."C", tempColor, colors.lightGray)
|
||||||
|
|
||||||
drawUpdatedText(4, 9, "Output Gate:", f.format_int(fluxgate.getSignalLowFlow()).." rf/t", colors.lightBlue)
|
local currentFlow = fluxgate.getSignalLowFlow()
|
||||||
drawUpdatedText(4, 10, "Input Gate:", f.format_int(inputFluxgate.getSignalLowFlow()).." rf/t", colors.lightBlue)
|
local outputText
|
||||||
|
if currentFlow ~= targetOutput then
|
||||||
|
local arrow = currentFlow < targetOutput and " ▲" or " ▼"
|
||||||
|
outputText = f.format_int(currentFlow).." → "..f.format_int(targetOutput).." rf/t"..arrow
|
||||||
|
else
|
||||||
|
outputText = f.format_int(currentFlow).." rf/t"
|
||||||
|
end
|
||||||
|
drawUpdatedText(4, 9, "Output:", outputText, colors.lightBlue, colors.cyan)
|
||||||
|
drawUpdatedText(4, 10, "Input:", f.format_int(inputFluxgate.getSignalLowFlow()).." rf/t", colors.lightBlue, colors.cyan)
|
||||||
|
|
||||||
local satPercent = getPercentage(ri.energySaturation, ri.maxEnergySaturation)
|
local satPercent = getPercentage(ri.energySaturation, ri.maxEnergySaturation)
|
||||||
drawUpdatedText(4, 12, "Energy Saturation:", satPercent.."%", colors.green)
|
drawUpdatedText(4, 12, "Energy Saturation:", satPercent.."%", colors.green, colors.green)
|
||||||
f.progress_bar(mon, 4, 13, monX-7, satPercent, 100, colors.green, colors.lightGray)
|
f.progress_bar(mon, 4, 13, monX-7, satPercent, 100, colors.green, colors.lightGray)
|
||||||
|
|
||||||
local fieldPercent = getPercentage(ri.fieldStrength, ri.maxFieldStrength)
|
local fieldPercent = getPercentage(ri.fieldStrength, ri.maxFieldStrength)
|
||||||
local fieldColor = getFieldColor(fieldPercent)
|
local fieldColor = getFieldColor(fieldPercent)
|
||||||
drawUpdatedText(4, 15, "Field Strength:", fieldPercent.."%", fieldColor)
|
drawUpdatedText(4, 15, "Field Strength:", fieldPercent.."%", fieldColor, colors.blue)
|
||||||
f.progress_bar(mon, 4, 16, monX-7, fieldPercent, 100, fieldColor, colors.lightGray)
|
f.progress_bar(mon, 4, 16, monX-7, fieldPercent, 100, fieldColor, colors.lightGray)
|
||||||
|
|
||||||
local fuelPercent = 100 - getPercentage(ri.fuelConversion, ri.maxFuelConversion)
|
local fuelPercent = 100 - getPercentage(ri.fuelConversion, ri.maxFuelConversion)
|
||||||
local fuelColor = getFuelColor(fuelPercent)
|
local fuelColor = getFuelColor(fuelPercent)
|
||||||
drawUpdatedText(4, 18, "Fuel:", fuelPercent.."%", fuelColor)
|
drawUpdatedText(4, 18, "Fuel:", fuelPercent.."%", fuelColor, colors.orange)
|
||||||
f.progress_bar(mon, 4, 19, monX-7, fuelPercent, 100, fuelColor, colors.lightGray)
|
f.progress_bar(mon, 4, 19, monX-7, fuelPercent, 100, fuelColor, colors.lightGray)
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawUpdatedText(x, y, label, value, color)
|
function drawUpdatedText(x, y, label, value, color, labelColor)
|
||||||
local key = label
|
local key = label
|
||||||
if lastValues[key] ~= value then
|
if lastValues[key] ~= value then
|
||||||
|
labelColor = labelColor or colors.white
|
||||||
f.draw_text_lr(mon, x, y, 3, " ", " ", colors.white, color, colors.black)
|
f.draw_text_lr(mon, x, y, 3, " ", " ", colors.white, color, colors.black)
|
||||||
f.draw_text_lr(mon, x, y, 3, label, value, colors.white, color, colors.black)
|
f.draw_text_lr(mon, x, y, 3, label, value, labelColor, color, colors.black)
|
||||||
lastValues[key] = value
|
lastValues[key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user