Fixed Science Info Not Updating

This commit is contained in:
Cooldude2606
2020-05-28 19:45:00 +01:00
parent 1e208537b5
commit 7f16a4439a
3 changed files with 30 additions and 31 deletions

View File

@@ -2,9 +2,9 @@
-- @config Science
return { -- list of all science packs to be shown in the gui
show_eta=true, --- @setting show_eta when true the eta for research completion will be shown
color_clamp=5, --- @setting color_clamp the amount required for the text to show as green or red
color_flux=0.1, --- @setting color_flux the ammount of flucuation allowed in production before icon change
show_eta = true, --- @setting show_eta when true the eta for research completion will be shown
color_cutoff = 0.8, --- @setting color_cutoff the amount that production can fall before the text changes color
color_flux = 0.1, --- @setting color_flux the amount of fluctuation allowed in production before the icon changes color
'automation-science-pack',
'logistic-science-pack',
'military-science-pack',

View File

@@ -187,21 +187,21 @@ end
-- Functions used to format production values
-- @section formating
--- Returns a color value bassed on the value that was given
-- @tparam number clamp value which seperates the different colours
-- @tparam number active_value first value tested, tested against clamp
-- @tparam number passive_value second value tested, tested against 0
--- Returns a color value based on the value that was given
-- @tparam number cutoff value which separates the different colours
-- @tparam number active_value first value tested, tested against cutoff
-- @tparam number passive_value second value tested, tested against 0 when active is 0
-- @treturn table contains r,g,b keys
function Production.get_color(clamp,active_value,passive_value)
if active_value > clamp then
function Production.get_color(cutoff, active_value, passive_value)
if active_value > cutoff then
return Colors.light_green
elseif active_value < -clamp then
elseif active_value < -cutoff then
return Colors.indian_red
elseif active_value ~= 0 then
return Colors.orange
elseif passive_value and passive_value > 0 then
return Colors.orange
elseif passive_value and passive_value ~= 0 then
elseif passive_value and passive_value < 0 then
return Colors.indian_red
else
return Colors.grey

View File

@@ -56,8 +56,8 @@ Gui.element(function(_,parent,production_label_data)
end)
-- Get the data that is used with the production label
local function get_production_label_data(name,tooltip,value,secondary)
local data_colour = Production.get_color(config.color_clamp, value, secondary)
local function get_production_label_data(name, tooltip, value, cutout, secondary)
local data_colour = Production.get_color(config.color_cutoff * cutout, value, secondary)
local surfix, caption = Production.format_number(value)
return {
@@ -134,9 +134,9 @@ Gui.element(function(_,parent,science_pack_data)
delta_table.style.padding = 0
-- Draw the production labels
update_production_label(delta_table,science_pack_data.positive)
update_production_label(delta_table,science_pack_data.negative)
update_production_label(parent,science_pack_data.net)
update_production_label(delta_table, science_pack_data.positive)
update_production_label(delta_table, science_pack_data.negative)
update_production_label(parent, science_pack_data.net)
-- Return the pack icon
return pack_icon
@@ -147,10 +147,9 @@ local function get_science_pack_data(player,science_pack)
-- Check that some packs have been made
local total = Production.get_production_total(force, science_pack)
if total.made == 0 then return end
local minute = Production.get_production(force, science_pack, defines.flow_precision_index.one_minute)
if total.made == 0 then
return
end
local hour = Production.get_production(force, science_pack, defines.flow_precision_index.one_hour)
-- Get the icon style
local icon_style = 'slot_button'
@@ -170,17 +169,17 @@ local function get_science_pack_data(player,science_pack)
positive = get_production_label_data(
'pos-'..science_pack,
{'science-info.pos-tooltip', total.made},
minute.made
minute.made, hour.made
),
negative = get_production_label_data(
'neg-'..science_pack,
{'science-info.neg-tooltip', total.used},
-minute.used
-minute.used, hour.used
),
net = get_production_label_data(
'net-'..science_pack,
{'science-info.net-tooltip', total.net},
minute.net,
minute.net, minute.net > 0 and hour.net or 0,
minute.made+minute.used
)
}
@@ -337,19 +336,19 @@ Event.on_nth_tick(60,function()
local scroll_table = container.scroll.table
local pack_data = force_pack_data[force_name]
if not pack_data then
-- No data in chache so it needs to be generated
-- No data in cache so it needs to be generated
pack_data = {}
force_pack_data[force_name] = pack_data
for _,science_pack in ipairs(config) do
local next_data = get_science_pack_data(player,science_pack)
for _, science_pack in ipairs(config) do
local next_data = get_science_pack_data(player, science_pack)
pack_data[science_pack] = next_data
update_science_pack(scroll_table,next_data)
update_science_pack(scroll_table, next_data)
end
else
-- Data found in chache is no need to generate it
for _,next_data in ipairs(pack_data) do
update_science_pack(scroll_table,next_data)
-- Data found in cache is no need to generate it
for _, next_data in pairs(pack_data) do
update_science_pack(scroll_table, next_data)
end
end
@@ -362,11 +361,11 @@ Event.on_nth_tick(60,function()
-- No data in chache so it needs to be generated
eta_data = get_eta_label_data(player)
force_eta_data[force_name] = eta_data
update_eta_label(eta_label,eta_data)
update_eta_label(eta_label, eta_data)
else
-- Data found in chache is no need to generate it
update_eta_label(eta_label,eta_data)
update_eta_label(eta_label, eta_data)
end