mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
place asset_tweak behind a feature
This commit is contained in:
parent
3c34301947
commit
8f86f474e8
@ -6,7 +6,7 @@ code-quality:
|
|||||||
script:
|
script:
|
||||||
- ln -s /dockercache/target target
|
- ln -s /dockercache/target target
|
||||||
- rm -r target/debug/incremental/* || echo "all good" # TMP FIX FOR 2021-03-22-nightly
|
- rm -r target/debug/incremental/* || echo "all good" # TMP FIX FOR 2021-03-22-nightly
|
||||||
- cargo clippy --all-targets --locked --features="bin_csv,bin_bot" -- -D warnings
|
- cargo clippy --all-targets --locked --features="bin_csv,bin_bot,asset_tweak" -- -D warnings
|
||||||
- cargo fmt --all -- --check
|
- cargo fmt --all -- --check
|
||||||
|
|
||||||
security:
|
security:
|
||||||
|
@ -14,5 +14,7 @@ dot_vox = "4.0"
|
|||||||
image = { version = "0.23.12", default-features = false, features = ["png"] }
|
image = { version = "0.23.12", default-features = false, features = ["png"] }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
serial_test = {version = "0.5", optional = true}
|
||||||
serial_test = "0.5"
|
|
||||||
|
[features]
|
||||||
|
asset_tweak = ["serial_test"]
|
||||||
|
@ -261,6 +261,7 @@ impl Compound for Directory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[warn(clippy::pedantic)]
|
#[warn(clippy::pedantic)]
|
||||||
|
#[cfg(feature = "asset_tweak")]
|
||||||
pub mod asset_tweak {
|
pub mod asset_tweak {
|
||||||
// Return path to repository by searching 10 directories back
|
// Return path to repository by searching 10 directories back
|
||||||
use super::{find_root, fs, Asset, AssetExt, Path, RonLoader};
|
use super::{find_root, fs, Asset, AssetExt, Path, RonLoader};
|
||||||
@ -280,8 +281,6 @@ pub mod asset_tweak {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
/// NOTE: Don't use it in production code, it's debug only
|
|
||||||
///
|
|
||||||
/// # Usage
|
/// # Usage
|
||||||
/// Create file with content which represent tweaked value
|
/// Create file with content which represent tweaked value
|
||||||
///
|
///
|
||||||
@ -299,13 +298,11 @@ pub mod asset_tweak {
|
|||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// 1) If given `asset_specifier` does not exists
|
/// 1) If given `asset_specifier` does not exists
|
||||||
|
/// 2) If asseet is broken
|
||||||
pub fn tweak_expect<T>(specifier: &str) -> T
|
pub fn tweak_expect<T>(specifier: &str) -> T
|
||||||
where
|
where
|
||||||
T: Clone + Sized + Send + Sync + 'static + DeserializeOwned,
|
T: Clone + Sized + Send + Sync + 'static + DeserializeOwned,
|
||||||
{
|
{
|
||||||
if cfg!(not(any(debug_assertions, test))) {
|
|
||||||
tracing::warn!("AssetTweaker used in release build!");
|
|
||||||
}
|
|
||||||
let asset_specifier: &str = &format!("tweak.{}", specifier);
|
let asset_specifier: &str = &format!("tweak.{}", specifier);
|
||||||
let handle = <AssetTweakWrapper<T> as AssetExt>::load_expect(asset_specifier);
|
let handle = <AssetTweakWrapper<T> as AssetExt>::load_expect(asset_specifier);
|
||||||
let AssetTweakWrapper(value) = handle.read().clone();
|
let AssetTweakWrapper(value) = handle.read().clone();
|
||||||
@ -313,11 +310,13 @@ pub mod asset_tweak {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
/// NOTE: Don't use it in production code, it's debug only
|
|
||||||
///
|
|
||||||
/// # Usage
|
/// # Usage
|
||||||
/// Will create file "assets/tweak/{specifier}.ron" if not exists.
|
/// Will create file "assets/tweak/{specifier}.ron" if not exists
|
||||||
/// If exists will read a value from such file.
|
/// and return passed `value`.
|
||||||
|
/// If file exists will read a value from such file.
|
||||||
|
///
|
||||||
|
/// In release builds (if `debug_assertions` == false) just returns passed
|
||||||
|
/// `value`
|
||||||
///
|
///
|
||||||
/// Example if you want to tweak integer value
|
/// Example if you want to tweak integer value
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
@ -338,8 +337,7 @@ pub mod asset_tweak {
|
|||||||
where
|
where
|
||||||
T: Clone + Sized + Send + Sync + 'static + DeserializeOwned + Serialize,
|
T: Clone + Sized + Send + Sync + 'static + DeserializeOwned + Serialize,
|
||||||
{
|
{
|
||||||
if cfg!(not(any(debug_assertions, test))) {
|
if cfg!(not(debug_assertions)) {
|
||||||
tracing::warn!("AssetTweaker used in release build!");
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,14 +363,10 @@ pub mod asset_tweak {
|
|||||||
value
|
value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{find_root, tweak_expect, tweak_expect_or_create};
|
||||||
asset_tweak::{tweak_expect, tweak_expect_or_create},
|
|
||||||
find_root,
|
|
||||||
};
|
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
use std::{
|
use std::{
|
||||||
convert::AsRef,
|
convert::AsRef,
|
||||||
@ -418,8 +412,8 @@ mod tests {
|
|||||||
P: AsRef<Path> + Debug,
|
P: AsRef<Path> + Debug,
|
||||||
{
|
{
|
||||||
fn create(file: P) -> (Self, File) {
|
fn create(file: P) -> (Self, File) {
|
||||||
let f =
|
let f = File::create(&file)
|
||||||
File::create(&file).unwrap_or_else(|_| panic!("failed to create file {:?}", &file));
|
.unwrap_or_else(|_| panic!("failed to create file {:?}", &file));
|
||||||
(Self { file }, f)
|
(Self { file }, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,3 +499,4 @@ mod tests {
|
|||||||
assert_eq!(x, 10);
|
assert_eq!(x, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user