示例#1
0
        public static InstructionSave SetPropertyValue(this NamedObjectSave instance, string propertyName, object valueToSet)
        {
            InstructionSave instruction = instance.GetInstructionFromMember(propertyName);

            if (instruction == null)
            {
                TypedMemberBase tmb = instance.TypedMembers.FirstOrDefault(member => member.MemberName == propertyName);

                if (tmb != null)
                {
                    instruction = instance.AddNewGenericInstructionFor(propertyName, tmb.MemberType);
                }
                else
                {
                    instruction = instance.AddNewGenericInstructionFor(propertyName, valueToSet.GetType());
                }

                if (tmb.CustomTypeName != null)
                {
                    instruction.Type = tmb.CustomTypeName;
                }
            }

            instruction.Value = valueToSet;
            return(instruction);
        }
        public static StateSave CreateCombinedState(StateSave firstState, StateSave secondState, float interpolationValue)
        {
            StateSave stateSave = new StateSave();


            float firstPercentage  = 1 - interpolationValue;// PercentageTrackBar.Value / 100.0f;
            float secondPercentage = interpolationValue;

            foreach (InstructionSave instruction in firstState.InstructionSaves)
            {
                // Does the 2nd also have this?
                InstructionSave matchingInstruction = secondState.GetInstruction(instruction.Member);

                if (matchingInstruction != null)
                {
                    InstructionSave combinedInstruction = instruction.Clone();

                    object value = null;

                    if (combinedInstruction.Value is int)
                    {
                        value = (int)((int)instruction.Value * firstPercentage + (int)matchingInstruction.Value * secondPercentage);
                    }
                    else if (combinedInstruction.Value is float)
                    {
                        value = (float)((float)instruction.Value * firstPercentage + (float)matchingInstruction.Value * secondPercentage);
                    }
                    else if (combinedInstruction.Value is double)
                    {
                        value = (double)((double)instruction.Value * firstPercentage + (double)matchingInstruction.Value * secondPercentage);
                    }
                    else if (combinedInstruction.Value is long)
                    {
                        value = (long)((long)instruction.Value * firstPercentage + (long)matchingInstruction.Value * secondPercentage);
                    }
                    else
                    {
                        if (secondPercentage == 1.0f)
                        {
                            value = matchingInstruction.Value;
                        }
                        else
                        {
                            value = instruction.Value;
                        }
                    }

                    combinedInstruction.Value = value;

                    stateSave.InstructionSaves.Add(combinedInstruction);
                }
            }



            return(stateSave);
        }
示例#3
0
        public object GetVariable(string variableName)
        {
            InstructionSave instructionSave = Variables.FirstOrDefault(item => item.Member == variableName);

            if (instructionSave != null)
            {
                return(instructionSave.Value);
            }

            return(null);
        }
示例#4
0
        public object GetPropertyValue(string propertyName)
        {
            InstructionSave instruction = GetInstructionFromMember(propertyName);

            if (instruction == null)
            {
                return(null);
            }
            else
            {
                return(instruction.Value);
            }
        }
示例#5
0
        public void AddVariable(InstructionSave instructionSave,
                                NamedObjectSave namedObjectSave, string rootName, string category)
        {
            if (variableDictionary.ContainsKey(category) == false)
            {
                variableDictionary[category] = new List <GlueVariableData>();
            }

            var data = new GlueVariableData();

            data.InstructionSave = instructionSave;
            data.NamedObjectSave = namedObjectSave;
            data.RootName        = rootName;
            variableDictionary[category].Add(data);
        }
示例#6
0
        public void SetVariable(string variableName, object value)
        {
            InstructionSave instructionSave = Variables.FirstOrDefault(item => item.Member == variableName);

            if (instructionSave == null)
            {
                instructionSave        = new InstructionSave();
                instructionSave.Member = variableName;
                Variables.Add(instructionSave);

                instructionSave.Type = value.GetType().Name;
            }

            instructionSave.Value = value;
        }
        public void SetVariable(string variableName, object value)
        {
            InstructionSave instructionSave = Variables.FirstOrDefault(item => item.Member == variableName);

            if (instructionSave == null)
            {
                instructionSave = new InstructionSave();
                instructionSave.Member = variableName;
                Variables.Add(instructionSave);

                instructionSave.Type = value.GetType().Name;
            }

            instructionSave.Value = value;
        }
        bool TryAdd(string memberName, string type, object defaultValue, CustomClassSave tileMapInfoClass)
        {
            bool shouldAdd = tileMapInfoClass.RequiredProperties.Any(item => item.Member == memberName) == false;

            if (shouldAdd)
            {
                InstructionSave instruction = new InstructionSave();
                instruction.Member = memberName;
                instruction.Type   = type;
                instruction.Value  = null;
                tileMapInfoClass.RequiredProperties.Add(instruction);
            }

            return(shouldAdd);
        }
示例#9
0
        private void CreateContainerEntityState()
        {
            StateSave stateSave = new StateSave();

            stateSave.Name = "SetContainedFirstState";

            InstructionSave instructionSave = new InstructionSave();

            instructionSave.Type   = "VariableState";
            instructionSave.Value  = "FirstState";
            instructionSave.Member = "StateTunnelVariable";

            stateSave.InstructionSaves.Add(instructionSave);

            mContainer.States.Add(stateSave);
        }
示例#10
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);
            }
        }
示例#11
0
        private void CreateEntitySaveState()
        {
            StateSave stateSave = new StateSave();

            stateSave.Name = "FirstState";

            InstructionSave instructionSave = new InstructionSave();

            instructionSave.Member = "X";
            instructionSave.Value  = 10.0f;
            stateSave.InstructionSaves.Add(instructionSave);

            instructionSave        = new InstructionSave();
            instructionSave.Member = "SpriteScaleX";
            instructionSave.Value  = 4.0f;
            stateSave.InstructionSaves.Add(instructionSave);

            mEntitySave.States.Add(stateSave);
        }
