Address review on exp_server_list

The controller and instance plugins are init functions with closures.
The controller batches refreshes with setMany and deleteMany, and the
instance gates updates on its status instead of a started flag.

short_name is now display_name. New always_on_top field sorts servers
first in get_servers. The record carries has_password from the game
password in factorio.settings, never the password itself, and the
description falls back to the one in factorio.settings. A controller
welcome is used when the instance has none, and the readme falls back
to a default welcome from the locale.

Lua gets is_synced for connect.lua. The readme passes an empty detail
instead of nil to the join tooltip so the player count stays in __2__,
restores the Password status, shows the welcome title as a centered
label and shortens long descriptions with the full text as a tooltip.

The Lua tests assert the lookups they index, which fixes the lint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-14 21:35:33 +00:00
1 parent 4d136853c9
commit c0289ed8a7
15 files changed
+528 -418

No files matched your search

+1 -1
View File
@@ -49,7 +49,7 @@ end
--- @param is_address boolean?
--- @return boolean, LocalisedString | ExpServerList.Server | string # True for success
local function resolve_server(server, is_address)
if is_address or not ExpServerList.get_current() then
if is_address or not ExpServerList.is_synced() then
return true, server
end
return find_server(server)
+32 -5
View File
@@ -16,6 +16,23 @@ local format_time = ExpUtil.format_time_factory_locale{ format = "long", days =
local frame_width = 595
local title_width = 270
local scroll_height = 275
local description_length = 120
--- Cut a string to a number of bytes without splitting a utf8 character
--- @param str string
--- @param length number
--- @return string
local function shorten(str, length)
if #str <= length then
return str
end
local next_byte = str:byte(length + 1)
while length > 0 and next_byte >= 0x80 and next_byte < 0xC0 do
length = length - 1
next_byte = str:byte(length + 1)
end
return str:sub(1, length) .. "..."
end
--- @class ExpGui_Readme.elements
local Elements = {}
@@ -137,12 +154,15 @@ function Elements.join_server.refresh(button, server)
status = "Current"
elseif current and server.factorio_version ~= current.factorio_version then
status, detail = "Version", server.factorio_version
elseif server.has_password then
status = "Password"
elseif current and server.mod_pack_name ~= current.mod_pack_name then
status, detail = "Modded", server.mod_pack_name
end
-- Factorio drops nil parameters, which would shift the player count into __1__
local player_count = server and server.player_count or 0
button.tooltip = { "exp-gui_readme.servers-connect-" .. status, detail, player_count }
button.tooltip = { "exp-gui_readme.servers-connect-" .. status, detail or "", player_count }
if status == "Offline" or status == "Current" then
button.enabled = false
@@ -154,6 +174,11 @@ function Elements.join_server.refresh(button, server)
button.sprite = "utility/shuffle"
button.hovered_sprite = "utility/shuffle"
elseif status == "Password" then
button.enabled = true
button.sprite = "utility/warning_white"
button.hovered_sprite = "utility/warning"
elseif status == "Modded" then
button.enabled = true
button.sprite = "utility/downloading_white"
@@ -192,7 +217,7 @@ define_tab(
if current then
server_details = {
name = current.name,
welcome = current.welcome,
welcome = current.welcome ~= "" and current.welcome or { "exp-gui_readme.welcome-default" },
reset_time = current.reset_time ~= "" and current.reset_time or "Not Set",
}
end
@@ -205,7 +230,7 @@ define_tab(
local center_flow = top_flow.add{ type = "flow", direction = "vertical" }
center_flow.style.horizontal_align = "center"
Gui.elements.title_label(center_flow, 62, { "exp-gui_readme.welcome-title", server_details.name })
Gui.elements.centered_label(center_flow, 380, { "exp-gui_readme.welcome-title", server_details.name })
Gui.elements.centered_label(center_flow, 380, server_details.welcome)
top_flow.add{ type = "sprite", sprite = "file/modules/exp_scenario/gui/logo.png" }
@@ -318,8 +343,10 @@ define_tab(
local factorio_servers = Elements.title_table(scroll_pane, 225, { "exp-gui_readme.servers-factorio" }, 3)
for _, server in ipairs(ExpServerList.get_servers()) do
Gui.elements.centered_label(factorio_servers, 110, server.short_name)
Gui.elements.centered_label(factorio_servers, 436, server.description)
local description = shorten(server.description, description_length)
local tooltip = description ~= server.description and server.description or nil
Gui.elements.centered_label(factorio_servers, 110, server.display_name)
Gui.elements.centered_label(factorio_servers, 436, description, tooltip)
Elements.join_server(factorio_servers, server)
end
+2
View File
@@ -320,6 +320,7 @@ main-tooltip=Information
welcome-tab=Welcome
welcome-tooltip=Welcome to __1__
welcome-title=Welcome to __1__
welcome-default=Thanks for playing on our server, we hope you enjoy your stay.
welcome-general=Welcome to __1__; we host many Factorio servers. While you are here, we ask you to follow our rules. You can find these in the tab above. You can also find our custom commands and links to our other servers. This map has been online for __2__.\nPlease note that our servers reset periodically, the next reset is: __3__
welcome-roles=We run a custom role system to help protect the work of others. As a result you may not be able to use your deconstruction planner yet or drop items on the ground. Roles also give you access to some custom features such as adding tasks to our task list or making new warp points.\nYou have been assigned the roles: __1__
welcome-chat=Chatting can be difficult for new players because it’s different than other games! It’s very simple, the button you need to press is the “GRAVE/TILDE” key (which is located under the “ESC key”). If you would like to change the key, go to your Controls tab in options.\nThe setting you need to change is “Toggle chat (and Lua console)” you currently have it set to "__CONTROL__toggle-console__"
@@ -353,6 +354,7 @@ servers-open-in-browser=Open in your browser
servers-connect-Offline=Server is currently offline
servers-connect-Current=This is your current server
servers-connect-Version=Server is on a different version: __1__
servers-connect-Password=Server requires a password\nPlayers online: __2__
servers-connect-Modded=Server uses the __1__ mod pack, mods may need to be downloaded\nPlayers online: __2__
servers-connect-Online=Server is online\nPlayers online: __2__
backers-tab=Backers
+1
View File
@@ -342,6 +342,7 @@ servers-factorio=異星工廠伺服器
servers-connect-Offline=該服務器目前沒有在運行
servers-connect-Current=你目前所在的伺服器
servers-connect-Version=該服務器運行不同的遊戲版本: __1__
servers-connect-Password=該服務器需要密碼
servers-connect-Modded=該服務器需要下載模組
servers-connect-Online=該服務器在線
servers-external=外部連結
+1
View File
@@ -342,6 +342,7 @@ servers-factorio=異星工廠伺服器
servers-connect-Offline=該服務器目前沒有在運行
servers-connect-Current=你目前所在的伺服器
servers-connect-Version=該服務器運行不同的遊戲版本: __1__
servers-connect-Password=該服務器需要密碼
servers-connect-Modded=該服務器需要下載模組
servers-connect-Online=該服務器在線
servers-external=外部連結