Example #1
0
        public Components Build(Dictionary <string, ComponentsBuilder> resources)
        {
            ComponentArgument root = Root;
            Dictionary <string, ComponentArgument> primary  = new Dictionary <string, ComponentArgument>(Primary);
            Dictionary <string, ComponentArgument> optional = new Dictionary <string, ComponentArgument>(Optional);
            ComponentsBuilder builder = this;

            while (builder.Parent != null)
            {
                builder = resources[builder.Parent];
                if (builder.Root != null)
                {
                    root = builder.Root;
                }
                foreach (KeyValuePair <string, ComponentArgument> pair in builder.Primary)
                {
                    primary.Add(pair.Key, pair.Value);
                }
                foreach (KeyValuePair <string, ComponentArgument> pair in builder.Optional)
                {
                    optional.Add(pair.Key, pair.Value);
                }
            }
            return(new Components(root, primary, optional));
        }
        public ReadResults ValidateFromRoot(IJsonArgument json, Components components)
        {
            ComponentArgument root       = components.GetRootComponent();
            JsonObject        rootObject = new JsonObject();

            rootObject.Add("root", json);
            return(root.Validate(rootObject, "root", this, components, StringReader, Start, Resources));
        }
Example #3
0
        public void ComponentArgument_ParseShouldSucceed_WithSimpleInput()
        {
            // Arrange
            ComponentArgument argument = new ComponentArgument();
            IStringReader     reader   = new StringReader("\"foo\"");

            // Act
            ReadResults readResults = argument.Parse(reader, out _);

            // Assert
            Assert.IsTrue(readResults.Successful);
        }
Example #4
0
        public void ComponentArgument_ParseShouldSucceed_WithComplexInput()
        {
            // Arrange
            Components.Set("{\"content\":{\"foo\":{\"type\":\"string\"}},\"formatting\":{\"bar\":{\"type\":\"number\"}}}");
            ComponentArgument argument = new ComponentArgument();
            IStringReader     reader   = new StringReader("{\"foo\":\"Hello world!\",\"bar\":3}");

            // Act
            ReadResults readResults = argument.Parse(reader, out _);

            // Assert
            Assert.IsTrue(readResults.Successful);
        }
Example #5
0
        private static Entity ParseEntity(XmlNode ObjectNode)
        {
            float           Width         = float.Parse(ObjectNode.Attributes["width"].Value);
            float           Height        = float.Parse(ObjectNode.Attributes["height"].Value);
            float           X             = float.Parse(ObjectNode.Attributes["x"].Value);
            float           Y             = float.Parse(ObjectNode.Attributes["y"].Value);
            string          BlueprintName = ObjectNode.Attributes["type"].Value.Trim();
            string          EntityName    = ObjectNode.Attributes["name"] == null ? null : ObjectNode.Attributes["name"].Value.Trim();
            EntityBlueprint Blueprint     = EntityBlueprint.GetBlueprint(BlueprintName);
            Entity          Entity        = Blueprint.CreateEntity();

            if (!String.IsNullOrWhiteSpace(EntityName))
            {
                Entity.Name = EntityName;
            }
            Entity.Position = new Vector2(X, Y);
            Entity.Size     = new Vector2(Width, Height);

            foreach (XmlNode PropertiesNode in ObjectNode.SelectNodes("properties"))
            {
                foreach (XmlNode PropertyNode in PropertiesNode.SelectNodes("property"))
                {
                    string Name = PropertyNode.Attributes["name"].Value.Trim();
                    // So, this is quite a hack.
                    // Tiled doesn't allow us to re-order properties; it's all alphabetical.
                    // So we just support sticking a # in front of the property to make it go to the top of the list, and then ignore that #.
                    while (Name.FirstOrDefault() == '#')
                    {
                        Name = Name.Substring(1);
                    }
                    string   Value             = PropertyNode.Attributes["value"].Value.Trim();
                    string[] NamePropertySplit = Name.Split('.');
                    if (NamePropertySplit.Length != 2)
                    {
                        throw new FormatException("Expected object property name to be in the format of 'PathComponent.Nodes'.");
                    }
                    string            ComponentName  = NamePropertySplit[0].Trim();
                    string            PropertyName   = NamePropertySplit[1].Trim();
                    ComponentArgument Argument       = ComponentArgument.Parse(Value).Single();
                    ComponentProperty ParsedProperty = new ComponentProperty(ComponentName, PropertyName, Argument);
                    var Component = Entity.Components[ComponentName];
                    ParsedProperty.ApplyValue(Component);
                }
            }
            return(Entity);
        }
 public static CommandError IncompleteComponent(string key, ComponentArgument component)
 {
     return(CommandError.InvalidChatComponent($"A {key} component needs at least {component.StringifyChildrenKeys()}"));
 }
Example #7
0
 public Components(ComponentArgument root, Dictionary <string, ComponentArgument> primary, Dictionary <string, ComponentArgument> optional)
 {
     Root     = root;
     Primary  = primary;
     Optional = optional;
 }