示例#12
0
        public void SortInstructionSaves(List <CustomVariable> customVariables)
        {
            int insertLocation = 0;

            for (int i = InstructionSaves.Count - 1; i > -1; i--)
            {
                InstructionSave instruction = InstructionSaves[i];
                bool            wasFound    = false;
                for (int j = 0; j < customVariables.Count; j++)
                {
                    if (customVariables[j].Name == instruction.Member)
                    {
                        wasFound = true;
                        break;
                    }
                }

                if (!wasFound)
                {
                    InstructionSaves.RemoveAt(i);
                }
            }


            for (int i = 0; i < customVariables.Count; i++)
            {
                string name = customVariables[i].Name;

                for (int j = insertLocation; j < InstructionSaves.Count; j++)
                {
                    InstructionSave instruction = InstructionSaves[j];

                    if (instruction.Member == name)
                    {
                        InstructionSaves.Remove(instruction);
                        InstructionSaves.Insert(insertLocation, instruction);
                        insertLocation++;
                        break;
                    }
                }
            }
        }
        public static void HandleWriteInstanceVariableAssignment(NamedObjectSave instance, ICodeBlock code, InstructionSave variable)
        {
            var shouldHandle = variable.Member == "AtlasedTexture" && instance.SourceClassType == "Sprite";

            if(shouldHandle)
            {
                var memberName = instance.InstanceName;

                // The code should look something like:
                // 
                // SpriteInstance.AtlasedTexture = FlatRedBall.Graphics.Texture.AtlasLoader.LoadAtlasedTexture("asdf");
                //
                // But I still need to make the AtlasLoader keep track of all loaded assets, and I need to have a "priority" system

                code = code.Block();
                {
                    // eventually this might exist
                    //var atlas = instance.GetInstructionFromMember("");
                    // for now we assume that the texture packer project is in global content
                    var rfs = GlueState.Self.CurrentGlueProject.GlobalFiles.FirstOrDefault(item =>
                    {
                        var ati = item.GetAssetTypeInfo();
                        if(ati != null)
                        {
                            return ati == AtiManager.Self.TextureAtlasAti;
                        }

                        return false;
                    });

                    if (rfs != null)
                    {
                        var atlas = $"{GlueState.Self.ProjectNamespace}.GlobalContent.{rfs.GetInstanceName()}";
                        code.Line($"var atlas = {atlas};");

                        code.Line($"{memberName}.AtlasedTexture = atlas.Sprite(\"{variable.Value}\");");
                    }
                }
            }
        }
示例#14
0
        public void Test()
        {
            StateSave       firstState      = new StateSave();
            InstructionSave instructionSave = new InstructionSave();

            instructionSave.Type   = "float";
            instructionSave.Value  = 0.0f;
            instructionSave.Member = "X";
            firstState.InstructionSaves.Add(instructionSave);

            StateSave secondState = new StateSave();

            instructionSave       = instructionSave.Clone();
            instructionSave.Value = 10.0f;
            secondState.InstructionSaves.Add(instructionSave);


            StateSave combined = StateSaveExtensionMethodsGlueView.CreateCombinedState(firstState, secondState, .5f);

            if (MathFunctions.RoundToInt((float)combined.InstructionSaves[0].Value) != 5)
            {
                throw new Exception("CreateCombined is not properly combining States");
            }
        }
示例#15
0
        public static CustomVariable GetCustomVariableFromNosOrElement(ElementRuntime elementRuntime, string variableName)
        {
            CustomVariable variable = elementRuntime.AssociatedIElement.GetCustomVariableRecursively(variableName);



            if (variable != null)
            {
                // The NOS may be overwriting the value from the element, so we need to set that if so:
                if (elementRuntime.AssociatedNamedObjectSave != null)
                {
                    NamedObjectSave nos = elementRuntime.AssociatedNamedObjectSave;

                    InstructionSave instruction = nos.GetInstructionFromMember(variable.Name);

                    if (instruction != null && instruction.Value != null)
                    {
                        variable = variable.Clone();
                        variable.DefaultValue = instruction.Value;
                    }
                }
            }
            return(variable);
        }
示例#16
0
        private void AddGumVariables(InstructionSave glueVariable, NamedObjectSave namedObject,
                                     GlueElement glueElement,
                                     List <VariableSave> gumVariables,
                                     List <VariableListSave> gumVariableLists,
                                     VariableGroupDictionary variableGroups, bool isInState = false)
        {
            string glueVariableName = glueVariable.Member;

            if (isInState)
            {
                // It's a state variable so it references a different variable that we have to find:
                var variableOnElement = glueElement.GetCustomVariable(glueVariable.Member);

                if (variableOnElement != null)
                {
                    glueVariableName = variableOnElement.SourceObjectProperty;
                }


                if (!string.IsNullOrEmpty(variableOnElement.SourceObject))
                {
                    namedObject = glueElement.AllNamedObjects
                                  .FirstOrDefault(item => item.InstanceName == variableOnElement.SourceObject);
                }
            }

            // Let's be explicit instead of expecting the names to match up:
            switch (glueVariableName)
            {
            case "Height":
            {
                var variableSave = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Height";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value;
                gumVariables.Add(variableSave);
            }
            break;

            case "Points":
            {
                var variableListSave = new VariableListSave <Vector2>();
                variableListSave.Name = $"{namedObject.InstanceName}.Points";

                var pointsPositiveYUp = glueVariable.Value as List <Vector2>;



                if (pointsPositiveYUp != null)
                {
                    foreach (var frbPoint in pointsPositiveYUp)
                    {
                        var newPoint = frbPoint;
                        newPoint.Y *= -1;

                        variableListSave.ValueAsIList.Add(newPoint);
                    }
                }
                gumVariableLists.Add(variableListSave);
            }
            break;

            case "Radius":
            {
                if (namedObject.SourceType == SourceType.FlatRedBallType && namedObject.SourceClassType == "Circle")
                {
                    var variableSave = new VariableSave();
                    variableSave.Name  = $"{namedObject.InstanceName}.Width";
                    variableSave.Type  = "float";
                    variableSave.Value = (float)glueVariable.Value * 2.0f;
                    variableSave.IsHiddenInPropertyGrid = true;
                    gumVariables.Add(variableSave);

                    variableSave       = new VariableSave();
                    variableSave.Name  = $"{namedObject.InstanceName}.Height";
                    variableSave.Type  = "float";
                    variableSave.Value = (float)glueVariable.Value * 2.0f;
                    variableSave.IsHiddenInPropertyGrid = true;
                    gumVariables.Add(variableSave);


                    variableSave       = new VariableSave();
                    variableSave.Name  = $"{namedObject.InstanceName}.Radius";
                    variableSave.Type  = "float";
                    variableSave.Value = (float)glueVariable.Value;
                    gumVariables.Add(variableSave);
                }
            }
            break;

            case "RotationZ":
            {
                var variableSave = new VariableSave();
                variableSave.Name = $"{namedObject.InstanceName}.Rotation";
                variableSave.Type = "float";
                var valueRadians = (float)glueVariable.Value;
                var degrees      = 360 * (valueRadians / (2 * Math.PI));
                variableSave.Value = (float)degrees;
                gumVariables.Add(variableSave);
            }

            break;

            case "RightTexturePixel":
            case "LeftTexturePixel":
            case "BottomTexturePixel":
            case "TopTexturePixel":
                variableGroups.AddVariable(glueVariable, namedObject,
                                           glueVariableName, GlueToGumTextureCoordinateConversionLogic.TextureCoordinatesCategory);
                break;

            case "Texture":
            {
                var variableSave = new VariableSave();
                variableSave.Name = $"{namedObject.InstanceName}.SourceFile";
                variableSave.Type = "string";

                //var referencedFileName = (string)glueVariable.Value;
                //var nos = glueElement.GetReferencedFileSave(referencedFileName);

                //if(nos == null)
                //{
                //    // todo - need to look in global content;
                //}

                // assume the content location is in a monogame DGL location, and the
                // file is a PNG. Eventually we can make this more intelligent
                var fileName = $"../Content/{glueElement.Name}/{(string)glueVariable.Value}.png";

                variableSave.Value  = fileName;
                variableSave.IsFile = true;
                gumVariables.Add(variableSave);

                variableGroups.AddVariable(glueVariable, namedObject, glueVariableName,
                                           GlueToGumTextureCoordinateConversionLogic.TextureCoordinatesCategory);
            }
            break;

            case "TextureScale":
            {
                var variableSave = new VariableSave();

                variableSave       = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Width";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value * 100;
                gumVariables.Add(variableSave);


                variableSave       = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Height";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value * 100;
                gumVariables.Add(variableSave);

                // todo width units?
            }
            break;

            case "X":
            {
                VariableSave variableSave = null;
                variableSave       = new VariableSave();
                variableSave.Type  = "float";
                variableSave.Name  = $"{namedObject.InstanceName}.X";
                variableSave.Value = (float)glueVariable.Value;
                gumVariables.Add(variableSave);
            }
            break;

            case "Width":
            {
                var variableSave = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Width";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value;
                gumVariables.Add(variableSave);
            }
            break;

            case "Y":
            {
                var variableSave = new VariableSave();
                variableSave.Name  = $"{namedObject.InstanceName}.Y";
                variableSave.Type  = "float";
                variableSave.Value = (float)glueVariable.Value;
                gumVariables.Add(variableSave);
            }
            break;

            default:
                int m = 3;
                break;
            }
        }
