Добавлены все обновления от сообщества, вплоть до #148

This commit is contained in:
2024-09-12 14:28:43 +03:00
parent 98159766c4
commit 487a0e6e16
8841 changed files with 23077 additions and 20175 deletions

View File

@@ -1,4 +1,13 @@
---------------------------------------------------------------------------------------------------
Version: 2.2.0
Date: 2023-11-24
Features:
- Added a map setting to adjust the number of entities visualized per tick. (#24)
- Re-added mouse-over visualization, toggled with Alt+H or the shortcut button. (#20)
- Pressing H while hovering will make that entity's fluid systems persist.
Bugfixes:
- Fixed a crash when an entity is invalidated while in the queue to be visualized. (#21)
---------------------------------------------------------------------------------------------------
Version: 2.1.0
Date: 2023-10-15
Features:

View File

@@ -5,6 +5,7 @@ handler.add_libraries({
require("__PipeVisualizer__/scripts/colors"),
require("__PipeVisualizer__/scripts/iterator"),
require("__PipeVisualizer__/scripts/mouseover"),
require("__PipeVisualizer__/scripts/order"),
require("__PipeVisualizer__/scripts/overlay"),
require("__PipeVisualizer__/scripts/renderer"),

View File

@@ -11,12 +11,50 @@ data:extend({
key_sequence = "SHIFT + H",
action = "lua",
},
{
type = "custom-input",
name = "pv-toggle-mouseover",
key_sequence = "ALT + H",
action = "lua",
},
{
type = "custom-input",
name = "pv-color-by-fluid-system",
key_sequence = "CONTROL + H",
action = "lua",
},
{
type = "shortcut",
name = "pv-toggle-mouseover",
order = "c[toggles]-p[pv-toggle-mouseover]",
icon = {
filename = "__PipeVisualizer__/graphics/mouseover-dark-x32.png",
size = 32,
mipmap_count = 2,
flags = { "gui-icon" },
},
disabled_icon = {
filename = "__PipeVisualizer__/graphics/mouseover-light-x32.png",
size = 32,
mipmap_count = 2,
flags = { "gui-icon" },
},
small_icon = {
filename = "__PipeVisualizer__/graphics/mouseover-dark-x24.png",
size = 24,
mipmap_count = 2,
flags = { "gui-icon" },
},
disabled_small_icon = {
filename = "__PipeVisualizer__/graphics/mouseover-light-x24.png",
size = 24,
mipmap_count = 2,
flags = { "gui-icon" },
},
associated_control_input = "pv-toggle-mouseover",
action = "lua",
toggleable = true,
},
{
type = "shortcut",
name = "pv-toggle-overlay",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 322 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 975 B

After

Width:  |  Height:  |  Size: 288 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 455 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 628 B

After

Width:  |  Height:  |  Size: 133 B

View File

@@ -1,6 +1,6 @@
{
"name": "PipeVisualizer",
"version": "2.1.0",
"version": "2.2.0",
"title": "Pipe Visualizer",
"description": "Visualize the layout and contents of pipe networks. Press H to draw the selected entity's fluid systems, or press Shift + H to draw all visible fluid systems. Press Control + H to toggle between color-by-fluid and color-by-system.",
"author": "raiguard",
@@ -10,7 +10,7 @@
"dependencies": [ "base >= 1.1.86", "flib >= 0.13.0" ],
"package": {
"git_publish_branch": "main",
"ignore": [ "imgui.ini", "screenshots/*", "stylua.toml" ],
"ignore": [ "imgui.ini", "screenshots/*" ],
"scripts": { "prepublish": "factorio-crowdin-sync" },
"sync_portal_details": true
}

View File

@@ -1,14 +1,22 @@
[controls]
pv-color-by-fluid-system=Color by fluid system
pv-toggle-mouseover=Toggle mouse-over pipe visualizer
pv-toggle-overlay=Toggle pipe visualizer overlay
pv-visualize-selected=Visualize selected pipe system
[message]
pv-color-by-fluid=Color by fluid
pv-color-by-system=Color by system
pv-mouseover-disabled=Disabled mouse-over pipe visualizer
pv-mouseover-enabled=Enabled mouse-over pipe visualizer
[mod-setting-description]
pv-entities-per-tick=Higher numbers will increase UPS impact, particularly when using the overlay.
[mod-setting-name]
pv-entities-per-tick=Entities per tick
pv-overlay-opacity=Overlay opacity
[shortcut-name]
pv-toggle-mouseover=Toggle mouse-over pipe visualizer
pv-toggle-overlay=Toggle pipe visualizer overlay

View File

@@ -7,7 +7,10 @@ pv-visualize-selected=Визуализация выбранной системы
pv-color-by-fluid=Цвет по жидкости
pv-color-by-system=Цвет по системе
[mod-setting-description]
[mod-setting-name]
pv-overlay-opacity=Непрозрачность оверлея
[shortcut-name]
pv-toggle-overlay=Вкл/выкл визуализатор труб

View File

@@ -7,7 +7,10 @@ pv-visualize-selected=Візуалізувати обрану систему т
pv-color-by-fluid=Колір за рідиною
pv-color-by-system=Колір за системою
[mod-setting-description]
[mod-setting-name]
pv-overlay-opacity=Прозорість накладання
[shortcut-name]
pv-toggle-overlay=Зображення візуалізатора труб

View File

@@ -14,15 +14,19 @@ local renderer = require("__PipeVisualizer__/scripts/renderer")
--- @field in_queue table<UnitNumber, boolean>
--- @field next_color_index integer
--- @field player_index PlayerIndex
--- @field queue Queue<LuaEntity>
--- @field scheduled table<FluidSystemID, {entity: LuaEntity?, tick: uint}>
--- @field queue Queue<ToIterateData>
--- @field systems table<FluidSystemID, FluidSystemData?>
--- @field to_ignore table<UnitNumber, boolean>
--- @class FluidSystemData
--- @field color Color
--- @field from_hover boolean
--- @field order uint
--- @class ToIterateData
--- @field entity LuaEntity
--- @field unit_number UnitNumber
--- @param iterator Iterator
--- @param entity LuaEntity
local function push(iterator, entity)
@@ -31,23 +35,23 @@ local function push(iterator, entity)
end
local unit_number = entity.unit_number --[[@as UnitNumber]]
iterator.in_queue[unit_number] = true
flib_queue.push_back(iterator.queue, entity)
flib_queue.push_back(iterator.queue, { entity = entity, unit_number = unit_number })
end
--- @param iterator Iterator
--- @return LuaEntity?
local function pop(iterator)
while true do
local entity = flib_queue.pop_front(iterator.queue)
if not entity then
local to_iterate = flib_queue.pop_front(iterator.queue)
if not to_iterate then
return
end
local unit_number = entity.unit_number --[[@as UnitNumber]]
local unit_number = to_iterate.unit_number
iterator.in_queue[unit_number] = nil
if iterator.to_ignore[unit_number] then
iterator.to_ignore[unit_number] = nil
else
return entity
elseif to_iterate.entity.valid then
return to_iterate.entity
end
end
end
@@ -55,8 +59,9 @@ end
--- @param entity LuaEntity
--- @param player_index PlayerIndex
--- @param in_overlay boolean
--- @param from_hover boolean?
--- @return boolean accepted
local function request(entity, player_index, in_overlay)
local function request(entity, player_index, in_overlay, from_hover)
if not global.iterator then
return false
end
@@ -88,6 +93,8 @@ local function request(entity, player_index, in_overlay)
return self.in_overlay -- To handle entities that cross chunk boundaries
end
from_hover = from_hover or false
local fluidbox = entity.fluidbox
local should_iterate = false
for fluidbox_index = 1, #fluidbox do
@@ -118,7 +125,7 @@ local function request(entity, player_index, in_overlay)
end
end
self.systems[fluid_system_id] = { color = color, order = order }
self.systems[fluid_system_id] = { color = color, from_hover = from_hover, order = order }
end
should_iterate = true
@@ -233,20 +240,63 @@ local function clear_all(player_index)
end
end
--- @param entity LuaEntity
--- @param player_index PlayerIndex
local function request_or_clear(entity, player_index)
local function clear_hovered(player_index)
if not global.iterator then
return
end
local iterator = global.iterator[player_index]
if not iterator then
local it = global.iterator[player_index]
if not it then
return
end
for system_id, system_data in pairs(it.systems) do
if system_data.from_hover then
clear_system(it, system_id)
end
end
if not next(it.systems) then
global.iterator[player_index] = nil
if not next(global.iterator) then
renderer.reset()
end
end
end
--- @param player_index PlayerIndex
--- @return Iterator?
local function get(player_index)
if not global.iterator then
return
end
return global.iterator[player_index]
end
--- @param entity LuaEntity
--- @param player_index PlayerIndex
local function request_or_clear(entity, player_index)
local it = get(player_index)
if not it then
request(entity, player_index, false)
return
end
if iterator.in_overlay then
if it.in_overlay then
return
end
-- If this entity was being hovered, change its systems to persistent instead of removing the visualization.
local entity_data = entity_data.get(it, entity)
if entity_data then
local did_change
for fluid_system_id in pairs(entity_data.connections) do
local system_data = it.systems[fluid_system_id]
if system_data and system_data.from_hover then
system_data.from_hover = false
did_change = true
end
end
if did_change then
return
end
end
if request(entity, player_index, false) then
return
end
@@ -254,8 +304,8 @@ local function request_or_clear(entity, player_index)
for fluidbox_index = 1, #fluidbox do
--- @cast fluidbox_index uint
local id = fluidbox.get_fluid_system_id(fluidbox_index)
if id and iterator.systems[id] then
clear_system(iterator, id)
if id and it.systems[id] then
clear_system(it, id)
end
end
end
@@ -264,7 +314,8 @@ local function on_tick()
if not global.iterator then
return
end
local entities_per_tick = math.ceil(30 / table_size(global.iterator))
local entities_per_tick =
math.ceil(settings.global["pv-entities-per-tick"].value --[[@as int]] / table_size(global.iterator))
for _, iterator in pairs(global.iterator) do
iterate(iterator, entities_per_tick)
end
@@ -306,6 +357,8 @@ iterator.events = {
iterator.clear = clear
iterator.clear_all = clear_all
iterator.clear_hovered = clear_hovered
iterator.get = get
iterator.request = request
return iterator

View File

@@ -1,6 +1,8 @@
local flib_migration = require("__flib__/migration")
local mod_gui = require("__core__/lualib/mod-gui")
local mouseover = require("__PipeVisualizer__/scripts/mouseover")
local version_migrations = {
["2.0.0"] = function()
global = {}
@@ -13,6 +15,9 @@ local version_migrations = {
end
end
end,
["2.2.0"] = function()
mouseover.on_init()
end,
}
local migrations = {}

View File

@@ -0,0 +1,81 @@
local entity_data = require("__PipeVisualizer__/scripts/entity-data")
local iterator = require("__PipeVisualizer__/scripts/iterator")
--- @param e EventData.CustomInputEvent|EventData.on_lua_shortcut
local function on_toggle_mouseover(e)
if e.prototype_name and e.prototype_name ~= "pv-toggle-mouseover" then
return
end
global.mouseover_enabled[e.player_index] = not global.mouseover_enabled[e.player_index]
local player = game.get_player(e.player_index)
if not player then
return
end
player.set_shortcut_toggled("pv-toggle-mouseover", global.mouseover_enabled[e.player_index])
if e.input_name then
local text
if global.mouseover_enabled[e.player_index] then
text = { "message.pv-mouseover-enabled" }
else
text = { "message.pv-mouseover-disabled" }
end
player.create_local_flying_text({
text = text,
create_at_cursor = true,
})
end
local it = iterator.get(e.player_index)
if it and it.in_overlay then
return
elseif it then
iterator.clear_hovered(e.player_index)
end
end
--- @param e EventData.on_selected_entity_changed
local function on_selected_entity_changed(e)
if not global.mouseover_enabled[e.player_index] then
return
end
local player = game.get_player(e.player_index)
if not player then
return
end
local it = iterator.get(e.player_index)
if it and it.in_overlay then
return
end
local selected = player.selected
if selected and it and entity_data.get(it, selected) then
return
end
if it then
iterator.clear_hovered(e.player_index)
end
if selected then
iterator.request(selected, e.player_index, false, true)
end
end
local mouseover = {}
function mouseover.on_init()
--- @type table<PlayerIndex, boolean>
global.mouseover_enabled = {}
end
mouseover.events = {
[defines.events.on_lua_shortcut] = on_toggle_mouseover,
[defines.events.on_selected_entity_changed] = on_selected_entity_changed,
["pv-toggle-mouseover"] = on_toggle_mouseover,
}
return mouseover

View File

@@ -69,7 +69,7 @@ local encoded_directions = {
--- @type Color
local default_color = { r = 0.4, g = 0.4, b = 0.4 }
--- @type FluidSystemData
local default_fluid_system = { color = default_color, order = flib_math.max_uint }
local default_fluid_system = { color = default_color, from_hover = false, order = flib_math.max_uint }
local renderer = {}

View File

@@ -7,4 +7,11 @@ data:extend({
minimum_value = 0,
maximum_value = 1,
},
{
type = "int-setting",
name = "pv-entities-per-tick",
setting_type = "runtime-global",
default_value = 30,
minimum_value = 1,
},
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB