Esempio n. 1
0
        /// <summary>
        ///     Play an audio file globally, without position.
        /// </summary>
        /// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
        /// <param name="audioParams"></param>
        public IPlayingAudioStream?Play(string filename, AudioParams?audioParams = null)
        {
            if (_resourceCache.TryGetResource <AudioResource>(new ResourcePath(filename), out var audio))
            {
                return(Play(audio, audioParams));
            }

            Logger.Error($"Server tried to play audio file {filename} which does not exist.");
            return(default);
        /// <inheritdoc />
        public override void Load(IResourceCache cache, string path, Stream stream)
        {
            if (!cache.TryGetResource(path, out TextureResource res))
            {
                res = new TextureResource();
                res.Load(cache, path, stream);
                cache.CacheResource(path, res);
            }

            Sprite = new Sprite(res.Texture);
        }
Esempio n. 3
0
    public RSI.State GetState(SpriteSpecifier.Rsi rsiSpecifier)
    {
        if (_resourceCache.TryGetResource <RSIResource>(
                SharedSpriteComponent.TextureRoot / rsiSpecifier.RsiPath,
                out var theRsi) &&
            theRsi.RSI.TryGetState(rsiSpecifier.RsiState, out var state))
        {
            return(state);
        }

        Logger.Error("Failed to load RSI {0}", rsiSpecifier.RsiPath);
        return(SpriteComponent.GetFallbackState(_resourceCache));
    }
        public Sprite GetDirectionalSprite()
        {
            Sprite spriteToUse = CurrentBaseSprite;

            if (CurrentBaseSprite == null)
            {
                return(null);
            }

            string dirName = (CurrentBaseSpriteKey + "_" + Direction).ToLowerInvariant();

            if (ResourceCache.TryGetResource(dirName, out SpriteResource spriteRes))
            {
                spriteToUse = spriteRes.Sprite;
            }

            return(spriteToUse);
        }
        public TextureResource GetDirectionalSprite()
        {
            var spriteToUse = CurrentBaseSprite;

            if (CurrentBaseSprite == null)
            {
                return(null);
            }

            string dirName = (CurrentBaseSpriteKey + "_" + Direction).ToLowerInvariant();

            if (ResourceCache.TryGetResource <TextureResource>(dirName, out var spriteRes))
            {
                return(spriteRes);
            }

            return(spriteToUse);
        }
Esempio n. 6
0
    private void OnInit(EntityUid uid, PipeAppearanceComponent component, ComponentInit args)
    {
        if (!TryComp(uid, out SpriteComponent? sprite))
        {
            return;
        }

        if (!_resCache.TryGetResource(SharedSpriteComponent.TextureRoot / component.RsiPath, out RSIResource? rsi))
        {
            Logger.Error($"{nameof(AtmosPipeAppearanceSystem)} could not load to load RSI {component.RsiPath}.");
            return;
        }

        foreach (PipeConnectionLayer layerKey in Enum.GetValues(typeof(PipeConnectionLayer)))
        {
            sprite.LayerMapReserveBlank(layerKey);
            var layer = sprite.LayerMapGet(layerKey);
            sprite.LayerSetRSI(layer, rsi.RSI);
            var layerState = component.State;
            sprite.LayerSetState(layer, layerState);
            sprite.LayerSetDirOffset(layer, ToOffset(layerKey));
        }
    }
        public override void OnChangeData(AppearanceComponent component)
        {
            // only start playing animations once.
            if (!_gameTiming.IsFirstTimePredicted)
            {
                return;
            }

            base.OnChangeData(component);

            var sprite     = _entMan.GetComponent <ISpriteComponent>(component.Owner);
            var animPlayer = _entMan.GetComponent <AnimationPlayerComponent>(component.Owner);

            if (!component.TryGetData(DoorVisuals.State, out DoorState state))
            {
                state = DoorState.Closed;
            }

            var door                   = _entMan.GetComponent <DoorComponent>(component.Owner);
            var unlitVisible           = true;
            var boltedVisible          = false;
            var emergencyLightsVisible = false;

            if (component.TryGetData(DoorVisuals.BaseRSI, out string baseRsi))
            {
                if (!_resourceCache.TryGetResource <RSIResource>(SharedSpriteComponent.TextureRoot / baseRsi, out var res))
                {
                    Logger.Error("Unable to load RSI '{0}'. Trace:\n{1}", baseRsi, Environment.StackTrace);
                }
                foreach (ISpriteLayer layer in sprite.AllLayers)
                {
                    layer.Rsi = res?.RSI;
                }
            }

            if (animPlayer.HasRunningAnimation(AnimationKey))
            {
                animPlayer.Stop(AnimationKey);
            }
            switch (state)
            {
            case DoorState.Open:
                sprite.LayerSetState(DoorVisualLayers.Base, "open");
                unlitVisible = _openUnlitVisible;
                if (_openUnlitVisible && !_simpleVisuals)
                {
                    sprite.LayerSetState(DoorVisualLayers.BaseUnlit, "open_unlit");
                }
                break;

            case DoorState.Closed:
                sprite.LayerSetState(DoorVisualLayers.Base, "closed");
                if (!_simpleVisuals)
                {
                    sprite.LayerSetState(DoorVisualLayers.BaseUnlit, "closed_unlit");
                    sprite.LayerSetState(DoorVisualLayers.BaseBolted, "bolted_unlit");
                }
                break;

            case DoorState.Opening:
                animPlayer.Play(OpenAnimation, AnimationKey);
                break;

            case DoorState.Closing:
                if (door.CurrentlyCrushing.Count == 0)
                {
                    animPlayer.Play(CloseAnimation, AnimationKey);
                }
                else
                {
                    sprite.LayerSetState(DoorVisualLayers.Base, "closed");
                }
                break;

            case DoorState.Denying:
                animPlayer.Play(DenyAnimation, AnimationKey);
                break;

            case DoorState.Welded:
                break;

            case DoorState.Emagging:
                animPlayer.Play(EmaggingAnimation, AnimationKey);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (component.TryGetData(DoorVisuals.Powered, out bool powered) && !powered)
            {
                unlitVisible = false;
            }
            if (component.TryGetData(DoorVisuals.BoltLights, out bool lights) && lights)
            {
                boltedVisible = true;
            }

            if (component.TryGetData(DoorVisuals.EmergencyLights, out bool eaLights) && eaLights)
            {
                emergencyLightsVisible = true;
            }

            if (!_simpleVisuals)
            {
                sprite.LayerSetVisible(DoorVisualLayers.BaseUnlit, unlitVisible && state != DoorState.Closed && state != DoorState.Welded);
                sprite.LayerSetVisible(DoorVisualLayers.BaseBolted, unlitVisible && boltedVisible);
                if (_emergencyAccessLayer)
                {
                    sprite.LayerSetVisible(DoorVisualLayers.BaseEmergencyAccess,
                                           emergencyLightsVisible &&
                                           state != DoorState.Open &&
                                           state != DoorState.Opening &&
                                           state != DoorState.Closing &&
                                           unlitVisible);
                }
            }
        }