Пример #1
0
    private void load_splits()
    {
        _split_model = GameView.load_game_model(_id);

        _name.text       = _split_model.run.game_meta.name;
        _start_time.text = _split_model.run.game_meta.start_offset;
        _attempts.text   = _split_model.run.game_meta.attempts_count.ToString();

        Texture2D tex = null;

        byte[] data;

        string thumb_path = Application.persistentDataPath + "/" + _id + "/game_thumb.png";

        if (File.Exists(thumb_path))
        {
            data = File.ReadAllBytes(thumb_path);
            tex  = new Texture2D(2, 2);
            tex.LoadImage(data);
            _thumb.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(.5f, .5f));
        }

        foreach (Transform s in _split_container.transform)
        {
            Destroy(s.gameObject);
        }

        foreach (speedrun.SplitMeta s in _split_model.run.split_meta)
        {
            Split split = Split.Instantiate(_split_row_prefab, _split_container.transform);
            split.model = s;
        }
    }
Пример #2
0
    private void update_gold()
    {
        _model = GameView.load_game_model(PlayerPrefs.GetString("active_game"));
        long sob = 0;

        foreach (speedrun.SplitMeta meta in _model.run.split_meta)
        {
            sob += meta.gold;
        }
        TimeSpan ts     = TimeSpan.FromMilliseconds(sob);
        string   format = "";

        if (ts.Hours > 0)
        {
            format += "HH";
        }
        _sob.text = ts.ToString(@"mm\:ss\.ff");
    }
Пример #3
0
    void Awake()
    {
        _id    = PlayerPrefs.GetString("active_game");
        _model = GameView.load_game_model(_id);

        if (_model.run.game_meta.limerick)
        {
            _limerick_mode = true;
        }
        var start_offset = _model.run.game_meta.start_offset;

        if (start_offset != null && start_offset != "")
        {
            _timer.offset = float.Parse(_model.run.game_meta.start_offset);
        }
        else
        {
            _timer.offset = 0.0f;
        }

        foreach (speedrun.SplitMeta s in _model.run.split_meta)
        {
            SplitRow split = SplitRow.Instantiate(_split_prefab, transform);
            split.model = s;
            if (_limerick_mode)
            {
                split.limerick_mode = true;
            }
        }

        if (_model.run.game_meta.finished_count == 0)
        {
            _model.run.game_meta.finished_count = 0;
            foreach (var a in _model.run.attempts)
            {
                if (a.finished == true)
                {
                    _model.run.game_meta.finished_count++;
                }
            }
            save();
        }
        on_attempts_update(_model.run.game_meta.attempts_count, _model.run.game_meta.finished_count);
    }
