1
0
mirror of https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git synced 2024-12-04 09:43:00 +02:00

Modding interface updates.

This commit is contained in:
Oarcinae 2024-11-26 22:04:08 -05:00
parent e0e21da26f
commit e80ceaa528
6 changed files with 50 additions and 71 deletions

View File

@ -5,6 +5,10 @@ Date: ????
- Fix crash when player spawns due to missing surface configuration due to a missing migration. - Fix crash when player spawns due to missing surface configuration due to a missing migration.
Changes: Changes:
- Images losslessly compressed to reduce mod size. (Thanks plexpt!) - Images losslessly compressed to reduce mod size. (Thanks plexpt!)
Modding:
- Adding first_spawn and is_host flags to oarc-mod-on-player-spawned event.
- Add additional remote interfaces: get_unique_spawns, get_player_home_spawn, get_player_primary_spawn.
- Adding new custom event: oarc-mod-on-spawn-choices-gui-displayed. Intended to let other modders customize the spawn choices GUI.
--------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------
Version: 2.1.14 Version: 2.1.14
Date: 2024-11-21 Date: 2024-11-21

View File

@ -162,6 +162,15 @@ end)
---@field name integer --For custom events, this is the event ID ---@field name integer --For custom events, this is the event ID
---@field tick integer ---@field tick integer
---@class OarcModOnSpawnChoicesGuiDisplayedEvent: OarcCustomEventBase
---@field player_index integer
---@field gui_element LuaGuiElement
script.on_event("oarc-mod-on-spawn-choices-gui-displayed", function(event)
log("EVENT - oarc-mod-on-spawn-choices-gui-displayed:" .. serpent.block(event --[[@as OarcModOnSpawnChoicesGuiDisplayedEvent]]))
-- The 4 main sub sections are called: spawn_settings_frame, solo_spawn_frame, shared_spawn_frame, and buddy_spawn_frame
end)
---@class OarcModOnSpawnCreatedEvent: OarcCustomEventBase ---@class OarcModOnSpawnCreatedEvent: OarcCustomEventBase
---@field spawn_data OarcUniqueSpawn ---@field spawn_data OarcUniqueSpawn
script.on_event("oarc-mod-on-spawn-created", function(event) script.on_event("oarc-mod-on-spawn-created", function(event)
@ -182,6 +191,8 @@ end)
---@class OarcModOnPlayerSpawnedEvent: OarcCustomEventBase ---@class OarcModOnPlayerSpawnedEvent: OarcCustomEventBase
---@field player_index integer ---@field player_index integer
---@field first_spawn boolean
---@field is_host boolean
script.on_event("oarc-mod-on-player-spawned", function(event) script.on_event("oarc-mod-on-player-spawned", function(event)
log("EVENT - oarc-mod-on-player-spawned:" .. serpent.block(event --[[@as OarcModOnPlayerSpawnedEvent]])) log("EVENT - oarc-mod-on-player-spawned:" .. serpent.block(event --[[@as OarcModOnPlayerSpawnedEvent]]))
end) end)
@ -452,7 +463,19 @@ local oarc_mod_interface =
{ {
get_mod_settings = function() get_mod_settings = function()
return storage.ocfg return storage.ocfg
end end,
get_unique_spawns = function()
return storage.unique_spawns
end,
get_player_home_spawn = function(player_name)
return FindPlayerHomeSpawn(player_name)
end,
get_player_primary_spawn = function(player_name)
return FindPrimaryUniqueSpawn(player_name)
end,
} }
remote.add_interface("oarc_mod", oarc_mod_interface) remote.add_interface("oarc_mod", oarc_mod_interface)

View File

@ -24,19 +24,24 @@ data:extend({
oarc_linked_chest, oarc_linked_power, oarc_linked_chest, oarc_linked_power,
}) })
-- See control.lua for the event type defs to see what each event provides you.
data:extend({ data:extend({
-- A player was presented with the spawn options
{
type = "custom-event",
name = "oarc-mod-on-spawn-choices-gui-displayed",
},
-- A spawn area was created (and is finished generating) -- A spawn area was created (and is finished generating)
{ {
type = "custom-event", type = "custom-event",
name = "oarc-mod-on-spawn-created", name = "oarc-mod-on-spawn-created",
-- Provides data table called spawn_data
}, },
-- A spawn area was REQUESTED to be removed. (Not that it has been removed already.) -- A spawn area was REQUESTED to be removed. (Not that it has been removed already.)
{ {
type = "custom-event", type = "custom-event",
name = "oarc-mod-on-spawn-remove-request", name = "oarc-mod-on-spawn-remove-request",
-- Provides data table called spawn_data
}, },
-- A player was reset (also called when a player is removed) -- A player was reset (also called when a player is removed)
@ -44,21 +49,18 @@ data:extend({
{ {
type = "custom-event", type = "custom-event",
name = "oarc-mod-on-player-reset", name = "oarc-mod-on-player-reset",
-- Provides player_index
}, },
-- A player was spawned (sent to a new spawn OR joined a shared spawn) -- A player was spawned (sent to a new spawn OR joined a shared spawn)
{ {
type = "custom-event", type = "custom-event",
name = "oarc-mod-on-player-spawned", name = "oarc-mod-on-player-spawned",
-- Provides player_index
}, },
-- A player moved from surface to space platform -- A player moved from surface to space platform
{ {
type = "custom-event", type = "custom-event",
name = "oarc-mod-character-surface-changed", name = "oarc-mod-character-surface-changed",
-- Provides player_index, old_surface_name, new_surface_name
}, },
}) })

View File

@ -543,7 +543,7 @@ function SpawnCtrlTabGuiClick(event)
end end
-- Send player to the host's primary spawn. -- Send player to the host's primary spawn.
SendPlayerToNewSpawn(joining_player_name, primary_spawn.surface_name, true) SendPlayerToNewSpawn(joining_player_name, primary_spawn.surface_name, true, false)
-- Render some welcoming text... -- Render some welcoming text...
DisplayWelcomeGroundTextAtSpawn(primary_spawn.surface_name, primary_spawn.position) DisplayWelcomeGroundTextAtSpawn(primary_spawn.surface_name, primary_spawn.position)

View File

@ -671,15 +671,16 @@ end
---@param player_name string ---@param player_name string
---@param surface_name string ---@param surface_name string
---@param first_spawn boolean ---@param first_spawn boolean
---@param is_host boolean
---@return nil ---@return nil
function SendPlayerToNewSpawn(player_name, surface_name, first_spawn) function SendPlayerToNewSpawn(player_name, surface_name, first_spawn, is_host)
local player = game.players[player_name] local player = game.players[player_name]
-- Check if player character is nil -- Check if player character is nil
if (player.character == nil) then if (player.character == nil) then
log("Player character is nil, can't send to spawn point just yet: " .. player_name) log("Player character is nil, can't send to spawn point just yet: " .. player_name)
QueueNilCharacterForNewSpawnTeleport(player_name, surface_name, first_spawn) QueueNilCharacterForNewSpawnTeleport(player_name, surface_name, first_spawn, is_host)
return return
end end
@ -694,10 +695,10 @@ function SendPlayerToNewSpawn(player_name, surface_name, first_spawn)
-- Only first time spawns get starter items. -- Only first time spawns get starter items.
if first_spawn then if first_spawn then
GivePlayerStarterItems(player) GivePlayerStarterItems(player)
-- Trigger the event that player was spawned too.
script.raise_event("oarc-mod-on-player-spawned", {player_index = player.index})
end end
-- Trigger the event that player was spawned too.
script.raise_event("oarc-mod-on-player-spawned", {player_index = player.index, first_spawn = first_spawn, is_host = is_host})
end end
---Displays some welcoming text at the spawn point on the ground. Fades out over time. ---Displays some welcoming text at the spawn point on the ground. Fades out over time.
@ -865,51 +866,6 @@ end
--]] --]]
-- ---Resets the player and destroys their force if they are not on the main one.
-- ---@param player LuaPlayer
-- ---@return nil
-- function ResetPlayerAndDestroyForce(player)
-- local player_old_force = player.force
-- player.force = storage.ocfg.gameplay.main_force_name
-- if ((#player_old_force.players == 0) and (player_old_force.name ~= storage.ocfg.gameplay.main_force_name)) then
-- SendBroadcastMsg("Team " ..
-- player_old_force.name .. " has been destroyed! All buildings will slowly be destroyed now.") --: localize
-- log("DestroyForce - FORCE DESTROYED: " .. player_old_force.name)
-- game.merge_forces(player_old_force, DESTROYED_FORCE_NAME)
-- end
-- RemoveOrResetPlayer(player, false, false, true, true)
-- SeparateSpawnsInitPlayer(player.index)
-- end
-- ---Resets the player and merges their force into the abandoned_force.
-- ---@param player LuaPlayer
-- ---@return nil
-- function ResetPlayerAndAbandonForce(player)
-- local player_old_force = player.force
-- player.force = storage.ocfg.gameplay.main_force_name
-- if ((#player_old_force.players == 0) and (player_old_force.name ~= storage.ocfg.gameplay.main_force_name)) then
-- SendBroadcastMsg("Team " .. player_old_force.name .. " has been abandoned!") --: localize
-- log("AbandonForce - FORCE ABANDONED: " .. player_old_force.name)
-- game.merge_forces(player_old_force, ABANDONED_FORCE_NAME)
-- end
-- RemoveOrResetPlayer(player, false, false, false, false)
-- SeparateSpawnsInitPlayer(player.index)
-- end
-- ---Reset player and merge their force to neutral
-- ---@param player LuaPlayer
-- ---@return nil
-- function ResetPlayerAndMergeForceToNeutral(player)
-- RemoveOrResetPlayer(player, false, true, true, true)
-- SeparateSpawnsInitPlayer(player.index)
-- end
---Call this if a player leaves the game early (or a player wants an early game reset) ---Call this if a player leaves the game early (or a player wants an early game reset)
---@param player LuaPlayer ---@param player LuaPlayer
---@param remove_player boolean Deletes player from the game assuming they are offline. ---@param remove_player boolean Deletes player from the game assuming they are offline.
@ -1210,10 +1166,11 @@ end
---@param player_name string ---@param player_name string
---@param surface_name string ---@param surface_name string
---@param first_spawn boolean ---@param first_spawn boolean
---@param is_host boolean
---@return nil ---@return nil
function QueueNilCharacterForNewSpawnTeleport(player_name, surface_name, first_spawn) function QueueNilCharacterForNewSpawnTeleport(player_name, surface_name, first_spawn, is_host)
if (storage.nil_character_teleport_queue[player_name] == nil) then if (storage.nil_character_teleport_queue[player_name] == nil) then
storage.nil_character_teleport_queue[player_name] = { surface_name = surface_name, first_spawn = first_spawn } storage.nil_character_teleport_queue[player_name] = { surface_name = surface_name, first_spawn = first_spawn, is_host = is_host }
end end
end end
@ -1231,7 +1188,7 @@ function OnTickNilCharacterTeleportQueue()
-- And hope to high heaven this doesn't recurse infinitely. -- And hope to high heaven this doesn't recurse infinitely.
elseif (player.character ~= nil) then elseif (player.character ~= nil) then
storage.nil_character_teleport_queue[player_name] = nil storage.nil_character_teleport_queue[player_name] = nil
SendPlayerToNewSpawn(player_name, data.surface_name, data.first_spawn) SendPlayerToNewSpawn(player_name, data.surface_name, data.first_spawn, data.is_host)
end end
end end
end end
@ -1691,7 +1648,7 @@ function DelayedSpawnOnTick()
for _,player_name in pairs(delayed_spawn.waiting_players) do for _,player_name in pairs(delayed_spawn.waiting_players) do
local player = game.players[player_name] local player = game.players[player_name]
if (player ~= nil) then if (player ~= nil) then
SendPlayerToNewSpawn(player_name, delayed_spawn.surface_name, delayed_spawn.primary) SendPlayerToNewSpawn(player_name, delayed_spawn.surface_name, delayed_spawn.primary, delayed_spawn.host_name == player_name)
end end
end end
@ -1878,4 +1835,4 @@ SPAWN_TEAM_CHOICE = {
---@alias OarcSurfaceSpawnSetting { primary: boolean, secondary: boolean} ---@alias OarcSurfaceSpawnSetting { primary: boolean, secondary: boolean}
---Entry for a nil_character_teleport_queue ---Entry for a nil_character_teleport_queue
---@alias OarcNilCharacterTeleportQueueEntry { surface_name: string, first_spawn: boolean } ---@alias OarcNilCharacterTeleportQueueEntry { surface_name: string, first_spawn: boolean, is_host: boolean }

View File

@ -127,15 +127,6 @@ function CreateSpawnMenuGuiFrame(player)
} }
subhead.style.height = 46 subhead.style.height = 46
subhead.style.horizontally_stretchable = true subhead.style.horizontally_stretchable = true
-- changelog_subheader_frame =
-- {
-- type = "frame_style",
-- parent = "subheader_frame",
-- left_padding = 12,
-- right_padding = 12,
-- top_padding = 4,
-- horizontally_stretchable = "on"
-- }
AddLabel(subhead, "warning_lbl1", { "oarc-click-info-btn-help" }, my_note_style) AddLabel(subhead, "warning_lbl1", { "oarc-click-info-btn-help" }, my_note_style)
return inside_frame return inside_frame
@ -623,6 +614,8 @@ function DisplaySpawnOptions(player)
CreateSoloSpawnFrame(sGui, gameplay.enable_shared_spawns, gameplay.number_of_players_per_shared_spawn) -- The primary method of spawning CreateSoloSpawnFrame(sGui, gameplay.enable_shared_spawns, gameplay.number_of_players_per_shared_spawn) -- The primary method of spawning
CreateSharedSpawnFrame(sGui, gameplay.enable_shared_spawns) -- Spawn options to join another player's base. CreateSharedSpawnFrame(sGui, gameplay.enable_shared_spawns) -- Spawn options to join another player's base.
CreateBuddySpawnFrame(sGui, player, gameplay.enable_buddy_spawn, gameplay.enable_separate_teams) -- Awesome buddy spawning system CreateBuddySpawnFrame(sGui, player, gameplay.enable_buddy_spawn, gameplay.enable_separate_teams) -- Awesome buddy spawning system
script.raise_event("oarc-mod-on-spawn-choices-gui-displayed", { player_index = player.index, gui_element = sGui })
end end