private void GenerateAnimateForCategory(ICodeBlock currentBlock, string categoryName, List<Gum.DataTypes.Variables.StateSave> states)
        {
            string propertyToAssign;
            if (categoryName == "VariableState")
            {
                propertyToAssign = "this.CurrentVariableState";
            }
            else
            {
                propertyToAssign = "this.Current" + categoryName + "State";
            }
            currentBlock = currentBlock.Function("public void", "Animate",
                "System.Collections.Generic.IEnumerable<FlatRedBall.Gum.Keyframe<" + categoryName + ">> keyframes");
            {
                currentBlock.Line("bool isFirst = true;");
                currentBlock.Line("FlatRedBall.Gum.Keyframe<" + categoryName + "> lastKeyframe = null;");

                var foreachBlock = currentBlock.ForEach("var frame in keyframes");
                {
                    var ifBlock = foreachBlock.If("isFirst");
                    {
                        ifBlock.Line("isFirst = false;");
                        ifBlock.Line(propertyToAssign + " = frame.State;");

                    }
                    var elseBlock = ifBlock.End().Else();
                    {
                        elseBlock.Line("float timeToTake = frame.Time - lastKeyframe.Time;");
                        elseBlock.Line("var fromState = lastKeyframe.State;");
                        elseBlock.Line("var toState = frame.State;");
                        elseBlock.Line("var interpolationType = lastKeyframe.InterpolationType;");
                        elseBlock.Line("var easing = lastKeyframe.Easing;");

                        elseBlock.Line(
                            "System.Action action = () => this.InterpolateTo(fromState, toState, timeToTake, interpolationType, easing, {});");

                        elseBlock.Line(
                            "FlatRedBall.Instructions.DelegateInstruction instruction = new FlatRedBall.Instructions.DelegateInstruction(action);");
                        elseBlock.Line("instruction.Target = this;");
                        elseBlock.Line("instruction.TimeToExecute = FlatRedBall.TimeManager.CurrentTime + lastKeyframe.Time;");

                        elseBlock.Line("FlatRedBall.Instructions.InstructionManager.Instructions.Add(instruction);");
                    }

                    foreachBlock.Line("lastKeyframe = frame;");
                }
            }
        }
Beispiel #2
0
        private static ICodeBlock CreateAddToListCode(ICodeBlock codeBlock, string className)
        {
            codeBlock
            .ForEach("var list in ListsToAddTo")
            .If($"SortAxis == FlatRedBall.Math.Axis.X && list is PositionedObjectList<{className}>")
            .Line($"var index = (list as PositionedObjectList<{className}>).GetFirstAfter(x, Axis.X, 0, list.Count);")
            .Line($"list.Insert(index, instance);")
            .End().ElseIf($"SortAxis == FlatRedBall.Math.Axis.Y && list is PositionedObjectList<{className}>")
            .Line($"var index = (list as PositionedObjectList<{className}>).GetFirstAfter(y, Axis.Y, 0, list.Count);")
            .Line($"list.Insert(index, instance);")
            .End().Else()
            .Line("// Sort Z not supported")
            .Line("list.Add(instance);")
            .End()
            .End();

            return(codeBlock);
        }
