Add debug text for missing assets

This commit is contained in:
Ebu
2025-12-02 12:38:10 +01:00
parent c46ae5b298
commit 8c28433bc8

View File

@@ -19,15 +19,15 @@ const FRESHENER_FRAME_WIDTH: f32 = 73.0;
const FRESHENER_FRAME_HEIGHT: f32 = 144.0; const FRESHENER_FRAME_HEIGHT: f32 = 144.0;
pub struct PluginGui { pub struct PluginGui {
font: Option<FontId>, font: Result<FontId, String>,
params: Arc<PluginParams>, params: Arc<PluginParams>,
canvas: Option<Canvas<OpenGl>>, canvas: Option<Canvas<OpenGl>>,
_gui_context: Arc<dyn GuiContext>, _gui_context: Arc<dyn GuiContext>,
scaling_factor: f32, scaling_factor: f32,
freshener_image: Option<ImageId>, freshener_image: Result<ImageId, String>,
not_so_fresh_image: Option<ImageId>, not_so_fresh_image: Result<ImageId, String>,
fresh_dumbledore_image: Option<ImageId>, fresh_dumbledore_image: Result<ImageId, String>,
freshener_bounds: Rect<f32>, freshener_bounds: Rect<f32>,
@@ -59,7 +59,7 @@ impl PluginGui {
scaling_factor: f32, scaling_factor: f32,
) -> Self { ) -> Self {
let mut this = Self { let mut this = Self {
font: None, font: Err("Not loaded".to_owned()),
params: params.clone(), params: params.clone(),
canvas: None, canvas: None,
_gui_context: gui_context, _gui_context: gui_context,
@@ -69,9 +69,9 @@ impl PluginGui {
drag_start_mouse_pos: (0.0, 0.0), drag_start_mouse_pos: (0.0, 0.0),
drag_start_parameter_value: 0.0, drag_start_parameter_value: 0.0,
dragging: false, dragging: false,
freshener_image: None, freshener_image: Err("Not loaded".to_owned()),
fresh_dumbledore_image: None, fresh_dumbledore_image: Err("Not loaded".to_owned()),
not_so_fresh_image: None, not_so_fresh_image: Err("Not loaded".to_owned()),
freshener_bounds: Rect { freshener_bounds: Rect {
x: 120.0, x: 120.0,
y: 20.0, y: 20.0,
@@ -85,21 +85,18 @@ impl PluginGui {
context.make_current(); context.make_current();
} }
if let Ok(mut canvas) = create_canvas(context, &params, scaling_factor) { if let Ok(mut canvas) = create_canvas(context, &params, scaling_factor) {
if let Ok(font) = canvas.add_font_mem(DROID_SANS_FONT) { this.font = canvas
this.font = Some(font); .add_font_mem(DROID_SANS_FONT)
} .map_err(|err| err.to_string());
if let Ok(image) = canvas.load_image_mem(FRESHENER_IMAGE, ImageFlags::empty()) { this.freshener_image = canvas
this.freshener_image = Some(image); .load_image_mem(FRESHENER_IMAGE, ImageFlags::empty())
} .map_err(|err| err.to_string());
if let Ok(image) = this.fresh_dumbledore_image = canvas
canvas.load_image_mem(FRESH_DUMBLEDORE_BG_IMAGE, ImageFlags::empty()) .load_image_mem(FRESH_DUMBLEDORE_BG_IMAGE, ImageFlags::empty())
{ .map_err(|err| err.to_string());
this.fresh_dumbledore_image = Some(image); this.not_so_fresh_image = canvas
} .load_image_mem(NOT_SO_FRESH_BG_IMAGE, ImageFlags::empty())
if let Ok(image) = canvas.load_image_mem(NOT_SO_FRESH_BG_IMAGE, ImageFlags::empty()) .map_err(|err| err.to_string());
{
this.not_so_fresh_image = Some(image);
}
this.canvas = Some(canvas); this.canvas = Some(canvas);
} }
unsafe { unsafe {
@@ -175,7 +172,7 @@ impl WindowHandler for PluginGui {
let frame_x = (frame_index % FRESHENER_FRAMES_X as f32).floor(); let frame_x = (frame_index % FRESHENER_FRAMES_X as f32).floor();
let frame_y = (frame_index / FRESHENER_FRAMES_X as f32).floor(); let frame_y = (frame_index / FRESHENER_FRAMES_X as f32).floor();
if let Some(not_so_fresh) = self.not_so_fresh_image { if let Ok(not_so_fresh) = self.not_so_fresh_image {
canvas.fill_path( canvas.fill_path(
&full_window_path, &full_window_path,
&Paint::image( &Paint::image(
@@ -189,7 +186,7 @@ impl WindowHandler for PluginGui {
), ),
); );
} }
if let Some(fresh_dumbledore) = self.fresh_dumbledore_image { if let Ok(fresh_dumbledore) = self.fresh_dumbledore_image {
canvas.fill_path( canvas.fill_path(
&full_window_path, &full_window_path,
&Paint::image( &Paint::image(
@@ -204,7 +201,7 @@ impl WindowHandler for PluginGui {
); );
} }
if let Some(freshener) = self.freshener_image { if let Ok(freshener) = self.freshener_image {
canvas.fill_path( canvas.fill_path(
&freshener_path, &freshener_path,
&Paint::image( &Paint::image(
@@ -222,18 +219,34 @@ impl WindowHandler for PluginGui {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ {
use femtovg::Baseline; use femtovg::Baseline;
if let Some(font) = self.font { if let Ok(font) = self.font {
let mut y = 5.0;
let mut print = |str: &str| {
canvas canvas
.fill_text( .fill_text(
5.0, 5.0,
5.0, y,
"Debug version", str,
&Paint::color(Color::white()) &Paint::color(Color::white())
.with_font(&[font]) .with_font(&[font])
.with_font_size(12.0) .with_font_size(12.0)
.with_text_baseline(Baseline::Top), .with_text_baseline(Baseline::Top),
) )
.ok(); .ok();
y += 12.0;
};
print("Debug version");
if let Err(e) = &self.freshener_image {
print(e);
}
if let Err(e) = &self.fresh_dumbledore_image {
print(e);
}
if let Err(e) = &self.not_so_fresh_image {
print(e);
}
} }
} }