Пример #1
0
        private static ICodeBlock AssignValuesUsingStartingValues(IElement element, ICodeBlock curBlock, Dictionary <InstructionSave, InterpolationCharacteristic> mInterpolationCharacteristics)
        {
            foreach (KeyValuePair <InstructionSave, InterpolationCharacteristic> kvp in mInterpolationCharacteristics)
            {
                if (kvp.Value != InterpolationCharacteristic.CantInterpolate)
                {
                    curBlock = curBlock.If("set" + kvp.Key.Member);

                    CustomVariable variable = element.GetCustomVariable(kvp.Key.Member);
                    var            nos      = element.GetNamedObjectRecursively(variable.SourceObject);

                    if (nos != null)
                    {
                        NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(curBlock, nos);
                    }

                    string relativeValue = InstructionManager.GetRelativeForAbsolute(kvp.Key.Member);

                    string variableToAssign = kvp.Key.Member;


                    string leftSideOfEqualsWithRelative = GetLeftSideOfEquals(element, variable, kvp.Key, true);

                    if (!string.IsNullOrEmpty(leftSideOfEqualsWithRelative) && leftSideOfEqualsWithRelative != kvp.Key.Member)
                    {
                        string beforeDotParent = variable.SourceObject;

                        if (string.IsNullOrEmpty(variable.SourceObject))
                        {
                            beforeDotParent = "this";
                        }

                        curBlock = curBlock.If(beforeDotParent + ".Parent != null");



                        AddAssignmentForInterpolationForVariable(curBlock, variable, variableToAssign, leftSideOfEqualsWithRelative);
                        curBlock = curBlock.End().Else();
                    }

                    AddAssignmentForInterpolationForVariable(curBlock, variable, variableToAssign, variableToAssign);

                    if (!string.IsNullOrEmpty(relativeValue))
                    {
                        curBlock = curBlock.End(); // end the else
                    }

                    curBlock = curBlock.End();
                    if (nos != null)
                    {
                        NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(curBlock, nos);
                    }
                }
            }
            return(curBlock);
        }
Пример #2
0
        private static string RelativeValueForInstruction(InstructionSave instruction, CustomVariable customVariable, IElement element)
        {
            if (!string.IsNullOrEmpty(customVariable.SourceObject))
            {
                string relativeMember = InstructionManager.GetRelativeForAbsolute(customVariable.SourceObjectProperty);

                return(relativeMember);
            }
            else
            {
                string relativeMember = null;

                if (element is EntitySave)
                {
                    relativeMember = InstructionManager.GetRelativeForAbsolute(instruction.Member);
                }
                return(relativeMember);
            }
        }
