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


C# MiniYaml.ToDictionary方法代码示例

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

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

示例1: 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


示例2: 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


示例3: 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


示例4: 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[] { };

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

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

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

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


示例5: CursorProvider

		public CursorProvider(ModData modData)
		{
			var sequenceFiles = modData.Manifest.Cursors;
			var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal));
			var shadowIndex = new int[] { };

			var nodesDict = sequences.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(GlobalFileSystem.Open(p.Value.Value), shadowIndex));

			Palettes = palettes.AsReadOnly();

			var frameCache = new FrameCache(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:Roger-luo,项目名称:OpenRA,代码行数:28,代码来源:CursorProvider.cs


示例6: 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


示例7: 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


示例8: 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


示例9: LoadVoxelsForUnit

		static void LoadVoxelsForUnit(string unit, MiniYaml sequences)
		{
			Game.ModData.LoadScreen.Display();
			try
			{
				var seq = sequences.ToDictionary(my => LoadVoxel(unit, my));
				units.Add(unit, seq);
			}
			catch (FileNotFoundException) { } // Do nothing; we can crash later if we actually wanted art
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:10,代码来源:VoxelProvider.cs


示例10: GetParent

		static MiniYaml GetParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
		{
			MiniYaml inherits;
			node.ToDictionary().TryGetValue( "Inherits", out inherits );
			if( inherits == null || string.IsNullOrEmpty( inherits.Value ) )
				return null;

			MiniYaml parent;
			allUnits.TryGetValue( inherits.Value, out parent );
			if (parent == null)
				throw new InvalidOperationException(
					"Bogus inheritance -- actor type {0} does not exist".F(inherits.Value));

			return parent;
		}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:15,代码来源:ActorInfo.cs


示例11: CursorSequence

		public CursorSequence(SpriteLoader loader, string cursorSrc, string palette, MiniYaml info)
		{
			sprites = loader.LoadAllSprites(cursorSrc);
			var d = info.ToDictionary();

			start = Exts.ParseIntegerInvariant(d["start"].Value);
			this.palette = palette;

			if ((d.ContainsKey("length") && d["length"].Value == "*") || (d.ContainsKey("end") && d["end"].Value == "*"))
				length = sprites.Length - start;
			else if (d.ContainsKey("length"))
				length = Exts.ParseIntegerInvariant(d["length"].Value);
			else if (d.ContainsKey("end"))
				length = Exts.ParseIntegerInvariant(d["end"].Value) - start;
			else
				length = 1;

			if (d.ContainsKey("x"))
				Exts.TryParseIntegerInvariant(d["x"].Value, out Hotspot.X);
			if (d.ContainsKey("y"))
				Exts.TryParseIntegerInvariant(d["y"].Value, out Hotspot.Y);
		}
开发者ID:JackKucan,项目名称:OpenRA,代码行数:22,代码来源:CursorSequence.cs


示例12: ValidateMods

		public static Dictionary<string, ModMetadata> ValidateMods(string[] mods)
		{
			var ret = new Dictionary<string, ModMetadata>();
			foreach (var m in mods)
			{
				var yamlPath = new[] { "mods", m, "mod.yaml" }.Aggregate(Path.Combine);
				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:JackKucan,项目名称:OpenRA,代码行数:22,代码来源:ModMetadata.cs


示例13: LoadTiles

		int[] LoadTiles(TileSet tileSet, MiniYaml y)
		{
			var nodes = y.ToDictionary()["Tiles"].Nodes;

			if (!PickAny)
			{
				var tiles = new int[Size.X * Size.Y];

				for (var i = 0; i < tiles.Length; i++)
					tiles[i] = -1;

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

					tiles[key] = tileSet.GetTerrainIndex(node.Value.Value);
				}

				return tiles;
			}
			else
			{
				var tiles = new int[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));

					tiles[key] = tileSet.GetTerrainIndex(node.Value.Value);
				}

				return tiles;
			}
		}
开发者ID:Berzeger,项目名称:OpenRA,代码行数:39,代码来源:TileSet.cs


示例14: 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)
			{
				try
				{
					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;

					if (nd.ContainsKey("ContentInstaller"))
						mod.Content = FieldLoader.Load<ContentInstaller>(nd["ContentInstaller"]);

					ret.Add(m, mod);
				}
				catch (Exception ex)
				{
					Console.WriteLine("An exception occured when trying to load ModMetadata for `{0}`:".F(m));
					Console.WriteLine(ex.Message);
				}
			}

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


