Skip to content

Commit

Permalink
loading assets at compile time!!
Browse files Browse the repository at this point in the history
  • Loading branch information
marci1175 committed Dec 14, 2024
1 parent 002aa5f commit c87ffb8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 41 deletions.
53 changes: 33 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use bevy::{
math::Quat, prelude::PluginGroup, text::cosmic_text::Angle, window::{Window, WindowPlugin}
asset::embedded_asset,
math::Quat,
prelude::PluginGroup,
text::cosmic_text::Angle,
window::{Window, WindowPlugin},
};
use std::{fs, path::PathBuf};
// hide console window on Windows in release
Expand All @@ -26,24 +30,28 @@ use miniz_oxide::deflate::CompressionLevel;
#[tokio::main]
async fn main()
{
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Ferris Draw".to_string(),
..Default::default()
}),
let mut app = App::new();

app.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Ferris Draw".to_string(),
..Default::default()
}))
.add_plugins(EguiPlugin)
.init_resource::<UiState>()
.init_resource::<Drawers>()
.init_resource::<LuaRuntime>()
.add_systems(Startup, setup)
.add_systems(PreUpdate, clear_screen)
.add_systems(Update, main_ui)
.add_systems(Update, draw)
.add_systems(Update, exit_handler)
.run();
}),
..Default::default()
}))
.add_plugins(EguiPlugin)
.init_resource::<UiState>()
.init_resource::<Drawers>()
.init_resource::<LuaRuntime>()
.add_systems(Startup, setup)
.add_systems(PreUpdate, clear_screen)
.add_systems(Update, main_ui)
.add_systems(Update, draw)
.add_systems(Update, exit_handler);

embedded_asset!(app, "../assets/ferris.png");

app.run();
}

fn setup(
Expand Down Expand Up @@ -121,10 +129,15 @@ fn draw(
DrawerEntity(id.clone()),
));

let icon: bevy::prelude::Handle<bevy::prelude::Image> =
asset_server.load("embedded://ferris_draw/../assets/ferris.png");

commands.spawn((
Sprite::from_image(asset_server.load("ferris.png")),
Sprite::from_image(icon),
Transform::from_xyz(drawer_info.pos.x, drawer_info.pos.y, 0.)
.with_rotation(Quat::from_rotation_z(Angle::from_degrees(drawer.ang.to_degrees() - 90.).to_radians()))
.with_rotation(Quat::from_rotation_z(
Angle::from_degrees(drawer.ang.to_degrees() - 90.).to_radians(),
))
.with_scale(vec3(0.1, 0.1, 1.)),
DrawerEntity(id.clone()),
));
Expand Down
42 changes: 21 additions & 21 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,27 +335,27 @@ pub fn main_ui(
});
});

if ui_state.manager_panel {
bevy_egui::egui::SidePanel::right("right_panel")
.resizable(true)
.show(ctx, |ui| {
let toasts = ui_state.toasts.clone();
let rename_buffer = ui_state.rename_buffer.clone();
let name_buffer = ui_state.name_buffer.clone();
ui_state.item_manager.ui(
&mut ManagerBehavior {
lua_runtime: lua_runtime.clone(),
toasts,
drawers: drawers.clone(),
rename_buffer,
name_buffer,
},
ui,
);
});
}
if ui_state.manager_panel {
bevy_egui::egui::SidePanel::right("right_panel")
.resizable(true)
.show(ctx, |ui| {
let toasts = ui_state.toasts.clone();

let rename_buffer = ui_state.rename_buffer.clone();
let name_buffer = ui_state.name_buffer.clone();

ui_state.item_manager.ui(
&mut ManagerBehavior {
lua_runtime: lua_runtime.clone(),
toasts,
drawers: drawers.clone(),
rename_buffer,
name_buffer,
},
ui,
);
});
}
if ui_state.command_panel {
bevy_egui::egui::TopBottomPanel::bottom("bottom_panel")
.resizable(true)
Expand Down

0 comments on commit c87ffb8

Please sign in to comment.