当前位置: 首页>>代码示例>>C#>>正文


C# MiniYaml类代码示例

本文整理汇总了C#中MiniYaml的典型用法代码示例。如果您正苦于以下问题:C# MiniYaml类的具体用法?C# MiniYaml怎么用?C# MiniYaml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MiniYaml类属于命名空间,在下文中一共展示了MiniYaml类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CursorProvider

        public CursorProvider(ModData modData)
        {
            var sequenceFiles = modData.Manifest.Cursors;

            cursors = new Dictionary<string, CursorSequence>();
            palettes = new Cache<string, PaletteReference>(CreatePaletteReference);
            var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal));
            var shadowIndex = new int[] { };

            if (sequences.NodesDict.ContainsKey("ShadowIndex"))
            {
                Array.Resize(ref shadowIndex, shadowIndex.Length + 1);
                Exts.TryParseIntegerInvariant(sequences.NodesDict["ShadowIndex"].Value,
                    out shadowIndex[shadowIndex.Length - 1]);
            }

            palette = new HardwarePalette();
            foreach (var p in sequences.NodesDict["Palettes"].Nodes)
                palette.AddPalette(p.Key, new Palette(GlobalFileSystem.Open(p.Value.Value), shadowIndex), false);

            var spriteLoader = new SpriteLoader(new string[0], new SheetBuilder(SheetType.Indexed));
            foreach (var s in sequences.NodesDict["Cursors"].Nodes)
                LoadSequencesForCursor(spriteLoader, s.Key, s.Value);

            palette.Initialize();
        }
开发者ID:RunCraze,项目名称:OpenRA,代码行数:26,代码来源:CursorProvider.cs

示例2: MergeAndPrint

        void MergeAndPrint(Map map, string key, MiniYaml value)
        {
            var nodes = new List<MiniYamlNode>();
            var includes = new List<string>();
            if (value != null && value.Value != null)
            {
                // The order of the included files matter, so we can defer to system files
                // only as long as they are included first.
                var include = false;
                var files = FieldLoader.GetValue<string[]>("value", value.Value);
                foreach (var f in files)
                {
                    include |= map.Package.Contains(f);
                    if (include)
                        nodes.AddRange(MiniYaml.FromStream(map.Open(f)));
                    else
                        includes.Add(f);
                }
            }

            if (value != null)
                nodes.AddRange(value.Nodes);

            var output = new MiniYaml(includes.JoinWith(", "), nodes);
            Console.WriteLine(output.ToLines(key).JoinWith("\n"));
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:26,代码来源:ExtractMapRules.cs

示例3: CursorProvider

        public CursorProvider(ModData modData)
        {
            var fileSystem = modData.DefaultFileSystem;
            var sequenceYaml = MiniYaml.Merge(modData.Manifest.Cursors.Select(
                s => MiniYaml.FromStream(fileSystem.Open(s), s)));

            var shadowIndex = new int[] { };

            var nodesDict = new MiniYaml(null, sequenceYaml).ToDictionary();
            if (nodesDict.ContainsKey("ShadowIndex"))
            {
                Array.Resize(ref shadowIndex, shadowIndex.Length + 1);
                Exts.TryParseIntegerInvariant(nodesDict["ShadowIndex"].Value,
                    out shadowIndex[shadowIndex.Length - 1]);
            }

            var palettes = new Dictionary<string, ImmutablePalette>();
            foreach (var p in nodesDict["Palettes"].Nodes)
                palettes.Add(p.Key, new ImmutablePalette(fileSystem.Open(p.Value.Value), shadowIndex));

            Palettes = palettes.AsReadOnly();

            var frameCache = new FrameCache(fileSystem, modData.SpriteLoaders);
            var cursors = new Dictionary<string, CursorSequence>();
            foreach (var s in nodesDict["Cursors"].Nodes)
                foreach (var sequence in s.Value.Nodes)
                    cursors.Add(sequence.Key, new CursorSequence(frameCache, sequence.Key, s.Key, s.Value.Value, sequence.Value));

            Cursors = cursors.AsReadOnly();
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:30,代码来源:CursorProvider.cs

示例4: LoadVersus

		static object LoadVersus(MiniYaml y)
		{
			var nd = y.ToDictionary();
			return nd.ContainsKey("Versus")
				? nd["Versus"].ToDictionary(my => FieldLoader.GetValue<float>("(value)", my.Value))
				: new Dictionary<string, float>();
		}
开发者ID:JackKucan,项目名称:OpenRA,代码行数:7,代码来源:WeaponInfo.cs

示例5: ProcessYaml

        static void ProcessYaml(ModData modData, Map map, MiniYaml yaml, int engineDate, UpgradeAction processYaml)
        {
            if (yaml == null)
                return;

            if (yaml.Value != null)
            {
                var files = FieldLoader.GetValue<string[]>("value", yaml.Value);
                foreach (var filename in files)
                {
                    var fileNodes = MiniYaml.FromStream(map.Open(filename), filename);
                    processYaml(modData, engineDate, ref fileNodes, null, 0);

                    // HACK: Obtain the writable save path using knowledge of the underlying filesystem workings
                    var packagePath = filename;
                    var package = map.Package;
                    if (filename.Contains("|"))
                        modData.DefaultFileSystem.TryGetPackageContaining(filename, out package, out packagePath);

                    ((IReadWritePackage)package).Update(packagePath, Encoding.ASCII.GetBytes(fileNodes.WriteToString()));
                }
            }

            processYaml(modData, engineDate, ref yaml.Nodes, null, 1);
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:25,代码来源:UpgradeMapCommand.cs

示例6: Load

 static Dictionary<string, string[]> Load(MiniYaml y, string name)
 {
     var nd = y.ToDictionary();
     return nd.ContainsKey(name)
         ? nd[name].ToDictionary(my => FieldLoader.GetValue<string[]>("(value)", my.Value))
         : new Dictionary<string, string[]>();
 }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:7,代码来源:SoundInfo.cs

示例7: TerrainTemplateInfo

        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);
                }
            }
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:33,代码来源:TileSet.cs

