Exemplo n.º 1
0
        public AGame(string code, string name, string creator, AnEngine engine, int[] tables, int[] tableSizes, List <APlaylist> playlists, string remap,
                     int voiceTable, int sampleTable, int sampleTableSize)
        {
            Code       = code; Name = name; Creator = creator; Engine = engine;
            SongTables = tables; SongTableSizes = tableSizes;
            Playlists  = playlists; Remap = remap;

            VoiceTable = voiceTable; SampleTable = sampleTable; SampleTableSize = sampleTableSize;
        }
Exemplo n.º 2
0
        void LoadGames()
        {
            var yaml = new YamlStream();

            yaml.Load(new StringReader(File.ReadAllText("Games.yaml")));

            var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

            Games = new Dictionary <string, AGame>();
            foreach (var g in mapping)
            {
                string           code, name, creator;
                EngineType       engineType = EngineType.M4A; ReverbType reverbType = ReverbType.Normal;
                byte             engineReverb = 0, engineVolume = 0xF, engineTrackLimit = 0x10;
                int              engineFrequency = 13379; bool engineHasGoldenSunSynths = false;
                int[]            tables, tableSizes;
                List <APlaylist> playlists;
                string           remap = string.Empty;
                int              voiceTable = 0, sampleTable = 0, sampleTableSize = 0;

                code = g.Key.ToString();
                var game = (YamlMappingNode)g.Value;

                // Basic info
                name = game.Children["Name"].ToString();

                // SongTables
                var songTables = game.Children["SongTable"].ToString().Split(' ');
                tables = new int[songTables.Length]; tableSizes = new int[songTables.Length];
                for (int i = 0; i < songTables.Length; i++)
                {
                    tables[i] = (int)Utils.ParseValue(songTables[i]);
                }

                // MLSS info
                if (game.Children.TryGetValue("VoiceTable", out YamlNode vTable))
                {
                    voiceTable = (int)Utils.ParseValue(vTable.ToString());
                }
                if (game.Children.TryGetValue("SampleTable", out YamlNode sTable))
                {
                    sampleTable = (int)Utils.ParseValue(sTable.ToString());
                }
                if (game.Children.TryGetValue("SampleTableSize", out YamlNode saTableSize))
                {
                    sampleTableSize = (int)Utils.ParseValue(saTableSize.ToString());
                }

                // If we are to copy another game's config
                if (game.Children.TryGetValue("Copy", out YamlNode copy))
                {
                    game = (YamlMappingNode)mapping.Children[copy];
                }

                // SongTable Sizes
                string[] sizes = { };
                if (game.Children.TryGetValue("SongTableSize", out YamlNode soTableSize))
                {
                    sizes = soTableSize.ToString().Split(' ');
                }
                for (int i = 0; i < songTables.Length; i++)
                {
                    tableSizes[i] = DefaultTableSize;
                    if (i < sizes.Length)
                    {
                        tableSizes[i] = (int)Utils.ParseValue(sizes[i]);
                    }
                }

                // Creator name (required)
                creator = game.Children["Creator"].ToString();

                // Remap
                if (game.Children.TryGetValue("Remap", out YamlNode rmap))
                {
                    remap = rmap.ToString();
                }

                // Engine
                if (game.Children.TryGetValue("Engine", out YamlNode yeng))
                {
                    var eng = (YamlMappingNode)yeng;
                    if (eng.Children.TryGetValue("Type", out YamlNode type))
                    {
                        engineType = (EngineType)Enum.Parse(typeof(EngineType), type.ToString());
                    }
                    if (eng.Children.TryGetValue("ReverbType", out YamlNode rType))
                    {
                        reverbType = (ReverbType)Enum.Parse(typeof(ReverbType), rType.ToString());
                    }
                    if (eng.Children.TryGetValue("Reverb", out YamlNode reverb))
                    {
                        engineReverb = (byte)Utils.ParseValue(reverb.ToString());
                    }
                    if (eng.Children.TryGetValue("Volume", out YamlNode volume))
                    {
                        engineVolume = (byte)Utils.ParseValue(volume.ToString());
                    }
                    if (eng.Children.TryGetValue("TrackLimit", out YamlNode trackLim))
                    {
                        engineTrackLimit = (byte)Utils.ParseValue(trackLim.ToString());
                    }
                    if (eng.Children.TryGetValue("Frequency", out YamlNode frequency))
                    {
                        engineFrequency = (int)Utils.ParseValue(frequency.ToString());
                    }
                    if (eng.Children.TryGetValue("GoldenSunSynths", out YamlNode synths))
                    {
                        engineHasGoldenSunSynths = bool.Parse(synths.ToString());
                    }
                }
                var engine = new AnEngine(engineType, reverbType, engineReverb, engineVolume, engineTrackLimit, engineFrequency, engineHasGoldenSunSynths);

                // Load playlists
                playlists = new List <APlaylist>();
                if (game.Children.TryGetValue("Music", out YamlNode ymusic))
                {
                    var music = (YamlMappingNode)ymusic;
                    foreach (var kvp in music)
                    {
                        var songs = new List <ASong>();
                        foreach (var song in (YamlMappingNode)kvp.Value)
                        {
                            songs.Add(new ASong(short.Parse(song.Key.ToString()), song.Value.ToString())); // No hex values. It prevents putting in duplicates by having one hex and one dec of the same song index
                        }
                        playlists.Add(new APlaylist(kvp.Key.ToString(), songs.ToArray()));
                    }
                }

                // Full playlist
                if (!playlists.Any(p => p.Name == "Music"))
                {
                    playlists.Insert(0, new APlaylist("Music", playlists.Select(p => p.Songs).UniteAll().OrderBy(s => s.Index).ToArray()));
                }

                // If playlist is empty, add an empty entry
                for (int i = 0; i < playlists.Count; i++)
                {
                    if (playlists[i].Songs.Length == 0)
                    {
                        playlists[i] = new APlaylist(playlists[i].Name, new ASong[] { new ASong(0, "Playlist is empty.") });
                    }
                }

                Games.Add(code, new AGame(code, name, creator, engine, tables, tableSizes, playlists, remap,
                                          voiceTable, sampleTable, sampleTableSize));
            }
        }