예제 #1
0
        public Sequence(string unit, string name, MiniYaml info)
        {
            srcOverride = info.Value;
            Name = name;
            var d = info.NodesDict;

            sprites = Game.modData.SpriteLoader.LoadAllSprites(string.IsNullOrEmpty(srcOverride) ? unit : srcOverride );
            start = int.Parse(d["Start"].Value);

            if (!d.ContainsKey("Length"))
                length = 1;
            else if (d["Length"].Value == "*")
                length = sprites.Length - Start;
            else
                length = int.Parse(d["Length"].Value);

            if(d.ContainsKey("Facings"))
                facings = int.Parse(d["Facings"].Value);
            else
                facings = 1;

            if(d.ContainsKey("Tick"))
                tick = int.Parse(d["Tick"].Value);
            else
                tick = 40;
        }
        static void LoadSequencesForCursor(string cursorSrc, MiniYaml cursor)
        {
            Game.modData.LoadScreen.Display();

            foreach (var sequence in cursor.Nodes)
                cursors.Add(sequence.Key, new CursorSequence(cursorSrc, cursor.Value, sequence.Value));
        }
예제 #3
0
 public MappedImage(string defaultSrc, MiniYaml info)
 {
     FieldLoader.LoadField(this, "rect", info.Value);
     FieldLoader.Load(this, info);
     if (src == null)
         src = defaultSrc;
 }
예제 #4
0
파일: Manifest.cs 프로젝트: Tsher/OpenRA
        public Manifest(string[] mods)
        {
            Mods = mods;
            var yaml = new MiniYaml(null, mods
                .Select(m => MiniYaml.FromFile("mods/" + m + "/mod.yaml"))
                .Aggregate(MiniYaml.MergeLiberal)).NodesDict;

            // TODO: Use fieldloader
            Folders = YamlList(yaml, "Folders");
            Packages = YamlList(yaml, "Packages");
            Rules = YamlList(yaml, "Rules");
            ServerTraits = YamlList(yaml, "ServerTraits");
            Sequences = YamlList(yaml, "Sequences");
            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");
            TileSets = YamlList(yaml, "TileSets");
            ChromeMetrics = YamlList(yaml, "ChromeMetrics");

            LoadScreen = yaml["LoadScreen"];
            Fonts = yaml["Fonts"].NodesDict.ToDictionary(x => x.Key,
                x => Pair.New(x.Value.NodesDict["Font"].Value,
                    int.Parse(x.Value.NodesDict["Size"].Value)));

            if (yaml.ContainsKey("TileSize"))
                TileSize = int.Parse(yaml["TileSize"].Value);
        }
예제 #5
0
        public Sequence(string unit, string name, MiniYaml info)
        {
            var srcOverride = info.Value;
            Name = name;
            var d = info.NodesDict;

            sprites = Game.modData.SpriteLoader.LoadAllSprites(srcOverride ?? unit);
            start = int.Parse(d["Start"].Value);

            if (!d.ContainsKey("Length"))
                length = 1;
            else if (d["Length"].Value == "*")
                length = sprites.Length - Start;
            else
                length = int.Parse(d["Length"].Value);

            if(d.ContainsKey("Facings"))
                facings = int.Parse(d["Facings"].Value);
            else
                facings = 1;

            if(d.ContainsKey("Tick"))
                tick = int.Parse(d["Tick"].Value);
            else
                tick = 40;

            if (start < 0 || start + facings * length > sprites.Length)
                throw new InvalidOperationException(
                    "{6}: Sequence {0}.{1} uses frames [{2}..{3}] of SHP `{4}`, but only 0..{5} actually exist"
                    .F(unit, name, start, start + facings * length - 1, srcOverride ?? unit, sprites.Length - 1,
                    info.Nodes[0].Location));
        }
예제 #6
0
 static IEnumerable<MiniYaml> GetInheritanceChain(MiniYaml node, Dictionary<string, MiniYaml> allUnits)
 {
     while (node != null)
     {
         yield return node;
         node = GetParent(node, allUnits);
     }
 }
