forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first * Update Resources/Locale/ru-RU/_CorvaxNext/dynamichostname/hostname.ftl
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
Content.Server/_CorvaxNext/DynamicHostname/DynamicHostnameSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Content.Server.GameTicking; | ||
using Content.Server.Maps; | ||
using Content.Shared.CCVar; | ||
using Content.Shared.GameTicking; | ||
using Robust.Shared; | ||
using Robust.Shared.Configuration; | ||
|
||
namespace Content.Server.DynamicHostname; | ||
|
||
|
||
/// <summary> | ||
/// This handles dynamically updating hostnames. | ||
/// </summary> | ||
public sealed class DynamicHostnameSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IConfigurationManager _configuration = default!; | ||
[Dependency] private readonly GameTicker _gameTicker = default!; | ||
[Dependency] private readonly IGameMapManager _mapManager = default!; | ||
|
||
private string OriginalHostname { get; set; } = string.Empty; | ||
|
||
/// <inheritdoc/> | ||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnRunLevelChanged); | ||
SubscribeLocalEvent<RoundStartedEvent>(OnRoundStarted); | ||
|
||
OriginalHostname = _configuration.GetCVar(CVars.GameHostName); | ||
AttemptUpdateHostname(); | ||
} | ||
|
||
private void OnRunLevelChanged(GameRunLevelChangedEvent ev) => AttemptUpdateHostname(); | ||
private void OnRoundStarted(RoundStartedEvent ev) => AttemptUpdateHostname(); | ||
|
||
private void OnValueChanged(bool newValue) | ||
{ | ||
if (!newValue) | ||
_configuration.SetCVar(CVars.GameHostName, OriginalHostname); | ||
|
||
AttemptUpdateHostname(); | ||
} | ||
|
||
private void AttemptUpdateHostname() | ||
{ | ||
var currentMapName = _mapManager.GetSelectedMap()?.MapName; | ||
var currentPresetName = _gameTicker.CurrentPreset?.ModeTitle; | ||
|
||
UpdateHostname(currentMapName, currentPresetName); | ||
} | ||
|
||
private string GetLocId() | ||
{ | ||
switch (_gameTicker.RunLevel) | ||
{ | ||
case GameRunLevel.InRound: | ||
return "in-round"; | ||
case GameRunLevel.PostRound: | ||
return "post-round"; | ||
default: | ||
return "in-lobby"; | ||
} | ||
} | ||
|
||
private void UpdateHostname(string? currentMapName = null, string? currentPresetName = null) | ||
{ | ||
var locId = GetLocId(); | ||
var presetName = "No preset"; | ||
|
||
if (currentPresetName != null) | ||
presetName = Loc.GetString(currentPresetName); | ||
|
||
var hostname = Loc.GetString($"dynamic-hostname-{locId}-hostname", | ||
("originalHostName", OriginalHostname), | ||
("preset", presetName), | ||
("mapName", currentMapName ?? "No Map")); | ||
|
||
_configuration.SetCVar(CVars.GameHostName, hostname); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Resources/Locale/ru-RU/_CorvaxNext/dynamichostname/hostname.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dynamic-hostname-in-lobby-hostname = { $originalHostName } | В Лобби | ||
dynamic-hostname-in-round-hostname = { $originalHostName } | Идёт раунд на { $mapName }! | ||
dynamic-hostname-post-round-hostname = { $originalHostName } | Раунд закончился! |