forked from amethyst/amethyst
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:amethyst/amethyst into tiles
- Loading branch information
Showing
15 changed files
with
832 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use std::collections::HashMap; | ||
|
||
use amethyst::{assets::Source, error::format_err, Error}; | ||
|
||
use derive_deref::{Deref, DerefMut}; | ||
use derive_new::new; | ||
|
||
/// Identifies the in-memory asset source. | ||
pub const IN_MEMORY_SOURCE_ID: &str = "in_memory_asset_source"; | ||
|
||
/// In-memory implementation of an asset `Source`, purely for tests. | ||
#[derive(Debug, Deref, DerefMut, new)] | ||
pub struct InMemorySource(#[new(default)] pub HashMap<String, Vec<u8>>); | ||
|
||
impl Source for InMemorySource { | ||
fn modified(&self, _path: &str) -> Result<u64, Error> { | ||
Ok(0) | ||
} | ||
|
||
fn load(&self, path: &str) -> Result<Vec<u8>, Error> { | ||
let path = path.to_string(); | ||
self.0.get(&path).cloned().ok_or_else(|| { | ||
format_err!( | ||
"The `{}` asset is not registered in the `InMemorySource` asset source", | ||
path | ||
) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use amethyst::{assets::ProgressCounter, ecs::WorldExt, State, StateData, Trans}; | ||
use derive_new::new; | ||
|
||
use crate::GameUpdate; | ||
|
||
/// Reads a `ProgressCounter` resource and waits for it to be `complete()`. | ||
#[derive(Debug, new)] | ||
pub struct WaitForLoad; | ||
|
||
impl<T, E> State<T, E> for WaitForLoad | ||
where | ||
T: GameUpdate, | ||
E: Send + Sync + 'static, | ||
{ | ||
fn update(&mut self, data: StateData<'_, T>) -> Trans<T, E> { | ||
data.data.update(&data.world); | ||
|
||
let progress_counter = data.world.read_resource::<ProgressCounter>(); | ||
if !progress_counter.is_complete() { | ||
Trans::None | ||
} else { | ||
Trans::Pop | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use amethyst::{ | ||
assets::{ | ||
Asset, AssetStorage, Handle, Loader, ProcessingState, Processor, ProgressCounter, | ||
RonFormat, | ||
}, | ||
ecs::{storage::VecStorage, WorldExt}, | ||
Error, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::WaitForLoad; | ||
use crate::{AmethystApplication, InMemorySource, IN_MEMORY_SOURCE_ID}; | ||
|
||
#[test] | ||
fn pops_when_progress_counter_is_complete() -> Result<(), Error> { | ||
AmethystApplication::blank() | ||
.with_system(Processor::<TestAsset>::new(), "test_asset_processor", &[]) | ||
.with_effect(|world| { | ||
let mut in_memory_source = InMemorySource::new(); | ||
in_memory_source.insert(String::from("file.ron"), b"(val: 123)".to_vec()); | ||
|
||
let mut loader = world.write_resource::<Loader>(); | ||
loader.add_source(IN_MEMORY_SOURCE_ID, in_memory_source); | ||
}) | ||
.with_effect(|world| { | ||
let mut progress_counter = ProgressCounter::new(); | ||
let test_asset_handle = { | ||
let loader = world.read_resource::<Loader>(); | ||
loader.load_from( | ||
"file.ron", | ||
RonFormat, | ||
IN_MEMORY_SOURCE_ID, | ||
&mut progress_counter, | ||
&world.read_resource::<AssetStorage<TestAsset>>(), | ||
) | ||
}; | ||
|
||
world.insert(test_asset_handle); | ||
world.insert(progress_counter); | ||
}) | ||
.with_state(WaitForLoad::new) | ||
.with_assertion(|world| { | ||
let test_asset_handle = world.read_resource::<Handle<TestAsset>>(); | ||
let test_assets = world.read_resource::<AssetStorage<TestAsset>>(); | ||
let test_asset = test_assets | ||
.get(&test_asset_handle) | ||
.expect("Expected `TestAsset` to be loaded."); | ||
|
||
assert_eq!(&TestAsset { val: 123 }, test_asset); | ||
}) | ||
.run() | ||
} | ||
|
||
#[derive(Debug, Deserialize, PartialEq, Serialize)] | ||
pub struct TestAsset { | ||
val: u32, | ||
} | ||
|
||
impl Asset for TestAsset { | ||
type Data = Self; | ||
type HandleStorage = VecStorage<Handle<Self>>; | ||
|
||
const NAME: &'static str = concat!(module_path!(), "::", stringify!(TestAsset)); | ||
} | ||
|
||
impl From<TestAsset> for Result<ProcessingState<TestAsset>, Error> { | ||
fn from(asset_data: TestAsset) -> Result<ProcessingState<TestAsset>, Error> { | ||
Ok(ProcessingState::Loaded(asset_data)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Specs Migration | ||
|
||
* Specs migration | ||
|
||
Quick fix: | ||
|
||
- Add `use amethyst::ecs::WorldExt` to imports. | ||
- Replace `world.add_resource` with `world.insert`. | ||
- Regex replace `\bResources\b` with `World`. Check for false replacements. | ||
- Replace `world.res` with `world`. | ||
- Regex replace `\bres\b` with `world`. | ||
|
||
`shred-derive` is re-exported by `amethyst`. Migration steps: | ||
|
||
- Remove `shred-derive` from `Cargo.toml`. | ||
- Remove `use amethyst::ecs::SystemData` from imports (if present). | ||
- Add `use amethyst::shred::{ResourceId, SystemData}` to imports. | ||
|
||
* `PrefabLoaderSystem` is initialized by `PrefabLoaderSystemDesc`. | ||
|
||
**Quick fix:** | ||
|
||
- Find: `PrefabLoaderSystem::<([A-Za-z]+)>::default\(\)`, | ||
- Replace: `PrefabLoaderSystemDesc::<\1>::default()` | ||
|
||
* `GltfSceneLoaderSystem` is initialized by `GltfSceneLoaderSystemDesc`. | ||
|
||
**Quick fix:** | ||
|
||
- Find: `GltfSceneLoaderSystem::<([A-Za-z]+)>::default\(\)`, | ||
- Replace: `GltfSceneLoaderSystemDesc::<\1>::default()` | ||
|
||
* `AmethystApplication::with_setup` runs the function before the dispatcher. | ||
|
||
**Quick fix:** | ||
|
||
- Find: `with_setup`, | ||
- Replace: `with_effect` | ||
|
||
* Renamed `UiTransformBuilder` to `UiTransformData`. | ||
* Renamed `UiTextBuilder` to `UiTextData`. | ||
* Renamed `UiButtonBuilder` to `UiButtonData`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.