示例8: ValidateMods

        static Dictionary<string, ModMetadata> ValidateMods()
        {
            var basePath = Platform.ResolvePath(".", "mods");
            var mods = Directory.GetDirectories(basePath)
                .Select(x => x.Substring(basePath.Length + 1));

            var ret = new Dictionary<string, ModMetadata>();
            foreach (var m in mods)
            {
                var yamlPath = Platform.ResolvePath(".", "mods", m, "mod.yaml");
                if (!File.Exists(yamlPath))
                    continue;

                var yaml = new MiniYaml(null, MiniYaml.FromFile(yamlPath));
                var nd = yaml.ToDictionary();
                if (!nd.ContainsKey("Metadata"))
                    continue;

                var mod = FieldLoader.Load<ModMetadata>(nd["Metadata"]);
                mod.Id = m;

                ret.Add(m, mod);
            }

            return ret;
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:26,代码来源:ModMetadata.cs

示例9: Manifest

		public Manifest(string mod)
		{
			var path = new[] { "mods", mod, "mod.yaml" }.Aggregate(Path.Combine);
			var yaml = new MiniYaml(null, MiniYaml.FromFile(path)).ToDictionary();

			Mod = FieldLoader.Load<ModMetadata>(yaml["Metadata"]);
			Mod.Id = mod;

			// TODO: Use fieldloader
			Folders = YamlList(yaml, "Folders");
			MapFolders = YamlDictionary(yaml, "MapFolders");
			Packages = YamlDictionary(yaml, "Packages");
			Rules = YamlList(yaml, "Rules");
			ServerTraits = YamlList(yaml, "ServerTraits");
			Sequences = YamlList(yaml, "Sequences");
			VoxelSequences = YamlList(yaml, "VoxelSequences");
			Cursors = YamlList(yaml, "Cursors");
			Chrome = YamlList(yaml, "Chrome");
			Assemblies = YamlList(yaml, "Assemblies");
			ChromeLayout = YamlList(yaml, "ChromeLayout");
			Weapons = YamlList(yaml, "Weapons");
			Voices = YamlList(yaml, "Voices");
			Notifications = YamlList(yaml, "Notifications");
			Music = YamlList(yaml, "Music");
			Movies = YamlList(yaml, "Movies");
			Translations = YamlList(yaml, "Translations");
			TileSets = YamlList(yaml, "TileSets");
			ChromeMetrics = YamlList(yaml, "ChromeMetrics");
			PackageContents = YamlList(yaml, "PackageContents");
			LuaScripts = YamlList(yaml, "LuaScripts");
			Missions = YamlList(yaml, "Missions");

			LoadScreen = yaml["LoadScreen"];
			LobbyDefaults = yaml["LobbyDefaults"];

			if (yaml.ContainsKey("ContentInstaller"))
				ContentInstaller = FieldLoader.Load<InstallData>(yaml["ContentInstaller"]);

			Fonts = yaml["Fonts"].ToDictionary(my =>
				{
					var nd = my.ToDictionary();
					return Pair.New(nd["Font"].Value, Exts.ParseIntegerInvariant(nd["Size"].Value));
				});

			if (yaml.ContainsKey("TileSize"))
				TileSize = FieldLoader.GetValue<Size>("TileSize", yaml["TileSize"].Value);

			if (yaml.ContainsKey("TileShape"))
				TileShape = FieldLoader.GetValue<TileShape>("TileShape", yaml["TileShape"].Value);

			// Allow inherited mods to import parent maps.
			var compat = new List<string>();
			compat.Add(mod);

			if (yaml.ContainsKey("SupportsMapsFrom"))
				foreach (var c in yaml["SupportsMapsFrom"].Value.Split(','))
					compat.Add(c.Trim());

			MapCompatibility = compat.ToArray();
		}
开发者ID:JackKucan,项目名称:OpenRA,代码行数:60,代码来源:Manifest.cs

示例10: MappedImage

 public MappedImage(string defaultSrc, MiniYaml info)
 {
     FieldLoader.LoadField(this, "rect", info.Value);
     FieldLoader.Load(this, info);
     if (src == null)
         src = defaultSrc;
 }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:7,代码来源:MappedImage.cs

示例11: SoundInfo

		public SoundInfo(MiniYaml y)
		{
			FieldLoader.Load(this, y);

			VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(a.Value)));
			NotificationsPools = Exts.Lazy(() => Notifications.ToDictionary(a => a.Key, a => new SoundPool(a.Value)));
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:7,代码来源:SoundInfo.cs

