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 float lasersReceived = 0;
private int lastGenerationRate = 0; private int lastGenerationRate = 0;
private int releasedThisTick = 0; // amount of energy released during current tick update private int releasedThisTick = 0; // amount of energy released during current tick update
private int releasedThisCycle = 0; // amount of energy released during current cycle private long releasedThisCycle = 0; // amount of energy released during current cycle
private int releasedLastCycle = 0; 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 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; private boolean isEnabled = false;
@ -89,7 +89,7 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
double amountToIncrease = WarpDriveConfig.ENAN_REACTOR_UPDATE_INTERVAL_TICKS 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)); * 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) { 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); instabilityValues[side] += amountToIncrease * (isNatural ? 1.0D : 0.25D);
} else { } else {
@ -179,8 +179,8 @@ public class TileEntityEnanReactorCore extends TileEntityAbstractEnergy implemen
} }
if (WarpDriveConfig.LOGGING_ENERGY) { if (WarpDriveConfig.LOGGING_ENERGY) {
WarpDrive.logger.info("tickCount " + tickCount + " releasedThisTick " + releasedThisTick + " lasersReceived " + lasersReceived WarpDrive.logger.info(String.format("tickCount %d releasedThisTick %6d lasersReceived %.5f releasedThisCycle %6d containedEnergy %8d",
+ " releasedThisCycle " + releasedThisCycle + " containedEnergy " + containedEnergy); tickCount, releasedThisTick, lasersReceived, releasedThisCycle, containedEnergy));
} }
releasedThisTick = 0; releasedThisTick = 0;

View file

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

View file

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

View file

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

View file

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