Skip to content

Commit

Permalink
add option to open .wasm game scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDavenport committed Sep 27, 2022
1 parent 36c2c33 commit 6e5aad1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gamercade_console/src/gui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Gui {
ui.horizontal(|ui| {
if ui.button("Select Game").clicked() {
self.game_file = FileDialog::new()
.add_filter("gcrom (.gcrom)", &["gcrom"])
.add_filter("gcrom (.gcrom), wasm (.wasm)", &["gcrom", "wasm"])
.pick_file();
};

Expand Down
24 changes: 18 additions & 6 deletions gamercade_fs/src/rom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
use gamercade_audio::SoundRom;
use gamercade_core::{FrameRate, GraphicsData, Resolution};

use crate::{GameAssetProvider, GameCodeProvider};
use crate::{bundle, EditorRom, GameAssetProvider, GameCodeProvider};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Rom {
Expand Down Expand Up @@ -45,14 +45,26 @@ impl Rom {

pub fn try_load(path: &PathBuf) -> Result<Self, String> {
let file = fs::File::open(path).map_err(|e| e.to_string())?;
let mut reader = zstd::Decoder::new(file).map_err(|e| e.to_string())?;

let mut buffer = Vec::new();
match path.extension().and_then(|path| path.to_str()) {
Some("gce") => {
let mut reader = zstd::Decoder::new(file).map_err(|e| e.to_string())?;

// We don't care about how many bytes are read
let _ = reader.read_to_end(&mut buffer).map_err(|e| e.to_string());
let mut buffer = Vec::new();

bincode::deserialize_from::<_, Rom>(&*buffer).map_err(|e| e.to_string())
// We don't care about how many bytes are read
let _ = reader.read_to_end(&mut buffer).map_err(|e| e.to_string());

bincode::deserialize_from::<_, Rom>(&*buffer).map_err(|e| e.to_string())
}
Some("wasm") => {
println!("No assets provided. Using default Asset pack.");
let code = crate::try_load_wasm(path)?;
let assets = EditorRom::default();
Ok(bundle(&code, &assets))
}
_ => Err("Invalid file extension.".to_string()),
}
}

pub fn try_save(&self, path: &PathBuf) -> Result<(), String> {
Expand Down

0 comments on commit 6e5aad1

Please sign in to comment.