From bfe22171127784231f2246c039c551a26fc3ab7c Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Thu, 30 Jul 2020 23:59:40 +0200 Subject: [PATCH] Use IMapInit in PoweredLightComponent --- .../PoweredLightComponent.cs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs index 01bf741a8a..2c50fde2c2 100644 --- a/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs +++ b/Content.Server/GameObjects/Components/Power/ApcNetComponents/PowerReceiverUsers/PoweredLightComponent.cs @@ -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. /// [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().OnPowerStateChanged += UpdateLight; - _lightBulbContainer = ContainerManagerComponent.Ensure("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("light_bulb", Owner); } public override void OnRemove() @@ -240,5 +228,18 @@ namespace Content.Server.GameObjects.Components.Power Owner.GetComponent().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); + } } }