mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Resolve warnings, mostly obsolete
* resolve via the entitymanager directly, not wref
* Ent<T>, why not
* minimize test diff
* StorageTest: consistent print order
* ChameleonProj: use Disguised value consistently
* GasArrayTest: TryComp
* OrganPickingMarker: cache ILocalizationManager
avoids warning from Loc.TryGetString, and avoids multiple IoCManager hits
* FormattedMessage.FromMarkup to FromMarkupOrThrow
* rerun tests 🙏
90 lines
2.9 KiB
C#
90 lines
2.9 KiB
C#
using Content.Server.Administration;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.Weather;
|
|
using Robust.Shared.Console;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.Weather.Commands;
|
|
|
|
/// <summary>
|
|
/// Removes all weather except the specified one. If the specified weather does not exist on the map, it adds it.
|
|
/// </summary>
|
|
[AdminCommand(AdminFlags.Fun)]
|
|
public sealed partial class WeatherSetCommand : LocalizedEntityCommands
|
|
{
|
|
[Dependency] private IPrototypeManager _proto = default!;
|
|
[Dependency] private SharedMapSystem _map = default!;
|
|
[Dependency] private WeatherSystem _weather = default!;
|
|
[Dependency] private IComponentFactory _compFactory = default!;
|
|
|
|
public override string Command => "weatherset";
|
|
|
|
public override void Execute(IConsoleShell shell, string argStr, string[] args)
|
|
{
|
|
if (args.Length < 2)
|
|
{
|
|
shell.WriteError(Loc.GetString("cmd-weather-error-no-arguments"));
|
|
return;
|
|
}
|
|
|
|
//MapId parse
|
|
if (!int.TryParse(args[0], out var mapInt))
|
|
return;
|
|
|
|
var mapId = new MapId(mapInt);
|
|
|
|
if (!_map.MapExists(mapId))
|
|
{
|
|
shell.WriteError(Loc.GetString("cmd-weather-error-wrong-map", ("id", mapId.ToString())));
|
|
return;
|
|
}
|
|
|
|
//Weather proto parse
|
|
EntProtoId? weatherProto = args[1];
|
|
if (args[1] == "null")
|
|
weatherProto = null;
|
|
else if (!_proto.TryIndex(weatherProto, out _))
|
|
{
|
|
shell.WriteError(Loc.GetString("cmd-weather-error-unknown-proto"));
|
|
return;
|
|
}
|
|
|
|
//Time parsing
|
|
TimeSpan? duration = null;
|
|
if (args.Length == 3)
|
|
{
|
|
if (int.TryParse(args[2], out var durationInt))
|
|
duration = TimeSpan.FromSeconds(durationInt);
|
|
else
|
|
shell.WriteError(Loc.GetString("cmd-weather-error-wrong-time"));
|
|
}
|
|
|
|
_weather.TrySetWeather(mapId, weatherProto, out _, duration);
|
|
}
|
|
|
|
|
|
public override CompletionResult GetCompletion(IConsoleShell shell, string[] args)
|
|
{
|
|
if (args.Length == 1)
|
|
return CompletionResult.FromHintOptions(CompletionHelper.MapIds(EntityManager), Loc.GetString("cmd-weather-hint-map-id"));
|
|
|
|
if (args.Length == 2)
|
|
{
|
|
var opts = new List<CompletionOption>();
|
|
foreach (var proto in _proto.EnumeratePrototypes<EntityPrototype>())
|
|
{
|
|
if (!proto.HasComp<WeatherStatusEffectComponent>(_compFactory))
|
|
continue;
|
|
|
|
opts.Add(new CompletionOption(proto.ID, proto.Name));
|
|
}
|
|
return CompletionResult.FromHintOptions(opts, Loc.GetString("cmd-weather-hint-prototype"));
|
|
}
|
|
|
|
if (args.Length == 3)
|
|
return CompletionResult.FromHint(Loc.GetString("cmd-weather-hint-time"));
|
|
|
|
return CompletionResult.Empty;
|
|
}
|
|
}
|