Compare commits

..

3 Commits

2 changed files with 15 additions and 11 deletions

View File

@@ -44,10 +44,12 @@ jobs:
- name: Cache vcpkg - name: Cache vcpkg
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
save-always: true # deprecated
path: target/vcpkg path: target/vcpkg
key: ${{ runner.os }}-vcpkg-${{ hashFiles('Cargo.toml', 'Cargo.lock') }} key: vcpkg-${{ runner.os }}-${{ matrix.target }}-${{ hashFiles('Cargo.toml', 'Cargo.lock') }}
restore-keys: | restore-keys: |
${{ runner.os }}-vcpkg- ${{ runner.os }}-vcpkg
vcpkg-${{ runner.os }}-${{ matrix.target }}-
- name: Vcpkg Linux Dependencies - name: Vcpkg Linux Dependencies
if: runner.os == 'Linux' if: runner.os == 'Linux'
@@ -89,7 +91,7 @@ jobs:
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup Emscripten SDK - name: Setup Emscripten SDK
uses: mymindstorm/setup-emsdk@v14 uses: pyodide/setup-emsdk@v15
with: with:
version: 3.1.43 version: 3.1.43
actions-cache-folder: "emsdk-cache" actions-cache-folder: "emsdk-cache"

View File

@@ -78,15 +78,17 @@ mod imp {
#[cfg(target_os = "emscripten")] #[cfg(target_os = "emscripten")]
mod imp { mod imp {
use super::*; use super::*;
use std::fs; use sdl2::rwops::RWops;
use std::path::Path; use std::io::Read;
pub fn get_asset_bytes(asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> { pub fn get_asset_bytes(asset: Asset) -> Result<Cow<'static, [u8]>, AssetError> {
let path = Path::new("assets/game").join(asset.path()); let path = format!("assets/game/{}", asset.path());
if !path.exists() { let mut rwops = RWops::from_file(&path, "rb").map_err(|_| AssetError::NotFound(asset.path().to_string()))?;
return Err(AssetError::NotFound(asset.path().to_string())); let len = rwops.len().ok_or_else(|| AssetError::NotFound(asset.path().to_string()))?;
} let mut buf = vec![0u8; len];
let bytes = fs::read(&path)?; rwops
Ok(Cow::Owned(bytes)) .read_exact(&mut buf)
.map_err(|e| AssetError::Io(std::io::Error::new(std::io::ErrorKind::Other, e)))?;
Ok(Cow::Owned(buf))
} }
} }