Ejemplo n.º 1
0
    void Save()
    {
        if (!changesPending)
        {
            return;
        }

        Target.StartingPlayerPosition.SetFromIndex(Player.Index);

        string s        = Target.Serialize();
        string fileName = LevelLoader.GetFullLevelPath(LevelId);

        if (File.Exists(fileName))
        {
            File.Delete(fileName);
        }
        else
        {
            LevelLoader.LevelCount++;
            SaveGame.AddLevel();
        }

        using (StreamWriter sw = File.CreateText(fileName))
            sw.Write(s.ToCharArray());

        changesPending = false;
        AudioLibrary.Instance.Play("Save");
    }
Ejemplo n.º 2
0
    void FetchLevelOnline()
    {
        WebClient client = new WebClient();
        int       id     = -1;

        byte[] raw    = client.DownloadData("https://raw.githubusercontent.com/LeBodro/KlSS/master/weekly.txt");
        string data   = System.Text.Encoding.ASCII.GetString(raw);
        int    length = data.IndexOf('\n');
        string rawId  = data.Substring(0, length + 1);

        if (!int.TryParse(rawId, out id))
        {
            Console.WriteLine("Failed to parse \"" + rawId + "\" as id.");
        }

        if (id > SaveGame.Weekly)
        {
            Console.WriteLine("Adding downloaded level.");
            data            = data.Replace(rawId, string.Empty);
            SaveGame.Weekly = id;
            using (StreamWriter sw = File.CreateText(GetFullLevelPath(LevelCount)))
                sw.Write(data.ToCharArray());
            LevelCount++;
            SaveGame.AddLevel();
        }
        else
        {
            Console.WriteLine("Already up to date.");
        }
    }