示例#17
0
        public void Test()
        {
            StateSave firstState = new StateSave();
            InstructionSave instructionSave = new InstructionSave();
            instructionSave.Type = "float";
            instructionSave.Value = 0.0f;
            instructionSave.Member = "X";
            firstState.InstructionSaves.Add(instructionSave);

            StateSave secondState = new StateSave();
            instructionSave = instructionSave.Clone();
            instructionSave.Value = 10.0f;
            secondState.InstructionSaves.Add(instructionSave);


            StateSave combined = StateSaveExtensionMethodsGlueView.CreateCombinedState(firstState, secondState, .5f);

            if (MathFunctions.RoundToInt((float)combined.InstructionSaves[0].Value) != 5)
            {
                throw new Exception("CreateCombined is not properly combining States");
            }
        }
示例#18
0
        private void CreateEntitySaveState()
        {
            StateSave stateSave = new StateSave();
            stateSave.Name = "FirstState";

            InstructionSave instructionSave = new InstructionSave();
            instructionSave.Member = "X";
            instructionSave.Value = 10.0f;
            stateSave.InstructionSaves.Add(instructionSave);

            instructionSave = new InstructionSave();
            instructionSave.Member = "SpriteScaleX";
            instructionSave.Value = 4.0f;
            stateSave.InstructionSaves.Add(instructionSave);

            mEntitySave.States.Add(stateSave);

        }
