Первый фикс

Пачки некоторых позиций увеличены
This commit is contained in:
2024-03-01 20:53:32 +03:00
commit 7c9c708c92
23653 changed files with 767936 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
return {
["1.1.0"] = function()
global.research_progress_strings = {}
end,
}

View File

@@ -0,0 +1,37 @@
local player_data = {}
local constants = require("constants")
local stats_gui = require("scripts.stats-gui")
function player_data.init(player_index)
global.players[player_index] = {
settings = {},
}
end
function player_data.update_settings(player, player_table)
local mod_settings = player.mod_settings
local settings = {
adjust_for_clock = mod_settings["statsgui-adjust-for-clock"].value,
adjust_for_ups = mod_settings["statsgui-adjust-for-fps-ups"].value,
single_line = mod_settings["statsgui-single-line"].value,
}
for _, sensor_data in pairs(constants.builtin_sensors) do
local sensor_name = sensor_data.name
settings["show_" .. sensor_name] = mod_settings["statsgui-show-sensor-" .. sensor_name].value
end
player_table.settings = settings
end
function player_data.refresh(player, player_table)
stats_gui.destroy(player_table)
player_data.update_settings(player, player_table)
stats_gui.build(player, player_table)
end
return player_data

View File

@@ -0,0 +1,5 @@
local preprocessors = {
require("scripts.research-progress"),
}
return preprocessors

View File

@@ -0,0 +1,56 @@
local misc = require("__flib__.misc")
local constants = require("constants")
-- Code based on "improved research queue" by sonaxaton
-- https://github.com/dbeckwith/factorio-research-queue/blob/af6404ab696502a86eec40a4baf7fe00d0c714c7/control.lua#L316
return function()
local strings = {}
for _, force in pairs(game.forces) do
local tech = force.current_research
if tech then
-- Retrieve or create progress samples table
local progress_samples = global.research_progress_samples[force.index]
if not progress_samples then
progress_samples = {}
global.research_progress_samples[force.index] = progress_samples
end
progress_samples[#progress_samples + 1] = { tech = tech.name, progress = force.research_progress }
if #progress_samples > constants.research_progress_samples_count then
table.remove(progress_samples, 1)
end
local estimated_ticks = 0
local num_samples = 0
if #progress_samples > 1 then
for i = 2, #progress_samples do
local previous_sample = progress_samples[i - 1]
local current_sample = progress_samples[i]
if previous_sample.tech == current_sample.tech then
-- How much the progress increased per tick
local speed = (current_sample.progress - previous_sample.progress) / 60
-- Don't add if the speed is negative for whatever reason
if speed > 0 then
-- How many ticks left until the research is finished
estimated_ticks = estimated_ticks + ((1 - current_sample.progress) / speed)
num_samples = num_samples + 1
end
end
end
-- Rolling average
if num_samples > 0 then
estimated_ticks = estimated_ticks / num_samples
end
end
if num_samples > 0 then
strings[force.index] = misc.ticks_to_timestring(estimated_ticks)
else
strings[force.index] = ""
end
end
end
global.research_progress_strings = strings
end

View File

@@ -0,0 +1,21 @@
return function(player)
if not global.players[player.index].settings.show_daytime then
return
end
local days = math.floor(1 + ((game.tick + 12500) / 25000))
local daytime = player.surface.daytime + 0.5
local daytime_minutes = math.floor(daytime * 24 * 60)
local daytime_hours = math.floor(daytime_minutes / 60) % 24
daytime_minutes = daytime_minutes - (daytime_minutes % 15)
return {
"",
{ "statsgui.time" },
" = " .. string.format("%d:%02d", daytime_hours, daytime_minutes % 60),
", ",
{ "statsgui.day" },
" " .. days,
}
end

View File

@@ -0,0 +1,13 @@
return function(player)
if not global.players[player.index].settings.show_evolution then
return
end
local evolution = game.forces.enemy.evolution_factor * 100
return {
"",
{ "statsgui.evolution" },
string.format(" = %.2f", evolution),
"%",
}
end

View File

@@ -0,0 +1,9 @@
local misc = require("__flib__.misc")
return function(player)
if not global.players[player.index].settings.show_playtime then
return
end
return { "", { "statsgui.playtime" }, " = ", misc.ticks_to_timestring(game.ticks_played) }
end

View File

@@ -0,0 +1,12 @@
return function(player)
if not global.players[player.index].settings.show_pollution then
return
end
return {
"",
{ "statsgui.pollution" },
string.format(" = %.2f", player.surface.get_pollution(player.position)),
" PU",
}
end

View File

@@ -0,0 +1,11 @@
local math = require("__flib__.math")
return function(player)
if not global.players[player.index].settings.show_position then
return
end
local position = player.position
return { "", { "statsgui.position" }, " = ", math.round(position.x), ", ", math.round(position.y) }
end

View File

@@ -0,0 +1,10 @@
return function(player)
if not global.players[player.index].settings.show_research then
return
end
local string = global.research_progress_strings[player.force.index]
if string then
return { "", { "statsgui.research-finished" }, " = ", string }
end
end

View File

@@ -0,0 +1,9 @@
local constants = require("constants")
local sensors = {}
for _, sensor_data in pairs(constants.builtin_sensors) do
sensors[#sensors + 1] = require("scripts.sensor." .. sensor_data.name)
end
return sensors

View File

@@ -0,0 +1,76 @@
local sensors = require("scripts.sensors")
local stats_gui = {}
function stats_gui.build(player, player_table)
local single_line = player_table.settings.single_line
local style = "statsgui_frame"
if player_table.settings.adjust_for_clock then
style = style .. "_clock"
end
if not player_table.settings.adjust_for_ups then
style = style .. "_no_ups"
end
local window = player.gui.screen.add({
type = "frame",
style = style,
direction = single_line and "horizontal" or "vertical",
ignored_by_interaction = true,
})
player_table.stats_window = window
stats_gui.set_width(player, player_table)
stats_gui.update(player, player_table)
end
function stats_gui.destroy(player_table)
local stats_window = player_table.stats_window
if stats_window and stats_window.valid then
stats_window.destroy()
player_table.stats_window = nil
end
end
function stats_gui.update(player, player_table)
local window = player_table.stats_window
if not window or not window.valid then
stats_gui.build(player, player_table)
window = player_table.stats_window
end
local children = window.children
local i = 0
for _, sensor in pairs(sensors) do
local caption = sensor(player)
if caption then
i = i + 1
local label = children[i]
if label then
label.caption = caption
else
window.add({
type = "label",
style = "statsgui_label",
caption = caption,
})
end
end
end
-- remove extra children
for j = i + 1, #children do
children[j].destroy()
end
end
function stats_gui.set_width(player, player_table)
local window = player_table.stats_window
if not window or not window.valid then
stats_gui.build(player, player_table)
window = player_table.stats_window
end
window.style.width = (player.display_resolution.width / player.display_scale)
end
return stats_gui