mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-11-19 23:23:12 +09:00
Merge branch 'main' into aperx
This commit is contained in:
commit
02a5b69616
115 files changed
+5014
-1456
No files matched your search
@@ -9,4 +9,4 @@ add_static("Gui", require("modules/exp_gui"))
|
||||
|
||||
add_static("Roles", require("modules/exp_roles"))
|
||||
add_static("Datastore", require("modules.exp_legacy.expcore.datastore"))
|
||||
add_static("External", require("modules.exp_legacy.expcore.external"))
|
||||
add_static("ExpServerList", require("modules/exp_server_list"))
|
||||
@@ -5,50 +5,56 @@ Adds a commands that allows you to request a player move to another server
|
||||
local Async = require("modules/exp_util/async")
|
||||
local Commands = require("modules/exp_commands")
|
||||
|
||||
local External = require("modules.exp_legacy.expcore.external") --- @dep expcore.external
|
||||
local request_connection_async = Async.register(External.request_connection)
|
||||
local ExpServerList = require("modules/exp_server_list")
|
||||
local request_connection_async = Async.register(ExpServerList.request_connection)
|
||||
|
||||
local concat = table.concat
|
||||
|
||||
--- Convert a server name into a server id, is not an Commands.InputParser because it does not accept addresses
|
||||
--- @param server string
|
||||
--- @return boolean, LocalisedString # True for success
|
||||
local function get_server_id(server)
|
||||
local servers = External.get_servers_filtered(server)
|
||||
local current_server = External.get_current_server()
|
||||
local current_version = current_server.version
|
||||
--- Find the one server matching a name, is not an Commands.InputParser because it does not accept addresses
|
||||
--- @param search string
|
||||
--- @return boolean, LocalisedString | ExpServerList.Server # True for success
|
||||
local function find_server(search)
|
||||
local current_server = ExpServerList.get_current() --- @cast current_server -nil
|
||||
local found = ExpServerList.find_servers(search)
|
||||
|
||||
local server_names_before, server_names = {}, {}
|
||||
local server_count_before, server_count = 0, 0
|
||||
for next_server_id, server_details in pairs(servers) do
|
||||
server_count_before = server_count_before + 1
|
||||
server_names_before[server_count_before] = server_details.name
|
||||
if server_details.version == current_version then
|
||||
server_count = server_count + 1
|
||||
server_names[server_count] = server_details.name
|
||||
else
|
||||
servers[next_server_id] = nil
|
||||
local names_all, names = {}, {}
|
||||
local matching = {} --- @type ExpServerList.Server[]
|
||||
for index, server in ipairs(found) do
|
||||
names_all[index] = server.name
|
||||
if server.factorio_version == current_server.factorio_version then
|
||||
matching[#matching + 1] = server
|
||||
names[#names + 1] = server.name
|
||||
end
|
||||
end
|
||||
|
||||
if server_count > 1 then
|
||||
return false, { "exp-commands_connect.too-many-matching", concat(server_names, ", ") }
|
||||
elseif server_count == 1 then
|
||||
local server_id, server_details = next(servers) --- @cast server_details -nil
|
||||
local status = External.get_server_status(server_id)
|
||||
if server_id == current_server.id then
|
||||
return false, { "exp-commands_connect.same-server", server_details.name }
|
||||
elseif status == "Offline" then
|
||||
return false, { "exp-commands_connect.offline", server_details.name }
|
||||
if #matching > 1 then
|
||||
return false, { "exp-commands_connect.too-many-matching", concat(names, ", ") }
|
||||
elseif #matching == 1 then
|
||||
local server = matching[1]
|
||||
if server.id == current_server.id then
|
||||
return false, { "exp-commands_connect.same-server", server.name }
|
||||
elseif not ExpServerList.is_online(server) then
|
||||
return false, { "exp-commands_connect.offline", server.name }
|
||||
end
|
||||
return true, server_id --[[@as string]]
|
||||
elseif server_count_before > 0 then
|
||||
return false, { "exp-commands_connect.wrong-version", concat(server_names_before, ", ") }
|
||||
return true, server
|
||||
elseif #found > 0 then
|
||||
return false, { "exp-commands_connect.wrong-version", concat(names_all, ", ") }
|
||||
else
|
||||
return false, { "exp-commands_connect.none-matching" }
|
||||
end
|
||||
end
|
||||
|
||||
--- Resolve the server argument to a server, or leave it as an address
|
||||
--- @param server string
|
||||
--- @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.is_synced() then
|
||||
return true, server
|
||||
end
|
||||
return find_server(server)
|
||||
end
|
||||
|
||||
--- Connect to a different server
|
||||
Commands.new("connect", { "exp-commands_connect.description" })
|
||||
:argument("server", { "exp-commands_connect.arg-server" }, Commands.types.string)
|
||||
@@ -57,15 +63,12 @@ Commands.new("connect", { "exp-commands_connect.description" })
|
||||
:register(function(player, server, is_address)
|
||||
--- @cast server string
|
||||
--- @cast is_address boolean?
|
||||
if not is_address and External.valid() then
|
||||
local success, result = get_server_id(server)
|
||||
if not success then
|
||||
return Commands.status.invalid_input(result)
|
||||
end
|
||||
server = result
|
||||
local success, result = resolve_server(server, is_address)
|
||||
if not success then
|
||||
return Commands.status.invalid_input(result)
|
||||
end
|
||||
|
||||
request_connection_async(player, server, true)
|
||||
request_connection_async(player, result, true)
|
||||
end)
|
||||
|
||||
--- Connect another player to a different server
|
||||
@@ -78,15 +81,12 @@ Commands.new("connect-player", { "exp-commands_connect.description-player" })
|
||||
--- @cast other_player LuaPlayer
|
||||
--- @cast server string
|
||||
--- @cast is_address boolean?
|
||||
if not is_address and External.valid() then
|
||||
local success, result = get_server_id(server)
|
||||
if not success then
|
||||
return Commands.status.invalid_input(result)
|
||||
end
|
||||
server = result
|
||||
local success, result = resolve_server(server, is_address)
|
||||
if not success then
|
||||
return Commands.status.invalid_input(result)
|
||||
end
|
||||
|
||||
request_connection_async(other_player, server)
|
||||
request_connection_async(other_player, result)
|
||||
end)
|
||||
|
||||
--- Connect all players to a different server
|
||||
@@ -97,15 +97,12 @@ Commands.new("connect-all", { "exp-commands_connect.description-all" })
|
||||
:register(function(player, server, is_address)
|
||||
--- @cast server string
|
||||
--- @cast is_address boolean?
|
||||
if not is_address and External.valid() then
|
||||
local success, result = get_server_id(server)
|
||||
if not success then
|
||||
return Commands.status.invalid_input(result)
|
||||
end
|
||||
server = result
|
||||
local success, result = resolve_server(server, is_address)
|
||||
if not success then
|
||||
return Commands.status.invalid_input(result)
|
||||
end
|
||||
|
||||
for _, next_player in pairs(game.connected_players) do
|
||||
request_connection_async(next_player, server)
|
||||
request_connection_async(next_player, result)
|
||||
end
|
||||
end)
|
||||
@@ -4,7 +4,7 @@
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
local Feature = require("modules/exp_scenario/features")
|
||||
local Async = require("modules/exp_util/async")
|
||||
local config_server_detail = require("modules.exp_legacy.config.server_detail") --- @dep config.server_detail
|
||||
local community_details = require("modules/exp_scenario/config/community_details").config
|
||||
|
||||
local floor = math.floor
|
||||
local random = math.random
|
||||
@@ -20,6 +20,15 @@ local send_message_async =
|
||||
end
|
||||
end)
|
||||
|
||||
--- Reply with a link from community_details, read when the reply is sent
|
||||
--- @param key string
|
||||
--- @return fun(): LocalisedString
|
||||
local function server_link(key)
|
||||
return function()
|
||||
return { "info." .. key, community_details[key] }
|
||||
end
|
||||
end
|
||||
|
||||
local afk_time_units = {
|
||||
minutes = true,
|
||||
seconds = true,
|
||||
@@ -28,13 +37,13 @@ local afk_time_units = {
|
||||
return Feature.register("chat_auto_reply", {
|
||||
--- @type table<string, LocalisedString | fun(player: LuaPlayer, is_command: boolean): LocalisedString>
|
||||
messages = { -- will trigger when ever the word is said
|
||||
["discord"] = { "info.discord", config_server_detail["discord"] },
|
||||
["expgaming"] = { "info.website", config_server_detail["website"] },
|
||||
["website"] = { "info.website", config_server_detail["website"] },
|
||||
["status"] = { "info.status", config_server_detail["status"] },
|
||||
["github"] = { "info.github", config_server_detail["github"] },
|
||||
["patreon"] = { "info.patreon", config_server_detail["patreon"] },
|
||||
["donate"] = { "info.patreon", config_server_detail["patreon"] },
|
||||
["discord"] = server_link("discord"),
|
||||
["expgaming"] = server_link("website"),
|
||||
["website"] = server_link("website"),
|
||||
["status"] = server_link("status"),
|
||||
["github"] = server_link("github"),
|
||||
["patreon"] = server_link("patreon"),
|
||||
["donate"] = server_link("patreon"),
|
||||
["command"] = { "info.custom-commands" },
|
||||
["commands"] = { "info.custom-commands" },
|
||||
["softmod"] = { "info.softmod" },
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
--- Names and links of the community, shown in chat, the readme, and the greeting
|
||||
-- @config Community-Details
|
||||
|
||||
local Feature = require("modules/exp_scenario/features")
|
||||
|
||||
--- The values are always used, disabling the feature changes nothing
|
||||
return Feature.register("community_details", {
|
||||
community_name = "Explosive Gaming",
|
||||
discord = "https://discord.explosivegaming.nl",
|
||||
website = "https://www.explosivegaming.nl",
|
||||
status = "https://status.explosivegaming.nl",
|
||||
github = "https://github.com/explosivegaming/ExpCluster",
|
||||
patreon = "https://www.patreon.com/ExpGaming",
|
||||
})
|
||||
@@ -52,11 +52,13 @@ add(require("modules/exp_scenario/control/discord_alerts"))
|
||||
add(require("modules/exp_scenario/control/features"))
|
||||
add(require("modules/exp_scenario/control/extra_logging"))
|
||||
add(require("modules/exp_scenario/control/fast_deconstruction"))
|
||||
add(require("modules/exp_scenario/control/greetings"))
|
||||
add(require("modules/exp_scenario/control/help_bubbles"))
|
||||
add(require("modules/exp_scenario/control/inserter_pickup"))
|
||||
add(require("modules/exp_scenario/control/inventory_clear"))
|
||||
add(require("modules/exp_scenario/control/mine_depletion"))
|
||||
add(require("modules/exp_scenario/control/nuke_protection"))
|
||||
add(require("modules/exp_scenario/control/player_settings"))
|
||||
add(require("modules/exp_scenario/control/pollution_grading"))
|
||||
add(require("modules/exp_scenario/control/popups"))
|
||||
add(require("modules/exp_scenario/control/protection"))
|
||||
|
||||
@@ -5,10 +5,14 @@ Makes trees which are marked for decon "decay" quickly to allow faster building
|
||||
local Gui = require("modules/exp_gui")
|
||||
local Async = require("modules/exp_util/async")
|
||||
local Roles = require("modules/exp_roles")
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data")
|
||||
local HasEnabledDecon = PlayerData.Settings:combine("HasEnabledDecon")
|
||||
HasEnabledDecon:set_default(false)
|
||||
--- Players who toggled fast decon on, by player index
|
||||
--- @type table<number, true>
|
||||
local enabled_players = {}
|
||||
Storage.register(enabled_players, function(tbl)
|
||||
enabled_players = tbl
|
||||
end)
|
||||
|
||||
local random = math.random
|
||||
local floor = math.floor
|
||||
@@ -58,7 +62,7 @@ local remove_trees_async =
|
||||
--- @return "fast" | "allow" | "disallow"
|
||||
local function get_permission(player)
|
||||
if Roles.player_has_permission(player, "exp_scenario.decon.fast_trees") then
|
||||
return HasEnabledDecon:get(player) and "fast" or "allow"
|
||||
return enabled_players[player.index] and "fast" or "allow"
|
||||
elseif Roles.player_has_permission(player, "exp_scenario.decon.standard") then
|
||||
return "allow"
|
||||
else
|
||||
@@ -105,7 +109,7 @@ Gui.toolbar.create_button{
|
||||
end
|
||||
}:on_click(function(def, player, element)
|
||||
local state = Gui.toolbar.get_button_toggled_state(def, player)
|
||||
HasEnabledDecon:set(player, state)
|
||||
enabled_players[player.index] = state or nil
|
||||
player.print{ "exp_fast-decon.chat-toggle", state and { "exp_fast-decon.chat-enabled" } or { "exp_fast-decon.chat-disabled" } }
|
||||
end)
|
||||
|
||||
@@ -164,8 +168,7 @@ local function on_entity_damaged(event)
|
||||
end
|
||||
|
||||
-- Mark the entity to be removed
|
||||
local allow = get_player_cache(driver.index)
|
||||
if allow == "fast" and HasEnabledDecon:get(driver) then
|
||||
if get_player_cache(driver.index).permission == "fast" then
|
||||
event.entity.destroy()
|
||||
else
|
||||
event.entity.order_deconstruction(event.force, driver)
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
--[[-- Control - Greetings
|
||||
Greets players when they join, and lets players set a message shown to everyone when they join
|
||||
|
||||
The join messages are kept by the controller, the instance plugin prints them when a player joins
|
||||
]]
|
||||
|
||||
local Commands = require("modules/exp_commands")
|
||||
local Feature = require("modules/exp_scenario/features")
|
||||
local clusterio_api = require("modules/clusterio/api")
|
||||
local community_details = require("modules/exp_scenario/config/community_details").config
|
||||
|
||||
local feature = Feature.register("greetings")
|
||||
|
||||
--- @param event EventData.on_player_joined_game
|
||||
local function on_player_joined_game(event)
|
||||
local player = assert(game.get_player(event.player_index))
|
||||
player.print{ "exp_greetings.greet", community_details.community_name, community_details.discord }
|
||||
end
|
||||
|
||||
--- Set your custom join message, or show it when no message is given
|
||||
Commands.new("set-join-message", { "exp_greetings.description-set" })
|
||||
:optional("message", { "exp_greetings.arg-message" }, Commands.types.string_max_length(255))
|
||||
:enable_auto_concatenation()
|
||||
:add_aliases{ "join-message" }
|
||||
:add_flags{ feature = feature }
|
||||
:register(function(player, message)
|
||||
--- @cast message string?
|
||||
if message then
|
||||
clusterio_api.send_json("exp_scenario:join_message_set", { player_name = player.name, message = message })
|
||||
return Commands.status.success{ "exp_greetings.message-set" }
|
||||
end
|
||||
-- The instance plugin prints the message
|
||||
clusterio_api.send_json("exp_scenario:join_message_get", { player_name = player.name })
|
||||
end)
|
||||
|
||||
--- Removes your custom join message
|
||||
Commands.new("remove-join-message", { "exp_greetings.description-remove" })
|
||||
:add_flags{ feature = feature }
|
||||
:register(function(player)
|
||||
clusterio_api.send_json("exp_scenario:join_message_set", { player_name = player.name })
|
||||
return Commands.status.success{ "exp_greetings.message-cleared" }
|
||||
end)
|
||||
|
||||
local e = defines.events
|
||||
|
||||
return feature:guard{
|
||||
events = {
|
||||
[e.on_player_joined_game] = on_player_joined_game,
|
||||
},
|
||||
}
|
||||
@@ -5,7 +5,7 @@ Adds friendly biters that walk around and give helpful messages
|
||||
local Async = require("modules/exp_util/async")
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
local Feature = require("modules/exp_scenario/features")
|
||||
local config_server_detail = require("modules.exp_legacy.config.server_detail")
|
||||
local community_details = require("modules/exp_scenario/config/community_details").config
|
||||
|
||||
local feature = Feature.register("help_bubbles")
|
||||
|
||||
@@ -16,19 +16,22 @@ local locations = {
|
||||
["Spawn"] = {
|
||||
spawn_position = { x = 0, y = 0 },
|
||||
spawn_surface = "nauvis",
|
||||
entity_name = "behemoth-biter",
|
||||
messages = {
|
||||
{ "info.website", config_server_detail["website"] },
|
||||
{ "info.read-readme" },
|
||||
{ "info.discord", config_server_detail["discord"] },
|
||||
{ "info.softmod" },
|
||||
{ "info.redmew" },
|
||||
{ "info.custom-commands" },
|
||||
{ "info.status", config_server_detail["status"] },
|
||||
{ "info.lhd" },
|
||||
{ "info.github", config_server_detail["github"] },
|
||||
{ "info.patreon", config_server_detail["patreon"] },
|
||||
},
|
||||
entity_name = "small-biter",
|
||||
--- Built each cycle so changes to community_details show without a restart
|
||||
messages = function()
|
||||
return {
|
||||
{ "info.website", community_details.website },
|
||||
{ "info.read-readme" },
|
||||
{ "info.discord", community_details.discord },
|
||||
{ "info.softmod" },
|
||||
{ "info.redmew" },
|
||||
{ "info.custom-commands" },
|
||||
{ "info.status", community_details.status },
|
||||
{ "info.lhd" },
|
||||
{ "info.github", community_details.github },
|
||||
{ "info.patreon", community_details.patreon },
|
||||
}
|
||||
end,
|
||||
}
|
||||
|
||||
}
|
||||
@@ -41,7 +44,8 @@ end)
|
||||
|
||||
--- @class speech_bubble_task_param
|
||||
--- @field entity LuaEntity
|
||||
--- @field messages LocalisedString[]
|
||||
--- @field messages LocalisedString[]?
|
||||
--- @field location string? Used when there are no messages, a key of locations
|
||||
--- @field previous_message LuaEntity?
|
||||
--- @field current_message_index number
|
||||
|
||||
@@ -60,8 +64,9 @@ local speech_bubble_task =
|
||||
return Async.status.complete()
|
||||
end
|
||||
|
||||
local messages = task.messages or locations[task.location].messages()
|
||||
local index = task.current_message_index
|
||||
if index > #task.messages then
|
||||
if index > #messages then
|
||||
index = 1
|
||||
end
|
||||
|
||||
@@ -71,7 +76,7 @@ local speech_bubble_task =
|
||||
end
|
||||
|
||||
speech_bubble_param.source = entity
|
||||
speech_bubble_param.text = task.messages[index]
|
||||
speech_bubble_param.text = messages[index]
|
||||
task.previous_message = entity.surface.create_entity(speech_bubble_param)
|
||||
|
||||
task.current_message_index = index + 1
|
||||
@@ -114,7 +119,11 @@ local function check_persistent_locations()
|
||||
goto continue
|
||||
end
|
||||
|
||||
persistent_locations[name] = register_entity(entity, location.messages)
|
||||
persistent_locations[name] = speech_bubble_task{
|
||||
entity = entity,
|
||||
location = name,
|
||||
current_message_index = 1,
|
||||
}
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
--[[-- Control - Player Settings
|
||||
Sends settings of players to the controller, which keeps them between servers
|
||||
|
||||
The toolbar is sent compressed when a player leaves, the instance plugin
|
||||
calls receive_toolbar with it when they join again
|
||||
]]
|
||||
|
||||
local Gui = require("modules/exp_gui")
|
||||
local clusterio_api = require("modules/clusterio/api")
|
||||
|
||||
--- @param event EventData.on_player_joined_game | EventData.on_player_locale_changed
|
||||
local function send_locale(event)
|
||||
local player = assert(game.get_player(event.player_index))
|
||||
clusterio_api.send_json("exp_scenario:locale", { player_name = player.name, locale = player.locale })
|
||||
end
|
||||
|
||||
--- @param event EventData.on_player_left_game
|
||||
local function send_toolbar(event)
|
||||
local player = assert(game.get_player(event.player_index))
|
||||
local success, state = pcall(Gui.toolbar.get_state, player)
|
||||
if not success then
|
||||
log("[WARNING] Could not read the toolbar of " .. player.name .. ": " .. tostring(state))
|
||||
return
|
||||
end
|
||||
local toolbar = helpers.encode_string(helpers.table_to_json(state))
|
||||
clusterio_api.send_json("exp_scenario:toolbar", { player_name = player.name, toolbar = toolbar })
|
||||
end
|
||||
|
||||
--- @param toolbar string
|
||||
--- @return Gui.ToolbarState?
|
||||
local function decode_toolbar(toolbar)
|
||||
local json = helpers.decode_string(toolbar)
|
||||
local state = json and helpers.json_to_table(json)
|
||||
if type(state) == "table" and type(state.order) == "table" and type(state.open) == "table"
|
||||
and type(state.visible) == "boolean" then
|
||||
return state --[[@as Gui.ToolbarState]]
|
||||
end
|
||||
end
|
||||
|
||||
--- Restore the toolbar of a player, called over rcon by the instance plugin
|
||||
--- @param player_name string
|
||||
--- @param toolbar string From send_toolbar
|
||||
local function receive_toolbar(player_name, toolbar)
|
||||
local player = game.get_player(player_name)
|
||||
if not player or not player.connected then
|
||||
return
|
||||
end
|
||||
|
||||
-- Stored states can name buttons which no longer exist
|
||||
local success, err = pcall(function()
|
||||
local state = assert(decode_toolbar(toolbar), "invalid toolbar state")
|
||||
Gui.toolbar.set_state(player, state)
|
||||
end)
|
||||
if not success then
|
||||
log("[WARNING] Could not restore the toolbar of " .. player_name .. ": " .. tostring(err))
|
||||
end
|
||||
end
|
||||
|
||||
local e = defines.events
|
||||
|
||||
return {
|
||||
events = {
|
||||
[e.on_player_joined_game] = send_locale,
|
||||
[e.on_player_locale_changed] = send_locale,
|
||||
[e.on_player_left_game] = send_toolbar,
|
||||
},
|
||||
receive_toolbar = receive_toolbar,
|
||||
}
|
||||
@@ -3,4 +3,5 @@
|
||||
-- Access using `/sc exp_scenario.features.foo()`
|
||||
exp_scenario = {
|
||||
features = require("modules/exp_scenario/features"),
|
||||
player_settings = require("modules/exp_scenario/control/player_settings"),
|
||||
}
|
||||
@@ -7,8 +7,8 @@ local Gui = require("modules/exp_gui")
|
||||
local Roles = require("modules/exp_roles")
|
||||
local Commands = require("modules/exp_commands")
|
||||
local PlayerData = require("modules.exp_legacy.expcore.player_data")
|
||||
local External = require("modules.exp_legacy.expcore.external")
|
||||
local config_server_detail = require("modules.exp_legacy.config.server_detail") --- @dep config.server_detail
|
||||
local ExpServerList = require("modules/exp_server_list")
|
||||
local community = require("modules/exp_scenario/config/community_details").config
|
||||
|
||||
local format_number = require("util").format_number
|
||||
local format_time = ExpUtil.format_time_factory_locale{ format = "long", days = true, hours = true, minutes = true }
|
||||
@@ -16,16 +16,33 @@ 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 = {}
|
||||
|
||||
--- @type table<number, { caption: LocalisedString, tooltip: LocalisedString, element: ExpElement }>
|
||||
--- @type table<number, { caption: LocalisedString, tooltip: LocalisedString | (fun(): LocalisedString), element: ExpElement }>
|
||||
local tabs = {}
|
||||
|
||||
--- Register a readme tab
|
||||
--- @param caption LocalisedString
|
||||
--- @param tooltip LocalisedString
|
||||
--- @param tooltip LocalisedString | fun(): LocalisedString Functions are called when the readme opens
|
||||
--- @param element ExpElement
|
||||
local function define_tab(caption, tooltip, element)
|
||||
tabs[#tabs + 1] = { caption = caption, tooltip = tooltip, element = element }
|
||||
@@ -84,16 +101,17 @@ Elements.sub_content = Gui.define("readme/sub_content")
|
||||
} --[[@as any]]
|
||||
|
||||
--- @class ExpGui_Readme.elements.join_server.elements
|
||||
--- @field server_id string
|
||||
--- @field server_id number
|
||||
|
||||
--- Join server button
|
||||
--- @class ExpGui_Readme.elements.join_server: ExpElement
|
||||
--- @field data table<LuaGuiElement, ExpGui_Readme.elements.join_server.elements>
|
||||
--- @overload fun(parent: LuaGuiElement, server_id: string, wrong_version: string?): LuaGuiElement
|
||||
--- @overload fun(parent: LuaGuiElement, server: ExpServerList.Server): LuaGuiElement
|
||||
Elements.join_server = Gui.define("readme/join_server")
|
||||
:track_all_elements()
|
||||
:draw(function(def, parent, server_id, wrong_version)
|
||||
:draw(function(def, parent, server)
|
||||
--- @cast def ExpGui_Readme.elements.join_server
|
||||
--- @cast server ExpServerList.Server
|
||||
local flow = parent.add{
|
||||
type = "flow",
|
||||
}
|
||||
@@ -106,10 +124,10 @@ Elements.join_server = Gui.define("readme/join_server")
|
||||
}
|
||||
|
||||
def.data[button] = {
|
||||
server_id = server_id,
|
||||
server_id = server.id,
|
||||
}
|
||||
|
||||
Elements.join_server.refresh(button, wrong_version)
|
||||
Elements.join_server.refresh(button, server)
|
||||
return button
|
||||
end)
|
||||
:style{
|
||||
@@ -118,22 +136,33 @@ Elements.join_server = Gui.define("readme/join_server")
|
||||
}
|
||||
:on_click(function(def, player, button)
|
||||
--- @cast def ExpGui_Readme.elements.join_server
|
||||
local server_id = def.data[button].server_id
|
||||
External.request_connection(player, server_id, true)
|
||||
local server = ExpServerList.get_server(def.data[button].server_id)
|
||||
if server and ExpServerList.is_online(server) then
|
||||
ExpServerList.request_connection(player, server, true)
|
||||
end
|
||||
end) --[[@as any]]
|
||||
|
||||
--- Refresh join server button
|
||||
--- @param button LuaGuiElement
|
||||
--- @param wrong_version string?
|
||||
function Elements.join_server.refresh(button, wrong_version)
|
||||
local server_id = Elements.join_server.data[button].server_id
|
||||
local status = External.get_server_status(server_id) or "Offline"
|
||||
|
||||
if wrong_version then
|
||||
status = "Version"
|
||||
--- @param server ExpServerList.Server?
|
||||
function Elements.join_server.refresh(button, server)
|
||||
local current = ExpServerList.get_current()
|
||||
local status, detail = "Online", nil
|
||||
if not server or not ExpServerList.is_online(server) then
|
||||
status = "Offline"
|
||||
elseif current and server.id == current.id then
|
||||
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
|
||||
|
||||
button.tooltip = { "exp-gui_readme.servers-connect-" .. status, wrong_version }
|
||||
-- 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 or "", player_count }
|
||||
|
||||
if status == "Offline" or status == "Current" then
|
||||
button.enabled = false
|
||||
@@ -162,40 +191,35 @@ function Elements.join_server.refresh(button, wrong_version)
|
||||
end
|
||||
end
|
||||
|
||||
--- Refresh all online join buttons
|
||||
--- Refresh all join buttons
|
||||
function Elements.join_server.refresh_all()
|
||||
if not External.valid() then
|
||||
return
|
||||
end
|
||||
|
||||
local current_version = External.get_current_server().version
|
||||
|
||||
for _, button in Elements.join_server:tracked_elements() do
|
||||
local server_id = Elements.join_server.data[button].server_id
|
||||
local server = External.get_servers()[server_id]
|
||||
|
||||
if server then
|
||||
Elements.join_server.refresh(button, current_version ~= server.version and server.version or nil)
|
||||
end
|
||||
Elements.join_server.refresh(button, ExpServerList.get_server(server_id))
|
||||
end
|
||||
end
|
||||
|
||||
--- Welcome tab
|
||||
define_tab(
|
||||
{ "exp-gui_readme.welcome-tab" },
|
||||
{ "exp-gui_readme.welcome-tooltip", config_server_detail["community_name"] },
|
||||
function() return { "exp-gui_readme.welcome-tooltip", community.community_name } end,
|
||||
Gui.define("readme/welcome")
|
||||
:draw(function(_, parent)
|
||||
local player = Gui.get_player(parent)
|
||||
|
||||
local server_details = {
|
||||
name = config_server_detail["community_name"] .. " S0 - Local",
|
||||
welcome = "Failed to load description: disconnected from external api.",
|
||||
name = community.community_name .. " S0 - Local",
|
||||
welcome = "Failed to load description: disconnected from the controller.",
|
||||
reset_time = "Not Set",
|
||||
}
|
||||
|
||||
if External.valid() then
|
||||
server_details = External.get_current_server()
|
||||
local current = ExpServerList.get_current()
|
||||
if current then
|
||||
server_details = {
|
||||
name = current.name,
|
||||
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
|
||||
|
||||
local container = parent.add{ type = "flow", direction = "vertical" }
|
||||
@@ -206,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" }
|
||||
@@ -224,7 +248,7 @@ define_tab(
|
||||
frame_width,
|
||||
{
|
||||
"exp-gui_readme.welcome-general",
|
||||
config_server_detail["community_name"],
|
||||
community.community_name,
|
||||
format_time(game.tick),
|
||||
server_details.reset_time,
|
||||
}
|
||||
@@ -317,28 +341,19 @@ define_tab(
|
||||
local scroll_pane = Elements.title_table_scroll(container)
|
||||
scroll_pane.style.maximal_height = scroll_height + 20
|
||||
|
||||
if External.valid() then
|
||||
local current_version = External.get_current_server().version
|
||||
|
||||
local factorio_servers = Elements.title_table(scroll_pane, 225, { "exp-gui_readme.servers-factorio" }, 3)
|
||||
|
||||
for server_id, server in pairs(External.get_servers()) do
|
||||
Gui.elements.centered_label(factorio_servers, 110, server.short_name)
|
||||
Gui.elements.centered_label(factorio_servers, 436, server.description)
|
||||
Elements.join_server(factorio_servers, server_id, current_version ~= server.version and server.version or nil)
|
||||
end
|
||||
else
|
||||
local factorio_servers = Elements.title_table(scroll_pane, 225, { "exp-gui_readme.servers-factorio" }, 2)
|
||||
for i = 1, 8 do
|
||||
Gui.elements.centered_label(factorio_servers, 110, { "exp-gui_readme.servers-" .. i })
|
||||
Gui.elements.centered_label(factorio_servers, 460, { "exp-gui_readme.servers-d" .. i })
|
||||
end
|
||||
local factorio_servers = Elements.title_table(scroll_pane, 225, { "exp-gui_readme.servers-factorio" }, 3)
|
||||
for _, server in ipairs(ExpServerList.get_servers()) do
|
||||
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
|
||||
|
||||
local external_links = Elements.title_table(scroll_pane, 235, { "exp-gui_readme.servers-external" }, 2)
|
||||
for _, key in ipairs{ "discord", "website", "patreon", "status", "github" } do
|
||||
Gui.elements.centered_label(external_links, 110, key:gsub("^%l", string.upper))
|
||||
Gui.elements.centered_label(external_links, 460, config_server_detail[key], { "exp-gui_readme.servers-open-in-browser" })
|
||||
Gui.elements.centered_label(external_links, 460, community[key], { "exp-gui_readme.servers-open-in-browser" })
|
||||
end
|
||||
|
||||
return container
|
||||
@@ -636,11 +651,16 @@ Elements.container = Gui.define("readme/container")
|
||||
}
|
||||
|
||||
for _, tab in ipairs(tabs) do
|
||||
local tooltip = tab.tooltip
|
||||
if type(tooltip) == "function" then
|
||||
tooltip = tooltip()
|
||||
end
|
||||
|
||||
local gui_tab = pane.add{
|
||||
type = "tab",
|
||||
style = "frame_tab",
|
||||
caption = tab.caption,
|
||||
tooltip = tab.tooltip,
|
||||
tooltip = tooltip,
|
||||
}
|
||||
|
||||
pane.add_tab(gui_tab, tab.element(pane))
|
||||
@@ -707,8 +727,6 @@ return {
|
||||
[e.on_player_created] = open_readme,
|
||||
[e.on_player_joined_game] = clear_readme,
|
||||
[e.on_player_respawned] = clear_readme,
|
||||
[ExpServerList.on_servers_updated] = Elements.join_server.refresh_all,
|
||||
},
|
||||
on_nth_tick = {
|
||||
[60 * 60] = Elements.join_server.refresh_all,
|
||||
}
|
||||
}
|
||||
@@ -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__"
|
||||
@@ -350,28 +351,12 @@ servers-general=This is only one of our Factorio servers, we host many others as
|
||||
servers-factorio=Factorio Servers
|
||||
servers-external=External Links
|
||||
servers-open-in-browser=Open in your browser
|
||||
servers-1=S1 Public
|
||||
servers-d1=This is our 48 hour reset server.
|
||||
servers-2=S2 Off
|
||||
servers-d2=This server is closed.
|
||||
servers-3=S3 Weekly
|
||||
servers-d3=This is our weekly reset server.
|
||||
servers-4=S4 Monthly
|
||||
servers-d4=This is our monthly reset server.
|
||||
servers-5=S5 Modded
|
||||
servers-d5=This is our modded server, see Discord for details.
|
||||
servers-6=S6 Donator
|
||||
servers-d6=This is our donator only server, online when requested.
|
||||
servers-7=S7 Event
|
||||
servers-d7=This is our event server, we try to run events at least once per week.
|
||||
servers-8=S8 T̷-̶s̶-̴:̷
|
||||
servers-d8=N̵o̴ ̶o̷-̶e̵ ̴k̸n̷-̶w̵s̸ ̴w̷h̷a̶-̶ ̷h̴a̴p̷p̴e̷n̷s̸ ̷o̶n̴ ̷t̶h̴-̶s̶ ̷s̷e̶r̸v̸e̴r̷,̶ ̸i̸t̴ ̷m̶-̸g̴h̶t̷ ̸n̸-̶t̵ ̷e̴v̸e̸n̶t̷ ̵-̷x̴i̵s̶t̸.̸
|
||||
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
|
||||
servers-connect-Modded=Server requires mods to be downloaded
|
||||
servers-connect-Online=Server is online
|
||||
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
|
||||
backers-tooltip=People who have helped make our server
|
||||
backers-general=We would like to thank all our staff and backers who have helped our community grow. Our staff have helped to keep our servers safe from trolls and a fun place to play. Our backers have helped us to cover our running costs and provide a great community for us all to enjoy together.
|
||||
@@ -601,6 +586,16 @@ chat-enabled=enabled
|
||||
chat-disabled=disabled
|
||||
chat-toggle=Fast decon has been __1__
|
||||
|
||||
[exp_greetings]
|
||||
description-set=Sets / Gets your custom join message.
|
||||
description-remove=Removes you custom join message.
|
||||
arg-message=Your custom join message.
|
||||
greet=[color=0,1,0] Welcome to __1__ community server! If you like the server join our discord: __2__ [/color]
|
||||
message-set=Your join message has been updated.
|
||||
message-get=Your join message is: __1__
|
||||
message-cleared=Your join message has been cleared.
|
||||
message-none=You have not set a join message.
|
||||
|
||||
[exp_nuke-protection]
|
||||
chat-found=You cannot have __1__ in your inventory, so it was placed into the chests at spawn.
|
||||
|
||||
|
||||
@@ -339,22 +339,6 @@ servers-tab=伺服器
|
||||
servers-tooltip=到其他伺服器及網站的連結
|
||||
servers-general=這是其中一個伺服器。你可以在下方找到其他同樣是由我們運行的伺服器資料。
|
||||
servers-factorio=異星工廠伺服器
|
||||
servers-1=S1 公共
|
||||
servers-d1=這個服務器每兩日重設。
|
||||
servers-2=S2 -
|
||||
servers-d2=這個服務器沒在營運。
|
||||
servers-3=S3 周
|
||||
servers-d3=這個服務器每週重設。
|
||||
servers-4=S4 月
|
||||
servers-d4=這個服務器每月重設。
|
||||
servers-5=S5 模組
|
||||
servers-d5=這個服務器運行模組,可在 Discord 中得到更多資訊。
|
||||
servers-6=S6 Donator
|
||||
servers-d6=這個服務器為支持者運行,可在 Discord 中得到更多資訊。
|
||||
servers-7=S7 項目
|
||||
servers-d7=這個服務器只在有項目期間運行。
|
||||
servers-8=S8 T̷-̶s̶-̴:̷
|
||||
servers-d8=N̵o̴ ̶o̷-̶e̵ ̴k̸n̷-̶w̵s̸ ̴w̷h̷a̶-̶ ̷h̴a̴p̷p̴e̷n̷s̸ ̷o̶n̴ ̷t̶h̴-̶s̶ ̷s̷e̶r̸v̸e̴r̷,̶ ̸i̸t̴ ̷m̶-̸g̴h̶t̷ ̸n̸-̶t̵ ̷e̴v̸e̸n̶t̷ ̵-̷x̴i̵s̶t̸。̸
|
||||
servers-connect-Offline=該服務器目前沒有在運行
|
||||
servers-connect-Current=你目前所在的伺服器
|
||||
servers-connect-Version=該服務器運行不同的遊戲版本: __1__
|
||||
@@ -594,6 +578,16 @@ chat-enabled=啟用
|
||||
chat-disabled=停用
|
||||
chat-toggle=樹木快速拆除已 __1__
|
||||
|
||||
[exp_greetings]
|
||||
description-set=設定 / 取得你的加入信息。
|
||||
description-remove=移除你的加入信息。
|
||||
arg-message=你的加入信息。
|
||||
greet=[color=0,1,0] 歡迎來到 __1__ 的服務器! 若果你喜歡本服務器可加入 Discord: __2__ [/color]
|
||||
message-set=你的加入信息已更新。
|
||||
message-get=你的加入信息為: __1__
|
||||
message-cleared=你的加入信息已清除。
|
||||
message-none=你沒有設定加入信息。
|
||||
|
||||
[exp_nuke-protection]
|
||||
chat-found=你的用戶組不允許你有 __1__ ,所以該物品已放在出生點的箱子。
|
||||
|
||||
|
||||
@@ -339,22 +339,6 @@ servers-tab=伺服器
|
||||
servers-tooltip=到其他伺服器及網站的連結
|
||||
servers-general=這是其中一個伺服器。你可以在下方找到其他同樣是由我們運行的伺服器資料。
|
||||
servers-factorio=異星工廠伺服器
|
||||
servers-1=S1 公共
|
||||
servers-d1=這個服務器每兩日重設。
|
||||
servers-2=S2 -
|
||||
servers-d2=這個服務器沒在營運。
|
||||
servers-3=S3 周
|
||||
servers-d3=這個服務器每週重設。
|
||||
servers-4=S4 月
|
||||
servers-d4=這個服務器每月重設。
|
||||
servers-5=S5 模組
|
||||
servers-d5=這個服務器運行模組,可在 Discord 中得到更多資訊。
|
||||
servers-6=S6 Donator
|
||||
servers-d6=這個服務器為支持者運行,可在 Discord 中得到更多資訊。
|
||||
servers-7=S7 項目
|
||||
servers-d7=這個服務器只在有項目期間運行。
|
||||
servers-8=S8 T̷-̶s̶-̴:̷
|
||||
servers-d8=N̵o̴ ̶o̷-̶e̵ ̴k̸n̷-̶w̵s̸ ̴w̷h̷a̶-̶ ̷h̴a̴p̷p̴e̷n̷s̸ ̷o̶n̴ ̷t̶h̴-̶s̶ ̷s̷e̶r̸v̸e̴r̷,̶ ̸i̸t̴ ̷m̶-̸g̴h̶t̷ ̸n̸-̶t̵ ̷e̴v̸e̸n̶t̷ ̵-̷x̴i̵s̶t̸。̸
|
||||
servers-connect-Offline=該服務器目前沒有在運行
|
||||
servers-connect-Current=你目前所在的伺服器
|
||||
servers-connect-Version=該服務器運行不同的遊戲版本: __1__
|
||||
@@ -594,6 +578,16 @@ chat-enabled=啟用
|
||||
chat-disabled=停用
|
||||
chat-toggle=樹木快速拆除已 __1__
|
||||
|
||||
[exp_greetings]
|
||||
description-set=設定 / 取得你的加入信息。
|
||||
description-remove=移除你的加入信息。
|
||||
arg-message=你的加入信息。
|
||||
greet=[color=0,1,0] 歡迎來到 __1__ 的服務器! 若果你喜歡本服務器可加入 Discord: __2__ [/color]
|
||||
message-set=你的加入信息已更新。
|
||||
message-get=你的加入信息為: __1__
|
||||
message-cleared=你的加入信息已清除。
|
||||
message-none=你沒有設定加入信息。
|
||||
|
||||
[exp_nuke-protection]
|
||||
chat-found=你的用戶組不允許你有 __1__ ,所以該物品已放在出生點的箱子。
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"exp_util": "*",
|
||||
"exp_roles": "*",
|
||||
"exp_reports": "*",
|
||||
"exp_server_list": "*",
|
||||
"exp_gui": "*",
|
||||
"exp_commands": "*"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user