Skip to content

Customize the root of the project in the examples #55

@gpetiot

Description

@gpetiot

I don't find it convenient to move into the directory of the examples to get them to work, as the paths to the resources are relative to that directory.

So, I propose to add an optional ROOT environment variable to each example, such as:

+let root = Bos.OS.Env.var "ROOT"
+
 let setup () =
   let open Raylib in
   init_window width height "raylib [textures] example - bunnymark";
-  let tex_bunny = load_texture "resources/wabbit_alpha.png" in
+  let tex_bunny =
+    let path =
+      match root with
+      | Some root -> Fmt.str "%s/resources/wabbit_alpha.png" root
+      | None -> "resources/wabbit_alpha.png"
+    in
+    load_texture path
+  in

We can also put this code in some helper library to avoid duplications.

So that we can run them with:

ROOT=examples/textures dune exec -- examples/textures/textures_bunnymark_ocaml_types.exe

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions