public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, FlatRedBall.Glue.SaveClasses.IElement element)
        {
            if (Active)
            {
                codeBlock.Line("TimeManager.SumTimeSection(\"Throwaway\");");
            }

            return(codeBlock);
        }
Esempio n. 2
0
 private void RemoveCodeFilesFromProject(GlueElement glueElement, IEnumerable <XElement> elements)
 {
     foreach (var removalCandidate in elements.ToArray())
     {
         if (ShouldRemove(glueElement, removalCandidate))
         {
             removalCandidate.Remove();
         }
         else
         {
             RemoveCodeFilesFromProject(glueElement, removalCandidate.Elements());
         }
     }
 }
Esempio n. 3
0
        private static GlueState GetOrCreateGlueState(FlatRedBall.Glue.SaveClasses.IElement glueElement, Gum.DataTypes.Variables.StateSave selectedGumState)
        {
            GlueState glueState;

            if (SelectedState.Self.SelectedStateCategorySave != null)
            {
                var glueCategory = glueElement.StateCategoryList
                                   .FirstOrDefault(item => item.Name == SelectedState.Self.SelectedStateCategorySave.Name);

                if (glueCategory == null)
                {
                    glueCategory = new FlatRedBall.Glue.SaveClasses.StateSaveCategory
                    {
                        Name = SelectedState.Self.SelectedStateCategorySave.Name
                    };
                    glueElement.StateCategoryList.Add(glueCategory);
                }

                glueState = glueCategory.GetState(selectedGumState.Name);

                if (glueState == null)
                {
                    glueState = new FlatRedBall.Glue.SaveClasses.StateSave()
                    {
                        Name = selectedGumState.Name
                    };

                    glueCategory.States.Add(glueState);
                }
                ;
            }
            else
            {
                glueState = glueElement.States.FirstOrDefault(item => item.Name == selectedGumState.Name);

                if (glueState == null)
                {
                    glueState = new FlatRedBall.Glue.SaveClasses.StateSave()
                    {
                        Name = selectedGumState.Name
                    };

                    glueElement.States.Add(glueState);
                }
            }

            return(glueState);
        }
Esempio n. 4
0
        private bool ShouldRemove(GlueElement glueElement, XElement removalCandidate)
        {
            var isCompile = removalCandidate.Name?.LocalName == "Compile";

            if (isCompile)
            {
                var includeAttribute = removalCandidate.Attributes().FirstOrDefault(item => item.Name.LocalName == "Include");

                if (includeAttribute != null)
                {
                    var customCodeLocation =
                        CodeCreationLogic.Self.GetCustomCodeFileLocationFor(glueElement, absolute: false);

                    var shouldRemove = includeAttribute.Value.StartsWith(glueElement.Name + ".") &&
                                       includeAttribute.Value.EndsWith(".cs");

                    return(shouldRemove);
                }
            }
            return(false);
        }
