Asset preload structures and their impls
This commit is contained in:
parent
367359e47f
commit
1cdd4efd78
5 changed files with 125 additions and 5 deletions
73
src/asset_preloader/mod.rs
Normal file
73
src/asset_preloader/mod.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::any::type_name;
|
||||||
|
|
||||||
|
pub enum AssetPreloadState{
|
||||||
|
Loading,
|
||||||
|
Ready
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub struct AssetPreloadChecker<T>
|
||||||
|
where T : Asset
|
||||||
|
{
|
||||||
|
pub data: Vec<T>,
|
||||||
|
typename: String
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct AssetPreloadCheckerBuilder<T>
|
||||||
|
where T: Asset
|
||||||
|
{
|
||||||
|
data : AssetPreloadChecker<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub(crate) struct AssetPreload(HashMap<String,bool>);
|
||||||
|
|
||||||
|
pub(crate) fn check_preload_status(gl_preloader: Res<AssetPreload>) {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn check_loader_status<T>(loader: Res<AssetPreloadChecker<T>>)
|
||||||
|
where T: Asset{
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AssetPreload{
|
||||||
|
pub(crate) fn new() -> Self{
|
||||||
|
AssetPreload(HashMap::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Asset> AssetPreloadChecker<T>{
|
||||||
|
pub(crate) fn build(asset_preload: &mut AssetPreload) -> AssetPreloadCheckerBuilder<T>
|
||||||
|
{
|
||||||
|
let checker = AssetPreloadChecker::new();
|
||||||
|
|
||||||
|
asset_preload.0.insert(checker.typename.clone(), false);
|
||||||
|
|
||||||
|
AssetPreloadCheckerBuilder{
|
||||||
|
data: checker
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new() -> Self{
|
||||||
|
AssetPreloadChecker
|
||||||
|
{
|
||||||
|
data: Vec::new(),
|
||||||
|
typename: type_name::<T>().to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Asset> AssetPreloadCheckerBuilder<T>{
|
||||||
|
pub fn finish(self) -> AssetPreloadChecker<T> {
|
||||||
|
self.data
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn map_vec<'a, F>(&'a mut self, mut f: F)
|
||||||
|
where F: FnMut(&mut Vec<T>) + 'a{
|
||||||
|
f(&mut self.data.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
33
src/lib.rs
33
src/lib.rs
|
|
@ -13,16 +13,44 @@ pub mod hand;
|
||||||
pub mod animal;
|
pub mod animal;
|
||||||
pub mod properties;
|
pub mod properties;
|
||||||
pub mod plugins;
|
pub mod plugins;
|
||||||
|
pub mod asset_preloader;
|
||||||
|
|
||||||
#[derive(Component)]
|
/*#[derive(Component)]
|
||||||
pub struct JustUpdated;
|
pub struct JustUpdated;
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct Systems {
|
pub struct Systems {
|
||||||
pub update_hand_dimensions: SystemId
|
pub update_hand_dimensions: SystemId
|
||||||
|
}*/
|
||||||
|
|
||||||
|
pub fn setup(mut commands: Commands,asset_server: Res<AssetServer>) {
|
||||||
|
let hand_img: Handle<Image> = asset_server.load("sprites/hand_9s.png");
|
||||||
|
|
||||||
|
commands.spawn(Camera2d);
|
||||||
|
commands.spawn(
|
||||||
|
(
|
||||||
|
Hand{name: "Rendo".to_string()},
|
||||||
|
Sprite {
|
||||||
|
image: hand_img,
|
||||||
|
image_mode: SpriteImageMode::Sliced(TextureSlicer {
|
||||||
|
border: BorderRect::square(4.),
|
||||||
|
center_scale_mode: SliceScaleMode::Stretch,
|
||||||
|
sides_scale_mode: SliceScaleMode::Stretch,
|
||||||
|
..default()
|
||||||
|
}),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
Transform::from_xyz(0., -300., 0.)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup(
|
pub fn setup_board()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*pub fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
) {
|
) {
|
||||||
|
|
@ -101,3 +129,4 @@ pub fn update_hand_dimensions(
|
||||||
hand.1.custom_size = Some(Vec2::new(hand_total_width, hand_height));
|
hand.1.custom_size = Some(Vec2::new(hand_total_width, hand_height));
|
||||||
commands.entity(hand.0).remove::<JustUpdated>();
|
commands.entity(hand.0).remove::<JustUpdated>();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
@ -2,7 +2,7 @@ use bevy::prelude::*;
|
||||||
|
|
||||||
use evolution_rs::{
|
use evolution_rs::{
|
||||||
plugins::*,
|
plugins::*,
|
||||||
setup, test_setup_hand, update_hand_dimensions
|
setup, //test_setup_hand, update_hand_dimensions
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -16,7 +16,9 @@ use evolution_rs::{
|
||||||
// P.S. оставляю комменты в коде, потому что так надёжнее, чем сообщениями, которые можно потерять
|
// P.S. оставляю комменты в коде, потому что так надёжнее, чем сообщениями, которые можно потерять
|
||||||
fn main() {
|
fn main() {
|
||||||
App::new()
|
App::new()
|
||||||
.add_plugins((DefaultPlugins,BasePropertiesPlugin))
|
.add_plugins((DefaultPlugins,BasePropertiesPlugin, asset_preloader::AssetPreloadPlugin))
|
||||||
.add_systems(Startup, (setup, test_setup_hand, update_hand_dimensions).chain())
|
|
||||||
|
.add_systems(Startup, setup)
|
||||||
|
//.add_systems(PostStartup, (test_setup_hand, update_hand_dimensions).chain())
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
src/plugins/asset_preloader.rs
Normal file
14
src/plugins/asset_preloader.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
use bevy::prelude::*;
|
||||||
|
use crate::asset_preloader::*;
|
||||||
|
|
||||||
|
pub struct AssetPreloadPlugin;
|
||||||
|
|
||||||
|
impl Plugin for AssetPreloadPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
//app.init_resource::<AssetPreloadChecker<Image>>();
|
||||||
|
let mut preload = AssetPreload::new();
|
||||||
|
let image: AssetPreloadChecker<Image> = AssetPreloadChecker::build(&mut preload).finish();
|
||||||
|
|
||||||
|
app.insert_resource(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,8 @@ use bevy::prelude::{App,Plugin};
|
||||||
|
|
||||||
use crate::properties::{Property, TestProperty};
|
use crate::properties::{Property, TestProperty};
|
||||||
|
|
||||||
|
pub mod asset_preloader;
|
||||||
|
|
||||||
pub struct BasePropertiesPlugin;
|
pub struct BasePropertiesPlugin;
|
||||||
|
|
||||||
impl Plugin for BasePropertiesPlugin
|
impl Plugin for BasePropertiesPlugin
|
||||||
Loading…
Add table
Add a link
Reference in a new issue