Beispiel #3
0
        private static void GenerateInitializeAnimations(ICodeBlock function)
        {
            function.Line("// initialize the animations:");
            function.Line("Dictionary<string, FlatRedBall.Graphics.Animation.AnimationChain> animationDictionary = new Dictionary<string, FlatRedBall.Graphics.Animation.AnimationChain>();");

            var outerForEach = function.ForEach("var item in levelInfoObject as System.Collections.Generic.List<DataTypes.TileMapInfo>");

            {
                var ifBlock = outerForEach.If("item.EmbeddedAnimation != null && item.EmbeddedAnimation.Count != 0");
                {
                    ifBlock.Line("FlatRedBall.Graphics.Animation.AnimationChain newChain = new FlatRedBall.Graphics.Animation.AnimationChain();");
                    ifBlock.Line("newChain.Name = item.Name + \"Animation\";");

                    ifBlock.Line("animationDictionary.Add(item.Name, newChain);");


                    var innerForEach = ifBlock.ForEach("var frameSave in item.EmbeddedAnimation");
                    {
                        innerForEach.Line("var frame = new FlatRedBall.Graphics.Animation.AnimationFrame();");

                        innerForEach.Line("int index = 0;");

                        innerForEach.Line("int.TryParse(frameSave.TextureName, out index);");

                        innerForEach.Line("frame.Texture = CurrentTileMap.MapLayers[index].Texture;");

                        innerForEach.Line("frame.FrameLength = frameSave.FrameLength;");

                        innerForEach.Line("// We use pixel coords in the Save:");
                        innerForEach.Line("frame.LeftCoordinate = frameSave.LeftCoordinate / frame.Texture.Width;");
                        innerForEach.Line("frame.RightCoordinate = frameSave.RightCoordinate / frame.Texture.Width;");

                        innerForEach.Line("frame.TopCoordinate = frameSave.TopCoordinate / frame.Texture.Height;");
                        innerForEach.Line("frame.BottomCoordinate = frameSave.BottomCoordinate / frame.Texture.Height;");
                        innerForEach.Line("// finish others");

                        innerForEach.Line("newChain.Add(frame);");
                    }
                }
            }

            function.Line("CurrentTileMap.Animation = new FlatRedBall.TileGraphics.LayeredTileMapAnimation(animationDictionary);");
        }
        private static void GenerateInitializeAnimations(ICodeBlock function)
        {
            function.Line("// initialize the animations:");
            function.Line("Dictionary<string, FlatRedBall.Graphics.Animation.AnimationChain> animationDictionary = new Dictionary<string, FlatRedBall.Graphics.Animation.AnimationChain>();");

            var outerForEach = function.ForEach("var item in levelInfoObject as System.Collections.Generic.List<DataTypes.TileMapInfo>");
            {
                var ifBlock = outerForEach.If("item.EmbeddedAnimation != null && item.EmbeddedAnimation.Count != 0");
                {
                    ifBlock.Line("FlatRedBall.Graphics.Animation.AnimationChain newChain = new FlatRedBall.Graphics.Animation.AnimationChain();");
                    ifBlock.Line("newChain.Name = item.Name + \"Animation\";");

                    ifBlock.Line("animationDictionary.Add(item.Name, newChain);");


                    var innerForEach = ifBlock.ForEach("var frameSave in item.EmbeddedAnimation");
                    {
                        innerForEach.Line("var frame = new FlatRedBall.Graphics.Animation.AnimationFrame();");

                        innerForEach.Line("int index = 0;");

                        innerForEach.Line("int.TryParse(frameSave.TextureName, out index);");

                        innerForEach.Line("frame.Texture = CurrentTileMap.MapLayers[index].Texture;");

                        innerForEach.Line("frame.FrameLength = frameSave.FrameLength;");

                        innerForEach.Line("// We use pixel coords in the Save:");
                        innerForEach.Line("frame.LeftCoordinate = frameSave.LeftCoordinate / frame.Texture.Width;");
                        innerForEach.Line("frame.RightCoordinate = frameSave.RightCoordinate / frame.Texture.Width;");

                        innerForEach.Line("frame.TopCoordinate = frameSave.TopCoordinate / frame.Texture.Height;");
                        innerForEach.Line("frame.BottomCoordinate = frameSave.BottomCoordinate / frame.Texture.Height;");
                        innerForEach.Line("// finish others");

                        innerForEach.Line("newChain.Add(frame);");
                    }
                }
            }

            function.Line("CurrentTileMap.Animation = new FlatRedBall.TileGraphics.LayeredTileMapAnimation(animationDictionary);");
        }