示例#19
0
        private void CreateContainerEntityState()
        {
            StateSave stateSave = new StateSave();
            stateSave.Name = "SetContainedFirstState";

            InstructionSave instructionSave = new InstructionSave();
            instructionSave.Type = "VariableState";
            instructionSave.Value = "FirstState";
            instructionSave.Member = "StateTunnelVariable";

            stateSave.InstructionSaves.Add(instructionSave);

            mContainer.States.Add(stateSave);
        }
        public static void SetValue(this StateSave stateSave, string variableName, object valueToSet)
        {
#if GLUE
            if (variableName.Contains(" set in "))
            {
                string withoutSpace = variableName.Substring(0, variableName.IndexOf(' '));

                DialogResult result =
                    MessageBox.Show("The variable " + withoutSpace + " is set in other categories that do not share states.  Are you sure you want to set it?", "Set variable?", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    variableName = withoutSpace;
                }
            }
#endif
            bool wasFound = false;

            // See if there is an instructionD

            #region Set the existing instruction's value if there is one already

            foreach (InstructionSave instructionSave in stateSave.InstructionSaves)
            {
                if (instructionSave.Member == variableName)
                {
                    wasFound = true;
                    instructionSave.Value = valueToSet;
                    break;
                }
            }

            #endregion

            if (!wasFound)
            {
                IElement container = ObjectFinder.Self.GetElementContaining(stateSave);

                CustomVariable variable = null;

                foreach (CustomVariable containedVariable in container.CustomVariables)
                {
                    if (containedVariable.Name == variableName)
                    {
                        variable = containedVariable;
                        break;
                    }
                }



                InstructionSave instructionSave = new InstructionSave();
                instructionSave.Value = valueToSet; // make it the default

                instructionSave.Type   = valueToSet.GetType().Name;
                instructionSave.Member = variableName;
                // Create a new instruction

                stateSave.InstructionSaves.Add(instructionSave);

                stateSave.SortInstructionSaves(container.CustomVariables);
            }
        }
        public static void SetValue(this StateSave stateSave, string variableName, object valueToSet)
        {
#if GLUE
            if (variableName.Contains(" set in "))
            {
                string withoutSpace = variableName.Substring(0, variableName.IndexOf(' '));

                DialogResult result = 
                    MessageBox.Show("The variable " + withoutSpace + " is set in other categories that do not share states.  Are you sure you want to set it?", "Set variable?", MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    variableName = withoutSpace;
                }
            }
#endif
            bool wasFound = false;

            // See if there is an instructionD

            #region Set the existing instruction's value if there is one already

            foreach (InstructionSave instructionSave in stateSave.InstructionSaves)
            {
                if (instructionSave.Member == variableName)
                {
                    wasFound = true;
                    instructionSave.Value = valueToSet;
                    break;
                }
            }

            #endregion

            if (!wasFound)
            {
                IElement container = ObjectFinder.Self.GetElementContaining(stateSave);

                CustomVariable variable = null;

                foreach (CustomVariable containedVariable in container.CustomVariables)
                {
                    if (containedVariable.Name == variableName)
                    {
                        variable = containedVariable;
                        break;
                    }
                }



                InstructionSave instructionSave = new InstructionSave();
                instructionSave.Value = valueToSet; // make it the default

                instructionSave.Type = valueToSet.GetType().Name;
                instructionSave.Member = variableName;
			    // Create a new instruction

                stateSave.InstructionSaves.Add(instructionSave);

                stateSave.SortInstructionSaves(container.CustomVariables);
            }
        }
        public static void HandleWriteInstanceVariableAssignment(NamedObjectSave instance, ICodeBlock code, InstructionSave variable)
        {
            var shouldHandle = variable.Member == "AtlasedTexture" && instance.SourceClassType == "Sprite";

            if (shouldHandle)
            {
                var memberName = instance.InstanceName;

                // The code should look something like:
                //
                // SpriteInstance.AtlasedTexture = FlatRedBall.Graphics.Texture.AtlasLoader.LoadAtlasedTexture("asdf");
                //
                // But I still need to make the AtlasLoader keep track of all loaded assets, and I need to have a "priority" system

                code = code.Block();
                {
                    // eventually this might exist
                    //var atlas = instance.GetInstructionFromMember("");
                    // for now we assume that the texture packer project is in global content
                    var rfs = GlueState.Self.CurrentGlueProject.GlobalFiles.FirstOrDefault(item =>
                    {
                        var ati = item.GetAssetTypeInfo();
                        if (ati != null)
                        {
                            return(ati == AtiManager.Self.TextureAtlasAti);
                        }

                        return(false);
                    });

                    if (rfs != null)
                    {
                        var atlas = $"{GlueState.Self.ProjectNamespace}.GlobalContent.{rfs.GetInstanceName()}";
                        code.Line($"var atlas = {atlas};");

                        code.Line($"{memberName}.AtlasedTexture = atlas.Sprite(\"{variable.Value}\");");
                    }
                }
            }
        }
        private static void AppendCustomVariableInInstanceStandard(NamedObjectSave namedObject, ICodeBlock codeBlock, InstructionSave instructionSave, AssetTypeInfo ati)
        {
            object objectToParse = instructionSave.Value;

            #region Determine the right-side value to assign

            CustomVariable customVariable = null;
            EntitySave entitySave = null;
            if (namedObject.SourceType == SourceType.Entity && !string.IsNullOrEmpty(namedObject.SourceClassType))
            {
                entitySave = ObjectFinder.Self.GetEntitySave(namedObject.SourceClassType);
                if (entitySave != null)
                {
                    customVariable = entitySave.GetCustomVariable(instructionSave.Member);
                }
            }


            IElement rootElementForVariable = entitySave;
            string rootVariable = instructionSave.Member;

            while (customVariable != null && customVariable.IsTunneling)
            {
                NamedObjectSave referencedNamedObject = rootElementForVariable.GetNamedObjectRecursively(customVariable.SourceObject);
                if (referencedNamedObject != null && referencedNamedObject.IsFullyDefined && referencedNamedObject.SourceType == SourceType.Entity)
                {
                    rootElementForVariable = ObjectFinder.Self.GetIElement(referencedNamedObject.SourceClassType);
                    rootVariable = customVariable.SourceObjectProperty;

                    customVariable = rootElementForVariable.GetCustomVariable(customVariable.SourceObjectProperty);
                }
                else
                {
                    break;
                }
            }


            string value = CodeParser.ParseObjectValue(objectToParse);


            if (CustomVariableExtensionMethods.GetIsFile(instructionSave.Type))
            {
                value = value.Replace("\"", "").Replace("-", "_");

                if (value == "<NONE>")
                {
                    value = "null";
                }
            }
            else if (ShouldAssignToCsv(customVariable, value))
            {
                value = GetAssignmentToCsvItem(customVariable, entitySave, value);
            }
            else if (instructionSave.Type == "Color")
            {
                value = "Color." + value.Replace("\"", "");

            }
            else if ((customVariable != null && customVariable.GetIsVariableState()) || (customVariable == null && rootVariable == "CurrentState"))
            {
                //string type = "VariableState";
                //if (customVariable != null && customVariable.Type.ToLower() != "string")
                //{
                //    type = customVariable.Type;
                //}
                value = StateCodeGenerator.GetRightSideAssignmentValueAsString(entitySave, instructionSave);
            }
            else
            {
                value = CodeWriter.MakeLocalizedIfNecessary(namedObject, instructionSave.Member, objectToParse, value, null);
            }
            if (namedObject.DoesMemberNeedToBeSetByContainer(instructionSave.Member))
            {
                value = value.Replace("\"", "");
            }
            #endregion

            string leftSideMember = instructionSave.Member;

            bool makeRelative = !string.IsNullOrEmpty(InstructionManager.GetRelativeForAbsolute(leftSideMember));

            if (makeRelative)
            {
                if (ati != null)
                {
                    // If it can't attach, then don't try to set relative values
                    makeRelative &= ati.ShouldAttach;
                }
            }

            var objectName = namedObject.InstanceName;

            if (makeRelative)
            {
                codeBlock = codeBlock.If(objectName + ".Parent == null");
            }

            bool needsEndif = false;
            if (value.StartsWith("FlatRedBall.Graphics.ColorOperation."))
            {
                codeBlock.Line("#if FRB_MDX");

                codeBlock.Line(objectName + "." + instructionSave.Member + " = " + value.Replace("FlatRedBall.Graphics.ColorOperation.", "Microsoft.DirectX.Direct3D.TextureOperation.") + ";");
                codeBlock.Line("#else");

                needsEndif = true;
            }


            if (value.StartsWith("Microsoft.Xna.Framework.Graphics.TextureAddressMode."))
            {

                codeBlock.Line("#if FRB_MDX");

                codeBlock.Line(objectName + "." + instructionSave.Member + " = " + value.Replace("Microsoft.Xna.Framework.Graphics.TextureAddressMode.", "Microsoft.DirectX.Direct3D.TextureAddress.") + ";");
                codeBlock.Line("#else");

                needsEndif = true;
            }

            if (namedObject.DefinedByBase)
            {
                objectName = "base." + objectName;
            }
            codeBlock.Line(objectName + "." + instructionSave.Member + " = " + value + ";");

            if (needsEndif)
            {
                codeBlock.Line("#endif");
            }

            if (makeRelative)
            {
                codeBlock = codeBlock.End().Else();

                // Special Case!
                // If this NOS is
                // attached to a Camera
                // then we have to subtract
                // 40 from the position.



                if (namedObject.AttachToCamera && leftSideMember == "Z")
                {
                    value = value + " - 40.0f";
                }



                codeBlock.Line(objectName + "." + InstructionManager.GetRelativeForAbsolute(leftSideMember) + " = " + value + ";");



                codeBlock = codeBlock.End();

            }
        }