Пример #3
0
        private static void GenerateInterpolateForIndividualStateWithSource(ref ICodeBlock codeBlock, IElement element, ref ICodeBlock otherBlock, CustomVariable customVariable, string valueAsString, NamedObjectSave sourceNamedObjectSave, string timeCastString)
        {
            if (customVariable.GetIsVariableState())
            {
                GenerateInterpolateForIndividualStateWithSourceStateVariable(codeBlock, customVariable, element, valueAsString.Replace("\"", ""));
            }
            else
            {
                string velocityMember =
                    FlatRedBall.Instructions.InstructionManager.GetVelocityForState(customVariable.SourceObjectProperty);



                bool generatedVelocity = false;

                if (velocityMember == null &&
                    customVariable.HasAccompanyingVelocityProperty)
                {
                    velocityMember    = customVariable.Name + "Velocity";
                    generatedVelocity = true;
                }
                bool velocityComesFromTunnel = false;

                if (velocityMember == null &&
                    // Only want to go 1 deep.  The reason is if the tunneled variable has a
                    // velocity value, we can use that.  However, if it's tunneled multiple times
                    // into a variable that ultimately has a velocity variable we may not be able to
                    // get to it, so we shouldn't just assume we can add "Velocity" to the variable name.
                    customVariable.HasAccompanyingVelocityConsideringTunneling(element, 1))
                {
                    velocityMember          = customVariable.SourceObjectProperty + "Velocity";
                    generatedVelocity       = true;
                    velocityComesFromTunnel = true;
                }

                if (!string.IsNullOrEmpty(velocityMember))
                {
                    string sourceDot = customVariable.SourceObject + ".";

                    IEnumerable <string> exposableVariables =
                        FlatRedBall.Glue.Reflection.ExposedVariableManager.GetExposableMembersFor(sourceNamedObjectSave).Select(item => item.Member);

                    // We will generate this if the variable is contained in exposable variables,
                    // if the user explicitly said to generate a velocity variable, or if
                    // this is a FRB type. The reason we check if it's a FRB Type is because FRB
                    // types have velocity variables which may not be exposable. We don't want Glue
                    // to mess with temporary values like Velocity, so they are removed from the exposab
                    // variable list:
                    bool shouldGenerate = exposableVariables.Contains(velocityMember) ||
                                          generatedVelocity ||
                                          sourceNamedObjectSave.SourceType == SourceType.FlatRedBallType;


                    if (shouldGenerate)
                    {
                        string relativeVelocity = InstructionManager.GetRelativeForAbsolute(velocityMember);

                        string leftHandPlusEquals = null;

                        if (!string.IsNullOrEmpty(relativeVelocity))
                        {
                            codeBlock = codeBlock
                                        .If(customVariable.SourceObject + ".Parent != null");

                            otherBlock = otherBlock
                                         .If(customVariable.SourceObject + ".Parent != null");

                            string sourceObjectPropertyRelative = InstructionManager.GetRelativeForAbsolute(customVariable.SourceObjectProperty);

                            leftHandPlusEquals = sourceDot + relativeVelocity + " = ";

                            codeBlock.Line(leftHandPlusEquals + "(" + valueAsString + " - " + sourceDot +
                                           sourceObjectPropertyRelative + ") / " + timeCastString +
                                           "secondsToTake;");

                            otherBlock.Line(leftHandPlusEquals + " 0;");

                            codeBlock = codeBlock
                                        .End()
                                        .Else();

                            otherBlock = otherBlock
                                         .End()
                                         .Else();
                        }

                        // If we're using a custom velocity value, we don't want to
                        // use the sourceDot.  We just want to use the velocity value
                        if (generatedVelocity && !velocityComesFromTunnel)
                        {
                            leftHandPlusEquals = velocityMember + " = ";
                        }
                        else
                        {
                            leftHandPlusEquals = sourceDot + velocityMember + " = ";
                        }
                        codeBlock.Line(leftHandPlusEquals + "(" + valueAsString + " - " + sourceDot +
                                       customVariable.SourceObjectProperty + ") / " + timeCastString +
                                       "secondsToTake;");

                        otherBlock.Line(leftHandPlusEquals + " 0;");

                        if (!string.IsNullOrEmpty(relativeVelocity))
                        {
                            codeBlock  = codeBlock.End();
                            otherBlock = otherBlock.End();
                        }
                    }
                }
            }
        }
Пример #4
0
        private static void GenerateInterpolateForIndividualStateNoSource(ref ICodeBlock codeBlock, IElement element, ref ICodeBlock otherBlock, InstructionSave instruction, CustomVariable customVariable, string valueAsString, string timeCastString)
        {
            string velocityMember =
                FlatRedBall.Instructions.InstructionManager.GetVelocityForState(instruction.Member);

            // If the velocityMember exists, we need to make sure it's actually exposable
            if (!ExposedVariableManager.GetExposableMembersFor(element, false).Any(item => item.Member == velocityMember))
            {
                velocityMember = null;
            }

            if (velocityMember == null && customVariable.HasAccompanyingVelocityProperty)
            {
                velocityMember = customVariable.Name + "Velocity";
            }

            if (!string.IsNullOrEmpty(velocityMember))
            {
                string relativeVelocity = InstructionManager.GetRelativeForAbsolute(velocityMember);

                string leftHandPlusEquals = null;

                if (!string.IsNullOrEmpty(relativeVelocity))
                {
                    codeBlock = codeBlock
                                .If("this.Parent != null");

                    otherBlock = otherBlock
                                 .If("this.Parent != null");

                    string instructionMemberRelative = InstructionManager.GetRelativeForAbsolute(instruction.Member);

                    leftHandPlusEquals = relativeVelocity + " = ";

                    codeBlock.Line(leftHandPlusEquals + "(" + valueAsString + " - " +
                                   instructionMemberRelative + ") / " + timeCastString + "secondsToTake;");

                    otherBlock.Line(leftHandPlusEquals + " 0;");

                    codeBlock = codeBlock
                                .End()
                                .Else();

                    otherBlock = otherBlock
                                 .End()
                                 .Else();
                }
                leftHandPlusEquals = velocityMember + " = ";

                codeBlock.Line(leftHandPlusEquals + "(" + valueAsString + " - " + instruction.Member +
                               ") / " + timeCastString + "secondsToTake;");

                otherBlock.Line(leftHandPlusEquals + " 0;");

                if (!string.IsNullOrEmpty(relativeVelocity))
                {
                    codeBlock  = codeBlock.End();
                    otherBlock = otherBlock.End();
                }
            }
        }