Random station names! (#5548)

This commit is contained in:
Moony
2021-11-26 07:54:32 -06:00
committed by GitHub
parent 522cb3cf9c
commit f60484b15c
9 changed files with 83 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Server.Chat.Managers;
using Content.Shared.CCVar;
using Robust.Server.Maps;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.IoC;
@@ -20,6 +21,7 @@ public class GameMapManager : IGameMapManager
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IMapLoader _mapLoader = default!;
private GameMapPrototype _currentMap = default!;
private bool _currentMapForced;
@@ -116,4 +118,12 @@ public class GameMapManager : IGameMapManager
{
return _prototypeManager.TryIndex(gameMap, out map);
}
}
public string GenerateMapName(GameMapPrototype gameMap)
{
if (gameMap.NameGenerator is not null && gameMap.MapNameTemplate is not null)
return gameMap.NameGenerator.FormatName(gameMap.MapNameTemplate);
else
return gameMap.MapName;
}
}

View File

@@ -1,10 +1,10 @@
using System.Collections.Generic;
using Content.Server.Maps.NameGenerators;
using Content.Shared.Roles;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
using Robust.Shared.ViewVariables;
namespace Content.Server.Maps;
@@ -31,11 +31,23 @@ public class GameMapPrototype : IPrototype
public uint MaxPlayers { get; } = uint.MaxValue;
/// <summary>
/// Name of the given map.
/// Name of the map to use in generic messages, like the map vote.
/// </summary>
[DataField("mapName", required: true)]
public string MapName { get; } = default!;
/// <summary>
/// Name of the given map.
/// </summary>
[DataField("mapNameTemplate")]
public string? MapNameTemplate { get; } = default!;
/// <summary>
/// Name generator to use for the map, if any.
/// </summary>
[DataField("nameGenerator")]
public GameMapNameGenerator? NameGenerator { get; } = default!;
/// <summary>
/// Relative directory path to the given map, i.e. `Maps/saltern.yml`
/// </summary>

View File

@@ -64,4 +64,6 @@ public interface IGameMapManager
/// <param name="gameMap">name of the map</param>
/// <returns>existence</returns>
bool CheckMapExists(string gameMap);
}
public string GenerateMapName(GameMapPrototype gameMap);
}

View File

@@ -0,0 +1,9 @@
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Maps.NameGenerators;
[ImplicitDataDefinitionForInheritors]
public abstract class GameMapNameGenerator
{
public abstract string FormatName(string input);
}

View File

@@ -0,0 +1,26 @@
using JetBrains.Annotations;
using Robust.Shared.IoC;
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Maps.NameGenerators;
[UsedImplicitly]
public class NanotrasenNameGenerator : GameMapNameGenerator
{
/// <summary>
/// Where the map comes from. Should be a two or three letter code, for example "VG" for Packedstation.
/// </summary>
[DataField("prefixCreator")] public string PrefixCreator = default!;
private string Prefix => "NT";
private string[] SuffixCodes => new []{ "LV", "NX", "EV", "QT", "PR" };
public override string FormatName(string input)
{
var random = IoCManager.Resolve<IRobustRandom>();
// No way in hell am I writing custom format code just to add nice names. You can live with {0}
return string.Format(input, $"{Prefix}{PrefixCreator}", $"{random.Pick(SuffixCodes)}-{random.Next(0, 999):D3}");
}
}