Fixed reactor ratings not showing

Added more fault tolerance to common library format_xxx() methods
This commit is contained in:
LemADEC 2017-05-30 14:34:13 +02:00
parent e1c52d545b
commit 417c43489b
5 changed files with 67 additions and 33 deletions

View file

@ -48,8 +48,8 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
private float lasersReceived = 0;
private int lastGenerationRate = 0;
private int releasedThisTick = 0; // amount of energy released during current tick update
private int releasedThisCycle = 0; // amount of energy released during current cycle
private int releasedLastCycle = 0;
private long releasedThisCycle = 0; // amount of energy released during current cycle
private long releasedLastCycle = 0;
private boolean hold = true; // hold updates and power output until reactor is controlled (i.e. don't explode on chunk-loading while computer is booting)
private boolean isEnabled = false;
@ -89,7 +89,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
double amountToIncrease = WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS
* Math.max(PR_MIN_INSTABILITY, PR_MAX_INSTABILITY * Math.pow((worldObj.rand.nextDouble() * containedEnergy) / WarpDriveConfig.ENAN_REACTOR_MAX_ENERGY_STORED, 0.1));
if (WarpDriveConfig.LOGGING_ENERGY) {
WarpDrive.logger.info("InsInc" + amountToIncrease);
WarpDrive.logger.info(String.format("increaseInstability %.5f", amountToIncrease));
}
instabilityValues[side] += amountToIncrease * (isNatural ? 1.0D : 0.25D);
} else {
@ -179,8 +179,8 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
}
if (WarpDriveConfig.LOGGING_ENERGY) {
WarpDrive.logger.info("tickCount " + tickCount + " releasedThisTick " + releasedThisTick + " lasersReceived " + lasersReceived
+ " releasedThisCycle " + releasedThisCycle + " containedEnergy " + containedEnergy);
WarpDrive.logger.info(String.format("tickCount %d releasedThisTick %6d lasersReceived %.5f releasedThisCycle %6d containedEnergy %8d",
tickCount, releasedThisTick, lasersReceived, releasedThisCycle, containedEnergy));
}
releasedThisTick = 0;

View file

