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 -- @config Science
return { -- list of all science packs to be shown in the gui 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 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_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 ammount of flucuation allowed in production before icon change color_flux = 0.1, --- @setting color_flux the amount of fluctuation allowed in production before the icon changes color
'automation-science-pack', 'automation-science-pack',
'logistic-science-pack', 'logistic-science-pack',
'military-science-pack', 'military-science-pack',

View File

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

View File

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