예제 #7
0
 static Dictionary<string, string[]> Load( MiniYaml y, string name )
 {
     return y.NodesDict.ContainsKey( name )
         ? y.NodesDict[ name ].NodesDict.ToDictionary(
             a => a.Key,
             a => FieldLoader.GetValue<string[]>( "(value)", a.Value.Value ) )
         : new Dictionary<string, string[]>();
 }
예제 #8
0
 static void LoadSequencesForUnit(string unit, MiniYaml sequences)
 {
     Game.modData.LoadScreen.Display();
     try {
         var seq = sequences.NodesDict.ToDictionary(x => x.Key, x => new Sequence(unit,x.Key,x.Value));
         units.Add(unit, seq);
     } catch (FileNotFoundException) {} // Do nothing; we can crash later if we actually wanted art
 }
예제 #9
0
파일: ActorInfo.cs 프로젝트: pdovy/OpenRA
        public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
        {
            var mergedNode = MergeWithParent( node, allUnits ).NodesDict;

            Name = name;
            foreach( var t in mergedNode )
                if( t.Key != "Inherits" && !t.Key.StartsWith("-") )
                    Traits.Add( LoadTraitInfo( t.Key.Split('@')[0], t.Value ) );
        }
예제 #10
0
파일: MapStub.cs 프로젝트: pdovy/OpenRA
 static object LoadWaypoints( MiniYaml y )
 {
     var ret = new Dictionary<string, int2>();
     foreach( var wp in y.NodesDict[ "Waypoints" ].NodesDict )
     {
         string[] loc = wp.Value.Value.Split( ',' );
         ret.Add( wp.Key, new int2( int.Parse( loc[ 0 ] ), int.Parse( loc[ 1 ] ) ) );
     }
     return ret;
 }
예제 #11
0
 public MiniYaml Save()
 {
     var ret = new MiniYaml( Type );
     foreach( var init in InitDict )
     {
         var initName = init.GetType().Name;
         ret.Nodes.Add( initName.Substring( 0, initName.Length - 4 ), FieldSaver.Save( init ) );
     }
     return ret;
 }
예제 #12
0
		public MusicInfo(string key, MiniYaml value)
		{
			Title = value.Value;

			var nd = value.ToDictionary();
			if (nd.ContainsKey("Hidden"))
				bool.TryParse(nd["Hidden"].Value, out Hidden);

			var ext = nd.ContainsKey("Extension") ? nd["Extension"].Value : "aud";
			Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key) + "." + ext;
		}
        public static void Initialize(string[] sequenceFiles)
        {
            cursors = new Dictionary<string, CursorSequence>();
            var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal));

            foreach (var s in sequences.NodesDict["Palettes"].Nodes)
                Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), false));

            foreach (var s in sequences.NodesDict["Cursors"].Nodes)
                LoadSequencesForCursor(s.Key, s.Value);
        }
예제 #14
0
파일: VoiceInfo.cs 프로젝트: max621/OpenRA
        public VoiceInfo( MiniYaml y )
        {
            FieldLoader.Load( this, y );
            Variants = Load(y, "Variants");
            Voices = Load(y, "Voices");

            if (!Voices.ContainsKey("Attack"))
                Voices.Add("Attack", Voices["Move"]);

            Pools = Lazy.New(() => Voices.ToDictionary( a => a.Key, a => new VoicePool(a.Value) ));
        }
예제 #15
0
        public MusicInfo( string key, MiniYaml value )
        {
            Filename = key+".aud";
            Title = value.Value;

            if (!FileSystem.Exists(Filename))
                return;

            Exists = true;
            Length = (int)AudLoader.SoundLength(FileSystem.Open(Filename));
        }
