63 lines
2.0 KiB
Rust
63 lines
2.0 KiB
Rust
use crate::firmware::firmware_state::{
|
|
AppCrashesStep, FirmwareState, GameRunningStep, HubHomeStep,
|
|
};
|
|
use crate::firmware::prometeu_context::PrometeuContext;
|
|
use prometeu_hal::cartridge::{AppMode, Cartridge};
|
|
use prometeu_hal::color::Color;
|
|
use prometeu_hal::log::{LogLevel, LogSource};
|
|
use prometeu_hal::window::Rect;
|
|
use prometeu_system::CrashReport;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct LoadCartridgeStep {
|
|
pub cartridge: Cartridge,
|
|
init_error: Option<CrashReport>,
|
|
}
|
|
|
|
impl LoadCartridgeStep {
|
|
pub fn new(cartridge: Cartridge) -> Self {
|
|
Self { cartridge, init_error: None }
|
|
}
|
|
|
|
pub fn on_enter(&mut self, ctx: &mut PrometeuContext) {
|
|
ctx.os.log(
|
|
LogLevel::Info,
|
|
LogSource::Pos,
|
|
0,
|
|
format!("Loading cartridge: {}", self.cartridge.title),
|
|
);
|
|
|
|
// Initialize Asset Manager
|
|
ctx.hw.assets_mut().initialize_for_cartridge(
|
|
self.cartridge.asset_table.clone(),
|
|
self.cartridge.preload.clone(),
|
|
self.cartridge.assets.clone(),
|
|
);
|
|
|
|
self.init_error = ctx.os.initialize_vm(ctx.vm, &self.cartridge).err();
|
|
}
|
|
|
|
pub fn on_update(&mut self, ctx: &mut PrometeuContext) -> Option<FirmwareState> {
|
|
if let Some(report) = self.init_error.take() {
|
|
return Some(FirmwareState::AppCrashes(AppCrashesStep { report }));
|
|
}
|
|
|
|
if self.cartridge.app_mode == AppMode::System {
|
|
let id = ctx.hub.window_manager.add_window(
|
|
self.cartridge.title.clone(),
|
|
Rect { x: 40, y: 20, w: 240, h: 140 },
|
|
Color::WHITE,
|
|
);
|
|
ctx.hub.window_manager.set_focus(id);
|
|
|
|
// System apps do not change the firmware state to GameRunning.
|
|
// They run in the background or via windows in the Hub.
|
|
return Some(FirmwareState::HubHome(HubHomeStep));
|
|
}
|
|
|
|
Some(FirmwareState::GameRunning(GameRunningStep))
|
|
}
|
|
|
|
pub fn on_exit(&mut self, _ctx: &mut PrometeuContext) {}
|
|
}
|