Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export save states #311

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tetanes-core/src/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,14 @@ impl Reset for Bus {
}

impl Sram for Bus {
fn save(&self, dir: impl AsRef<Path>) -> fs::Result<()> {
fs::save(dir.as_ref().with_extension(".sram"), self.sram())?;
self.ppu.bus.mapper.save(dir)
fn save(&self, path: impl AsRef<Path>) -> fs::Result<()> {
fs::save(path.as_ref(), self.sram())?;
self.ppu.bus.mapper.save(path)
}

fn load(&mut self, dir: impl AsRef<Path>) -> fs::Result<()> {
fs::load(dir.as_ref().with_extension(".sram")).map(|data| self.load_sram(data))?;
self.ppu.bus.mapper.load(dir)
fn load(&mut self, path: impl AsRef<Path>) -> fs::Result<()> {
fs::load(path.as_ref()).map(|data| self.load_sram(data))?;
self.ppu.bus.mapper.load(path)
}
}

Expand Down
12 changes: 10 additions & 2 deletions tetanes-core/src/control_deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ impl Config {
pub const BASE_DIR: &'static str = "tetanes";
/// Directory for storing battery-backed Cart RAM.
pub const SRAM_DIR: &'static str = "sram";
/// File extension for battery-backed Cart RAM.
pub const SRAM_EXTENSION: &'static str = "sram";

/// Returns the default directory where TetaNES data is stored.
#[inline]
Expand Down Expand Up @@ -470,7 +472,10 @@ impl ControlDeck {
}

info!("saving SRAM...");
self.cpu.bus.save(path).map_err(Error::Sram)?;
self.cpu
.bus
.save(path.with_extension(Config::SRAM_EXTENSION))
.map_err(Error::Sram)?;
}
Ok(())
}
Expand All @@ -488,7 +493,10 @@ impl ControlDeck {
}
if path.is_file() {
info!("loading SRAM...");
self.cpu.bus.load(path).map_err(Error::Sram)?;
self.cpu
.bus
.load(path.with_extension(Config::SRAM_EXTENSION))
.map_err(Error::Sram)?;
}
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tetanes-core/src/sys/fs/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct StoreReader {
cursor: io::Cursor<Vec<u8>>,
}

fn local_storage() -> Result<web_sys::Storage> {
pub fn local_storage() -> Result<web_sys::Storage> {
let window = web_sys::window().ok_or_else(|| Error::custom("failed to get js window"))?;
window
.local_storage()
Expand Down
2 changes: 2 additions & 0 deletions tetanes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ web-sys = { workspace = true, features = [
] }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
zip = { version = "2.1", default-features = false, features = ["deflate"] }
base64 = "0.22"

[package.metadata.docs.rs]
rustc-args = ["--cfg=web_sys_unstable_apis"]
Expand Down
52 changes: 26 additions & 26 deletions tetanes/src/nes/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ impl AsRef<str> for Action {
Ui::LoadReplay => "Load Replay",
},
Action::Menu(menu) => match menu {
Menu::About => "Toggle About Window",
Menu::Keybinds => "Toggle Keybinds Menu",
Menu::PerfStats => "Toggle Performance Stats Window",
Menu::About => "Toggle About",
Menu::Keybinds => "Toggle Keybinds",
Menu::PerfStats => "Toggle Performance Stats",
Menu::PpuViewer => "Toggle PPU Viewer",
Menu::Preferences => "Toggle Preferences Menu",
Menu::Preferences => "Toggle Preferences",
},
Action::Feature(feature) => match feature {
Feature::ToggleReplayRecording => "Toggle Replay Recording",
Expand All @@ -214,10 +214,10 @@ impl AsRef<str> for Action {
Setting::ToggleScreenReader => "Toggle Screen Reader",
Setting::ToggleFps => "Toggle FPS",
Setting::FastForward => "Fast Forward",
Setting::IncrementScale => "Increment Scale",
Setting::DecrementScale => "Decrement Scale",
Setting::IncrementSpeed => "Increment Speed",
Setting::DecrementSpeed => "Decrement Speed",
Setting::IncrementScale => "Scale Increment",
Setting::DecrementScale => "Scale Decrement",
Setting::IncrementSpeed => "Speed Increment",
Setting::DecrementSpeed => "Speed Increment",
},
Action::Deck(deck) => match deck {
DeckAction::Reset(kind) => match kind {
Expand All @@ -236,13 +236,13 @@ impl AsRef<str> for Action {
JoypadBtn::Select => "Joypad Select",
JoypadBtn::Start => "Joypad Start",
},
DeckAction::ToggleZapperConnected => "Toggle Zapper Connected",
DeckAction::ToggleZapperConnected => "Zapper Gun Toggle",
DeckAction::ZapperAim(_) => "Zapper Aim",
DeckAction::ZapperAimOffscreen => "Zapper Aim Offscreen (Hold)",
DeckAction::ZapperTrigger => "Zapper Trigger",
DeckAction::FourPlayer(FourPlayer::Disabled) => "Disable Four Player Mode",
DeckAction::FourPlayer(FourPlayer::FourScore) => "Enable Four Player (FourScore)",
DeckAction::FourPlayer(FourPlayer::Satellite) => "Enable Four Player (Satellite)",
DeckAction::FourPlayer(FourPlayer::Disabled) => "4-Player Disable",
DeckAction::FourPlayer(FourPlayer::FourScore) => "4-Player Enable (FourScore)",
DeckAction::FourPlayer(FourPlayer::Satellite) => "4-Player Enable (Satellite)",
DeckAction::SetSaveSlot(1) => "Set Save Slot 1",
DeckAction::SetSaveSlot(2) => "Set Save Slot 2",
DeckAction::SetSaveSlot(3) => "Set Save Slot 3",
Expand All @@ -264,17 +264,17 @@ impl AsRef<str> for Action {
},
DeckAction::MapperRevision(rev) => match rev {
MapperRevision::Mmc3(mmc3) => match mmc3 {
Mmc3Revision::A => "Set Mapper Rev. to MMC3A",
Mmc3Revision::BC => "Set Mapper Rev. to MMC3B/C",
Mmc3Revision::Acc => "Set Mapper Rev. to MC-ACC",
Mmc3Revision::A => "Set Mapper to MMC3A",
Mmc3Revision::BC => "Set Mapper to MMC3B/C",
Mmc3Revision::Acc => "Set Mapper to MC-ACC",
},
MapperRevision::Bf909(bf909) => match bf909 {
Bf909Revision::Bf909x => "Set Mapper Rev. to BF909x",
Bf909Revision::Bf9097 => "Set Mapper Rev. to BF9097",
Bf909Revision::Bf909x => "Set Mapper to BF909x",
Bf909Revision::Bf9097 => "Set Mapper to BF9097",
},
},
DeckAction::SetNesRegion(region) => match region {
NesRegion::Auto => "Set Region to Auto-Detect",
NesRegion::Auto => "Set Region to Auto",
NesRegion::Ntsc => "Set Region to NTSC",
NesRegion::Pal => "Set Region to PAL",
NesRegion::Dendy => "Set Region to Dendy",
Expand All @@ -286,16 +286,16 @@ impl AsRef<str> for Action {
},
Action::Debug(debug) => match debug {
Debug::Toggle(debugger) => match debugger {
Debugger::Cpu => "Toggle CPU Debugger",
Debugger::Ppu => "Toggle PPU Debugger",
Debugger::Apu => "Toggle APU Debugger",
Debugger::Cpu => "Toggle Debugger",
Debugger::Ppu => "Toggle PPU Viewer",
Debugger::Apu => "Toggle APU Mixer",
},
Debug::Step(step) => match step {
DebugStep::Into => "Step Into (CPU Debugger)",
DebugStep::Out => "Step Out (CPU Debugger)",
DebugStep::Over => "Step Over (CPU Debugger)",
DebugStep::Scanline => "Step Scanline (CPU Debugger)",
DebugStep::Frame => "Step Frame (CPU Debugger)",
DebugStep::Into => "Debug Step",
DebugStep::Out => "Debug Step Out",
DebugStep::Over => "Debug Step Over",
DebugStep::Scanline => "Debug Step Scanline",
DebugStep::Frame => "Debug Step Frame",
},
},
}
Expand Down
3 changes: 2 additions & 1 deletion tetanes/src/nes/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ pub struct Config {

impl Config {
pub const SAVE_DIR: &'static str = "save";
pub const SAVE_EXTENSION: &'static str = "sav";
pub const WINDOW_TITLE: &'static str = "TetaNES";
pub const FILENAME: &'static str = "config.json";

Expand Down Expand Up @@ -333,7 +334,7 @@ impl Config {
.join(Self::SAVE_DIR)
.join(name)
.join(format!("slot-{}", slot))
.with_extension("sav")
.with_extension(Self::SAVE_EXTENSION)
}

pub fn reset(&mut self) {
Expand Down
6 changes: 6 additions & 0 deletions tetanes/src/nes/renderer/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ impl Gui {
Self::light_theme()
};
ctx.set_visuals(theme);
ctx.style_mut(|ctx| {
let scroll = &mut ctx.spacing.scroll;
scroll.floating = false;
scroll.foreground_color = false;
scroll.bar_width = 8.0;
});

const FONT: (&str, &[u8]) = (
"pixeloid-sans",
Expand Down
10 changes: 5 additions & 5 deletions tetanes/src/nes/renderer/gui/keybinds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,18 @@ impl State {
#[cfg(feature = "profiling")]
puffin::profile_function!();

ui.set_min_height(ui.available_height());

if let Some(player) = player {
self.player_gamepad_combo(ui, player, connected_gamepads);

ui.separator();
}

ScrollArea::both().show(ui, |ui| {
ui.set_width(ui.available_width()); // Pushes scrollbar to the right of the window

ScrollArea::both().auto_shrink(false).show(ui, |ui| {
let grid = Grid::new("keybind_list")
.num_columns(3)
.spacing([40.0, 6.0]);
.num_columns(4)
.spacing([10.0, 6.0]);
grid.show(ui, |ui| {
ui.heading("Action");
ui.heading("Binding #1");
Expand Down
Loading