Esempio n. 5
0
        private static bool TryHandleAssigningMultipleVariables(ElementSave gumElement, GumInstance gumInstance, string variableName, GlueElement glueElement, FlatRedBall.Glue.SaveClasses.NamedObjectSave foundNos, object gumValue)
        {
            var isTextureValue = variableName == "Texture Address" ||
                                 variableName == "Texture Left" ||
                                 variableName == "Texture Top" ||
                                 variableName == "Texture Width" ||
                                 variableName == "Texture Height";

            var handled = false;

            if (isTextureValue)
            {
                string variablePrefix = null;
                if (gumInstance != null)
                {
                    variablePrefix = $"{gumInstance.Name}.";
                }
                var state = SelectedState.Self.SelectedStateSave;
                var addressValueGumCurrent       = state.GetValue($"{variablePrefix}Texture Address");
                var textureLeftValueGumCurrent   = state.GetValue($"{variablePrefix}Texture Left");
                var textureWidthValueGumCurrent  = state.GetValue($"{variablePrefix}Texture Width");
                var textureTopValueGumCurrent    = state.GetValue($"{variablePrefix}Texture Top");
                var textureHeightValueGumCurrent = state.GetValue($"{variablePrefix}Texture Height");

                var setsAny = addressValueGumCurrent != null ||
                              textureLeftValueGumCurrent != null ||
                              textureWidthValueGumCurrent != null ||
                              textureTopValueGumCurrent != null ||
                              textureHeightValueGumCurrent != null;

                if (setsAny)
                {
                    var rvf = new RecursiveVariableFinder(state);
                    var addressValueGumRecursive = rvf.GetValue <TextureAddress>($"{variablePrefix}Texture Address");

                    // set them all

                    if (addressValueGumRecursive == TextureAddress.EntireTexture)
                    {
                        // null them out:
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, null);
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, null);
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, null);
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null);
                    }
                    else
                    {
                        // set the values:
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, IntToNullOrFloat(textureLeftValueGumCurrent));
                        HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, IntToNullOrFloat(textureTopValueGumCurrent));

                        // right and bottom depend on left/top plus width/height
                        if (textureLeftValueGumCurrent != null && textureWidthValueGumCurrent != null)
                        {
                            var combined = (int)textureLeftValueGumCurrent + (int)textureWidthValueGumCurrent;
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, (float)combined);
                        }
                        else
                        {
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, IntToNullOrFloat(null));
                        }

                        if (textureTopValueGumCurrent != null && textureHeightValueGumCurrent != null)
                        {
                            var combined = (int)textureTopValueGumCurrent + (int)textureHeightValueGumCurrent;
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, (float)combined);
                        }
                        else
                        {
                            HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null);
                        }
                    }
                }
                else
                {
                    // null them all
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Left", glueElement, foundNos, null);
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Right", glueElement, foundNos, null);
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Top", glueElement, foundNos, null);
                    HandleIndividualVariableAssignment(gumElement, gumInstance, "Texture Bottom", glueElement, foundNos, null);
                }



                handled = true;
            }

            return(handled);
        }