예제 #16
0
        public SoundInfo( MiniYaml y )
        {
            FieldLoader.Load( this, y );
            Variants = Load(y, "Variants");
            Prefixes = Load(y, "Prefixes");
            Voices = Load(y, "Voices");
            Notifications = Load(y, "Notifications");

            VoicePools = Lazy.New(() => Voices.ToDictionary( a => a.Key, a => new SoundPool(a.Value) ));
            NotificationsPools = Lazy.New(() => Notifications.ToDictionary( a => a.Key, a => new SoundPool(a.Value) ));
        }
예제 #17
0
        void LoadSectionYaml(MiniYaml yaml, object section)
        {
            object defaults = Activator.CreateInstance(section.GetType());
            FieldLoader.InvalidValueAction = (s,t,f) =>
            {
                object ret = defaults.GetType().GetField(f).GetValue(defaults);
                //System.Console.WriteLine("FieldLoader: Cannot parse `{0}` into `{2}:{1}`; substituting default `{3}`".F(s,t.Name,f,ret) );
                return ret;
            };

            FieldLoader.Load(section, yaml);
        }
예제 #18
0
        public VoiceInfo( MiniYaml y )
        {
            FieldLoader.Load(this, y);

            Pools = Lazy.New(() =>
                new Dictionary<string, VoicePool>
                {
                    { "Select", new VoicePool(Select) },
                    { "Move", new VoicePool(Move) },
                    { "Attack", new VoicePool( Attack ?? Move ) },
                    { "Die", new VoicePool(Die) },
                });
        }
예제 #19
0
        public MusicInfo( string key, MiniYaml value )
        {
            Title = value.Value;

            var nd = value.NodesDict;
            var ext = nd.ContainsKey("Extension") ? nd["Extension"].Value : "aud";
            Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key)+"."+ext;
            if (!GlobalFileSystem.Exists(Filename))
                return;

            Exists = true;
            Length = (int)AudLoader.SoundLength(GlobalFileSystem.Open(Filename));
        }
예제 #20
0
        public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
        {
            var mergedNode = MergeWithParent( node, allUnits ).Nodes;

            Name = name;
            MiniYaml categoryNode;
            if( mergedNode.TryGetValue( "Category", out categoryNode ) )
                Category = categoryNode.Value;

            foreach( var t in mergedNode )
                if( t.Key != "Inherits" && t.Key != "Category" && !t.Key.StartsWith("-") )
                    Traits.Add( LoadTraitInfo( t.Key.Split('@')[0], t.Value ) );
        }
예제 #21
0
        public MissionBrowserLogic(Widget widget, Action onStart, Action onExit)
        {
            this.onStart = onStart;

            var missionList = widget.Get<ScrollPanelWidget>("MISSION_LIST");
            var template = widget.Get<ScrollItemWidget>("MISSION_TEMPLATE");

            widget.Get("MISSION_INFO").IsVisible = () => selectedMapPreview != null;

            var previewWidget = widget.Get<MapPreviewWidget>("MISSION_PREVIEW");
            previewWidget.Preview = () => selectedMapPreview;

            descriptionPanel = widget.Get<ScrollPanelWidget>("MISSION_DESCRIPTION_PANEL");
            description = widget.Get<LabelWidget>("MISSION_DESCRIPTION");
            descriptionFont = Game.Renderer.Fonts[description.Font];

            var yaml = new MiniYaml(null, Game.modData.Manifest.Missions.Select(MiniYaml.FromFile).Aggregate(MiniYaml.MergeLiberal)).NodesDict;

            var missionMapPaths = yaml["Missions"].Nodes.Select(n => Path.GetFullPath(n.Key));

            var maps = Game.modData.MapCache
                .Where(p => p.Status == MapStatus.Available && missionMapPaths.Contains(Path.GetFullPath(p.Map.Path)))
                .Select(p => p.Map);

            missionList.RemoveChildren();
            foreach (var m in maps)
            {
                var map = m;

                var item = ScrollItemWidget.Setup(template,
                    () => selectedMapPreview != null && selectedMapPreview.Uid == map.Uid,
                    () => SelectMap(map),
                    StartMission);

                item.Get<LabelWidget>("TITLE").GetText = () => map.Title;
                missionList.AddChild(item);
            }

            if (maps.Any())
                SelectMap(maps.First());

            widget.Get<ButtonWidget>("STARTGAME_BUTTON").OnClick = StartMission;

            widget.Get<ButtonWidget>("BACK_BUTTON").OnClick = () =>
            {
                Game.Disconnect();
                Ui.CloseWindow();
                onExit();
            };
        }
