diff --git a/lib/button.lua b/lib/button.lua index ea3fb53..db0f120 100644 --- a/lib/button.lua +++ b/lib/button.lua @@ -63,11 +63,10 @@ function checkxy(x, y) for name, data in pairs(button) do if y>=data["ymin"] and y <= data["ymax"] then if x>=data["xmin"] and x<= data["xmax"] then + fill(name, colors.lightGray, data) data["func"](data["elem"], data["elem2"]) - --flash(data['name']) + fill(name, data["color"], data) return true - --data["active"] = not data["active"] - --print(name) end end end diff --git a/reactor.lua b/reactor.lua index 4bfdf7f..3988da6 100644 --- a/reactor.lua +++ b/reactor.lua @@ -13,6 +13,7 @@ local version = 0.3 local autoInputGate = 1 local curInputGate = 222000 +local targetOutput local mon, monitor, monX, monY @@ -151,6 +152,7 @@ function save_config() sw = fs.open("reactorconfig.txt", "w") sw.writeLine(autoInputGate) sw.writeLine(curInputGate) + sw.writeLine(targetOutput or 0) sw.close() end @@ -158,6 +160,7 @@ function load_config() sr = fs.open("reactorconfig.txt", "r") autoInputGate = tonumber(sr.readLine()) curInputGate = tonumber(sr.readLine()) + targetOutput = tonumber(sr.readLine()) sr.close() end @@ -167,6 +170,10 @@ else load_config() end +if not targetOutput then + targetOutput = fluxgate.getSignalLowFlow() +end + function reset() term.clear() term.setCursorPos(1,1) @@ -247,8 +254,26 @@ function reactorControl() inputFluxgate.setSignalLowFlow(fluxval) end - -- Emergency Safeguards - checkReactorSafety(ri) + -- 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 + checkReactorSafety(ri) sleep(0.2) -- Keeps CPU usage low while maintaining constant monitoring ::continue:: @@ -343,15 +368,13 @@ function buttonControls() end function changeOutputValue(num, val) - local cFlow = fluxgate.getSignalLowFlow() - if val == 1 then - cFlow = cFlow+num + targetOutput = math.min(targetOutput + num, 2000000000) else - cFlow = cFlow-num + targetOutput = math.max(targetOutput - num, 0) end - fluxgate.setSignalLowFlow(cFlow) updateReactorInfo() + save_config() end @@ -450,36 +473,44 @@ function updateReactorInfo() if not ri then return end - -- Update only when values change - 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) + drawUpdatedText(4, 4, "Status:", reactorStatus(ri.status)[1], reactorStatus(ri.status)[2], colors.white) + drawUpdatedText(4, 5, "Generation:", f.format_int(ri.generationRate).." rf/t", colors.lime, colors.yellow) 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) - drawUpdatedText(4, 10, "Input Gate:", f.format_int(inputFluxgate.getSignalLowFlow()).." rf/t", colors.lightBlue) + local currentFlow = fluxgate.getSignalLowFlow() + 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) - 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) local fieldPercent = getPercentage(ri.fieldStrength, ri.maxFieldStrength) 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) local fuelPercent = 100 - getPercentage(ri.fuelConversion, ri.maxFuelConversion) 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) end -function drawUpdatedText(x, y, label, value, color) +function drawUpdatedText(x, y, label, value, color, labelColor) local key = label 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, label, value, colors.white, color, colors.black) + f.draw_text_lr(mon, x, y, 3, label, value, labelColor, color, colors.black) lastValues[key] = value end end