Esempio n. 6
0
        private static void HandleIndividualVariableAssignment(ElementSave gumElement, GumInstance gumInstance, string variableName, GlueElement glueElement, FlatRedBall.Glue.SaveClasses.NamedObjectSave foundNos, object gumValue)
        {
            var gumToGlueConverter = GumToGlueConverter.Self;
            var glueVariableName   = gumToGlueConverter.ConvertVariableName(variableName, gumInstance);
            var glueValue          = gumToGlueConverter
                                     .ConvertVariableValue(variableName, gumValue, gumInstance);
            var type = gumToGlueConverter.ConvertType(variableName, gumValue, gumInstance);

            var handled = gumToGlueConverter.ApplyGumVariableCustom(gumInstance, gumElement, glueVariableName, glueValue);

            if (!handled)
            {
                var selectedGumState = SelectedState.Self.SelectedStateSave;
                if (selectedGumState == SelectedState.Self.SelectedElement?.DefaultState)
                {
                    var glueVariable = foundNos.SetVariableValue(glueVariableName, glueValue);

                    glueVariable.Type = type;
                }
                else
                {
                    GlueState glueState;

                    glueState = GetOrCreateGlueState(glueElement, selectedGumState);

                    if (gumInstance != null)
                    {
                        // The only way Glue states can set this value is to have a tunneled variable, so we gotta look for that
                        var tunneledVariable = glueElement.CustomVariables
                                               .FirstOrDefault(item => item.SourceObject == gumInstance.Name && item.SourceObjectProperty == glueVariableName);

                        if (tunneledVariable == null)
                        {
                            tunneledVariable                      = new FlatRedBall.Glue.SaveClasses.CustomVariable();
                            tunneledVariable.Name                 = gumInstance.Name + glueVariableName;
                            tunneledVariable.DefaultValue         = null;
                            tunneledVariable.SourceObject         = gumInstance.Name;
                            tunneledVariable.SourceObjectProperty = glueVariableName;
                            tunneledVariable.Type                 = type;

                            glueElement.CustomVariables.Add(tunneledVariable);
                        }

                        var stateVariable = glueState.InstructionSaves.FirstOrDefault(item => item.Member == tunneledVariable.Name);

                        if (stateVariable == null)
                        {
                            stateVariable        = new FlatRedBall.Content.Instructions.InstructionSave();
                            stateVariable.Member = tunneledVariable.Name;
                            glueState.InstructionSaves.Add(stateVariable);
                        }

                        stateVariable.Value = glueValue;
                    }
                    else
                    {
                        var stateVariable = glueState.InstructionSaves.FirstOrDefault(item => item.Member == glueVariableName);

                        if (stateVariable == null)
                        {
                            stateVariable        = new FlatRedBall.Content.Instructions.InstructionSave();
                            stateVariable.Member = glueVariableName;
                            glueState.InstructionSaves.Add(stateVariable);
                        }

                        stateVariable.Value = glueValue;
                    }
                }
            }
        }
 public void CodeGenerationStart(FlatRedBall.Glue.SaveClasses.IElement element)
 {
 }
        public void ApplyTextureCoordinatesVariables(VariableGroupDictionary variableGroups, List <VariableSave> gumVariables, GlueElement glueElement)
        {
            var variableGroup = variableGroups.GetVariablesInCategory(TextureCoordinatesCategory);

            var rightTexturePixelVar  = variableGroup.FirstOrDefault(item => item.RootName == "RightTexturePixel");
            var leftTexturePixelVar   = variableGroup.FirstOrDefault(item => item.RootName == "LeftTexturePixel");
            var bottomTexturePixelVar = variableGroup.FirstOrDefault(item => item.RootName == "BottomTexturePixel");
            var topTexturePixelVar    = variableGroup.FirstOrDefault(item => item.RootName == "TopTexturePixel");
            var textureVariable       = variableGroup.FirstOrDefault(item => item.RootName == "Texture");

            var namedObject = variableGroup.First().NamedObjectSave;

            var setsAny = rightTexturePixelVar != null ||
                          leftTexturePixelVar != null ||
                          bottomTexturePixelVar != null ||
                          topTexturePixelVar != null;


            if (setsAny == false)
            {
                ApplyTextureAddress(gumVariables, namedObject, Gum.Managers.TextureAddress.EntireTexture);
            }
            else
            {
                // Sets some, but not all, so read the texture to fill the value
                // This sucks, because the non-set values are either 0 or 1 depending on
                // which side they're on, but if they're 1, we can't have Gum mimic that behavior
                // Eventually we might, if it becomes an issue, but for now we'll explicitly set the
                // values.
                ApplyTextureAddress(gumVariables, namedObject, Gum.Managers.TextureAddress.Custom);

                float left;
                float top;
                if (leftTexturePixelVar != null)
                {
                    left = (float)leftTexturePixelVar.InstructionSave.Value;
                }
                else
                {
                    left = 0;
                }

                ApplyTextureLeft(gumVariables, left, namedObject);

                if (topTexturePixelVar != null)
                {
                    top = (float)topTexturePixelVar.InstructionSave.Value;
                }
                else
                {
                    top = 0;
                }
                ApplyTextureTop(gumVariables, top, namedObject);

                float right;
                float bottom;

                BitmapDecoder decoder = null;

                string fileName = null;
                if (textureVariable != null)
                {
                    fileName = $"{GluePluginState.Self.GlueProjectFilePath.StandardizedCaseSensitive}../Content/{glueElement.Name}/{(string)textureVariable.InstructionSave.Value}.png";
                    fileName = ToolsUtilities.FileManager.RemoveDotDotSlash(fileName);
                }


                if (rightTexturePixelVar?.InstructionSave.Value is float)
                {
                    right = (float)rightTexturePixelVar.InstructionSave.Value;
                }
                else
                {
                    decoder = TryLoadDecoder(fileName);
                    // todo - get the texture value:
                    right = decoder?.Frames[0].PixelWidth ?? 256;
                }
                ApplyTextureWidth(gumVariables, right - left, namedObject);

                if (bottomTexturePixelVar?.InstructionSave.Value is float)
                {
                    bottom = (float)bottomTexturePixelVar.InstructionSave.Value;
                }
                else
                {
                    if (decoder == null)
                    {
                        decoder = TryLoadDecoder(fileName);
                    }
                    // todo - get the value from the entire texture:
                    bottom = decoder?.Frames[0].PixelHeight ?? 256;
                }
                ApplyTextureHeight(gumVariables, bottom - top, namedObject);
            }
        }