asset_preloader refactor
This commit is contained in:
parent
1cdd4efd78
commit
f70340db24
4 changed files with 71 additions and 63 deletions
50
src/asset_preloader/checker.rs
Normal file
50
src/asset_preloader/checker.rs
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
use bevy::prelude::{Resource, Asset};
|
||||||
|
use crate::asset_preloader::preloader::*;
|
||||||
|
use std::any::type_name;
|
||||||
|
|
||||||
|
|
||||||
|
#[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>
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,28 +1,9 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use std::collections::HashMap;
|
use preloader::*;
|
||||||
use std::any::type_name;
|
use checker::*;
|
||||||
|
|
||||||
pub enum AssetPreloadState{
|
pub mod preloader;
|
||||||
Loading,
|
pub mod checker;
|
||||||
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>) {
|
pub(crate) fn check_preload_status(gl_preloader: Res<AssetPreload>) {
|
||||||
todo!();
|
todo!();
|
||||||
|
|
@ -32,42 +13,3 @@ pub(crate) fn check_loader_status<T>(loader: Res<AssetPreloadChecker<T>>)
|
||||||
where T: Asset{
|
where T: Asset{
|
||||||
todo!();
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
16
src/asset_preloader/preloader.rs
Normal file
16
src/asset_preloader/preloader.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use bevy::prelude::Resource;
|
||||||
|
|
||||||
|
pub enum AssetPreloadState{
|
||||||
|
Loading,
|
||||||
|
Ready
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub(crate) struct AssetPreload(pub(crate) HashMap<String,bool>);
|
||||||
|
|
||||||
|
impl AssetPreload{
|
||||||
|
pub(crate) fn new() -> Self{
|
||||||
|
AssetPreload(HashMap::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use crate::asset_preloader::*;
|
use crate::asset_preloader::{preloader::AssetPreload,checker::AssetPreloadChecker};
|
||||||
|
|
||||||
pub struct AssetPreloadPlugin;
|
pub struct AssetPreloadPlugin;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue