예제 #1
0
        private GumState ToGumState(FlatRedBall.Glue.SaveClasses.StateSave glueState, GlueElement glueElement)
        {
            var gumState = new GumState();

            gumState.Name = glueState.Name;

            VariableGroupDictionary variableGroups = new VariableGroupDictionary();

            foreach (var glueVariable in glueState.InstructionSaves)
            {
                AddGumVariables(glueVariable, null, glueElement, gumState.Variables, gumState.VariableLists, variableGroups, isInState: true);
            }

            ApplyVariableGroups(variableGroups, glueElement, gumState.Variables);


            // everything should set value
            foreach (var gumVariable in gumState.Variables)
            {
                gumVariable.SetsValue = true;
            }


            return(gumState);
        }
예제 #2
0
 private void ApplyVariableGroups(VariableGroupDictionary variableGroups, GlueElement glueElement,
                                  List <VariableSave> gumVariables)
 {
     if (variableGroups.HasCategory(GlueToGumTextureCoordinateConversionLogic.TextureCoordinatesCategory))
     {
         GlueToGumTextureCoordinateConversionLogic.Self.ApplyTextureCoordinatesVariables(variableGroups, gumVariables, glueElement);
     }
 }
예제 #3
0
        private void GetVariableSaves(NamedObjectSave namedObject, NamedObjectSave parentNamedObject, GlueElement glueElement,
                                      out List <VariableSave> gumVariables, out List <VariableListSave> gumVariableLists)
        {
            VariableGroupDictionary variableGroups = new VariableGroupDictionary();

            gumVariables     = new List <VariableSave>();
            gumVariableLists = new List <VariableListSave>();
            foreach (var glueVariable in namedObject.InstructionSaves)
            {
                AddGumVariables(glueVariable, namedObject, glueElement, gumVariables, gumVariableLists, variableGroups);
            }

            ApplyVariableGroups(variableGroups, glueElement, gumVariables);

            if (namedObject.SourceType == SourceType.FlatRedBallType &&
                namedObject.SourceClassType == "PositionedObjectList<T>" &&
                namedObject.SourceClassGenericType != null)
            {
                AddVariablesForPositionedObjectList(namedObject, gumVariables);
            }

            if (namedObject.SourceType == SourceType.FlatRedBallType &&
                namedObject.SourceClassType == "ShapeCollection")
            {
                AddVariablesForShapeCollection(namedObject, gumVariables);
            }

            if (parentNamedObject != null)
            {
                var parentVariable = new VariableSave();
                parentVariable.Value     = parentNamedObject.InstanceName;
                parentVariable.SetsValue = true;
                parentVariable.Type      = "string";
                parentVariable.Name      = $"{namedObject.InstanceName}.Parent";
                gumVariables.Add(parentVariable);
            }


            // everything should set value
            foreach (var gumVariable in gumVariables)
            {
                gumVariable.SetsValue = true;
            }
        }
예제 #4
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;
            }
        }
        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);
            }
        }