Пример #1
0
    public void start_run()
    {
        _previous_diff = System.TimeSpan.Zero;
        speedrun.RunAttempt new_attempt = new speedrun.RunAttempt();
        new_attempt.attempt_index = _model.run.game_meta.attempts_count;

        DateTime now = DateTime.Now;

        new_attempt.start_datetime = now.ToString("yyyyMMddTHH:mm.ss");

        GetComponentsInChildren <SplitRow>()[_split_index].split_in();
        _current_split_row = GetComponentsInChildren <SplitRow>()[0];
        _current_attempt   = new_attempt;
        _model.run.game_meta.attempts_count++;
        _previous_split = null;
        _timer.new_run();

        SplitRow last_split = GetComponentsInChildren <SplitRow>()[GetComponentsInChildren <SplitRow>().Length - 1];

        on_run_start(last_split.model.pb, last_split.thumb);
        on_split(
            _current_split_row.model.name,
            0,
            _current_split_row.model.gold,
            _current_split_row.model.pb
            );
        on_update_split_thumb(_current_split_row.thumb);
    }
Пример #2
0
    public void skip_split()
    {
        if (_split_index + 1 > _model.run.split_meta.Count - 1)
        {
            // can't skip if it is last split!
            return;
        }

        _split_index++;

        speedrun.Split split = create_split(-1);
        _current_split_row.delta.text = "-";
        split.split_duration          = 0; // or -1 or something?
        //GetComponentsInChildren<SplitRow>()[_split_index].split_in(); // might need to tell it it can't gold!

        _previous_split = split;
        _current_split_row.split_out();
        _current_split_row = GetComponentsInChildren <SplitRow>()[_split_index];
        _current_split_row.split_in(true);


        on_split(
            _current_split_row.model.name,
            _previous_split.split_time,
            _current_split_row.model.gold,
            _current_split_row.model.pb,
            true
            );
        on_update_split_thumb(_current_split_row.thumb);
    }
Пример #3
0
    private speedrun.Split create_split(long split_time)
    {
        speedrun.Split split = new speedrun.Split();
        split.attempt_index = _current_attempt.attempt_index;
        split.split_time    = split_time;
        _model.run.split_meta[_split_index].history.Add(split);

        _current_split_row.split_out();
        return(split);
    }
Пример #4
0
    private void change_view_mode(SplitsManager.ViewMode mode)
    {
        System.TimeSpan t;
        switch (mode)
        {
        case SplitsManager.ViewMode.PB:
            _time.text = System.TimeSpan.FromMilliseconds(_model.pb).ToString(@"m\:ss");
            break;

        case SplitsManager.ViewMode.GLOD:
            //_time.text = System.TimeSpan.FromMilliseconds(_model.gold).ToString(@"m\:ss\.ff");
            t          = System.TimeSpan.FromMilliseconds(_model.gold);
            _time.text = string.Format("{0}:{1}.<size=16>{2}", t.Minutes, t.Seconds, t.Milliseconds);
            break;

        case SplitsManager.ViewMode.DURATION:
        case SplitsManager.ViewMode.POSSIBLE_SAVE:
            speedrun.Split i = null;
            foreach (var pb in _model.history)
            {
                if (pb.attempt_index == _model.pb_index)
                {
                    i = pb;
                    break;
                }
            }

            if (mode == SplitsManager.ViewMode.DURATION)
            {
                t          = System.TimeSpan.FromMilliseconds(i.split_duration);
                _time.text = string.Format("{0}:{1}.<size=16>{2}", t.Minutes, t.Seconds, t.Milliseconds);
                //_time.text = System.TimeSpan.FromMilliseconds(i.split_duration).ToString(@"m\:ss");
            }
            else if (mode == SplitsManager.ViewMode.POSSIBLE_SAVE)
            {
                t          = System.TimeSpan.FromMilliseconds(i.split_duration - _model.gold);
                _time.text = string.Format("{0}:{1}.<size=16>{2}", t.Minutes, t.Seconds, t.Milliseconds);
                //_time.text = System.TimeSpan.FromMilliseconds(i.split_duration - _model.gold).ToString(@"m\:ss");
            }
            break;
        }
    }
Пример #5
0
    public void split()
    {
        if (_current_split_row && _current_split_row.model.pause_state)
        {
            _timer.resume();
        }

        speedrun.Split split   = create_split(_timer.elapsed_ms);
        TimeSpan       elapsed = _timer.elapsed_ts; // total milliseconds for precission?

        _current_split_row.time.text = elapsed.ToString(@"m\:ss");

        long pb_time_left = _current_split_row.model.pb - _timer.elapsed_ms;

        System.TimeSpan ts = System.TimeSpan.FromMilliseconds(pb_time_left);
        _current_split_row.delta_image.color = new Color(0.0f, 0.0f, 0.0f, 0.2f);

        string ts_string = @"hh\:mm\:ss";

        if (ts.Hours == 0)
        {
            if (ts.Minutes == 0)
            {
                ts_string = @"s\.f";
            }
            else
            {
                ts_string = @"mm\:ss";
            }
        }
        _current_split_row.delta.text = (pb_time_left > 0 ? "-" : "+") + ts.ToString(ts_string);

        long split_gold = _model.run.split_meta[_split_index].gold;

        split.split_duration = split.split_time - (_previous_split == null ? 0 : _previous_split.split_time);


        if (_current_split_row.skipped == false && (split.split_duration < split_gold || split_gold == 0))
        {
            long old_gold = _model.run.split_meta[_split_index].gold;
            _model.run.split_meta[_split_index].gold        = split.split_duration;
            _current_split_row.GetComponent <Image>().color = new Color(1.0f, 0.92f, 0.0f, 0.25f);

            System.TimeSpan glod_ts = System.TimeSpan.FromMilliseconds(split.split_duration - old_gold);
            on_split_compare(glod_ts, new Color(1.0f, 0.92f, 0.0f, 0.9f));
        }
        else
        {
            //long time_left = _current_split_row.model.pb - _timer.stopwatch.ElapsedMilliseconds;
            //System.TimeSpan ts = System.TimeSpan.FromMilliseconds(time_left);
            //string ts_string = ts.Minutes == 0 ? @"s\.f" : @"m\:ss";

            System.TimeSpan diff_ts = (ts - _previous_diff);

            //on_split_compare(time_left, time_left > 0 ? Color.green:Color.red);
            on_split_compare(diff_ts, diff_ts.Ticks > 0 ? Color.green:Color.red);
        }
        _previous_diff = ts;

        if (++_split_index >= _model.run.split_meta.Count)
        {
            end_run();
        }
        else
        {
            GetComponentsInChildren <SplitRow>()[_split_index].split_in();

            float offset = (float)_split_index / _model.run.split_meta.Count;
            if (_split_index + 1 == _model.run.split_meta.Count)
            {
                offset = 1.0f;
            }
            _scrollbar.split(offset);
        }
        _previous_split    = split;
        _current_split_row = GetComponentsInChildren <SplitRow>()[_split_index];

        if (_current_split_row.model.pause_state)
        {
            _timer.pause();
        }

        on_split(
            _current_split_row.model.name,
            _previous_split.split_time,
            _current_split_row.model.gold,
            _current_split_row.model.pb
            );

        on_update_split_thumb(_current_split_row.thumb);
    }
Пример #6
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
    }