示例15: CursorSequence

        public CursorSequence(FrameCache cache, string name, string cursorSrc, string palette, MiniYaml info)
        {
            var d = info.ToDictionary();

            Start = Exts.ParseIntegerInvariant(d["Start"].Value);
            Palette = palette;
            Name = name;

            if ((d.ContainsKey("Length") && d["Length"].Value == "*") || (d.ContainsKey("End") && d["End"].Value == "*"))
                Length = Frames.Length - Start;
            else if (d.ContainsKey("Length"))
                Length = Exts.ParseIntegerInvariant(d["Length"].Value);
            else if (d.ContainsKey("End"))
                Length = Exts.ParseIntegerInvariant(d["End"].Value) - Start;
            else
                Length = 1;

            Frames = cache[cursorSrc]
                .Skip(Start)
                .Take(Length)
                .ToArray();

            if (d.ContainsKey("X"))
            {
                int x;
                Exts.TryParseIntegerInvariant(d["X"].Value, out x);
                Hotspot = Hotspot.WithX(x);
            }

            if (d.ContainsKey("Y"))
            {
                int y;
                Exts.TryParseIntegerInvariant(d["Y"].Value, out y);
                Hotspot = Hotspot.WithY(y);
            }
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:36,代码来源:CursorSequence.cs


示例16: UpgradeMapFormat

        internal static void UpgradeMapFormat(ModData modData, IReadWritePackage package)
        {
            if (package == null)
                return;

            var yamlStream = package.GetStream("map.yaml");
            if (yamlStream == null)
                return;

            var yaml = new MiniYaml(null, MiniYaml.FromStream(yamlStream, package.Name));
            var nd = yaml.ToDictionary();
            var mapFormat = FieldLoader.GetValue<int>("MapFormat", nd["MapFormat"].Value);
            if (mapFormat < 6)
                throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(mapFormat, package.Name));

            // Format 6 -> 7 combined the Selectable and UseAsShellmap flags into the Class enum
            if (mapFormat < 7)
            {
                MiniYaml useAsShellmap;
                if (nd.TryGetValue("UseAsShellmap", out useAsShellmap) && bool.Parse(useAsShellmap.Value))
                    yaml.Nodes.Add(new MiniYamlNode("Visibility", new MiniYaml("Shellmap")));
                else if (nd["Type"].Value == "Mission" || nd["Type"].Value == "Campaign")
                    yaml.Nodes.Add(new MiniYamlNode("Visibility", new MiniYaml("MissionSelector")));
            }

            // Format 7 -> 8 replaced normalized HSL triples with rgb(a) hex colors
            if (mapFormat < 8)
            {
                var players = yaml.Nodes.FirstOrDefault(n => n.Key == "Players");
                if (players != null)
                {
                    bool noteHexColors = false;
                    bool noteColorRamp = false;
                    foreach (var player in players.Value.Nodes)
                    {
                        var colorRampNode = player.Value.Nodes.FirstOrDefault(n => n.Key == "ColorRamp");
                        if (colorRampNode != null)
                        {
                            Color dummy;
                            var parts = colorRampNode.Value.Value.Split(',');
                            if (parts.Length == 3 || parts.Length == 4)
                            {
                                // Try to convert old normalized HSL value to a rgb hex color
                                try
                                {
                                    HSLColor color = new HSLColor(
                                        (byte)Exts.ParseIntegerInvariant(parts[0].Trim()).Clamp(0, 255),
                                        (byte)Exts.ParseIntegerInvariant(parts[1].Trim()).Clamp(0, 255),
                                        (byte)Exts.ParseIntegerInvariant(parts[2].Trim()).Clamp(0, 255));
                                    colorRampNode.Value.Value = FieldSaver.FormatValue(color);
                                    noteHexColors = true;
                                }
                                catch (Exception)
                                {
                                    throw new InvalidDataException("Invalid ColorRamp value.\n File: " + package.Name);
                                }
                            }
                            else if (parts.Length != 1 || !HSLColor.TryParseRGB(parts[0], out dummy))
                                throw new InvalidDataException("Invalid ColorRamp value.\n File: " + package.Name);

                            colorRampNode.Key = "Color";
                            noteColorRamp = true;
                        }
                    }

                    if (noteHexColors)
                        Console.WriteLine("ColorRamp is now called Color and uses rgb(a) hex value - rrggbb[aa].");
                    else if (noteColorRamp)
                        Console.WriteLine("ColorRamp is now called Color.");
                }
            }

            // Format 8 -> 9 moved map options and videos from the map file itself to traits
            if (mapFormat < 9)
            {
                var rules = yaml.Nodes.FirstOrDefault(n => n.Key == "Rules");
                var worldNode = rules.Value.Nodes.FirstOrDefault(n => n.Key == "World");
                if (worldNode == null)
                    worldNode = new MiniYamlNode("World", new MiniYaml("", new List<MiniYamlNode>()));

                var playerNode = rules.Value.Nodes.FirstOrDefault(n => n.Key == "Player");
                if (playerNode == null)
                    playerNode = new MiniYamlNode("Player", new MiniYaml("", new List<MiniYamlNode>()));

                var visibilityNode = yaml.Nodes.FirstOrDefault(n => n.Key == "Visibility");
                if (visibilityNode != null)
                {
                    var visibility = FieldLoader.GetValue<MapVisibility>("Visibility", visibilityNode.Value.Value);
                    if (visibility.HasFlag(MapVisibility.MissionSelector))
                    {
                        var missionData = new MiniYamlNode("MissionData", new MiniYaml("", new List<MiniYamlNode>()));
                        worldNode.Value.Nodes.Add(missionData);

                        var description = yaml.Nodes.FirstOrDefault(n => n.Key == "Description");
                        if (description != null)
                            missionData.Value.Nodes.Add(new MiniYamlNode("Briefing", description.Value.Value));

                        var videos = yaml.Nodes.FirstOrDefault(n => n.Key == "Videos");
                        if (videos != null && videos.Value.Nodes.Any())
                        {
//.........这里部分代码省略.........
开发者ID:OpenRA,项目名称:OpenRA,代码行数:101,代码来源:UpgradeRules.cs


示例17: LoadPercents

 static object LoadPercents(MiniYaml y)
 {
     return y.ToDictionary()["TerrainModifier"].Nodes.ToDictionary(
         kv => FieldLoader.GetValue<string>("(key)", kv.Key),
         kv => FieldLoader.GetValue<int>("(value)", kv.Value.Value));
 }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:6,代码来源:TerrainModifiesDamage.cs


示例18: LoadVideos

        static object LoadVideos(MiniYaml y)
        {
            var videos = new MapVideos();
            var nodesDict = y.ToDictionary();
            if (nodesDict.ContainsKey("Videos"))
                FieldLoader.Load(videos, nodesDict["Videos"]);

            return videos;
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:9,代码来源:Map.cs


示例19: Map

        // The standard constructor for most purposes
        public Map(string path)
        {
            Path = path;
            Container = GlobalFileSystem.OpenPackage(path, null, int.MaxValue);

            AssertExists("map.yaml");
            AssertExists("map.bin");

            var yaml = new MiniYaml(null, MiniYaml.FromStream(Container.GetContent("map.yaml"), path));
            FieldLoader.Load(this, yaml);

            // Support for formats 1-3 dropped 2011-02-11.
            // Use release-20110207 to convert older maps to format 4
            // Use release-20110511 to convert older maps to format 5
            // Use release-20141029 to convert older maps to format 6
            if (MapFormat < 6)
                throw new InvalidDataException("Map format {0} is not supported.\n File: {1}".F(MapFormat, path));

            var nd = yaml.ToDictionary();

            // Format 6 -> 7 combined the Selectable and UseAsShellmap flags into the Class enum
            if (MapFormat < 7)
            {
                MiniYaml useAsShellmap;
                if (nd.TryGetValue("UseAsShellmap", out useAsShellmap) && bool.Parse(useAsShellmap.Value))
                    Visibility = MapVisibility.Shellmap;
                else if (Type == "Mission" || Type == "Campaign")
                    Visibility = MapVisibility.MissionSelector;
            }

            SpawnPoints = Exts.Lazy(() =>
            {
                var spawns = new List<CPos>();
                foreach (var kv in ActorDefinitions.Where(d => d.Value.Value == "mpspawn"))
                {
                    var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());

                    spawns.Add(s.InitDict.Get<LocationInit>().Value(null));
                }

                return spawns.ToArray();
            });

            RuleDefinitions = MiniYaml.NodesOrEmpty(yaml, "Rules");
            SequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Sequences");
            VoxelSequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "VoxelSequences");
            WeaponDefinitions = MiniYaml.NodesOrEmpty(yaml, "Weapons");
            VoiceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Voices");
            NotificationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Notifications");
            TranslationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Translations");
            PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players");

            ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors");
            SmudgeDefinitions = MiniYaml.NodesOrEmpty(yaml, "Smudges");

            MapTiles = Exts.Lazy(LoadMapTiles);
            MapResources = Exts.Lazy(LoadResourceTiles);
            MapHeight = Exts.Lazy(LoadMapHeight);

            TileShape = Game.ModData.Manifest.TileShape;
            SubCellOffsets = Game.ModData.Manifest.SubCellOffsets;
            LastSubCell = (SubCell)(SubCellOffsets.Length - 1);
            DefaultSubCell = (SubCell)Game.ModData.Manifest.SubCellDefaultIndex;

            if (Container.Exists("map.png"))
                using (var dataStream = Container.GetContent("map.png"))
                    CustomPreview = new Bitmap(dataStream);

            PostInit();

            // The Uid is calculated from the data on-disk, so
            // format changes must be flushed to disk.
            // TODO: this isn't very nice
            if (MapFormat < 7)
                Save(path);

            Uid = ComputeHash();
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:79,代码来源:Map.cs


示例20: LoadOptions

        static object LoadOptions(MiniYaml y)
        {
            var options = new MapOptions();
            var nodesDict = y.ToDictionary();
            if (nodesDict.ContainsKey("Options"))
                FieldLoader.Load(options, nodesDict["Options"]);

            return options;
        }
开发者ID:ushardul,项目名称:OpenRA,代码行数:9,代码来源:Map.cs



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