• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A Nix-friendly SQLite-enhanced fork of Flitter, a speedrunning split timer for Unix-style terminals


Commit MetaInfo

Révision8aa997f0c15b38ce52569a1387afea104f4bcdb5 (tree)
l'heure2023-07-07 12:19:42
AuteurCorbin <cds@corb...>
CommiterCorbin

Message de Log

Make Gold.to_image foldable.

Okay! This was the missing piece. Now to restore the big patch...

Change Summary

Modification

--- a/src/display.mli
+++ b/src/display.mli
@@ -1,10 +1,8 @@
11 type t
22
33 val time_col_width : int
4-
54 val left_pad : int -> Notty.image -> Notty.image
65 val join_pad : int -> Notty.image -> Notty.image -> Notty.image
7-
86 val make : unit -> t
97 val draw : t -> Timer_types.timer -> unit
108 val close : t -> unit
--- a/src/gold.ml
+++ b/src/gold.ml
@@ -17,7 +17,7 @@ let sum_of_best =
1717 match (min, sd) with Some best, Some d -> Some (d + best) | _, _ -> None)
1818 (Some 0)
1919
20-let to_image (_, s) ((avg, stddev, min), md) ~width ~now =
20+let to_image s ((avg, stddev, min), md) ~width ~now =
2121 (* XXX should be Colors.selection_bg on the active split;
2222 parameterize the color and add a zipper to Run.t? *)
2323 let bg_attr = Colors.default_bg in
@@ -48,19 +48,24 @@ let to_image (_, s) ((avg, stddev, min), md) ~width ~now =
4848
4949 (* Compute the image of the split's segment time *)
5050 let sgmt_image = plain_duration min in
51+ fun mcd ->
52+ (* Compute the image of the split's absolute time *)
53+ let time_image = plain_duration mcd in
5154
52- (* Compute the image of the split's absolute time *)
53- (* XXX needs to fold and sum *)
54- let time_image = plain_duration None in
55+ (* Combine the three time columns together with proper padding *)
56+ let time_cells = [ delta_image; sgmt_image; time_image ] in
57+ let time_cols_combined =
58+ List.map (Display.left_pad Display.time_col_width) time_cells
59+ |> Notty.I.hcat
60+ in
5561
56- (* Combine the three time columns together with proper padding *)
57- let time_cells = [ delta_image; sgmt_image; time_image ] in
58- let time_cols_combined =
59- List.map (Display.left_pad Display.time_col_width) time_cells
60- |> Notty.I.hcat
61- in
62-
63- (* Add the split title and background color to fill in the padding *)
64- let row_top = Display.join_pad width title time_cols_combined in
65- let row_bottom = Notty.I.char bg_attr ' ' width 1 in
66- Notty.I.(row_top </> row_bottom)
62+ (* Add the split title and background color to fill in the padding *)
63+ let row_top = Display.join_pad width title time_cols_combined in
64+ let row_bottom = Notty.I.char bg_attr ' ' width 1 in
65+ let c =
66+ match (mcd, md, min) with
67+ | Some cd, Some d, _ -> Some (cd + d)
68+ | Some cd, None, Some m -> Some (cd + m)
69+ | _ -> None
70+ in
71+ (Notty.I.(row_top </> row_bottom), c)
--- a/src/gold.mli
+++ b/src/gold.mli
@@ -9,4 +9,10 @@ val is_gold : t -> Duration.t -> bool
99 val ahead_by : t -> Duration.t -> Duration.t option
1010 val sum_of_best : t list -> Duration.t option
1111
12-val to_image : string * string -> t * Duration.t option -> width:int -> now:float -> Notty.image
12+val to_image :
13+ string ->
14+ t * Duration.t option ->
15+ width:int ->
16+ now:float ->
17+ Duration.t option ->
18+ Notty.image * Duration.t option
--- a/src/run.ml
+++ b/src/run.ml
@@ -25,7 +25,7 @@ let from_db db game category =
2525 Gold.of_stats
2626 ( Some (int_of_float (Sqlite3.Data.to_float_exn row.(2))),
2727 Some (int_of_float (Sqlite3.Data.to_float_exn row.(3))),
28- Some (Sqlite3.Data.to_int_exn row.(4))))))
28+ Some (Sqlite3.Data.to_int_exn row.(4)) ) )) )
2929
3030 let map f (i, l) = (i, List.map ~f:(fun (s, t, x) -> (s, t, f x)) l)
3131 let iter f (_, l) = List.iter ~f:(fun (s, t, x) -> f x) l