Example #1
0
        /// <summary>
        /// 加载飞行体
        /// </summary>
        /// <param name="yaml"></param>
        /// <returns></returns>
        static object LoadProjectile(MiniYaml yaml)
        {
            MiniYaml proj;

            if (!yaml.ToDictionary().TryGetValue("Projectile", out proj))
            {
                return(null);
            }

            var ret = WarGame.CreateObject <IProjectileInfo>(proj.Value + "Info");

            FieldLoader.Load(ret, proj);
            return(ret);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="self"></param>
        /// <param name="my"></param>
        public static void Load(object self, MiniYaml my)
        {
            var loadInfo = TypeLoadInfo[self.GetType()];
            var missing  = new List <string>();

            Dictionary <string, MiniYaml> md = null;

            foreach (var fli in loadInfo)
            {
                object val;
                if (md == null)
                {
                    md = my.ToDictionary();
                }
                if (fli.Loader != null)
                {
                    if (!fli.Attribute.Required || md.ContainsKey(fli.YamlName))
                    {
                        val = fli.Loader(my);
                    }
                    else
                    {
                        missing.Add(fli.YamlName);
                        continue;
                    }
                }
                else
                {
                    if (!TryGetValueFromYaml(fli.YamlName, fli.Field, md, out val))
                    {
                        if (fli.Attribute.Required)
                        {
                            missing.Add(fli.YamlName);
                        }
                        continue;
                    }
                }
                fli.Field.SetValue(self, val);
            }

            if (missing.Any())
            {
                throw new MissingFieldsException(missing.ToArray());
            }
        }
Example #3
0
        public TerrainTemplateInfo(TileSet tileSet, MiniYaml my)
        {
            FieldLoader.Load(this, my);

            var nodes = my.ToDictionary()["Tiles"].Nodes;

            if (!PickAny)
            {
                tileInfo = new TerrainTileInfo[Size.X * Size.Y];
                foreach (var node in nodes)
                {
                    int key;
                    if (!int.TryParse(node.Key, out key) || key < 0 || key >= tileInfo.Length)
                    {
                        throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
                    }

                    tileInfo[key] = LoadTileInfo(tileSet, node.Value);
                }
            }
            else
            {
                tileInfo = new TerrainTileInfo[nodes.Count];

                var i = 0;
                foreach (var node in nodes)
                {
                    int key;
                    if (!int.TryParse(node.Key, out key) || key != i++)
                    {
                        throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
                    }

                    tileInfo[key] = LoadTileInfo(tileSet, node.Value);
                }
            }
        }
Example #4
0
 public ModelSequenceFormat(MiniYaml yaml)
 {
     Type     = yaml.Value;
     Metadata = new ReadOnlyDictionary <string, MiniYaml>(yaml.ToDictionary());
 }
Example #5
0
        public static List <MiniYamlNode> NodesOrEmpty(MiniYaml y, string s)
        {
            var nd = y.ToDictionary();

            return(nd.ContainsKey(s) ? nd[s].Nodes : new List <MiniYamlNode>());
        }