示例#24
0
        private static string GetLeftSideOfEquals(IElement element, CustomVariable customVariable, InstructionSave instruction, bool switchToRelative)
        {
            string leftSideOfEquals = instruction.Member;

            if (switchToRelative && customVariable != null)
            {
                string possibleLeftSide = RelativeValueForInstruction(instruction, customVariable, element);
                if (!string.IsNullOrEmpty(possibleLeftSide))
                {
                    leftSideOfEquals = possibleLeftSide;
                    if (!string.IsNullOrEmpty(customVariable.SourceObject))
                    {
                        leftSideOfEquals = customVariable.SourceObject + "." + leftSideOfEquals;
                    }
                }
            }

            return(leftSideOfEquals);
        }
        public static ICodeBlock AppendAssignmentForCustomVariableInInstance(NamedObjectSave namedObject, ICodeBlock codeBlock, 
            InstructionSave instructionSave)
        {
            // We don't support assigning lists yet, and lists are generic, so we're going to test for generic assignments
            // Eventually I may need to make this a little more accurate.
            if (instructionSave.Value != null && instructionSave.Value.GetType().IsGenericType == false)
            {
                bool usesStandardCodeGen = true;

                var ati = namedObject.GetAssetTypeInfo();
                if(ati != null)
                {
                    var foundVariableDefinition = ati.VariableDefinitions.FirstOrDefault(item => item.Name == instructionSave.Member);

                    if(foundVariableDefinition != null && foundVariableDefinition.UsesCustomCodeGeneration)
                    {
                        usesStandardCodeGen = false;
                    }
                }


                if (usesStandardCodeGen)
                {
                    AppendCustomVariableInInstanceStandard(namedObject, codeBlock, instructionSave, ati);
                }
                else
                {
                    PluginManager.WriteInstanceVariableAssignment(namedObject, codeBlock, instructionSave);
                }
            }

            return codeBlock;
        }
示例#26
0
        void CreateElementRuntime()
        {
            mEntitySave = new EntitySave { Name = "VariableSettingEntity" };

            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);
            
            var xVariable = new CustomVariable
            {
                Name = "X",
                Type = "float",
                DefaultValue = 0
            };
            mEntitySave.CustomVariables.Add(xVariable);

            // Needs the Z variable exposed so that the uncategorized state below can use it:
            var zVariable = new CustomVariable
            {
                Name = "Z",
                Type = "float",
                DefaultValue = 0
            };
            mEntitySave.CustomVariables.Add(zVariable);

            CustomVariable stateVariable = new CustomVariable
            {
                Name = "CurrentStateSaveCategoryState",
                Type = "StateSaveCategory",
                DefaultValue = "FirstState"
            };
            stateVariable.SetByDerived = true;
            mEntitySave.CustomVariables.Add(stateVariable);


            CustomVariable uncategorizedStateVariable = new CustomVariable
            {
                Name = "CurrentState",
                Type = "VariableState",
                //DefaultValue = "Uncategorized", // Don't set a default value - the derived will do this
                SetByDerived = true
            };
            mEntitySave.CustomVariables.Add(uncategorizedStateVariable);




            StateSave uncategorized = new StateSave();
            uncategorized.Name = "Uncategorized";
            InstructionSave instruction = new InstructionSave();
            instruction.Member = "Z";
            instruction.Value = 8.0f;
            uncategorized.InstructionSaves.Add(instruction);
            mEntitySave.States.Add(uncategorized);
            
            StateSave stateSave = new StateSave();
            stateSave.Name = "FirstState";
            instruction = new InstructionSave();
            instruction.Member = "X";
            instruction.Value = 10;
            stateSave.InstructionSaves.Add(instruction);

            StateSave secondStateSave = new StateSave();
            secondStateSave.Name = "SecondState";
            instruction = new InstructionSave();
            instruction.Member = "X";
            instruction.Value = -10;
            secondStateSave.InstructionSaves.Add(instruction);


            StateSaveCategory category = new StateSaveCategory();
            category.Name = "StateSaveCategory";
            category.States.Add(stateSave);
            category.States.Add(secondStateSave);

            mEntitySave.StateCategoryList.Add(category);
            mElementRuntime = new ElementRuntime(mEntitySave, null, null, null, null);
            mElementRuntime.AfterVariableApply += AfterVariableSet;



        }
