コード例 #1
0
        public override void Initialize()
        {
            base.Initialize();

            _sprite   = Owner.GetComponent <ISpriteComponent>();
            _snapGrid = Owner.GetComponent <SnapGridComponent>();
        }
コード例 #2
0
    private Animation GetStopAnimation(OrbitVisualsComponent component, ISpriteComponent sprite)
    {
        var length = component.OrbitStopLength;

        return(new Animation()
        {
            Length = TimeSpan.FromSeconds(length),
            AnimationTracks =
            {
                new AnimationTrackComponentProperty()
                {
                    ComponentType = typeof(ISpriteComponent),
                    Property = nameof(ISpriteComponent.Offset),
                    KeyFrames =
                    {
                        new AnimationTrackProperty.KeyFrame(sprite.Offset,     0f),
                        new AnimationTrackProperty.KeyFrame(Vector2.Zero,  length),
                    },
                    InterpolationMode = AnimationInterpolationMode.Linear
                },
                new AnimationTrackComponentProperty()
                {
                    ComponentType = typeof(ISpriteComponent),
                    Property = nameof(ISpriteComponent.Rotation),
                    KeyFrames =
                    {
                        new AnimationTrackProperty.KeyFrame(sprite.Rotation.Reduced(),     0f),
                        new AnimationTrackProperty.KeyFrame(Angle.Zero,                length),
                    },
                    InterpolationMode = AnimationInterpolationMode.Linear
                }
            }
        });
    }
コード例 #3
0
        public bool CheckDirBound(ISpriteComponent sprite, Angle relativeRotation, Vector2 localPos)
        {
            if (Bounds == null)
            {
                return(false);
            }

            // These explicit bounds only work for either 1 or 4 directional sprites.

            // This would be the orientation of a 4-directional sprite.
            var direction = relativeRotation.GetCardinalDir();

            var modLocalPos = sprite.NoRotation
                ? localPos
                : direction.ToAngle().RotateVec(localPos);

            // First, check the bounding box that is valid for all orientations
            if (Bounds.All.Contains(modLocalPos))
            {
                return(true);
            }

            // Next, get and check the appropriate bounding box for the current sprite orientation
            var boundsForDir = (sprite.EnableDirectionOverride ? sprite.DirectionOverride : direction) switch
            {
                Direction.East => Bounds.East,
                Direction.North => Bounds.North,
                Direction.South => Bounds.South,
                Direction.West => Bounds.West,
                _ => throw new InvalidOperationException()
            };

            return(boundsForDir.Contains(modLocalPos));
        }
コード例 #4
0
        private void HideLayers(ISpriteComponent spriteComponent)
        {
            foreach (var layer in spriteComponent.AllLayers)
            {
                layer.Visible = false;
            }

            spriteComponent.LayerSetVisible(VendingMachineVisualLayers.Unlit, true);
        }
コード例 #5
0
        private void ActivateAnimation(ISpriteComponent spriteComponent, AnimationPlayerComponent animationPlayer, string key)
        {
            if (!_animations.TryGetValue(key, out var animation))
            {
                return;
            }

            if (!animationPlayer.HasRunningAnimation(key))
            {
                spriteComponent.LayerSetVisible(LayerMap[key], true);
                animationPlayer.Play(animation, key);
            }
        }
コード例 #6
0
        // Helper methods just to avoid all of that hard-to-read-indented code
        private void ActivateState(ISpriteComponent spriteComponent, string stateId)
        {
            // No state for it on the rsi :(
            if (!_baseStates[stateId])
            {
                return;
            }

            var stateLayer = LayerMap[stateId];

            spriteComponent.LayerSetVisible(stateLayer, true);
            spriteComponent.LayerSetState(stateLayer, stateId);
        }
コード例 #7
0
        private void UpdateAppearance(AppearanceComponent component, ISpriteComponent sprite)
        {
            var state = _stateOff;

            if (component.TryGetData(ConveyorVisuals.State, out ConveyorState conveyorState) && conveyorState != ConveyorState.Off)
            {
                state = _stateOn;
            }

            if (component.TryGetData(RecyclerVisuals.Bloody, out bool bloody) && bloody)
            {
                state += "bld";
            }

            sprite.LayerSetState(RecyclerVisualLayers.Main, state);
        }
