Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/amethyst/amethyst into tr…
Browse files Browse the repository at this point in the history
…ansev
  • Loading branch information
AnneKitsune committed Oct 25, 2018
2 parents b38b67f + e70c9ac commit b2af844
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 12 additions & 6 deletions amethyst_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ where
/// Loads a configuration structure from a file.
fn load_no_fallback<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError>;

/// Loads configuration structure from raw bytes.
fn load_bytes(bytes: &[u8]) -> Result<Self, ConfigError>;

/// Writes a configuration structure to a file.
fn write<P: AsRef<Path>>(&self, path: P) -> Result<(), ConfigError>;
}
Expand All @@ -127,7 +130,6 @@ where
}

fn load_no_fallback<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError> {
use ron::de::Deserializer;
use std::fs::File;
use std::io::Read;

Expand All @@ -142,16 +144,20 @@ where
};

if path.extension().and_then(|e| e.to_str()) == Some("ron") {
let mut d = Deserializer::from_bytes(&content)?;
let val = T::deserialize(&mut d)?;
d.end()?;

Ok(val)
Self::load_bytes(&content)
} else {
Err(ConfigError::Extension(path.to_path_buf()))
}
}

fn load_bytes(bytes: &[u8]) -> Result<Self, ConfigError> {
let mut de = ron::de::Deserializer::from_bytes(bytes)?;
let val = T::deserialize(&mut de)?;
de.end()?;

Ok(val)
}

fn write<P: AsRef<Path>>(&self, path: P) -> Result<(), ConfigError> {
use ron::ser::to_string_pretty;
use std::fs::File;
Expand Down
4 changes: 3 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ The format is based on [Keep a Changelog][kc], and this project adheres to
* Added configurable width for debug lines. ([#1016])
* Added `TextureMetadata::srgb_scale()` for default texture metadata with nearest filter. ([#1023])
* Added motivation to use Amethyst over gluing the building blocks yourself in the book. ([#1057])
* Added `Config::load_bytes` for reading configuration from raw bytes. ([#1067])

### Changed
* Sprites contain their dimensions and offsets to render them with the right size and desired position. ([#829], [#830])
Expand All @@ -76,7 +77,7 @@ The format is based on [Keep a Changelog][kc], and this project adheres to
* The z in UiTransformBuilder now defaults to 1 instead of 0, allowing to skip defining the z in the ui prefabs. ([#946])
* Added comments to ui prefab. ([#946])
* Summarized all `use amethyst::` statements to allow collapsing in IDE's. ([#974])
* `Application` now uses `EventReader`s to determine what events to send to the `State`s, more information in the `State`
* `Application` now uses `EventReader`s to determine what events to send to the `State`s, more information in the `State`
book chapter ([#996])
* Breaking: Refactor `TextureMetadata` so filter method and clamping can be configured more easily ([#981])
* Renamed `PrefabData` functions to be easier to understand ([#1008])
Expand Down Expand Up @@ -147,6 +148,7 @@ The format is based on [Keep a Changelog][kc], and this project adheres to
[#1023]: https://github.com/amethyst/amethyst/pull/1023
[#1057]: https://github.com/amethyst/amethyst/pull/1057
[#1049]: https://github.com/amethyst/amethyst/pull/1049
[#1067]: https://github.com/amethyst/amethyst/pull/1067
[winit_017]: https://github.com/tomaka/winit/blob/master/CHANGELOG.md#version-0172-2018-08-19
[glutin_018]: https://github.com/tomaka/glutin/blob/master/CHANGELOG.md#version-0180-2018-08-03

Expand Down

0 comments on commit b2af844

Please sign in to comment.