예제 #22
0
파일: ActorInfo.cs 프로젝트: pdovy/OpenRA
        static MiniYaml GetParent( MiniYaml node, Dictionary<string, MiniYaml> allUnits )
        {
            MiniYaml inherits;
            node.NodesDict.TryGetValue( "Inherits", out inherits );
            if( inherits == null || string.IsNullOrEmpty( inherits.Value ) )
                return null;

            MiniYaml parent;
            allUnits.TryGetValue( inherits.Value, out parent );
            if( parent == null )
                return null;

            return parent;
        }
예제 #23
0
        public Manifest(string mod)
        {
            var path = new[] { "mods", mod, "mod.yaml" }.Aggregate(Path.Combine);
            var yaml = new MiniYaml(null, MiniYaml.FromFile(path)).NodesDict;

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

            // TODO: Use fieldloader
            Folders = YamlList(yaml, "Folders");
            MapFolders = YamlList(yaml, "MapFolders");
            Packages = yaml["Packages"].NodesDict.ToDictionary(x => x.Key, x => x.Value.Value);
            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");

            LoadScreen = yaml["LoadScreen"];
            LobbyDefaults = yaml["LobbyDefaults"];
            Fonts = yaml["Fonts"].NodesDict.ToDictionary(x => x.Key,
                x => Pair.New(x.Value.NodesDict["Font"].Value,
                    int.Parse(x.Value.NodesDict["Size"].Value)));

            if (yaml.ContainsKey("TileSize"))
                TileSize = int.Parse(yaml["TileSize"].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();
        }
예제 #24
0
        static Voxel LoadVoxel(string unit, string name, MiniYaml info)
        {
            var vxl = unit;
            var hva = unit;
            if (info.Value != null)
            {
                var fields = info.Value.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
                if (fields.Length >= 1)
                    vxl = hva = fields[0].Trim();

                if (fields.Length >= 2)
                    hva = fields[1].Trim();
            }

            return Game.modData.VoxelLoader.Load(vxl, hva);
        }
예제 #25
0
파일: Mod.cs 프로젝트: katzsmile/OpenRA
        public static Dictionary<string, Mod> ValidateMods(string[] mods)
        {
            var ret = new Dictionary<string, Mod>();
            foreach (var m in mods)
            {
                if (!File.Exists("mods" + Path.DirectorySeparatorChar + m + Path.DirectorySeparatorChar + "mod.yaml"))
                    continue;

                var yaml = new MiniYaml(null, MiniYaml.FromFile("mods" + Path.DirectorySeparatorChar + m + Path.DirectorySeparatorChar + "mod.yaml"));
                if (!yaml.NodesDict.ContainsKey("Metadata"))
                    continue;

                ret.Add(m, FieldLoader.Load<Mod>(yaml.NodesDict["Metadata"]));
            }
            return ret;
        }
예제 #26
0
        public ActorInfo( string name, MiniYaml node, Dictionary<string, MiniYaml> allUnits )
        {
            try
            {
                var mergedNode = MergeWithParent(node, allUnits).NodesDict;

                Name = name;
                foreach (var t in mergedNode)
                    if (t.Key != "Inherits" && !t.Key.StartsWith("-"))
                        Traits.Add(LoadTraitInfo(t.Key.Split('@')[0], t.Value));
            }
            catch (YamlException e)
            {
                throw new YamlException("Actor type {0}: {1}".F(name, e.Message));
            }
        }
예제 #27
0
        public MusicInfo(string key, MiniYaml value)
        {
            Title = value.Value;

            var nd = value.ToDictionary();
            var ext = nd.ContainsKey("Extension") ? nd["Extension"].Value : "aud";
            Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key) + "." + ext;
            if (!GlobalFileSystem.Exists(Filename))
                return;

            Exists = true;
            using (var s = GlobalFileSystem.Open(Filename))
                if (Filename.ToLowerInvariant().EndsWith("wav"))
                    Length = (int)WavLoader.WaveLength(s);
                else
                    Length = (int)AudLoader.SoundLength(s);
        }
