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); }
public void unsplit() { if (_split_index - 1 < 0) { // can't unsplit past first split! return; } _split_index--; // clean up current row _current_split_row.delta.text = "-"; //_current_split_row.time // reactivate the last split. //_previous_split = split; _current_split_row.split_out(true); _current_split_row = GetComponentsInChildren <SplitRow>()[_split_index]; _current_split_row.split_in(); 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); }
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); }
void OnDisable() { SplitRow i = transform.GetChild(transform.childCount - 1).GetComponent <SplitRow>(); i.thumb_updated -= set_final_split; Timer.on_run_start -= run_start; }
void OnEnable() { SplitRow i = transform.GetChild(transform.childCount - 1).GetComponent <SplitRow>(); i.thumb_updated += set_final_split; on_run_end(); Timer.on_run_start += run_start; }
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); }
private void reset() { SplitRow[] rows = GetComponentsInChildren <SplitRow>(); for (int i = 0; i < rows.Length; i++) { SplitRow s = rows[i]; s.model = _model.run.split_meta[i]; s.reset(); limerick_mode = _limerick_mode; } _split_index = 0; on_reset(rows[0].model.name); if (_timer.state == Timer.TimeState.Running) { on_run_end(); } _timer.reset(); }
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); }