Use IMapInit in PoweredLightComponent
This commit is contained in:
@@ -8,6 +8,7 @@ using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
@@ -23,7 +24,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
/// Component that represents a wall light. It has a light bulb that can be replaced when broken.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class PoweredLightComponent : Component, IInteractHand, IInteractUsing
|
||||
public class PoweredLightComponent : Component, IInteractHand, IInteractUsing, IMapInit
|
||||
{
|
||||
public override string Name => "PoweredLight";
|
||||
|
||||
@@ -219,20 +220,7 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
|
||||
Owner.GetComponent<PowerReceiverComponent>().OnPowerStateChanged += UpdateLight;
|
||||
|
||||
_lightBulbContainer = ContainerManagerComponent.Ensure<ContainerSlot>("light_bulb", Owner, out var existed);
|
||||
|
||||
if (!existed) // Insert a light tube if there wasn't any.
|
||||
{
|
||||
switch (BulbType)
|
||||
{
|
||||
case LightBulbType.Tube:
|
||||
_lightBulbContainer.Insert(Owner.EntityManager.SpawnEntity("LightTube", Owner.Transform.GridPosition));
|
||||
break;
|
||||
case LightBulbType.Bulb:
|
||||
_lightBulbContainer.Insert(Owner.EntityManager.SpawnEntity("LightBulb", Owner.Transform.GridPosition));
|
||||
break;
|
||||
}
|
||||
}
|
||||
_lightBulbContainer = ContainerManagerComponent.Ensure<ContainerSlot>("light_bulb", Owner);
|
||||
}
|
||||
|
||||
public override void OnRemove()
|
||||
@@ -240,5 +228,18 @@ namespace Content.Server.GameObjects.Components.Power
|
||||
Owner.GetComponent<PowerReceiverComponent>().OnPowerStateChanged -= UpdateLight;
|
||||
base.OnRemove();
|
||||
}
|
||||
|
||||
void IMapInit.MapInit()
|
||||
{
|
||||
var prototype = BulbType switch
|
||||
{
|
||||
LightBulbType.Bulb => "LightBulb",
|
||||
LightBulbType.Tube => "LightTube",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
var entity = Owner.EntityManager.SpawnEntity(prototype, Owner.Transform.GridPosition);
|
||||
_lightBulbContainer.Insert(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user