mirror of
https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git
synced 2024-12-04 09:43:00 +02:00
Add Better Chatting compatibility (#252)
* Add CompatSend * Replace all other prints with CompatSend I used the regex `(\w+)\.print\(` and replaced it with `CompatSend($1, ` Was really easy.
This commit is contained in:
parent
1e1f3364ef
commit
e18bd34d52
@ -102,7 +102,7 @@ function OarcItemShopGuiClick(event)
|
||||
button.parent.parent.player_store_wallet_lbl.caption = { "oarc-coins-available", wallet }
|
||||
end
|
||||
else
|
||||
player.print({ "oarc-broke-message" })
|
||||
CompatSend(player, { "oarc-broke-message" })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -148,7 +148,7 @@ function PlayerListTabGuiClick(event)
|
||||
local target_player = game.players[player_name]
|
||||
|
||||
if (target_player == nil) then
|
||||
player.print({"oarc-player-not-found", player_name})
|
||||
CompatSend(player, {"oarc-player-not-found", player_name})
|
||||
return
|
||||
end
|
||||
|
||||
@ -161,6 +161,6 @@ function PlayerListTabGuiClick(event)
|
||||
surface = target_player.surface
|
||||
end
|
||||
player.set_controller{type = defines.controllers.remote, position = position, surface = surface}
|
||||
player.print({"", target_player.name, ": ", GetGPStext(surface.name, position)})
|
||||
CompatSend(player, {"", target_player.name, ": ", GetGPStext(surface.name, position)})
|
||||
end
|
||||
end
|
@ -590,13 +590,13 @@ function SettingsSurfaceControlsTabGuiClick(event)
|
||||
local ok, copy = serpent.load(import_text)
|
||||
if (not ok) or (type(copy) ~= "table") or (next(copy) == nil) then
|
||||
log("Error importing settings!")
|
||||
player.print("Error importing settings!")
|
||||
CompatSend(player, "Error importing settings!")
|
||||
else
|
||||
storage.ocfg = table.deepcopy(copy)
|
||||
ValidateSettings() -- Some basic validation, not 100% foolproof
|
||||
SyncModSettingsToOCFG() -- Sync the mod settings.
|
||||
log("Imported settings!")
|
||||
player.print("Imported settings!")
|
||||
CompatSend(player, "Imported settings!")
|
||||
OarcGuiRefreshContent(player)
|
||||
end
|
||||
end
|
||||
|
@ -408,26 +408,26 @@ function SpawnCtrlTabGuiClick(event)
|
||||
|
||||
-- Check if player has a valid character
|
||||
if (player.character == nil) then
|
||||
player.print({ "oarc-no-valid-player-character" })
|
||||
CompatSend(player, { "oarc-no-valid-player-character" })
|
||||
return
|
||||
end
|
||||
|
||||
-- Check if player is in a vehicle
|
||||
if player.driving then
|
||||
player.print({ "oarc-player-character-in-vehicle" })
|
||||
CompatSend(player, { "oarc-player-character-in-vehicle" })
|
||||
return
|
||||
end
|
||||
|
||||
-- Check if the surface is blacklisted
|
||||
local surface_name = player.character.surface.name
|
||||
if IsSurfaceBlacklisted(surface_name) then
|
||||
player.print({"oarc-no-respawn-this-surface"})
|
||||
CompatSend(player, {"oarc-no-respawn-this-surface"})
|
||||
return
|
||||
end
|
||||
|
||||
SetPlayerRespawn(player.name, surface_name, player.character.position, true)
|
||||
OarcGuiRefreshContent(player)
|
||||
player.print({ "oarc-spawn-point-updated" })
|
||||
CompatSend(player, { "oarc-spawn-point-updated" })
|
||||
|
||||
-- Shows the spawn location on the map
|
||||
elseif (tags.setting == "show_location") then
|
||||
@ -435,7 +435,7 @@ function SpawnCtrlTabGuiClick(event)
|
||||
local position = tags.position --[[@as MapPosition]]
|
||||
|
||||
player.set_controller{type = defines.controllers.remote, position = position, surface = surface_name}
|
||||
player.print({"", { "oarc-spawn-gps-location" }, " ", GetGPStext(surface_name, position)})
|
||||
CompatSend(player, {"", { "oarc-spawn-gps-location" }, " ", GetGPStext(surface_name, position)})
|
||||
|
||||
-- Teleports the player to their home base
|
||||
elseif (tags.setting == "teleport_home") then
|
||||
@ -444,13 +444,13 @@ function SpawnCtrlTabGuiClick(event)
|
||||
|
||||
-- Check if player has a valid character
|
||||
if (player.character == nil) then
|
||||
player.print({ "oarc-no-valid-player-character" })
|
||||
CompatSend(player, { "oarc-no-valid-player-character" })
|
||||
return
|
||||
end
|
||||
|
||||
-- Check if player is in a vehicle
|
||||
if player.driving then
|
||||
player.print({ "oarc-player-character-in-vehicle" })
|
||||
CompatSend(player, { "oarc-player-character-in-vehicle" })
|
||||
return
|
||||
end
|
||||
|
||||
@ -478,7 +478,7 @@ function SpawnCtrlTabGuiClick(event)
|
||||
|
||||
if ((event.element.parent.join_queue_dropdown == nil) or
|
||||
(event.element.parent.join_queue_dropdown.selected_index == 0)) then
|
||||
player.print({ "oarc-selected-player-not-valid" })
|
||||
CompatSend(player, { "oarc-selected-player-not-valid" })
|
||||
OarcGuiRefreshContent(player)
|
||||
return
|
||||
end
|
||||
@ -488,7 +488,7 @@ function SpawnCtrlTabGuiClick(event)
|
||||
|
||||
-- Shouldn't be able to hit this since we force a GUI refresh when they leave?
|
||||
if ((game.players[join_queue_player_choice] == nil) or (not game.players[join_queue_player_choice].connected)) then
|
||||
player.print({ "oarc-selected-player-not-wait" })
|
||||
CompatSend(player, { "oarc-selected-player-not-wait" })
|
||||
OarcGuiRefreshContent(player)
|
||||
return
|
||||
end
|
||||
@ -500,7 +500,7 @@ function SpawnCtrlTabGuiClick(event)
|
||||
RemovePlayerFromJoinQueue(join_queue_player_choice) -- This also refreshes the host gui
|
||||
|
||||
-- Inform the host that the player was rejected
|
||||
player.print({ "oarc-reject-joiner", join_queue_player_choice })
|
||||
CompatSend(player, { "oarc-reject-joiner", join_queue_player_choice })
|
||||
-- Inform the player that their request was rejected
|
||||
SendMsg(join_queue_player_choice, { "oarc-your-request-rejected" })
|
||||
|
||||
@ -514,7 +514,7 @@ function SpawnCtrlTabGuiClick(event)
|
||||
|
||||
-- Check if there is space first
|
||||
if (table_size(primary_spawn.joiners) >= storage.ocfg.gameplay.number_of_players_per_shared_spawn - 1) then
|
||||
player.print({ "oarc-shared-spawn-full" })
|
||||
CompatSend(player, { "oarc-shared-spawn-full" })
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -733,7 +733,7 @@ function SurfaceConfigTabGuiConfirmed(event)
|
||||
|
||||
-- Check if an item is selected first.
|
||||
if (tags.item_name == "") then
|
||||
player.print("Please select an item first!")
|
||||
CompatSend(player, "Please select an item first!")
|
||||
event.element.text = "0"
|
||||
return
|
||||
end
|
||||
@ -754,7 +754,7 @@ function SurfaceConfigTabGuiConfirmed(event)
|
||||
|
||||
-- Check if an item is selected first.
|
||||
if (tags.resource_name == "") then
|
||||
player.print("Please select a resource first!")
|
||||
CompatSend(player, "Please select a resource first!")
|
||||
event.element.text = "0"
|
||||
return
|
||||
end
|
||||
@ -780,7 +780,7 @@ function SurfaceConfigTabGuiConfirmed(event)
|
||||
|
||||
-- Check if an item is selected first.
|
||||
if (tags.resource_name == "") then
|
||||
player.print("Please select a resource first!")
|
||||
CompatSend(player, "Please select a resource first!")
|
||||
event.element.text = "0"
|
||||
return
|
||||
end
|
||||
@ -844,7 +844,7 @@ function SurfaceConfigTabGuiElemChanged(event)
|
||||
local setting_name = parent.tags.setting --[[@as string]]
|
||||
|
||||
if (storage.ocfg.surfaces_config[surface_name].starting_items[setting_name][new_item_name]) then
|
||||
player.print("Item already exists in list! " .. new_item_name)
|
||||
CompatSend(player, "Item already exists in list! " .. new_item_name)
|
||||
event.element.elem_value = nil
|
||||
return
|
||||
end
|
||||
@ -874,7 +874,7 @@ function SurfaceConfigTabGuiElemChanged(event)
|
||||
end
|
||||
|
||||
if (prototypes.entity[new_resource_name].resource_category ~= "basic-solid") then
|
||||
player.print("Resource must be a solid resource! " .. new_resource_name)
|
||||
CompatSend(player, "Resource must be a solid resource! " .. new_resource_name)
|
||||
event.element.elem_value = nil
|
||||
return
|
||||
end
|
||||
@ -892,7 +892,7 @@ function SurfaceConfigTabGuiElemChanged(event)
|
||||
local setting_name = parent.tags.setting --[[@as string]]
|
||||
|
||||
if (storage.ocfg.surfaces_config[surface_name].spawn_config[setting_name][new_resource_name]) then
|
||||
player.print("Resource already exists in list! " .. new_resource_name)
|
||||
CompatSend(player, "Resource already exists in list! " .. new_resource_name)
|
||||
event.element.elem_value = nil
|
||||
return
|
||||
end
|
||||
@ -922,7 +922,7 @@ function SurfaceConfigTabGuiElemChanged(event)
|
||||
end
|
||||
|
||||
if (prototypes.entity[new_resource_name].resource_category ~= "basic-fluid") then
|
||||
player.print("Resource must be a fluid resource! " .. new_resource_name)
|
||||
CompatSend(player, "Resource must be a fluid resource! " .. new_resource_name)
|
||||
event.element.elem_value = nil
|
||||
return
|
||||
end
|
||||
@ -940,7 +940,7 @@ function SurfaceConfigTabGuiElemChanged(event)
|
||||
local setting_name = parent.tags.setting --[[@as string]]
|
||||
|
||||
if (storage.ocfg.surfaces_config[surface_name].spawn_config[setting_name][new_resource_name]) then
|
||||
player.print("Resource already exists in list! " .. new_resource_name)
|
||||
CompatSend(player, "Resource already exists in list! " .. new_resource_name)
|
||||
event.element.elem_value = nil
|
||||
return
|
||||
end
|
||||
@ -1030,7 +1030,7 @@ function SurfaceConfigTabGuiClick(event)
|
||||
|
||||
local surface_name = event.element.parent["surface_dropdown"].items[event.element.parent["surface_dropdown"].selected_index] --[[@as string]]
|
||||
|
||||
player.print("Revert to default: " .. surface_name)
|
||||
CompatSend(player, "Revert to default: " .. surface_name)
|
||||
storage.ocfg.surfaces_config[surface_name].starting_items = table.deepcopy(NAUVIS_STARTER_ITEMS)
|
||||
storage.ocfg.surfaces_config[surface_name].spawn_config = table.deepcopy(NAUVIS_SPAWN_CONFIG)
|
||||
|
||||
@ -1047,11 +1047,11 @@ function SurfaceConfigTabGuiClick(event)
|
||||
local surface_name = event.element.parent["surface_dropdown"].items[event.element.parent["surface_dropdown"].selected_index] --[[@as string]]
|
||||
|
||||
if (surface_name == "nauvis") then
|
||||
player.print("Already on nauvis, select a different surface to copy nauvis settings to!")
|
||||
CompatSend(player, "Already on nauvis, select a different surface to copy nauvis settings to!")
|
||||
return
|
||||
end
|
||||
|
||||
player.print("Copy nauvis to " .. surface_name)
|
||||
CompatSend(player, "Copy nauvis to " .. surface_name)
|
||||
storage.ocfg.surfaces_config[surface_name].starting_items = storage.ocfg.surfaces_config["nauvis"].starting_items
|
||||
storage.ocfg.surfaces_config[surface_name].spawn_config = storage.ocfg.surfaces_config["nauvis"].spawn_config
|
||||
|
||||
|
@ -210,7 +210,7 @@ end
|
||||
function DudeWheresMyCargoPod(player)
|
||||
|
||||
if not player.character then
|
||||
player.print({ "oarc-character-invalid" })
|
||||
CompatSend(player, { "oarc-character-invalid" })
|
||||
return
|
||||
end
|
||||
|
||||
@ -221,7 +221,7 @@ function DudeWheresMyCargoPod(player)
|
||||
local pods = surface.find_entities_filtered{area=search_area, name="cargo-pod-container", force=player.force}
|
||||
|
||||
if #pods == 0 then
|
||||
player.print({ "oarc-no-cargo-pods" })
|
||||
CompatSend(player, { "oarc-no-cargo-pods" })
|
||||
return
|
||||
end
|
||||
|
||||
@ -230,12 +230,12 @@ function DudeWheresMyCargoPod(player)
|
||||
local new_position = surface.find_non_colliding_position("cargo-pod-container", player.character.position, CHUNK_SIZE, 1)
|
||||
|
||||
if new_position == nil then
|
||||
player.print({ "oarc-teleport-cargo-pod-fail" })
|
||||
CompatSend(player, { "oarc-teleport-cargo-pod-fail" })
|
||||
return
|
||||
end
|
||||
|
||||
cargo_pod.teleport(new_position)
|
||||
player.print({ "oarc-teleport-cargo-pod-success" })
|
||||
CompatSend(player, { "oarc-teleport-cargo-pod-success" })
|
||||
end
|
||||
end
|
||||
|
||||
@ -261,7 +261,7 @@ function RerollSpawn(player)
|
||||
|
||||
-- If it is a buddy spawn, tell them we don't support this:
|
||||
if (spawn_choices.buddy ~= nil) then
|
||||
player.print({ "oarc-no-reroll-buddy-spawn" })
|
||||
CompatSend(player, { "oarc-no-reroll-buddy-spawn" })
|
||||
return
|
||||
end
|
||||
|
||||
@ -281,7 +281,7 @@ function RerollSpawn(player)
|
||||
local spawn_position = FindUngeneratedCoordinates(surface_name, spawn_choices.distance, 3)
|
||||
-- If that fails, just throw a warning and don't spawn them. They can try again.
|
||||
if ((spawn_position.x == 0) and (spawn_position.y == 0)) then
|
||||
player.print({ "oarc-no-ungenerated-land-error" })
|
||||
CompatSend(player, { "oarc-no-ungenerated-land-error" })
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -95,12 +95,54 @@ function FadeoutRenderOnTick()
|
||||
end
|
||||
end
|
||||
|
||||
---@type boolean?
|
||||
local has_better_chat = nil
|
||||
--- Safely attempts to print via the Better Chatting's interface
|
||||
---@param recipient LuaGameScript|LuaForce|LuaPlayer
|
||||
---@param msg LocalisedString
|
||||
---@param print_settings PrintSettings?
|
||||
function CompatSend(recipient, msg, print_settings)
|
||||
if has_better_chat == nil then
|
||||
local better_chat = remote.interfaces["better-chat"]
|
||||
has_better_chat = better_chat and better_chat["send"]
|
||||
end
|
||||
|
||||
if not has_better_chat then return recipient.print(msg, print_settings) end
|
||||
print_settings = print_settings or {}
|
||||
|
||||
|
||||
---@type "global"|"force"|"player", int?
|
||||
local send_level, send_index
|
||||
local recipient_type = recipient.object_name
|
||||
|
||||
if recipient_type == "LuaGameScript" then
|
||||
send_level = "global"
|
||||
else
|
||||
---@cast recipient -LuaGameScript
|
||||
send_index = recipient.index
|
||||
if recipient_type == "LuaForce" then
|
||||
send_level = "force"
|
||||
elseif recipient_type == "LuaPlayer" then
|
||||
send_level = "player"
|
||||
else
|
||||
error("Invalid Recipient", 2)
|
||||
end
|
||||
end
|
||||
|
||||
remote.call("better-chat", "send", {
|
||||
message = msg,
|
||||
send_level = send_level,
|
||||
color = print_settings.color,
|
||||
recipient = send_index,
|
||||
})
|
||||
end
|
||||
|
||||
--- Broadcast messages to all connected players
|
||||
---@param msg LocalisedString
|
||||
---@return nil
|
||||
function SendBroadcastMsg(msg)
|
||||
for name, player in pairs(game.connected_players) do
|
||||
player.print(msg)
|
||||
CompatSend(player, msg)
|
||||
end
|
||||
end
|
||||
|
||||
@ -109,8 +151,9 @@ end
|
||||
---@param msg LocalisedString
|
||||
---@return nil
|
||||
function SendMsg(playerName, msg)
|
||||
if ((game.players[playerName] ~= nil) and (game.players[playerName].connected)) then
|
||||
game.players[playerName].print(msg)
|
||||
local player = game.players[playerName]
|
||||
if ((player ~= nil) and (player.connected)) then
|
||||
CompatSend(player, msg)
|
||||
end
|
||||
end
|
||||
|
||||
@ -411,7 +454,7 @@ function ShareChatBetweenForces(player, msg)
|
||||
(force.name ~= "neutral") and
|
||||
(force.name ~= "player") and
|
||||
(force ~= player.force)) then
|
||||
force.print(player.name..": "..msg)
|
||||
CompatSend(force, {"", player.name, ": ", msg})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1622,7 +1622,7 @@ function SecondarySpawn(player, surface_name)
|
||||
local spawn_position = FindUngeneratedCoordinates(surface_name, spawn_choices.distance, 3)
|
||||
-- If that fails, just throw a warning and don't spawn them. They can try again.
|
||||
if ((spawn_position.x == 0) and (spawn_position.y == 0)) then
|
||||
player.print({ "oarc-no-ungenerated-land-error" })
|
||||
CompatSend(player, { "oarc-no-ungenerated-land-error" })
|
||||
return
|
||||
end
|
||||
|
||||
@ -1651,7 +1651,7 @@ function SecondarySpawn(player, surface_name)
|
||||
SendBroadcastMsg({"", { "oarc-player-new-secondary", player_name, surface_name }, " ", GetGPStext(surface_name, spawn_position)})
|
||||
|
||||
-- Tell the player about the reroll command:
|
||||
player.print({ "oarc-reroll-spawn-command" })
|
||||
CompatSend(player, { "oarc-reroll-spawn-command" })
|
||||
end
|
||||
|
||||
-- Check a table to see if there are any players waiting to spawn
|
||||
@ -1787,7 +1787,7 @@ function CreatePlayerCustomForce(player)
|
||||
if (newForce.name == player.name) then
|
||||
SendBroadcastMsg({ "oarc-player-started-own-team", player.name })
|
||||
else
|
||||
player.print({ "oarc-player-no-new-teams-sorry" })
|
||||
CompatSend(player, { "oarc-player-no-new-teams-sorry" })
|
||||
end
|
||||
|
||||
return newForce
|
||||
|
@ -704,11 +704,11 @@ end
|
||||
---@return nil
|
||||
function RequestBuddySpawn(player)
|
||||
local buddy_choice = storage.spawn_choices[player.name].buddy
|
||||
if (buddy_choice == nil) then player.print({ "oarc-invalid-buddy" }) return end
|
||||
if (buddy_choice == nil) then CompatSend(player, { "oarc-invalid-buddy" }) return end
|
||||
local buddy = game.players[buddy_choice]
|
||||
if (buddy == nil) then player.print({ "oarc-invalid-buddy" }) return end
|
||||
if (buddy == nil) then CompatSend(player, { "oarc-invalid-buddy" }) return end
|
||||
-- Confirm the buddy is still in the spawn menu!
|
||||
if (buddy.gui.screen.spawn_opts == nil) then player.print({ "oarc-invalid-buddy", buddy.name }) return end
|
||||
if (buddy.gui.screen.spawn_opts == nil) then CompatSend(player, { "oarc-invalid-buddy", buddy.name }) return end
|
||||
|
||||
DisplayBuddySpawnWaitMenu(player)
|
||||
DisplayBuddySpawnRequestMenu(buddy, player.name)
|
||||
@ -736,7 +736,7 @@ function CancelBuddySpawnWaitMenu(player)
|
||||
DisplaySpawnOptions(buddy)
|
||||
end
|
||||
|
||||
buddy.print({ "oarc-buddy-cancel-request", player.name })
|
||||
CompatSend(buddy, { "oarc-buddy-cancel-request", player.name })
|
||||
end
|
||||
|
||||
---Request to join someone's shared spawn
|
||||
@ -749,7 +749,7 @@ function RequestToJoinSharedSpawn(player)
|
||||
end
|
||||
|
||||
local host_name = storage.spawn_choices[player.name].host_name
|
||||
if (host_name == nil) then player.print({ "oarc-no-shared-spawn-selected" }) return end
|
||||
if (host_name == nil) then CompatSend(player, { "oarc-no-shared-spawn-selected" }) return end
|
||||
|
||||
-- Clear the spawn options gui
|
||||
if (player.gui.screen.spawn_opts ~= nil) then
|
||||
@ -767,7 +767,7 @@ function RequestToJoinSharedSpawn(player)
|
||||
game.players[host_name].print({ "oarc-player-requesting-join-you", player.name })
|
||||
OarcGuiRefreshContent(game.players[host_name])
|
||||
else
|
||||
player.print({ "oarc-invalid-host-shared-spawn" })
|
||||
CompatSend(player, { "oarc-invalid-host-shared-spawn" })
|
||||
|
||||
DisplaySpawnOptions(player)
|
||||
end
|
||||
@ -865,7 +865,7 @@ function SharedSpawnSelect(gui_element, player)
|
||||
button.caption = { "oarc-join-shared-button-enable", host_name, primary_spawn.surface_name }
|
||||
button.style = "green_button"
|
||||
else
|
||||
player.print({ "oarc-invalid-host-shared-spawn" })
|
||||
CompatSend(player, { "oarc-invalid-host-shared-spawn" })
|
||||
storage.spawn_choices[player.name].host_name = nil
|
||||
gui_element.selected_index = 0
|
||||
button.enabled = false
|
||||
@ -896,7 +896,7 @@ function PrimarySpawnRequest(player)
|
||||
|
||||
-- If that fails, just throw a warning and don't spawn them. They can try again.
|
||||
if ((spawn_position.x == 0) and (spawn_position.y == 0)) then
|
||||
player.print({ "oarc-no-ungenerated-land-error" })
|
||||
CompatSend(player, { "oarc-no-ungenerated-land-error" })
|
||||
return
|
||||
end
|
||||
|
||||
@ -1146,7 +1146,7 @@ function AcceptBuddyRequest(player, requesting_buddy_name)
|
||||
|
||||
-- If that fails, just throw a warning and don't spawn them. They can try again.
|
||||
if ((spawn_position.x == 0) and (spawn_position.y == 0)) then
|
||||
player.print({ "oarc-no-ungenerated-land-error" })
|
||||
CompatSend(player, { "oarc-no-ungenerated-land-error" })
|
||||
return
|
||||
end
|
||||
|
||||
@ -1212,7 +1212,7 @@ function RejectBuddyRequest(player, requesting_buddy_name)
|
||||
DisplaySpawnOptions(requester_buddy)
|
||||
end
|
||||
|
||||
requester_buddy.print({ "oarc-buddy-declined", player.name })
|
||||
CompatSend(requester_buddy, { "oarc-buddy-declined", player.name })
|
||||
end
|
||||
|
||||
---Display the please wait dialog
|
||||
|
Loading…
Reference in New Issue
Block a user