Use explicit states for sims

This commit is contained in:
2025-01-02 23:06:33 -05:00
parent be8cdd958a
commit a5b5f8e80f
4 changed files with 116 additions and 75 deletions
+15 -10
View File
@@ -2,7 +2,7 @@ use std::sync::mpsc;
use crate::{
app::UserEvent,
emulator::{EmulatorClient, EmulatorCommand, SimId},
emulator::{EmulatorClient, EmulatorCommand, EmulatorState, SimId, SimState},
persistence::Persistence,
};
use egui::{
@@ -73,7 +73,7 @@ impl GameWindow {
.pick_file();
if let Some(path) = rom {
self.client
.send_command(EmulatorCommand::LoadGame(SimId::Player1, path));
.send_command(EmulatorCommand::LoadGame(self.sim_id, path));
}
ui.close_menu();
}
@@ -82,17 +82,21 @@ impl GameWindow {
}
});
ui.menu_button("Emulation", |ui| {
let has_game = self.client.has_game(self.sim_id);
if self.client.is_running(self.sim_id) {
if ui.add_enabled(has_game, Button::new("Pause")).clicked() {
let state = self.client.emulator_state();
let can_interact = self.client.sim_state(self.sim_id) == SimState::Ready;
if state == EmulatorState::Running {
if ui.add_enabled(can_interact, Button::new("Pause")).clicked() {
self.client.send_command(EmulatorCommand::Pause);
ui.close_menu();
}
} else if ui.add_enabled(has_game, Button::new("Resume")).clicked() {
} else if ui
.add_enabled(can_interact, Button::new("Resume"))
.clicked()
{
self.client.send_command(EmulatorCommand::Resume);
ui.close_menu();
}
if ui.add_enabled(has_game, Button::new("Reset")).clicked() {
if ui.add_enabled(can_interact, Button::new("Reset")).clicked() {
self.client
.send_command(EmulatorCommand::Reset(self.sim_id));
ui.close_menu();
@@ -100,8 +104,9 @@ impl GameWindow {
});
ui.menu_button("Options", |ui| self.show_options_menu(ctx, ui));
ui.menu_button("Multiplayer", |ui| {
let has_player_2 = self.client.sim_state(SimId::Player2) != SimState::Uninitialized;
if self.sim_id == SimId::Player1
&& !self.client.has_player_2()
&& !has_player_2
&& ui.button("Open Player 2").clicked()
{
self.client
@@ -109,7 +114,7 @@ impl GameWindow {
self.proxy.send_event(UserEvent::OpenPlayer2).unwrap();
ui.close_menu();
}
if self.client.has_player_2() {
if has_player_2 {
let linked = self.client.are_sims_linked();
if linked && ui.button("Unlink").clicked() {
self.client.send_command(EmulatorCommand::Unlink);
@@ -207,7 +212,7 @@ impl GameWindow {
let color_str = |color: Color32| {
format!("{:02x}{:02x}{:02x}", color.r(), color.g(), color.b())
};
let is_running = self.client.is_running(self.sim_id);
let is_running = self.client.emulator_state() == EmulatorState::Running;
if is_running {
self.client.send_command(EmulatorCommand::Pause);
}