Remove component.Initialize calls (#18230)
This commit is contained in:
@@ -1,51 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Robust.Client.Animations;
|
|
||||||
using Robust.Client.GameObjects;
|
|
||||||
using Robust.Shared.Animations;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Maths;
|
|
||||||
|
|
||||||
namespace Content.Client.Animations
|
|
||||||
{
|
|
||||||
[RegisterComponent]
|
|
||||||
public sealed class AnimationsTestComponent : Component
|
|
||||||
{
|
|
||||||
protected override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
|
|
||||||
var animations = IoCManager.Resolve<IEntityManager>().GetComponent<AnimationPlayerComponent>(Owner);
|
|
||||||
animations.Play(new Animation
|
|
||||||
{
|
|
||||||
Length = TimeSpan.FromSeconds(20),
|
|
||||||
AnimationTracks =
|
|
||||||
{
|
|
||||||
new AnimationTrackComponentProperty
|
|
||||||
{
|
|
||||||
ComponentType = typeof(TransformComponent),
|
|
||||||
Property = nameof(TransformComponent.LocalRotation),
|
|
||||||
InterpolationMode = AnimationInterpolationMode.Linear,
|
|
||||||
KeyFrames =
|
|
||||||
{
|
|
||||||
new AnimationTrackProperty.KeyFrame(Angle.Zero, 0),
|
|
||||||
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(1440), 20)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new AnimationTrackComponentProperty
|
|
||||||
{
|
|
||||||
ComponentType = typeof(SpriteComponent),
|
|
||||||
Property = "layer/0/texture",
|
|
||||||
KeyFrames =
|
|
||||||
{
|
|
||||||
new AnimationTrackProperty.KeyFrame("Objects/toolbox_r.png", 0),
|
|
||||||
new AnimationTrackProperty.KeyFrame("Objects/Toolbox_b.png", 5),
|
|
||||||
new AnimationTrackProperty.KeyFrame("Objects/Toolbox_y.png", 5),
|
|
||||||
new AnimationTrackProperty.KeyFrame("Objects/toolbox_r.png", 5),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, "yes");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
|
||||||
|
|
||||||
namespace Content.Client.Spawners
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Spawns a set of entities on the client only, and removes them when this component is removed.
|
|
||||||
/// </summary>
|
|
||||||
[RegisterComponent]
|
|
||||||
[ComponentProtoName("ClientEntitySpawner")]
|
|
||||||
public sealed class ClientEntitySpawnerComponent : Component
|
|
||||||
{
|
|
||||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
||||||
|
|
||||||
[DataField("prototypes")] private List<string> _prototypes = new() { "HVDummyWire" };
|
|
||||||
|
|
||||||
private readonly List<EntityUid> _entity = new();
|
|
||||||
|
|
||||||
protected override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
SpawnEntities();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnRemove()
|
|
||||||
{
|
|
||||||
RemoveEntities();
|
|
||||||
base.OnRemove();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SpawnEntities()
|
|
||||||
{
|
|
||||||
foreach (var proto in _prototypes)
|
|
||||||
{
|
|
||||||
var entity = _entMan.SpawnEntity(proto, _entMan.GetComponent<TransformComponent>(Owner).Coordinates);
|
|
||||||
_entity.Add(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RemoveEntities()
|
|
||||||
{
|
|
||||||
foreach (var entity in _entity)
|
|
||||||
{
|
|
||||||
_entMan.DeleteEntity(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,14 +7,12 @@ namespace Content.Server.Entry
|
|||||||
"ConstructionGhost",
|
"ConstructionGhost",
|
||||||
"IconSmooth",
|
"IconSmooth",
|
||||||
"InteractionOutline",
|
"InteractionOutline",
|
||||||
"AnimationsTest",
|
|
||||||
"ItemStatus",
|
"ItemStatus",
|
||||||
"Marker",
|
"Marker",
|
||||||
"GuidebookControlsTest",
|
"GuidebookControlsTest",
|
||||||
"GuideHelp",
|
"GuideHelp",
|
||||||
"Clickable",
|
"Clickable",
|
||||||
"Icon",
|
"Icon",
|
||||||
"ClientEntitySpawner",
|
|
||||||
"HandheldGPS",
|
"HandheldGPS",
|
||||||
"CableVisualizer",
|
"CableVisualizer",
|
||||||
"UIFragment",
|
"UIFragment",
|
||||||
|
|||||||
@@ -25,21 +25,10 @@ namespace Content.Server.Power.Components
|
|||||||
public TNetType? Net { get => _net; set => SetNet(value); }
|
public TNetType? Net { get => _net; set => SetNet(value); }
|
||||||
private TNetType? _net;
|
private TNetType? _net;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables] public bool NeedsNet => _net != null;
|
||||||
private bool _needsNet => _net != null;
|
|
||||||
|
|
||||||
[DataField("node")] public string? NodeId { get; set; }
|
[DataField("node")] public string? NodeId { get; set; }
|
||||||
|
|
||||||
protected override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
|
|
||||||
if (_needsNet)
|
|
||||||
{
|
|
||||||
TryFindAndSetNet();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnRemove()
|
protected override void OnRemove()
|
||||||
{
|
{
|
||||||
ClearNet();
|
ClearNet();
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
using Content.Server.Power.Components;
|
||||||
|
using Content.Server.Power.NodeGroups;
|
||||||
|
|
||||||
|
namespace Content.Server.Power.EntitySystems;
|
||||||
|
|
||||||
|
public sealed class PowerNetConnectorSystem : EntitySystem
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<ApcComponent, ComponentInit>(OnApcInit);
|
||||||
|
SubscribeLocalEvent<ApcPowerProviderComponent, ComponentInit>(OnApcPowerProviderInit);
|
||||||
|
SubscribeLocalEvent<BatteryChargerComponent, ComponentInit>(OnBatteryChargerInit);
|
||||||
|
SubscribeLocalEvent<BatteryDischargerComponent, ComponentInit>(OnBatteryDischargerInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPowerSupplierInit(EntityUid uid, PowerSupplierComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
BaseNetConnectorInit(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBatteryDischargerInit(EntityUid uid, BatteryDischargerComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
BaseNetConnectorInit(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnBatteryChargerInit(EntityUid uid, BatteryChargerComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
BaseNetConnectorInit(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnApcPowerProviderInit(EntityUid uid, ApcPowerProviderComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
BaseNetConnectorInit(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnApcInit(EntityUid uid, ApcComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
BaseNetConnectorInit(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void BaseNetConnectorInit<T>(BaseNetConnectorComponent<T> component)
|
||||||
|
{
|
||||||
|
if (component.NeedsNet)
|
||||||
|
{
|
||||||
|
component.TryFindAndSetNet();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
public sealed class PowerNetSystem : EntitySystem
|
public sealed class PowerNetSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
[Dependency] private readonly AppearanceSystem _appearance = default!;
|
||||||
|
[Dependency] private readonly PowerNetConnectorSystem _powerNetConnector = default!;
|
||||||
[Dependency] private readonly IParallelManager _parMan = default!;
|
[Dependency] private readonly IParallelManager _parMan = default!;
|
||||||
|
|
||||||
private readonly PowerState _powerState = new();
|
private readonly PowerState _powerState = new();
|
||||||
@@ -101,6 +102,7 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
|
|
||||||
private void PowerConsumerInit(EntityUid uid, PowerConsumerComponent component, ComponentInit args)
|
private void PowerConsumerInit(EntityUid uid, PowerConsumerComponent component, ComponentInit args)
|
||||||
{
|
{
|
||||||
|
_powerNetConnector.BaseNetConnectorInit(component);
|
||||||
AllocLoad(component.NetworkLoad);
|
AllocLoad(component.NetworkLoad);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,6 +123,7 @@ namespace Content.Server.Power.EntitySystems
|
|||||||
|
|
||||||
private void PowerSupplierInit(EntityUid uid, PowerSupplierComponent component, ComponentInit args)
|
private void PowerSupplierInit(EntityUid uid, PowerSupplierComponent component, ComponentInit args)
|
||||||
{
|
{
|
||||||
|
_powerNetConnector.BaseNetConnectorInit(component);
|
||||||
AllocSupply(component.NetworkSupply);
|
AllocSupply(component.NetworkSupply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ namespace Content.Server.Spawners.Components
|
|||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class TimedSpawnerComponent : Component, ISerializationHooks
|
public sealed class TimedSpawnerComponent : Component, ISerializationHooks
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
[DataField("prototypes", customTypeSerializer:typeof(PrototypeIdListSerializer<EntityPrototype>))]
|
[DataField("prototypes", customTypeSerializer:typeof(PrototypeIdListSerializer<EntityPrototype>))]
|
||||||
public List<string> Prototypes { get; set; } = new();
|
public List<string> Prototypes { get; set; } = new();
|
||||||
@@ -38,32 +36,5 @@ namespace Content.Server.Spawners.Components
|
|||||||
if (MinimumEntitiesSpawned > MaximumEntitiesSpawned)
|
if (MinimumEntitiesSpawned > MaximumEntitiesSpawned)
|
||||||
throw new ArgumentException("MaximumEntitiesSpawned can't be lower than MinimumEntitiesSpawned!");
|
throw new ArgumentException("MaximumEntitiesSpawned can't be lower than MinimumEntitiesSpawned!");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
SetupTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetupTimer()
|
|
||||||
{
|
|
||||||
TokenSource?.Cancel();
|
|
||||||
TokenSource = new CancellationTokenSource();
|
|
||||||
Owner.SpawnRepeatingTimer(TimeSpan.FromSeconds(IntervalSeconds), OnTimerFired, TokenSource.Token);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTimerFired()
|
|
||||||
{
|
|
||||||
if (!_robustRandom.Prob(Chance))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var number = _robustRandom.Next(MinimumEntitiesSpawned, MaximumEntitiesSpawned);
|
|
||||||
|
|
||||||
for (int i = 0; i < number; i++)
|
|
||||||
{
|
|
||||||
var entity = _robustRandom.Pick(Prototypes);
|
|
||||||
IoCManager.Resolve<IEntityManager>().SpawnEntity(entity, IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(Owner).Coordinates);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
Content.Server/Spawners/EntitySystems/SpawnerSystem.cs
Normal file
38
Content.Server/Spawners/EntitySystems/SpawnerSystem.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using Content.Server.Spawners.Components;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
namespace Content.Server.Spawners.EntitySystems;
|
||||||
|
|
||||||
|
public sealed class SpawnerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<TimedSpawnerComponent, ComponentInit>(OnSpawnerInit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSpawnerInit(EntityUid uid, TimedSpawnerComponent component, ComponentInit args)
|
||||||
|
{
|
||||||
|
component.TokenSource?.Cancel();
|
||||||
|
component.TokenSource = new CancellationTokenSource();
|
||||||
|
uid.SpawnRepeatingTimer(TimeSpan.FromSeconds(component.IntervalSeconds), () => OnTimerFired(uid, component), component.TokenSource.Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTimerFired(EntityUid uid, TimedSpawnerComponent component)
|
||||||
|
{
|
||||||
|
if (!_random.Prob(component.Chance))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var number = _random.Next(component.MinimumEntitiesSpawned, component.MaximumEntitiesSpawned);
|
||||||
|
var coordinates = Transform(uid).Coordinates;
|
||||||
|
|
||||||
|
for (var i = 0; i < number; i++)
|
||||||
|
{
|
||||||
|
var entity = _random.Pick(component.Prototypes);
|
||||||
|
Spawn(entity, coordinates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#- type: entity
|
|
||||||
# id: AnimationsTest
|
|
||||||
# components:
|
|
||||||
# - type: Sprite
|
|
||||||
# texture: Objects/Toolbox_b.png
|
|
||||||
# offset: 2, 0
|
|
||||||
# noRot: false
|
|
||||||
# - type: AnimationPlayer
|
|
||||||
# - type: AnimationsTest
|
|
||||||
Reference in New Issue
Block a user