make Grid.draw more flexible
- printer callback includes Vec2.t in the arguments now - added optional rev_x and rev_y params
This commit is contained in:
1 parent
a7c039197b
commit
490696c63d
3 files changed
+12
-8
No files matched your search
+1
-1
@@ -9,7 +9,7 @@ type tile =
|
||||
| Path_L
|
||||
| Path_R
|
||||
|
||||
let char_of_tile = function
|
||||
let char_of_tile _ = function
|
||||
| Empty -> '-'
|
||||
| Rock -> '#'
|
||||
| Sand -> 'o'
|
||||
|
||||
+10
-6
@@ -82,12 +82,16 @@ let iter grid callback =
|
||||
iter_region grid a b callback
|
||||
;;
|
||||
|
||||
let draw grid printer =
|
||||
let str = ref [] in
|
||||
let draw grid ?(rev_y = false) ?(rev_x = false) printer =
|
||||
let line = ref [] in
|
||||
let lines = ref [] in
|
||||
iter grid (fun point ->
|
||||
let item = grid.%(point) in
|
||||
let char = printer @@ Option.get_exn_or "iter is broken" item in
|
||||
str := !str @ [ char ];
|
||||
if point.x = grid.width - 1 then str := !str @ [ '\n' ]);
|
||||
String.of_list !str
|
||||
let char = printer point (Option.get_exn_or "iter is broken" item) in
|
||||
line := if rev_x then char :: !line else !line @ [ char ];
|
||||
if List.length !line = grid.width
|
||||
then (
|
||||
lines := !lines @ [ String.of_list !line ];
|
||||
line := []));
|
||||
String.concat "\n" (if rev_y then List.rev !lines else !lines)
|
||||
;;
|
||||
+1
-1
@@ -11,4 +11,4 @@ val find : 'a t -> ('a -> bool) -> (Vec2.t * 'a) option
|
||||
val count : 'a t -> ('a -> bool) -> int
|
||||
val iter_region : 'a t -> Vec2.t -> Vec2.t -> (Vec2.t -> unit) -> unit
|
||||
val iter : 'a t -> (Vec2.t -> unit) -> unit
|
||||
val draw : 'a t -> ('a -> char) -> string
|
||||
val draw : 'a t -> ?rev_y:bool -> ?rev_x:bool -> (Vec2.t -> 'a -> char) -> string
|
||||
Reference in new issue
Block a user