]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Weather fix (#30857)
authorEd <96445749+TheShuEd@users.noreply.github.com>
Sun, 25 Aug 2024 15:20:47 +0000 (20:20 +0500)
committerGitHub <noreply@github.com>
Sun, 25 Aug 2024 15:20:47 +0000 (01:20 +1000)
* weather fix

* localize errors

Content.Server/Weather/WeatherSystem.cs
Content.Shared/Weather/SharedWeatherSystem.cs
Resources/Locale/en-US/weather/weather.ftl

index c3af49944d99c52d84d8086ed81153574d26d4ee..dbee62a72fc2d3896633105d75fd63005841cfcc 100644 (file)
@@ -33,58 +33,50 @@ public sealed class WeatherSystem : SharedWeatherSystem
     {
         if (args.Length < 2)
         {
-            shell.WriteError($"A");
+            shell.WriteError(Loc.GetString("cmd-weather-error-no-arguments"));
             return;
         }
 
         if (!int.TryParse(args[0], out var mapInt))
-        {
             return;
-        }
 
         var mapId = new MapId(mapInt);
 
         if (!MapManager.MapExists(mapId))
-        {
             return;
+
+        if (!_mapSystem.TryGetMap(mapId, out var mapUid))
+            return;
+
+        var weatherComp = EnsureComp<WeatherComponent>(mapUid.Value);
+
+        //Weather Proto parsing
+        WeatherPrototype? weather = null;
+        if (!args[1].Equals("null"))
+        {
+            if (!ProtoMan.TryIndex(args[1], out weather))
+            {
+                shell.WriteError(Loc.GetString("cmd-weather-error-unknown-proto"));
+                return;
+            }
         }
 
+        //Time parsing
         TimeSpan? endTime = null;
-
         if (args.Length == 3)
         {
+            var curTime = Timing.CurTime;
             if (int.TryParse(args[2], out var durationInt))
             {
-                var curTime = Timing.CurTime;
-                var maxTime = TimeSpan.MaxValue;
-
-                // If it's already running then just fade out with how much time we're into the weather.
-                if (_mapSystem.TryGetMap(mapId, out var mapUid) &&
-                    TryComp<WeatherComponent>(mapUid, out var weatherComp) &&
-                    weatherComp.Weather.TryGetValue(args[1], out var existing))
-                {
-                    maxTime = curTime - existing.StartTime;
-                }
-
                 endTime = curTime + TimeSpan.FromSeconds(durationInt);
-
-                if (endTime > maxTime)
-                    endTime = maxTime;
+            }
+            else
+            {
+                shell.WriteError(Loc.GetString("cmd-weather-error-wrong-time"));
             }
         }
 
-        if (args[1].Equals("null"))
-        {
-            SetWeather(mapId, null, endTime);
-        }
-        else if (ProtoMan.TryIndex<WeatherPrototype>(args[1], out var weatherProto))
-        {
-            SetWeather(mapId, weatherProto, endTime);
-        }
-        else
-        {
-            shell.WriteError($"Unable to parse weather prototype");
-        }
+        SetWeather(mapId, weather, endTime);
     }
 
     private CompletionResult WeatherCompletion(IConsoleShell shell, string[] args)
index 61419021247fade5724e8c9855f664d5be7293c1..acd430553882de92ebfa1ba767ecf0ab6d79abd0 100644 (file)
@@ -156,11 +156,14 @@ public abstract class SharedWeatherSystem : EntitySystem
 
         foreach (var (eProto, weather) in weatherComp.Weather)
         {
+            // if we turn off the weather, we don't want endTime = null
+            if (proto == null)
+                endTime ??= Timing.CurTime + WeatherComponent.ShutdownTime;
+
             // Reset cooldown if it's an existing one.
-            if (proto == null || eProto == proto.ID)
+            if (proto is not null && eProto == proto.ID)
             {
                 weather.EndTime = endTime;
-
                 if (weather.State == WeatherState.Ending)
                     weather.State = WeatherState.Running;
 
index de5dbd8890574231940f7409b99c7b63257e04b2..67e6eec35f2ce2116868fbfea0974b54efcc9a9c 100644 (file)
@@ -1,3 +1,7 @@
 cmd-weather-desc = Sets the weather for the current map.
 cmd-weather-help = weather <mapId> <prototype / null>
 cmd-weather-hint = Weather prototype
+
+cmd-weather-error-no-arguments = Not enough arguments!
+cmd-weather-error-unknown-proto = Unknown Weather prototype!
+cmd-weather-error-wrong-time = Time is in the wrong format!
\ No newline at end of file