コード例 #8
0
        private Animation GetAnimation(JitteringComponent jittering, ISpriteComponent sprite)
        {
            var amplitude = MathF.Min(4f, jittering.Amplitude / 100f + 1f) / 10f;
            var offset    = new Vector2(_random.NextFloat(amplitude / 4f, amplitude),
                                        _random.NextFloat(amplitude / 4f, amplitude / 3f));

            offset.X *= _random.Pick(_sign);
            offset.Y *= _random.Pick(_sign);

            if (Math.Sign(offset.X) == Math.Sign(jittering.LastJitter.X) ||
                Math.Sign(offset.Y) == Math.Sign(jittering.LastJitter.Y))
            {
                // If the sign is the same as last time on both axis we flip one randomly
                // to avoid jitter staying in one quadrant too much.
                if (_random.Prob(0.5f))
                {
                    offset.X *= -1;
                }
                else
                {
                    offset.Y *= -1;
                }
            }

            // Animation length shouldn't be too high so we will cap it at 2 seconds...
            var length = Math.Min((1f / jittering.Frequency), 2f);

            jittering.LastJitter = offset;

            return(new Animation()
            {
                Length = TimeSpan.FromSeconds(length),
                AnimationTracks =
                {
                    new AnimationTrackComponentProperty()
                    {
                        ComponentType = typeof(ISpriteComponent),
                        Property = nameof(ISpriteComponent.Offset),
                        KeyFrames =
                        {
                            new AnimationTrackProperty.KeyFrame(sprite.Offset,     0f),
                            new AnimationTrackProperty.KeyFrame(offset,        length),
                        }
                    }
                }
            });
        }
コード例 #9
0
        public override void Initialize()
        {
            base.Initialize();

            var state0 = $"{StateBase}0";

            SnapGrid = Owner.GetComponent <SnapGridComponent>();
            Sprite   = Owner.GetComponent <ISpriteComponent>();
            Sprite.LayerMapSet(CornerLayers.SE, Sprite.AddLayerState(state0));
            Sprite.LayerSetDirOffset(CornerLayers.SE, DirectionOffset.None);
            Sprite.LayerMapSet(CornerLayers.NE, Sprite.AddLayerState(state0));
            Sprite.LayerSetDirOffset(CornerLayers.NE, DirectionOffset.CounterClockwise);
            Sprite.LayerMapSet(CornerLayers.NW, Sprite.AddLayerState(state0));
            Sprite.LayerSetDirOffset(CornerLayers.NW, DirectionOffset.Flip);
            Sprite.LayerMapSet(CornerLayers.SW, Sprite.AddLayerState(state0));
            Sprite.LayerSetDirOffset(CornerLayers.SW, DirectionOffset.Clockwise);
        }
コード例 #10
0
        protected override void Startup()
        {
            base.Startup();

            _overlayEntity = Owner.EntityManager.SpawnEntity("LowWallOverlay", Owner.Transform.Coordinates);
            _overlayEntity.Transform.AttachParent(Owner);

            _overlaySprite = _overlayEntity.GetComponent <ISpriteComponent>();

            var overState0 = $"{StateBase}over_0";

            _overlaySprite.LayerMapSet(OverCornerLayers.SE, _overlaySprite.AddLayerState(overState0));
            _overlaySprite.LayerSetDirOffset(OverCornerLayers.SE, DirectionOffset.None);
            _overlaySprite.LayerMapSet(OverCornerLayers.NE, _overlaySprite.AddLayerState(overState0));
            _overlaySprite.LayerSetDirOffset(OverCornerLayers.NE, DirectionOffset.CounterClockwise);
            _overlaySprite.LayerMapSet(OverCornerLayers.NW, _overlaySprite.AddLayerState(overState0));
            _overlaySprite.LayerSetDirOffset(OverCornerLayers.NW, DirectionOffset.Flip);
            _overlaySprite.LayerMapSet(OverCornerLayers.SW, _overlaySprite.AddLayerState(overState0));
            _overlaySprite.LayerSetDirOffset(OverCornerLayers.SW, DirectionOffset.Clockwise);
        }