示例#27
0
        void CreateElementRuntime()
        {
            mEntitySave = new EntitySave {
                Name = "VariableSettingEntity"
            };

            ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave);

            var xVariable = new CustomVariable
            {
                Name         = "X",
                Type         = "float",
                DefaultValue = 0
            };

            mEntitySave.CustomVariables.Add(xVariable);

            // Needs the Z variable exposed so that the uncategorized state below can use it:
            var zVariable = new CustomVariable
            {
                Name         = "Z",
                Type         = "float",
                DefaultValue = 0
            };

            mEntitySave.CustomVariables.Add(zVariable);

            CustomVariable stateVariable = new CustomVariable
            {
                Name         = "CurrentStateSaveCategoryState",
                Type         = "StateSaveCategory",
                DefaultValue = "FirstState"
            };

            stateVariable.SetByDerived = true;
            mEntitySave.CustomVariables.Add(stateVariable);


            CustomVariable uncategorizedStateVariable = new CustomVariable
            {
                Name = "CurrentState",
                Type = "VariableState",
                //DefaultValue = "Uncategorized", // Don't set a default value - the derived will do this
                SetByDerived = true
            };

            mEntitySave.CustomVariables.Add(uncategorizedStateVariable);



            StateSave uncategorized = new StateSave();

            uncategorized.Name = "Uncategorized";
            InstructionSave instruction = new InstructionSave();

            instruction.Member = "Z";
            instruction.Value  = 8.0f;
            uncategorized.InstructionSaves.Add(instruction);
            mEntitySave.States.Add(uncategorized);

            StateSave stateSave = new StateSave();

            stateSave.Name     = "FirstState";
            instruction        = new InstructionSave();
            instruction.Member = "X";
            instruction.Value  = 10;
            stateSave.InstructionSaves.Add(instruction);

            StateSave secondStateSave = new StateSave();

            secondStateSave.Name = "SecondState";
            instruction          = new InstructionSave();
            instruction.Member   = "X";
            instruction.Value    = -10;
            secondStateSave.InstructionSaves.Add(instruction);


            StateSaveCategory category = new StateSaveCategory();

            category.Name = "StateSaveCategory";
            category.States.Add(stateSave);
            category.States.Add(secondStateSave);

            mEntitySave.StateCategoryList.Add(category);
            mElementRuntime = new ElementRuntime(mEntitySave, null, null, null, null);
            mElementRuntime.AfterVariableApply += AfterVariableSet;
        }
        private static object GetDefaultValueFor(NamedObjectSave nos, string property, string overridingType)
        {
            if (!string.IsNullOrEmpty(overridingType))
            {
                Type overridingTypeAsType = TypeManager.GetTypeFromString(overridingType);


                string valueAsString = TypeManager.GetDefaultForType(overridingType);

                return(PropertyValuePair.ConvertStringToType(valueAsString, overridingTypeAsType));
            }



            switch (nos.SourceType)
            {
            case SourceType.File:

                if (!string.IsNullOrEmpty(nos.SourceFile) && !string.IsNullOrEmpty(nos.SourceNameWithoutParenthesis))
                {
                    string absoluteFileName = ProjectManager.MakeAbsolute(nos.SourceFile, true);



                    return(ContentParser.GetValueForProperty(absoluteFileName, nos.SourceNameWithoutParenthesis, property));
                }



                break;

            case SourceType.Entity:
                if (!string.IsNullOrEmpty(nos.SourceClassType))
                {
                    IElement element = ObjectFinder.Self.GetIElement(nos.SourceClassType);

                    if (element != null)
                    {
                        CustomVariable customVariable = element.GetCustomVariable(property);

                        if (customVariable != null)
                        {
                            return(GetDefaultValueFor(customVariable, element));
                        }
                        else if (property == "Visible" && element is EntitySave &&
                                 ((EntitySave)element).ImplementsIVisible)
                        {
                            return(true);
                        }
                        else if (property == "Enabled" && element is EntitySave &&
                                 ((EntitySave)element).ImplementsIWindow)
                        {
                            return(true);
                        }
                    }
                }
                break;

            case SourceType.FlatRedBallType:
                if (!string.IsNullOrEmpty(nos.SourceClassType))
                {
                    // See if there is a variable set for this already - there may be
                    // now that we allow users to specify values right on FlatRedBall-type
                    // NamedObjectSaves
                    InstructionSave instructionSave = nos.GetCustomVariable(property);
                    if (instructionSave != null && instructionSave.Value != null)
                    {
                        return(instructionSave.Value);
                    }
                    else
                    {
                        object value = GetExceptionForFlatRedBallTypeDefaultValue(nos, property);

                        if (value != null)
                        {
                            return(value);
                        }
                        else
                        {
                            string classType = nos.SourceClassType;

                            value = GetDefaultValueForPropertyInType(property, classType);

                            return(value);
                        }
                    }
                }

                break;
            }

            return(null);
        }
        void CreateElementRuntime(string name)
        {
            var entitySave = new EntitySave {
                Name = name
            };

            ObjectFinder.Self.GlueProject.Entities.Add(entitySave);

            #region Create CustomVariables
            var xVariable = new CustomVariable
            {
                Name         = "X",
                Type         = "float",
                DefaultValue = 3.0f
            };
            entitySave.CustomVariables.Add(xVariable);

            var yVariable = new CustomVariable
            {
                Name         = "Y",
                Type         = "float",
                DefaultValue = 4.0f
            };
            entitySave.CustomVariables.Add(yVariable);


            var customVariable = new CustomVariable
            {
                Name         = "SomeNewVar",
                Type         = "double",
                DefaultValue = 3.333
            };
            entitySave.CustomVariables.Add(customVariable);

            var csvTypeVAriable = new CustomVariable
            {
                Name         = "CsvTypeVariable",
                Type         = "CsvType.csv",
                DefaultValue = null
            };
            entitySave.CustomVariables.Add(csvTypeVAriable);

            var csvTypeVariable2 = new CustomVariable
            {
                Name         = "EnemyInfoVariable",
                Type         = "EnemyInfo.csv",
                DefaultValue = "Imp"
            };
            entitySave.CustomVariables.Add(csvTypeVariable2);

            var scaleXVariable = new CustomVariable
            {
                Name         = "ScaleX",
                Type         = "float",
                DefaultValue = 10.0f
            };
            entitySave.CustomVariables.Add(scaleXVariable);


            #endregion

            #region Create the NamedObjectsSave

            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType      = SourceType.FlatRedBallType;
            nos.SourceClassType = "Sprite";
            nos.InstanceName    = "SpriteObject";
            nos.UpdateCustomProperties();
            nos.SetPropertyValue("ScaleX", 3.0f);
            entitySave.NamedObjects.Add(nos);


            #endregion

            #region Create the ReferencedFileSaves

            ReferencedFileSave rfs = new ReferencedFileSave();
            rfs.Name = "Content/Entities/ReferencedFileSaveTestsBaseEntity/SceneFile.scnx";
            entitySave.ReferencedFiles.Add(rfs);

            rfs      = new ReferencedFileSave();
            rfs.Name = "Content/EnemyInfo.csv";
            rfs.CreatesDictionary = true;

            entitySave.ReferencedFiles.Add(rfs);


            #endregion

            mElementRuntime = new ElementRuntime()
            {
                X = (float)xVariable.DefaultValue,
                Y = (float)yVariable.DefaultValue
            };
            mElementRuntime.Initialize(entitySave, null, null, null, null);


            #region Create the uncategorized states

            var leftX = new InstructionSave
            {
                Member = "X",
                Value  = -10,
                Type   = "float"
            };



            var rightX = new InstructionSave
            {
                Member = "X",
                Value  = 10,
                Type   = "float"
            };

            var someNewVarSetLeft = new InstructionSave
            {
                Member = "SomeNewVar",
                Value  = -10.0,
                Type   = "double"
            };


            var someNewVarSetRight = new InstructionSave
            {
                Member = "SomeNewVar",
                Value  = 10.0,
                Type   = "double"
            };

            var leftState = new StateSave {
                Name = "Left"
            };
            leftState.InstructionSaves.Add(leftX);
            leftState.InstructionSaves.Add(someNewVarSetLeft);

            var rightState = new StateSave {
                Name = "Right"
            };
            rightState.InstructionSaves.Add(rightX);
            rightState.InstructionSaves.Add(someNewVarSetRight);


            entitySave.States.Add(leftState);
            entitySave.States.Add(rightState);

            #endregion

            #region Create the categorized states

            StateSaveCategory category = new StateSaveCategory();
            category.SharesVariablesWithOtherCategories = false;

            category.Name = "StateCategory";

            var topY = new InstructionSave
            {
                Member = "Y",
                Value  = 10,
                Type   = "float"
            };

            var bottomY = new InstructionSave
            {
                Member = "Y",
                Value  = 10,
                Type   = "float"
            };

            var topState = new StateSave {
                Name = "Top"
            };
            topState.InstructionSaves.Add(topY);
            var bottomState = new StateSave {
                Name = "Bottom"
            };
            bottomState.InstructionSaves.Add(rightX);

            category.States.Add(topState);
            category.States.Add(bottomState);

            entitySave.StateCategoryList.Add(category);

            #endregion
        }