示例12: ActorInfo

        public ActorInfo(string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits)
        {
            try
            {
                var allParents = new HashSet<string>();
                var abstractActorType = name.StartsWith("^");

                // Guard against circular inheritance
                allParents.Add(name);
                var mergedNode = MergeWithParents(node, allUnits, allParents).ToDictionary();

                Name = name;

                foreach (var t in mergedNode)
                {
                    if (t.Key[0] == '-')
                        throw new YamlException("Bogus trait removal: " + t.Key);

                    if (t.Key != "Inherits" && !t.Key.StartsWith("[email protected]"))
                        try
                        {
                            Traits.Add(LoadTraitInfo(t.Key.Split('@')[0], t.Value));
                        }
                        catch (FieldLoader.MissingFieldsException e)
                        {
                            if (!abstractActorType)
                                throw new YamlException(e.Message);
                        }
                }
            }
            catch (YamlException e)
            {
                throw new YamlException("Actor type {0}: {1}".F(name, e.Message));
            }
        }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:35,代码来源:ActorInfo.cs

示例13: LoadFilesToExtract

        public static Dictionary<string, string[]> LoadFilesToExtract(MiniYaml yaml)
        {
            var md = yaml.ToDictionary();

            return md.ContainsKey("ExtractFilesFromCD")
                ? md["ExtractFilesFromCD"].ToDictionary(my => FieldLoader.GetValue<string[]>("(value)", my.Value))
                : new Dictionary<string, string[]>();
        }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:8,代码来源:InstallUtils.cs

示例14: LoadSpeeds

		static object LoadSpeeds(MiniYaml y)
		{
			var ret = new Dictionary<string, GameSpeed>();
			foreach (var node in y.Nodes)
				ret.Add(node.Key, FieldLoader.Load<GameSpeed>(node.Value));

			return ret;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:8,代码来源:GameSpeed.cs

示例15: LoadProjectile

		static object LoadProjectile(MiniYaml yaml)
		{
			MiniYaml proj;
			if (!yaml.ToDictionary().TryGetValue("Projectile", out proj))
				return null;
			var ret = Game.CreateObject<IProjectileInfo>(proj.Value + "Info");
			FieldLoader.Load(ret, proj);
			return ret;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:9,代码来源:WeaponInfo.cs


注:本文中的MiniYaml类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。