Пример #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
        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
        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
 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
        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
        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
        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
		public TileTemplate(MiniYaml my) { FieldLoader.Load( this, my ); }
Пример #33
0
		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);
 }