示例#30
0
 private void HandleWriteInstanceVariableAssignment(NamedObjectSave instance, ICodeBlock code, InstructionSave variable)
 {
     VariableAssignmentCodeGenerator.HandleWriteInstanceVariableAssignment(instance, code, variable);
 }
示例#31
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;
            }

        }
        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();
                }
            }
        }
示例#33
0
        public static string GetRightSideAssignmentValueAsString(IElement element, InstructionSave instruction)
        {
            CustomVariable customVariable = element.GetCustomVariableRecursively(instruction.Member);

            IElement referencedElement = null;

            #region Determine if the assignment is a file

            bool isFile = false;

            if (customVariable != null)
            {
                referencedElement =
                    BaseElementTreeNode.GetElementIfCustomVariableIsVariableState(customVariable, element);

                isFile = customVariable.GetIsFile();
            }

            #endregion

            string valueAsString = "";

            if (referencedElement == null)
            {
                valueAsString = CodeParser.ParseObjectValue(instruction.Value);

                if (isFile)
                {
                    valueAsString = valueAsString.Replace("\"", "");

                    if (valueAsString == "<NONE>")
                    {
                        valueAsString = "null";
                    }
                }
                else if (CustomVariableCodeGenerator.ShouldAssignToCsv(customVariable, valueAsString))
                {
                    valueAsString = CustomVariableCodeGenerator.GetAssignmentToCsvItem(customVariable, element, valueAsString);
                }
                else if (customVariable != null && customVariable.Type == "Color")
                {
                    valueAsString = "Color." + valueAsString.Replace("\"", "");
                }
                if (customVariable != null && !string.IsNullOrEmpty(customVariable.SourceObject) && !isFile)
                {
                    NamedObjectSave namedObject = element.GetNamedObjectRecursively(customVariable.SourceObject);

                    bool isVariableState = customVariable.GetIsVariableState();

                    IElement objectElement = null;

                    if (namedObject != null)
                    {
                        ObjectFinder.Self.GetIElement(namedObject.SourceClassType);
                    }

                    if (objectElement != null)
                    {
                        if (isVariableState)
                        {
                            string typeName = "VariableState";

                            StateSaveCategory category = objectElement.GetStateCategoryRecursively(customVariable.Type);

                            if (category != null && category.SharesVariablesWithOtherCategories == false)
                            {
                                typeName = category.Name;
                            }
                            valueAsString = objectElement.Name.Replace("/", ".").Replace("\\", ".") + "." + typeName + "." + valueAsString.Replace("\"", "");
                        }
                    }

                    valueAsString = CodeWriter.MakeLocalizedIfNecessary(
                        namedObject,
                        instruction.Member,
                        instruction.Value,
                        valueAsString,
                        customVariable);
                }
            }
            else
            {
                string enumValue = (string)instruction.Value;

                if (!string.IsNullOrEmpty(enumValue) && enumValue != "<NONE>")
                {
                    string variableType = "VariableState";

                    if (customVariable != null && customVariable.Type.ToLower() != "string")
                    {
                        variableType = customVariable.Type;
                    }
                    valueAsString = FullyQualifyStateValue(referencedElement, enumValue, variableType);
                }
            }
            return(valueAsString);
        }
示例#34
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();
                }
            }
        }
示例#35
0
 private void HandleWriteInstanceVariableAssignment(NamedObjectSave instance, ICodeBlock code, InstructionSave variable)
 {
     VariableAssignmentCodeGenerator.HandleWriteInstanceVariableAssignment(instance, code, variable);
 }
示例#36
0
        private static string GetLeftSideOfEquals(IElement element, CustomVariable customVariable, InstructionSave instruction, bool switchToRelative)
        {
            string leftSideOfEquals = instruction.Member;

            if (switchToRelative && customVariable != null)
            {
                string possibleLeftSide = RelativeValueForInstruction(instruction, customVariable, element);
                if (!string.IsNullOrEmpty(possibleLeftSide))
                {
                    
                    leftSideOfEquals = possibleLeftSide;
                    if (!string.IsNullOrEmpty(customVariable.SourceObject))
                    {
                        leftSideOfEquals = customVariable.SourceObject + "." + leftSideOfEquals;
                    }
                }
            }

            return leftSideOfEquals;
        }
示例#37
0
        public static void WriteInstanceVariableAssignment(NamedObjectSave namedObject, ICodeBlock codeBlock, InstructionSave instructionSave)
        {
            TypeConverter toReturn = null;

            SaveRelativeDirectory();

            CallMethodOnPlugin(
                delegate (PluginBase plugin)
                {
                    if (plugin.WriteInstanceVariableAssignment != null)
                    {
                        plugin.WriteInstanceVariableAssignment(namedObject, codeBlock, instructionSave);
                    }
                },
                "WriteInstanceVariableAssignment");

            ResumeRelativeDirectory("GetTypeConverter");
        }