@ -350,7 +350,11 @@ end
local function format_float(value, nbchar)
local str = "?"
if value ~= nil then
str = string.format("%g", value)
if type(value) == "number" then
str = string.format("%g", value)
else
str = type(value)
end
end
if nbchar ~= nil then
str = string.sub(" " .. str, -nbchar)
@ -361,7 +365,11 @@ end
local function format_integer(value, nbchar)
local str = "?"
if value ~= nil then
str = string.format("%d", value)
if type(value) == "number" then
str = string.format("%d", value)
else
str = type(value)
end
end
if nbchar ~= nil then
str = string.sub(" " .. str, -nbchar)
@ -371,10 +379,14 @@ end
local function format_boolean(value, strTrue, strFalse)
if value ~= nil then
if value then
return strTrue
if type(value) == "boolean" then
if value then
return strTrue
else
return strFalse
end
else
return strFalse
return type(value)
end
end
return "?"
@ -421,6 +433,7 @@ local function input_readNumber(currentValue)
if firstParam == nil then firstParam = "none" end
if eventName == "key" then
local keycode = params[2]
if keycode >= 2 and keycode <= 10 then -- 1 to 9
input = input .. string.format(keycode - 1)
ignoreNextChar = true
@ -487,7 +500,7 @@ local function input_readNumber(currentValue)
inputAbort = true
else
local isSupported, needRedraw = w.event_handler(eventName, params[2])
local isSupported, needRedraw = w.event_handler(eventName, firstParam)
if not isSupported then
w.status_showWarning("Event '" .. eventName .. "', " .. firstParam .. " is unsupported")
end
@ -523,6 +536,7 @@ local function input_readText(currentValue)
if firstParam == nil then firstParam = "none" end
if eventName == "key" then
local keycode = params[2]
if keycode == 14 then -- Backspace
input = string.sub(input, 1, string.len(input) - 1)
ignoreNextChar = true
@ -552,7 +566,7 @@ local function input_readText(currentValue)
inputAbort = true
else
local isSupported, needRedraw = w.event_handler(eventName, params[2])
local isSupported, needRedraw = w.event_handler(eventName, firstParam)
if not isSupported then
w.status_showWarning("Event '" .. eventName .. "', " .. firstParam .. " is unsupported")
end
@ -579,6 +593,7 @@ local function input_readConfirmation(message)
if firstParam == nil then firstParam = "none" end
if eventName == "key" then
local keycode = params[2]
if keycode == 28 then -- Return or Enter
w.status_clear()
return true
@ -597,9 +612,9 @@ local function input_readConfirmation(message)
return false
else
local isSupported, needRedraw = w.event_handler(eventName, params[2])
local isSupported, needRedraw = w.event_handler(eventName, firstParam)
if not isSupported then
w.status_showWarning("Event '" .. eventName .. "', " .. params[2] .. " is unsupported")
w.status_showWarning("Event '" .. eventName .. "', " .. firstParam .. " is unsupported")
end
end
if not w.status_isActive() then
@ -661,6 +676,7 @@ local function input_readEnum(currentValue, list, toValue, toDescription, noValu
if firstParam == nil then firstParam = "none" end
if eventName == "key" then
local keycode = params[2]
if keycode == 14 or keycode == 211 then -- Backspace or Delete
inputKey = nil
ignoreNextChar = true
@ -710,7 +726,7 @@ local function input_readEnum(currentValue, list, toValue, toDescription, noValu
elseif eventName == "terminate" then
inputAbort = true
elseif not w.event_handler(eventName, params[2]) then
elseif not w.event_handler(eventName, firstParam) then
w.status_showWarning("Event '" .. eventName .. "', " .. firstParam .. " is unsupported")
end
until inputAbort
@ -1068,6 +1084,7 @@ local function run()
if eventName == "key" then
local keycode = params[2]
ignoreNextChar = false
if keycode == 11 or keycode == 82 then -- 0
if selectPage('0') then
@ -1130,7 +1147,7 @@ local function run()
abort = true
else
local isSupported, needRedraw = w.event_handler(eventName, params[2])
local isSupported, needRedraw = w.event_handler(eventName, firstParam)
if not isSupported then
w.status_showWarning("Event '" .. eventName .. "', " .. firstParam .. " is unsupported")
end

View file

@ -355,9 +355,9 @@ function reactor_register()
w.device_register("warpdriveEnanReactorLaser",
function(deviceType, address, wrap) table.insert(reactorlasers, { side = wrap.side(), wrap = wrap }) end,
function() end)
w.event_register("reactorPulse" , function() reactor_pulse(param) return false end )
w.event_register("reactorDeactivation", function() w.status_showWarning("Reactor deactivated") return false end )
w.event_register("reactorActivation" , function() w.status_showWarning("Reactor activated") return false end )
w.event_register("reactorPulse" , function(eventName, param) reactor_pulse(param) return false end )
w.event_register("reactorDeactivation", function( ) w.status_showWarning("Reactor deactivated") return false end )
w.event_register("reactorActivation" , function( ) w.status_showWarning("Reactor activated") return false end )
w.data_register("reactor", reactor_read, nil)
end

View file

@ -358,7 +358,11 @@ end
local function format_float(value, nbchar)
local str = "?"
if value ~= nil then
str = string.format("%g", value)
if type(value) == "number" then
str = string.format("%g", value)
else
str = type(value)
end
end
if nbchar ~= nil then
str = string.sub(" " .. str, -nbchar)
@ -369,7 +373,11 @@ end
local function format_integer(value, nbchar)
local str = "?"
if value ~= nil then
str = string.format("%d", value)
if type(value) == "number" then
str = string.format("%d", value)
else
str = type(value)
end
end
if nbchar ~= nil then
str = string.sub(" " .. str, -nbchar)
@ -379,10 +387,14 @@ end
local function format_boolean(value, strTrue, strFalse)
if value ~= nil then
if value then
return strTrue
if type(value) == "boolean" then
if value then
return strTrue
else
return strFalse
end
else
return strFalse
return type(value)
end
end
return "?"
@ -497,7 +509,7 @@ local function input_readNumber(currentValue)
inputAbort = true
else
local isSupported, needRedraw = w.event_handler(eventName, params[2])
local isSupported, needRedraw = w.event_handler(eventName, firstParam)
if not isSupported then
w.status_showWarning("Event '" .. eventName .. "', " .. address .. " , " .. firstParam .. " is unsupported")
end
@ -536,6 +548,7 @@ local function input_readText(currentValue)
if eventName == "key_down" then
local character = string.char(params[3])
local keycode = params[4]
if keycode == 14 then -- Backspace
input = string.sub(input, 1, string.len(input) - 1)
ignoreNextChar = true
@ -563,7 +576,7 @@ local function input_readText(currentValue)
inputAbort = true
else
local isSupported, needRedraw = w.event_handler(eventName, params[2])
local isSupported, needRedraw = w.event_handler(eventName, firstParam)
if not isSupported then
w.status_showWarning("Event '" .. eventName .. "', " .. address .. ", " .. firstParam .. " is unsupported")
end
@ -593,6 +606,7 @@ local function input_readConfirmation(message)
if eventName == "key_down" then
local character = string.char(params[3])
local keycode = params[4]
if keycode == 28 then -- Return or Enter
w.status_clear()
return true
@ -609,9 +623,9 @@ local function input_readConfirmation(message)
return false
else
local isSupported, needRedraw = w.event_handler(eventName, params[2])
local isSupported, needRedraw = w.event_handler(eventName, firstParam)
if not isSupported then
w.status_showWarning("Event '" .. eventName .. "', " .. params[2] .. " is unsupported")
w.status_showWarning("Event '" .. eventName .. "', " .. firstParam .. " is unsupported")
end
end
if not w.status_isActive() then
@ -676,6 +690,7 @@ local function input_readEnum(currentValue, list, toValue, toDescription, noValu
if eventName == "key_down" then
local character = string.char(params[3])
local keycode = params[4]
if keycode == 14 or keycode == 211 then -- Backspace or Delete
inputKey = nil
ignoreNextChar = true
@ -723,7 +738,7 @@ local function input_readEnum(currentValue, list, toValue, toDescription, noValu
elseif eventName == "interrupted" then
inputAbort = true
elseif not w.event_handler(eventName, params[2]) then
elseif not w.event_handler(eventName, firstParam) then
w.status_showWarning("Event '" .. eventName .. "', " .. address .. ", " .. firstParam .. " is unsupported")
end
until inputAbort
@ -793,6 +808,7 @@ local function event_handler(eventName, param)
elseif eventName == "component_unavailable" then
-- not supported: task_complete, rednet_message, modem_message
elseif event_handlers[eventName] ~= nil then
w.status_showSuccess("param '" .. param .. "' of type " .. type(param))
needRedraw = event_handlers[eventName](eventName, param)
else
return false, needRedraw
@ -1044,6 +1060,7 @@ local function run()
if eventName == "key_down" then
local character = string.char(params[3])
local keycode = params[4]
ignoreNextChar = false
if keycode == 11 or keycode == 82 then -- 0
if selectPage('0') then
@ -1102,7 +1119,7 @@ local function run()
abort = true
else
local isSupported, needRedraw = w.event_handler(eventName, params[2])
local isSupported, needRedraw = w.event_handler(eventName, firstParam)
if not isSupported then
w.status_showWarning("Event '" .. eventName .. "', " .. firstParam .. " is unsupported")
end

View file

@ -360,9 +360,9 @@ function reactor_register()
w.device_register("warpdriveEnanReactorLaser",
function(deviceType, address, wrap) table.insert(reactorlasers, { side = wrap.side(), wrap = wrap }) end,
function() end)
w.event_register("reactorPulse" , function() reactor_pulse(param) return false end )
w.event_register("reactorDeactivation", function() w.status_showWarning("Reactor deactivated") return false end )
w.event_register("reactorActivation" , function() w.status_showWarning("Reactor activated") return false end )
w.event_register("reactorPulse" , function(eventName, param) reactor_pulse(param) return false end )
w.event_register("reactorDeactivation", function( ) w.status_showWarning("Reactor deactivated") return false end )
w.event_register("reactorActivation" , function( ) w.status_showWarning("Reactor activated") return false end )
w.data_register("reactor", reactor_read, nil)
end