clean up weather systems (#28792)
* clean up weather systems * Update WeatherComponent.cs * Update SharedWeatherSystem.cs * some fix * Update SharedWeatherSystem.cs * Update WeatherComponent.cs * Update WeatherComponent.cs * revert autoPause * Update SharedWeatherSystem.cs
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -18,15 +16,14 @@ public abstract class SharedWeatherSystem : EntitySystem
|
||||
[Dependency] private readonly ITileDefinitionManager _tileDefManager = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metadata = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
|
||||
|
||||
private EntityQuery<BlockWeatherComponent> _blockQuery;
|
||||
private EntityQuery<PhysicsComponent> _physicsQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_blockQuery = GetEntityQuery<BlockWeatherComponent>();
|
||||
_physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
SubscribeLocalEvent<WeatherComponent, EntityUnpausedEvent>(OnWeatherUnpaused);
|
||||
}
|
||||
|
||||
@@ -41,9 +38,7 @@ public abstract class SharedWeatherSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanWeatherAffect(
|
||||
MapGridComponent grid,
|
||||
TileRef tileRef)
|
||||
public bool CanWeatherAffect(EntityUid uid, MapGridComponent grid, TileRef tileRef)
|
||||
{
|
||||
if (tileRef.Tile.IsEmpty)
|
||||
return true;
|
||||
@@ -53,9 +48,9 @@ public abstract class SharedWeatherSystem : EntitySystem
|
||||
if (!tileDef.Weather)
|
||||
return false;
|
||||
|
||||
var anchoredEnts = grid.GetAnchoredEntitiesEnumerator(tileRef.GridIndices);
|
||||
var anchoredEntities = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, tileRef.GridIndices);
|
||||
|
||||
while (anchoredEnts.MoveNext(out var ent))
|
||||
while (anchoredEntities.MoveNext(out var ent))
|
||||
{
|
||||
if (_blockQuery.HasComponent(ent.Value))
|
||||
return false;
|
||||
@@ -154,20 +149,22 @@ public abstract class SharedWeatherSystem : EntitySystem
|
||||
/// </summary>
|
||||
public void SetWeather(MapId mapId, WeatherPrototype? proto, TimeSpan? endTime)
|
||||
{
|
||||
var mapUid = MapManager.GetMapEntityId(mapId);
|
||||
var weatherComp = EnsureComp<WeatherComponent>(mapUid);
|
||||
if (!_mapSystem.TryGetMap(mapId, out var mapUid))
|
||||
return;
|
||||
|
||||
var weatherComp = EnsureComp<WeatherComponent>(mapUid.Value);
|
||||
|
||||
foreach (var (eProto, weather) in weatherComp.Weather)
|
||||
{
|
||||
// Reset cooldown if it's an existing one.
|
||||
if (eProto == proto?.ID)
|
||||
if (proto == null || eProto == proto.ID)
|
||||
{
|
||||
weather.EndTime = endTime;
|
||||
|
||||
if (weather.State == WeatherState.Ending)
|
||||
weather.State = WeatherState.Running;
|
||||
|
||||
Dirty(mapUid, weatherComp);
|
||||
Dirty(mapUid.Value, weatherComp);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -177,12 +174,12 @@ public abstract class SharedWeatherSystem : EntitySystem
|
||||
if (weather.EndTime == null || weather.EndTime > end)
|
||||
{
|
||||
weather.EndTime = end;
|
||||
Dirty(mapUid, weatherComp);
|
||||
Dirty(mapUid.Value, weatherComp);
|
||||
}
|
||||
}
|
||||
|
||||
if (proto != null)
|
||||
StartWeather(mapUid, weatherComp, proto, endTime);
|
||||
StartWeather(mapUid.Value, weatherComp, proto, endTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -229,9 +226,9 @@ public abstract class SharedWeatherSystem : EntitySystem
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class WeatherComponentState : ComponentState
|
||||
{
|
||||
public Dictionary<string, WeatherData> Weather;
|
||||
public Dictionary<ProtoId<WeatherPrototype>, WeatherData> Weather;
|
||||
|
||||
public WeatherComponentState(Dictionary<string, WeatherData> weather)
|
||||
public WeatherComponentState(Dictionary<ProtoId<WeatherPrototype>, WeatherData> weather)
|
||||
{
|
||||
Weather = weather;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user