@@ -53,17 +53,17 @@ module Textures = struct
53
53
type t = {
54
54
maps : (Gmap .area * R.Texture .t ) list ;
55
55
pics : (string , R.Texture .t ) Hashtbl .t ;
56
+ map : R.Texture .t ;
56
57
}
57
58
58
- let make () = {maps= [] ; pics= Hashtbl. create 20 }
59
-
60
- let of_resources win res =
59
+ let of_resources win res area =
61
60
let maps = List. map (fun (a , v ) -> a, R.Texture. make win @@ Gmap. to_img v) res.res_maps in
61
+ let map = List. assoc ~eq: (Stdlib. (= )) area maps in
62
62
let pics = Hashtbl. to_iter res.res_pics
63
63
|> Iter. map (fun (s , arr ) -> s, R.Texture. make win arr)
64
64
|> Hashtbl. of_iter
65
65
in
66
- {maps; pics}
66
+ {maps; pics; map }
67
67
end
68
68
69
69
type state = {
@@ -79,26 +79,26 @@ let run ?(view=Screen.MapGen None) ?(area=Gmap.WestUS) () : unit =
79
79
let random = Random. get_state () in
80
80
81
81
Printf. printf " Loading resources..." ;
82
- let res_maps = List. map (fun (x ,s ) -> x, " ./data/" ^ s |> Gmap. of_file) map_names in
83
- let res_cities = List. map Mapgen. load_city_list Gmap. areas |>
84
- List. combine Gmap. areas
85
- in
86
- let res_pics = load_pics () in
87
- let res_fonts = Font. load_all () in
88
- let resources = {res_maps; res_pics; res_fonts; res_cities} in
89
82
90
- let screen = Screen. make view in
83
+ let init_fn win =
84
+ let res_maps = List. map (fun (x ,s ) -> x, " ./data/" ^ s |> Gmap. of_file) map_names in
85
+ let res_cities = List. map Mapgen. load_city_list Gmap. areas |>
86
+ List. combine Gmap. areas
87
+ in
88
+ let res_pics = load_pics () in
89
+ let res_fonts = Font. load_all () in
90
+ let resources = {res_maps; res_pics; res_fonts; res_cities} in
91
91
92
- let map = List. assoc ~eq: (Stdlib. (= )) area res_maps in
93
- let cities = List. assoc ~eq: (Stdlib. (= )) area res_cities |> Array. of_list in
94
- let game = {map; area; cities} in
95
- let textures = Textures. make () in
96
- let state = {game; screen; resources; random; textures} in
97
- Printf. printf " done.\n " ;
92
+ let screen = Screen. make view in
98
93
99
- let init_fn win =
100
- let textures = Textures. of_resources win state.resources in
101
- let state = {state with textures} in
94
+ let map = List. assoc ~eq: (Stdlib. (= )) area res_maps in
95
+ let cities = List. assoc ~eq: (Stdlib. (= )) area res_cities |> Array. of_list in
96
+ let game = {map; area; cities} in
97
+
98
+ let textures = Textures. of_resources win resources area in
99
+ let state = {game; screen; resources; random; textures} in
100
+
101
+ Printf. printf " done.\n " ;
102
102
103
103
let update (s :state ) _event =
104
104
let state =
@@ -122,6 +122,7 @@ let run ?(view=Screen.MapGen None) ?(area=Gmap.WestUS) () : unit =
122
122
let () = R. error_handle @@
123
123
let * () = R. clear_screen win in
124
124
let * () = R. render win bg_tex in
125
+ let * () = R. render win @@ List. assoc ~eq: (Gmap. equal_area) area s.textures.maps in
125
126
Result. return ()
126
127
in
127
128
s
0 commit comments