Добавлены все обновления от сообщества, вплоть до #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

@@ -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 = {}