示例#38
0
        public static string GetRightSideAssignmentValueAsString(IElement element, InstructionSave instruction)
        {
            CustomVariable customVariable = element.GetCustomVariableRecursively(instruction.Member);

            IElement referencedElement = null;

            #region Determine if the assignment is a file

            bool isFile = false;

            if (customVariable != null)
            {
                referencedElement =
                    BaseElementTreeNode.GetElementIfCustomVariableIsVariableState(customVariable, element);

                isFile = customVariable.GetIsFile();

            }

            #endregion

            string valueAsString = "";

            if (referencedElement == null)
            {

                valueAsString = CodeParser.ParseObjectValue(instruction.Value);

                if (isFile)
                {
                    valueAsString = valueAsString.Replace("\"", "");

                    if (valueAsString == "<NONE>")
                    {
                        valueAsString = "null";
                    }
                }
                else if (CustomVariableCodeGenerator.ShouldAssignToCsv(customVariable, valueAsString))
                {
                    valueAsString = CustomVariableCodeGenerator.GetAssignmentToCsvItem(customVariable, element, valueAsString);
                }
                else if (customVariable != null && customVariable.Type == "Color")
                {
                    valueAsString = "Color." + valueAsString.Replace("\"", "");
                }
                if (customVariable != null && !string.IsNullOrEmpty(customVariable.SourceObject) && !isFile)
                {
                    NamedObjectSave namedObject = element.GetNamedObjectRecursively(customVariable.SourceObject);

                    bool isVariableState = customVariable.GetIsVariableState();

                    IElement objectElement = null;

                    if (namedObject != null)
                    {
                        ObjectFinder.Self.GetIElement(namedObject.SourceClassType);
                    }

                    if (objectElement != null)
                    {
                        if (isVariableState)
                        {
                            string typeName = "VariableState";

                            StateSaveCategory category = objectElement.GetStateCategoryRecursively(customVariable.Type);

                            if(category != null && category.SharesVariablesWithOtherCategories == false)
                            {
                                typeName = category.Name;
                            }
                            valueAsString = objectElement.Name.Replace("/", ".").Replace("\\", ".") + "." + typeName + "." + valueAsString.Replace("\"", "");
                        }
                    }

                    valueAsString = CodeWriter.MakeLocalizedIfNecessary(
                        namedObject,
                        instruction.Member,
                        instruction.Value,
                        valueAsString,
                        customVariable);
                }
            }
            else
            {
                string enumValue = (string)instruction.Value;

                if (!string.IsNullOrEmpty(enumValue))
                {
                    string variableType = "VariableState";

                    if (customVariable != null && customVariable.Type.ToLower() != "string")
                    {
                        variableType = customVariable.Type;
                    }
                    valueAsString = FullyQualifyStateValue(referencedElement, enumValue, variableType);
                }

            }
            return valueAsString;
        }
        void CreateElementRuntime(string name)
        {
            var entitySave = new EntitySave {Name = name};

            ObjectFinder.Self.GlueProject.Entities.Add(entitySave);

            #region Create CustomVariables
            var xVariable = new CustomVariable
                                {
                                    Name = "X", 
                                    Type = "float", 
                                    DefaultValue = 3.0f
                                };
            entitySave.CustomVariables.Add(xVariable);

            var yVariable = new CustomVariable
                                {
                                    Name = "Y", 
                                    Type = "float", 
                                    DefaultValue = 4.0f
                                };
            entitySave.CustomVariables.Add(yVariable);


            var customVariable = new CustomVariable
                                {
                                    Name = "SomeNewVar",
                                    Type = "double",
                                    DefaultValue = 3.333
                                };
            entitySave.CustomVariables.Add(customVariable);

            var csvTypeVAriable = new CustomVariable
                                {
                                    Name = "CsvTypeVariable",
                                    Type = "CsvType.csv",
                                    DefaultValue = null

                                };
            entitySave.CustomVariables.Add(csvTypeVAriable);

            var csvTypeVariable2 = new CustomVariable
                                {
                                    Name = "EnemyInfoVariable",
                                    Type = "EnemyInfo.csv",
                                    DefaultValue = "Imp"

                                };
            entitySave.CustomVariables.Add(csvTypeVariable2);

            var scaleXVariable = new CustomVariable
            {
                Name = "ScaleX",
                Type = "float",
                DefaultValue = 10.0f
            };
            entitySave.CustomVariables.Add(scaleXVariable);


            #endregion

            #region Create the NamedObjectsSave

            NamedObjectSave nos = new NamedObjectSave();
            nos.SourceType = SourceType.FlatRedBallType;
            nos.SourceClassType = "Sprite";
            nos.InstanceName = "SpriteObject";
            nos.UpdateCustomProperties();
            nos.SetPropertyValue("ScaleX", 3.0f);
            entitySave.NamedObjects.Add(nos);


            #endregion

            #region Create the ReferencedFileSaves

            ReferencedFileSave rfs = new ReferencedFileSave();
            rfs.Name = "Content/Entities/ReferencedFileSaveTestsBaseEntity/SceneFile.scnx";
            entitySave.ReferencedFiles.Add(rfs);

            rfs = new ReferencedFileSave();
            rfs.Name = "Content/EnemyInfo.csv";
            rfs.CreatesDictionary = true;

            entitySave.ReferencedFiles.Add(rfs);


            #endregion

            mElementRuntime = new ElementRuntime(entitySave, null, null, null, null)
                                  {
                                      X = (float) xVariable.DefaultValue, 
                                      Y = (float) yVariable.DefaultValue
                                  };


            #region Create the uncategorized states

            var leftX = new InstructionSave
            {
                Member = "X",
                Value = -10,
                Type = "float"
            };




            var rightX = new InstructionSave
            {
                Member = "X",
                Value = 10,
                Type = "float"
            };

            var someNewVarSetLeft = new InstructionSave
            {
                Member = "SomeNewVar",
                Value = -10.0,
                Type = "double"

            };


            var someNewVarSetRight = new InstructionSave
            {
                Member = "SomeNewVar",
                Value = 10.0,
                Type = "double"

            };

            var leftState = new StateSave {Name = "Left"};
            leftState.InstructionSaves.Add(leftX);
            leftState.InstructionSaves.Add(someNewVarSetLeft);

            var rightState = new StateSave {Name = "Right"};
            rightState.InstructionSaves.Add(rightX);
            rightState.InstructionSaves.Add(someNewVarSetRight);


            entitySave.States.Add(leftState);
            entitySave.States.Add(rightState);

            #endregion

            #region Create the categorized states

            StateSaveCategory category = new StateSaveCategory();
            category.SharesVariablesWithOtherCategories = false;

            category.Name = "StateCategory";

            var topY = new InstructionSave
            {
                Member = "Y",
                Value = 10,
                Type = "float"
            };

            var bottomY = new InstructionSave
            {
                Member = "Y",
                Value = 10,
                Type = "float"
            };

            var topState = new StateSave { Name = "Top" };
            topState.InstructionSaves.Add(topY);
            var bottomState = new StateSave { Name = "Bottom" };
            bottomState.InstructionSaves.Add(rightX);

            category.States.Add(topState);
            category.States.Add(bottomState);

            entitySave.StateCategoryList.Add(category);

            #endregion
        }