mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Refactor legacy addons into Clusterio format (#413)
* Refactor custom start * Refactor afk kick * Fix use of assert get player * Refactor chat popup * Refactor chat auto reply * Refactor help bubbles * Refactor damage popups * Refactor death markers * Refactor deconstruction log * Remove FAGC logging * Refactor discord alerts * Refactor insert pickup * Refactor inventory clear * Refactor extra logging * Refactor nuke protection * Refactor pollution grading * Refactor protection jail * Refactor report jail * Refactor mine depletion * Refactor degrading tiles * Refactor station auto name * Refactor spawn area * Refactor fast deconstruction * Bug Fixes
This commit is contained in:
48
exp_scenario/module/control/chat_popup.lua
Normal file
48
exp_scenario/module/control/chat_popup.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
--[[-- Control - Chat Popup
|
||||
Creates flying text entities when a player sends a message in chat
|
||||
]]
|
||||
|
||||
local FlyingText = require("modules/exp_util/flying_text")
|
||||
local config = require("modules.exp_legacy.config.popup_messages")
|
||||
|
||||
local lower = string.lower
|
||||
local find = string.find
|
||||
|
||||
--- Create a chat bubble when a player types a message
|
||||
--- @param event EventData.on_console_chat
|
||||
local function on_console_chat(event)
|
||||
if not event.player_index then return end
|
||||
local player = assert(game.get_player(event.player_index))
|
||||
local name = player.name
|
||||
|
||||
-- Sends the message as text above them
|
||||
if config.show_player_messages then
|
||||
FlyingText.create_as_player{
|
||||
target_player = player,
|
||||
text = { "exp_chat-popup.flying-text-message", name, event.message },
|
||||
}
|
||||
end
|
||||
|
||||
if not config.show_player_mentions then return end
|
||||
|
||||
-- Loops over online players to see if they name is included
|
||||
local search_string = lower(event.message)
|
||||
for _, mentioned_player in ipairs(game.connected_players) do
|
||||
if mentioned_player.index ~= player.index then
|
||||
if find(search_string, lower(mentioned_player.name), 1, true) then
|
||||
FlyingText.create_as_player{
|
||||
target_player = mentioned_player,
|
||||
text = { "exp_chat-popup.flying-text-ping", name },
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local e = defines.events
|
||||
|
||||
return {
|
||||
events = {
|
||||
[e.on_console_chat] = on_console_chat,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user