Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: Minimize GameModeInit class dependencies #89

Merged
merged 5 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CTF.Host.Settings;
namespace CTF.Application.Common;

public class ServerSettings
{
Expand Down
32 changes: 32 additions & 0 deletions src/Application/Maps/Systems/SetDefaultMapSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace CTF.Application.Maps.Systems;

public class SetDefaultMapSystem(
IWorldService worldService,
IServerService serverService,
MapInfoService mapInfoService,
TeamPickupService teamPickupService,
TeamIconService teamIconService,
MapTextDrawRenderer mapTextDrawRenderer,
ServerSettings serverSettings) : ISystem
{
[Event]
public void OnGameModeInit()
{
Result<IMap> mapResult = MapCollection.GetByName(serverSettings.MapName);
if (mapResult.IsSuccess)
{
mapInfoService.Load(mapResult.Value);
}
CurrentMap currentMap = mapInfoService.Read();
serverService.SendRconCommand($"mapname {currentMap.Name}");
serverService.SendRconCommand($"loadfs {currentMap.Name}");
mapTextDrawRenderer.UpdateMapName();

worldService.SetWeather(currentMap.Weather);
serverService.SetWorldTime(currentMap.WorldTime);
teamPickupService.CreateFlagFromBasePosition(Team.Alpha);
teamPickupService.CreateFlagFromBasePosition(Team.Beta);
teamIconService.CreateFromBasePosition(Team.Alpha);
teamIconService.CreateFromBasePosition(Team.Beta);
}
}
7 changes: 7 additions & 0 deletions src/Application/Teams/ClassSelection/ClassSelectionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ public class ClassSelectionSystem(
ClassSelectionTextDrawRenderer classSelectionTextDrawRenderer,
TeamTextDrawRenderer teamTextDrawRenderer) : ISystem
{
[Event]
public void OnGameModeInit(IServerService serverService)
{
serverService.AddPlayerClass((int)Team.Alpha.SkinId, new Vector3(0, 0, 0), 0);
serverService.AddPlayerClass((int)Team.Beta.SkinId, new Vector3(0, 0, 0), 0);
}

[Event]
public void OnPlayerConnect(Player player)
{
Expand Down
26 changes: 1 addition & 25 deletions src/Host/GameModeInit.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
namespace CTF.Host;

public class GameModeInit(
IWorldService worldService,
IServerService serverService,
MapInfoService mapInfoService,
MapTextDrawRenderer mapTextDrawRenderer,
TeamPickupService teamPickupService,
TeamIconService teamIconService,
ServerSettings serverSettings) : ISystem
{
[Event]
Expand All @@ -25,24 +20,5 @@ public void OnGameModeInit()
serverService.SetGameModeText(serverSettings.GameModeText);
serverService.UsePlayerPedAnims();
serverService.DisableInteriorEnterExits();
serverService.AddPlayerClass((int)Team.Alpha.SkinId, new Vector3(0, 0, 0), 0);
serverService.AddPlayerClass((int)Team.Beta.SkinId, new Vector3(0, 0, 0), 0);

Result<IMap> mapResult = MapCollection.GetByName(serverSettings.MapName);
if (mapResult.IsSuccess)
{
mapInfoService.Load(mapResult.Value);
}
CurrentMap currentMap = mapInfoService.Read();
serverService.SendRconCommand($"mapname {currentMap.Name}");
serverService.SendRconCommand($"loadfs {currentMap.Name}");
mapTextDrawRenderer.UpdateMapName();

worldService.SetWeather(currentMap.Weather);
serverService.SetWorldTime(currentMap.WorldTime);
teamPickupService.CreateFlagFromBasePosition(Team.Alpha);
teamPickupService.CreateFlagFromBasePosition(Team.Beta);
teamIconService.CreateFromBasePosition(Team.Alpha);
teamIconService.CreateFromBasePosition(Team.Beta);
}
}
}
5 changes: 0 additions & 5 deletions src/Host/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@
global using CTF.Application;
global using CTF.Application.Common;
global using CTF.Application.Common.Services;
global using CTF.Application.Teams;
global using CTF.Application.Teams.Services;
global using CTF.Application.Maps;
global using CTF.Application.Maps.Services;
global using CTF.Host.Extensions;
global using CTF.Host.Services;
global using CTF.Host.Settings;
global using Persistence.SQLite;
global using Persistence.MariaDB;
global using Persistence.InMemory;
Loading