Пример #4
0
    public static speedrun.RunModel load_game_model(string game_id)
    {
        //string path = Application.persistentDataPath + "/" + game_id + "/splits/split.json";
        string path = PlayerPrefs.GetString(game_id);

        if (File.Exists(path))
        {
            //BinaryFormatter formatter = new BinaryFormatter();
            FileStream   fs = new FileStream(path, FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            string json = sr.ReadToEnd();
            sr.Close();
            fs.Close();
            speedrun.RunModel model = JsonConvert.DeserializeObject <speedrun.RunModel>(json);
            return(model);
        }
        else
        {
            Debug.Log("no file found for: " + path);
            Debug.Log("creating from known data");

            string game_path = Application.persistentDataPath + "/" + game_id + "/gameinfo.bgi";

            BinaryFormatter    formatter  = new BinaryFormatter();
            FileStream         fs         = new FileStream(game_path, FileMode.Open);
            speedrun.GameModel game_model = formatter.Deserialize(fs) as speedrun.GameModel;
            fs.Close();

            speedrun.RunModel model = new speedrun.RunModel();
            model.run = new speedrun.Run();
            model.run.game_meta.thumb_path = "game_thumb.png";
            model.run.game_meta.name       = game_model.data.names.international;

            // also need to write it to file, so we aren't missing it next time!

            return(model);
        }
    }
Пример #5
0
    private void create_splits_from_xml(string xml_path)
    {
        speedrun.RunModel run = new speedrun.RunModel();

        XmlDocument doc = new XmlDocument();

        doc.Load(xml_path);

        ///////////////////
        // Run meta-data
        run.run.game_meta.name      = doc.DocumentElement.SelectSingleNode("/Run/GameName").InnerText;
        run.run.game_meta.catergory = doc.DocumentElement.SelectSingleNode("/Run/CategoryName").InnerText;
        System.TimeSpan ts = System.TimeSpan.Parse(doc.DocumentElement.SelectSingleNode("/Run/Offset").InnerText);
        //run.run.game_meta.start_offset = string.Format("{0}.{0}", ts.Seconds, ts.Milliseconds);
        run.run.game_meta.start_offset = ts.Seconds + "." + ts.Milliseconds;

        run.run.game_meta.attempts_count = System.Int32.Parse(doc.DocumentElement.SelectSingleNode("/Run/AttemptCount").InnerText);

        ////////////////
        // Split meta-data
        XmlNode segment_nodelist = doc.DocumentElement.SelectSingleNode("/Run/Segments");

        foreach (XmlNode node in segment_nodelist)
        {
            speedrun.SplitMeta m = new speedrun.SplitMeta();

            m.name       = node.SelectSingleNode("Name").InnerText;
            m.thumb_path = node.SelectSingleNode("Icon").InnerText;
            // need to take the info which is formated in hh:mm:ss.fffffff in livesplit
            // and make it a timestamp-friendly time..(ms I think I use..)
            string          pb_time = node.SelectSingleNode("SplitTimes/SplitTime/RealTime").InnerText;
            System.TimeSpan pb_dt   = System.TimeSpan.Parse(pb_time);
            m.pb = (long)pb_dt.TotalMilliseconds;
            // need to find the pb-index when parsing history!
            string          glod_time = node.SelectSingleNode("BestSegmentTime/RealTime").InnerText;
            System.TimeSpan glod_dt   = System.TimeSpan.Parse(glod_time);
            m.gold = (long)glod_dt.TotalMilliseconds;

            /////////////////////////////////
            // parse the history for the run!
            XmlNode history = node.SelectSingleNode("SegmentHistory");
            foreach (XmlNode entry in history)
            {
                speedrun.Split split = new speedrun.Split();

                split.attempt_index = System.Int32.Parse(entry.Attributes.GetNamedItem("id").InnerText);
                System.TimeSpan entry_ts = System.TimeSpan.Parse(entry.SelectSingleNode("RealTime").InnerText);
                split.split_time     = (long)entry_ts.TotalMilliseconds;
                split.split_duration = (long)entry_ts.TotalMilliseconds;
                // duration is tricky it is what livesplit actually store..
                // I am not sure we'll have to try it out and figure out as we go.. do we just skip duration, or do we try to calculate it?

                m.history.Add(split);
            }
            run.run.split_meta.Add(m);
        }

        ///////////
        // Attempts
        XmlNode attempts = doc.DocumentElement.SelectSingleNode("/Run/AttemptHistory");

        foreach (XmlNode attempt_node in attempts)
        {
            speedrun.RunAttempt attempt = new speedrun.RunAttempt();
            attempt.attempt_index  = System.Int32.Parse(attempt_node.Attributes.GetNamedItem("id").InnerText);
            attempt.start_datetime = attempt_node.Attributes.GetNamedItem("started").InnerText;
            attempt.end_datetime   = attempt_node.Attributes.GetNamedItem("ended").InnerText;
            attempt.finished       = attempt_node.HasChildNodes;

            run.run.attempts.Add(attempt);
        }

        string json_path = System.IO.Path.GetFileName(xml_path);

        json_path = json_path.Replace(".lss", ".json");

        string id   = PlayerPrefs.GetString("active_game");
        string path = Application.persistentDataPath + "/" + id + "/splits/" + json_path;

        run.save(path);
        on_import_done(json_path);

        //run.run.split_meta
    }