#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "android",)))]
use crate::input::gamepad;
use crate::{
audio,
filesystem::Filesystem,
graphics,
input::{input_handler::InputHandler, KeyboardContext, MouseContext},
timer::TimeContext,
};
pub struct Context {
pub filesystem: Filesystem,
pub audio_context: audio::AudioContext,
pub gfx_context: graphics::GraphicsContext,
pub mouse_context: MouseContext,
pub keyboard_context: KeyboardContext,
#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "android",)))]
pub gamepad_context: Box<dyn gamepad::GamepadContext>,
pub timer_context: TimeContext,
pub continuing: bool,
}
impl Context {
pub(crate) fn new(quad_ctx: &mut miniquad::Context, filesystem: Filesystem) -> Context {
let input_handler = InputHandler::new();
#[cfg(not(any(target_arch = "wasm32", target_os = "ios", target_os = "android",)))]
{
let gamepad_context: Box<dyn gamepad::GamepadContext> =
if let Ok(g_context) = gamepad::GilrsGamepadContext::new() {
Box::new(g_context)
} else {
Box::new(gamepad::NullGamepadContext::default())
};
Context {
filesystem,
gfx_context: graphics::GraphicsContext::new(quad_ctx),
audio_context: audio::AudioContext::new(),
mouse_context: MouseContext::new(input_handler),
keyboard_context: KeyboardContext::new(),
gamepad_context,
timer_context: TimeContext::new(),
continuing: true,
}
}
#[cfg(any(target_arch = "wasm32", target_os = "ios", target_os = "android",))]
{
Context {
filesystem,
gfx_context: graphics::GraphicsContext::new(quad_ctx),
audio_context: audio::AudioContext::new(),
mouse_context: MouseContext::new(input_handler),
keyboard_context: KeyboardContext::new(),
timer_context: TimeContext::new(),
continuing: true,
}
}
}
pub(crate) fn framebuffer(&mut self) -> Option<miniquad::RenderPass> {
self.gfx_context
.canvas
.as_ref()
.map(|canvas| canvas.offscreen_pass)
}
}