예제 #28
0
        public static void Initialize(string[] sequenceFiles)
        {
            cursors = new Dictionary<string, CursorSequence>();
            var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal));
            int[] ShadowIndex = { };

            if (sequences.NodesDict.ContainsKey("ShadowIndex"))
                {
                    Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1);
                    ShadowIndex[ShadowIndex.Length - 1] = Convert.ToInt32(sequences.NodesDict["ShadowIndex"].Value);
                }

            foreach (var s in sequences.NodesDict["Palettes"].Nodes)
                Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), ShadowIndex));

            foreach (var s in sequences.NodesDict["Cursors"].Nodes)
                LoadSequencesForCursor(s.Key, s.Value);
        }
예제 #29
0
        public static Dictionary<string, Mod> ValidateMods(string[] mods)
        {
            var ret = new Dictionary<string, Mod>();
            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));
                if (!yaml.NodesDict.ContainsKey("Metadata"))
                    continue;

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

                ret.Add(m, mod);
            }
            return ret;
        }
예제 #30
0
        public static void Initialize(string[] sequenceFiles)
        {
            cursors = new Dictionary<string, CursorSequence>();
            var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal));
            int[] ShadowIndex = { };

            if (sequences.NodesDict.ContainsKey("ShadowIndex"))
            {
                Array.Resize(ref ShadowIndex, ShadowIndex.Length + 1);
                int.TryParse(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(FileSystem.Open(p.Value.Value), ShadowIndex), false);

            foreach (var s in sequences.NodesDict["Cursors"].Nodes)
                LoadSequencesForCursor(s.Key, s.Value);

            Palette.Initialize();
        }
예제 #31
0
 public static List <MiniYamlNode> NodesOrEmpty(MiniYaml y, string s)
 {
     return(y.NodesDict.ContainsKey(s) ? y.NodesDict[s].Nodes : new List <MiniYamlNode>());
 }
예제 #32
0
파일: TileSet.cs 프로젝트: test71/OpenRA
		public TileTemplate(MiniYaml my) { FieldLoader.Load( this, my ); }
예제 #33
0
파일: TileSet.cs 프로젝트: test71/OpenRA
		static object LoadTiles( MiniYaml y )
		{
			return y.NodesDict["Tiles"].NodesDict.ToDictionary(
				t => byte.Parse(t.Key),
				t => t.Value.Value );
		}
예제 #34
0
 public static MiniYaml MergeLiberal(MiniYaml a, MiniYaml b)
 {
     return(Merge(a, b, false));
 }
예제 #35
0
 public static MiniYaml MergeStrict(MiniYaml a, MiniYaml b)
 {
     return(Merge(a, b, true));
 }
예제 #36
0
 public PlayerReference(MiniYaml my)
 {
     FieldLoader.Load(this, my);
 }
예제 #37
0
 public MiniYamlNode(string k, MiniYaml v, SourceLocation loc)
     : this(k, v)
 {
     Location = loc;
 }
예제 #38
0
 public MiniYamlNode(string k, MiniYaml v)
 {
     Key   = k;
     Value = v;
 }
예제 #39
0
 public TerrainTypeInfo(MiniYaml my)
 {
     FieldLoader.Load(this, my);
 }