jice-nospam / doryen-rs

ascii roguelike library in rust with native and wasm support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

open_file attempts to load from www/, not working directory

09silverware opened this issue · comments

According to the documentation here: https://docs.rs/doryen-rs/latest/doryen_rs/trait.DoryenApi.html#tymethod.set_font_path

During development, this references $PROJECT_ROOT/static/terminal.png. Once deployed, terminal.png should be in the same directory as your game’s executable or index.html.

However, open_file in src/file.rs is incorrectly setup to load from "./www/" instead of "./" or "./static/"
This looks to be configured this way to ensure the examples work, and reference the git www. But means that games created with the crate are also attempting to load files from "./www/" instead of "./"

This happens even when the target_arch is not "wasm32", at least in my testing. (Unless I am just being stupid somehow)

fn open_file(filename: &str) -> Result<uni_app::fs::File, std::io::Error> {
    let ffilename =
        if cfg!(not(target_arch = "wasm32")) && &filename[0..1] != "/" && &filename[1..2] != ":" {
            "www/".to_owned() + filename
        } else {
            filename.to_owned()
        };
    uni_app::fs::FileSystem::open(&ffilename)
}

This should probably be replaced with just

fn open_file(filename: &str) -> Result<uni_app::fs::File, std::io::Error> {
    let ffilename = filename.to_owned();
    uni_app::fs::FileSystem::open(&ffilename)
}

And the documentation/examples should be updated appropriately.

commented

Indeed, this is a recent change due to the switch to wasm_bindgen. The documentation is not up to date yet. I'll probably do what you suggest