Exemple #1
0
        /// <summary>
        /// Save this setting into the config.ini file.
        /// </summary>
        /// <param name="category">Category to save under</param>
        /// <param name="key">The key to modify.</param>
        public virtual void Save(string category, string key)
        {
            switch (Type)
            {
            case "float":
                Config.SetFloat(category, key, (float)GetSaveValue());
                break;

            case "int":
                Config.SetInt(category, key, (int)GetSaveValue());
                break;

            case "double":
                Config.SetDouble(category, key, (double)GetSaveValue());
                break;

            case "bool":
                Config.SetBool(category, key, (bool)GetSaveValue());
                break;

            case "string":
                Config.SetString(category, key, (string)GetSaveValue());
                break;

            default:
                PulsarcLogger.Error($"Cannot save type {Type.ToString()} in category {category} for setting {key}", LogType.Runtime);
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// Start playing audio
        /// </summary>
        public static void StartLazyPlayer()
        {
            Stop();

            if (songPath == "")
            {
                return;
            }

            // Initialize the song
            try
            {
                song = new AudioTrack(songPath)
                {
                    Rate   = audioRate,
                    Volume = Config.GetInt("Audio", "MusicVolume"),
                };
            }
            catch (AudioEngineException)
            {
                PulsarcLogger.Error(ManagedBass.Bass.LastError.ToString(), LogType.Runtime);
            }

            song.ApplyRate(Config.GetBool("Audio", "RatePitch"));

            song.Play();
            active = true;
        }
Exemple #3
0
 /// <summary>
 /// Write a property to file
 /// </summary>
 /// <param name="file"></param>
 /// <param name="beatmap"></param>
 /// <param name="property"></param>
 static private void WriteProperty(StreamWriter file, Beatmap beatmap, string property)
 {
     try
     {
         // Use reflection to write any property. The property needs to implement ToString()
         file.WriteLine(property + ": " + beatmap.GetType().GetProperty(property).GetValue(beatmap, null));
     }
     catch
     {
         PulsarcLogger.Error($"Trying to write invalid property {property}", LogType.Runtime);
     }
 }
Exemple #4
0
        /// <summary>
        /// Load a skin from the folder name provided.
        /// </summary>
        /// <param name="name">The folder name of the skin to be loaded.</param>
        public static void LoadSkin(string name)
        {
            Assets  = new Dictionary <string, Texture2D>();
            Configs = new Dictionary <String, IniData>();
            Judges  = new Dictionary <int, Texture2D>();
            Sounds  = new Dictionary <string, AudioSample>();
            Loaded  = false;

            string skinFolder = $"Skins/{name}/";

            if (Directory.Exists(skinFolder))
            {
                // Load configs
                LoadConfigs(skinFolder);

                // Load gameplay assets
                LoadSkinTexture($"{skinFolder}Gameplay/", "arcs");
                LoadSkinTexture($"{skinFolder}Gameplay/", "crosshair");
                LoadSkinTexture($"{skinFolder}Gameplay/", "map_timer");

                // Load cursor asset
                LoadSkinTexture($"{skinFolder}UI/", "cursor");

                // Load Main Menu assets
                LoadMainMenu(skinFolder);

                // Load Result Screen assets (not including Grades)
                LoadResultScreen(skinFolder);

                // Load Song Select assets
                LoadSongSelect(skinFolder);

                // Load settings assets
                LoadSettings(skinFolder);

                // Load Grade assets
                LoadGrades(skinFolder);

                // Load judge assets
                LoadJudges(skinFolder);

                // Load sounds
                LoadSounds(skinFolder);

                Loaded = true;
            }
            else
            {
                PulsarcLogger.Error($"Could not find the skin {name}", LogType.Network);
            }
        }
Exemple #5
0
        public static Texture2D LoadFileTexture(string path)
        {
            Texture2D texture;

            try
            {
                texture = Texture2D.FromStream(Pulsarc.Graphics.GraphicsDevice, File.Open(path, FileMode.Open));
            }
            catch
            {
                PulsarcLogger.Error($"Failed to load {path}", LogType.Runtime);
                texture = Skin.DefaultTexture;
            }

            return(texture);
        }
Exemple #6
0
        public override void Draw()
        {
            if (caught)
            {
                return;
            }

            try
            {
                Pulsarc.SpriteBatch.DrawString(font, Text, processedPosition, Color, 0, origin, fontScale, SpriteEffects.None, 0);
            }
            catch
            {
                PulsarcLogger.Error($"Could not write {Text}, Aborting Draw() calls for this TextDisplayElement until Update() has been called.", LogType.Runtime);
                caught = true; // Don't need to spam the console with Errors
            }
        }
Exemple #7
0
        /// <summary>
        /// Load a single Beatmap.
        /// </summary>
        /// <param name="path">The path to the beatmap folder.</param>
        /// <param name="fileName">The fileName of the .psc file.</param>
        static public Beatmap Load(string path, string fileName)
        {
            Beatmap parsed = new Beatmap();

            parsed.Path     = path;
            parsed.FileName = fileName;

            var state = "";

            var lines = File.ReadLines($"{path}/{fileName}");

            foreach (var line in lines)
            {
                if (line.Length > 0)
                {
                    // Information like Metadata are in the form 'Type: Data'
                    Queue <string> lineParts = new Queue <string>(line.Split(':'));

                    // If we recognize this form, it's an attribute.
                    // Otherwise, it is a more complex data form, like an event
                    if (lineParts.Count > 1)
                    {
                        var type      = lineParts.Dequeue();
                        var rightPart = string.Concat(lineParts.ToArray()).Trim();

                        // Use reflection to set the Beatmap's attributes
                        switch (type)
                        {
                        case "FormatVersion":
                        case "Title":
                        case "Artist":
                        case "Mapper":
                        case "Version":
                        case "MapOffset":
                            try
                            {
                                parsed.GetType().GetProperty(type).SetValue(parsed, rightPart);
                            }
                            catch
                            {
                                PulsarcLogger.Error($"Unknown beatmap field : {type}", LogType.Runtime);
                            }
                            break;

                        case "Audio":
                            try
                            {
                                parsed.GetType().GetProperty(type).SetValue(parsed, rightPart);
                            }
                            catch
                            {
                                PulsarcLogger.Error($"Unknown beatmap field : {type}", LogType.Runtime);
                            }
                            break;

                        case "Background":
                        {
                            try
                            {
                                parsed.GetType().GetProperty(type).SetValue(parsed, rightPart);
                            }
                            catch
                            {
                                PulsarcLogger.Error($"Unknown beatmap field : {type}", LogType.Runtime);
                            }
                            break;
                        }

                        case "PreviewTime":
                        case "KeyCount":
                            try
                            {
                                parsed.GetType().GetProperty(type).SetValue(parsed, int.Parse(rightPart));
                            }
                            catch
                            {
                                PulsarcLogger.Error($"Unknown beatmap field : {type}", LogType.Runtime);
                            }
                            break;

                        case "Difficulty":
                            try
                            {
                                parsed.GetType().GetProperty(type).SetValue(parsed, Double.Parse(rightPart, CultureInfo.InvariantCulture));
                            }
                            catch
                            {
                                PulsarcLogger.Error($"Unknown beatmap field : {type}", LogType.Runtime);
                            }
                            break;

                        case "Events":
                        case "TimingPoints":
                        case "SpeedVariations":
                        case "Arcs":
                            state = type;
                            break;

                        default:
                            // Should probably ingore this really, like why would we need to know that?
                            //PulsarcLogger.Error($"Unknown beatmap field : {type}", LogType.Runtime);
                            break;
                        }
                    }
                    else
                    {
                        // Each event is comma separated and can have any amount of values.
                        var eventParts = line.Split(',');

                        // Handling depends on the data type (or the current reading state)
                        switch (state)
                        {
                        case "Events":
                            try
                            {
                                int type = int.Parse(eventParts[(int)EventIndex.Type]);

                                Event evnt = MakeEvent(line, (EventType)type);
                                if (evnt != null)
                                {
                                    parsed.Events.Add(evnt);
                                }
                            }
                            catch
                            {
                                PulsarcLogger.Error($"Invalid Event : {line}", LogType.Runtime);
                            }
                            break;

                        case "TimingPoints":
                            try
                            {
                                parsed.TimingPoints.Add(new TimingPoint(Convert.ToInt32(eventParts[0]), Convert.ToInt32(eventParts[1])));
                            }
                            catch
                            {
                                PulsarcLogger.Error($"Invalid TimingPoint : {line}", LogType.Runtime);
                            }
                            break;

                        case "Arcs":
                            try
                            {
                                parsed.Arcs.Add(new Arc(Convert.ToInt32(eventParts[0]), Convert.ToInt32(eventParts[1], 2)));
                            }
                            catch
                            {
                                PulsarcLogger.Error($"Invalid Arc : {line}", LogType.Runtime);
                            }
                            break;

                        default:
                            PulsarcLogger.Error($"Invalid state : {line}", LogType.Runtime);
                            break;
                        }
                    }
                }
            }

            // If no difficulty has been provided in the game file, process it now.
            if (parsed.Difficulty == 0)
            {
                parsed.Difficulty = DifficultyCalculation.GetDifficulty(parsed);
            }

            parsed.FullyLoaded = true;

            return(parsed);
        }