示例#1
0
        private void UpdateBarSignVisuals(EntityUid owner, BarSignComponent component, PowerChangedEvent args)
        {
            if (component.LifeStage is < ComponentLifeStage.Initialized or > ComponentLifeStage.Running)
            {
                return;
            }

            if (!TryComp(owner, out SpriteComponent? sprite))
            {
                Logger.ErrorS("barSign", "Barsign is missing sprite component");
                return;
            }

            if (!TryGetBarSignPrototype(component, out var prototype))
            {
                prototype = Setup(owner, component);
            }

            if (args.Powered)
            {
                sprite.LayerSetState(0, prototype.Icon);
                sprite.LayerSetShader(0, "unshaded");
            }
            else
            {
                sprite.LayerSetState(0, "empty");
                sprite.LayerSetShader(0, "shaded");
            }
        }
示例#2
0
        private void UpdateBarSignVisuals(BarSignComponent component)
        {
            if (component.CurrentSign == null)
            {
                return;
            }

            if (!_prototypeManager.TryIndex(component.CurrentSign, out BarSignPrototype? prototype))
            {
                Logger.ErrorS("barSign", $"Invalid bar sign prototype: \"{component.CurrentSign}\"");
                return;
            }

            if (component.Owner.TryGetComponent(out SpriteComponent? sprite))
            {
                if (!component.Owner.TryGetComponent(out ApcPowerReceiverComponent? receiver) || receiver.Powered)
                {
                    sprite.LayerSetState(0, "empty");
                    sprite.LayerSetShader(0, "shaded");
                }
                else
                {
                    sprite.LayerSetState(0, prototype.Icon);
                    sprite.LayerSetShader(0, "unshaded");
                }
            }
示例#3
0
        private void OnMapInit(EntityUid uid, BarSignComponent component, MapInitEvent args)
        {
            if (component.CurrentSign != null)
            {
                return;
            }

            var prototypes = _prototypeManager.EnumeratePrototypes <BarSignPrototype>().Where(p => !p.Hidden)
                             .ToList();
            var prototype = _random.Pick(prototypes);

            component.CurrentSign = prototype.ID;
        }
示例#4
0
 private bool TryGetBarSignPrototype(BarSignComponent component, [NotNullWhen(true)] out BarSignPrototype?prototype)
 {
     if (component.CurrentSign != null)
     {
         if (_prototypeManager.TryIndex(component.CurrentSign, out prototype))
         {
             return(true);
         }
         Logger.ErrorS("barSign", $"Invalid bar sign prototype: \"{component.CurrentSign}\"");
     }
     else
     {
         prototype = null;
     }
     return(false);
 }
示例#5
0
        private BarSignPrototype Setup(EntityUid owner, BarSignComponent component)
        {
            var prototypes = _prototypeManager
                             .EnumeratePrototypes <BarSignPrototype>()
                             .Where(p => !p.Hidden)
                             .ToList();

            var newPrototype = _random.Pick(prototypes);

            var meta = Comp <MetaDataComponent>(owner);

            meta.EntityName        = newPrototype.Name != string.Empty ? newPrototype.Name : Loc.GetString("barsign-component-name");
            meta.EntityDescription = newPrototype.Description;

            component.CurrentSign = newPrototype.ID;
            return(newPrototype);
        }
示例#6
0
        private void UpdateBarSignVisuals(BarSignComponent component)
        {
            if (component.CurrentSign == null)
            {
                return;
            }

            if (!_prototypeManager.TryIndex(component.CurrentSign, out BarSignPrototype? prototype))
            {
                Logger.ErrorS("barSign", $"Invalid bar sign prototype: \"{component.CurrentSign}\"");
                return;
            }

            if (EntityManager.TryGetComponent(component.Owner, out SpriteComponent? sprite))
            {
                if (!EntityManager.TryGetComponent(component.Owner, out ApcPowerReceiverComponent? receiver) || !receiver.Powered)
                {
                    sprite.LayerSetState(0, "empty");
                    sprite.LayerSetShader(0, "shaded");
                }
                else
                {
                    sprite.LayerSetState(0, prototype.Icon);
                    sprite.LayerSetShader(0, "unshaded");
                }
            }

            if (!string.IsNullOrEmpty(prototype.Name))
            {
                EntityManager.GetComponent <MetaDataComponent>(component.Owner).EntityName = prototype.Name;
            }
            else
            {
                string val = Loc.GetString("barsign-component-name");
                EntityManager.GetComponent <MetaDataComponent>(component.Owner).EntityName = val;
            }

            EntityManager.GetComponent <MetaDataComponent>(component.Owner).EntityDescription = prototype.Description;
        }
示例#7
0
 private void OnPowerChanged(EntityUid uid, BarSignComponent component, PowerChangedEvent args)
 {
     UpdateBarSignVisuals(component);
 }
示例#8
0
 private void OnComponentInit(EntityUid uid, BarSignComponent component, ComponentInit args)
 {
     UpdateBarSignVisuals(component);
 }
示例#9
0
 public void SetBarSign(BarSignComponent component, string barSign)
 {
     component.CurrentSign = barSign;
     UpdateBarSignVisuals(component);
 }