Merge branch 'main' into aperx

This commit is contained in:
phidias committed 2026-10-15 17:32:53 +09:00
commit 02a5b69616
115 files changed
+5014 -1456

No files matched your search

@@ -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)
+50
View File
@@ -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,
},
}
+27 -18
View File
@@ -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,
}