Half way implementing fog tweakfile changes
Parsing the fog parameter in toml is a PITA but a good lesson for future tweaks I guess...main
parent
ff7b707bef
commit
296d79afeb
@ -1,15 +1,15 @@
|
|||||||
[display2d]
|
[audio.display2d]
|
||||||
pick_up = "/SFX/2D/2DPickUpPiece"
|
pick_up = "/SFX/2D/2DPickUpPiece"
|
||||||
put_down = "/SFX/2D/2DPutDownPiece"
|
put_down = "/SFX/2D/2DPutDownPiece"
|
||||||
|
|
||||||
[display3d]
|
[audio.display3d]
|
||||||
pick_up = "/SFX/3D/3DPickUpPiece"
|
pick_up = "/SFX/3D/3DPickUpPiece"
|
||||||
put_down = "/SFX/3D/3DPutDownPiece"
|
put_down = "/SFX/3D/3DPutDownPiece"
|
||||||
idle = "/SFX/3D/3DPickup-Idle-PutdownWhirr"
|
idle = "/SFX/3D/3DPickup-Idle-PutdownWhirr"
|
||||||
invalid = "/sfx/3D/3DInvalidMove"
|
invalid = "/sfx/3D/3DInvalidMove"
|
||||||
|
|
||||||
[music]
|
[audio.music]
|
||||||
main = "/Music/Main Track2"
|
main = "/Music/Main Track2"
|
||||||
|
|
||||||
[menu]
|
[audio.menu]
|
||||||
select = "/SFX/MenuSelect"
|
select = "/SFX/MenuSelect"
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
use crate::prelude::*;
|
||||||
|
use bevy::{
|
||||||
|
asset::{AssetLoader, LoadContext, LoadedAsset},
|
||||||
|
reflect::{TypePath, TypeUuid},
|
||||||
|
utils::BoxedFuture,
|
||||||
|
};
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
/// A Tweakfile is resource used to specify game customization like asset names,
|
||||||
|
/// and non-user customizations made to the game during development.
|
||||||
|
pub(crate) struct TweakPlugin;
|
||||||
|
|
||||||
|
impl Plugin for TweakPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
|
||||||
|
app.add_systems(OnEnter(GameState::Loading), load_tweakfile);
|
||||||
|
|
||||||
|
app.add_asset::<Tweakfile>()
|
||||||
|
.init_asset_loader::<TweakfileLoader>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_tweakfile(server: Res<AssetServer>, mut commands: Commands) {
|
||||||
|
let handle: Handle<Tweakfile> = server.load("martian.tweak.toml");
|
||||||
|
commands.insert_resource(GameTweakfile(handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Resource)]
|
||||||
|
struct GameTweakfile(Handle<Tweakfile>);
|
||||||
|
|
||||||
|
/// Tweakfile contains tweaks made to other parts of the game
|
||||||
|
#[derive(Debug, Deserialize, TypeUuid, TypePath)]
|
||||||
|
#[uuid = "e5768efe-edce-4267-bdf4-dd8f8ca613c7"]
|
||||||
|
pub(crate) struct Tweakfile {
|
||||||
|
#[serde(default)]
|
||||||
|
pub audio: audio::AudioTweaks,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct TweakfileLoader;
|
||||||
|
|
||||||
|
impl AssetLoader for TweakfileLoader {
|
||||||
|
fn load<'a>(
|
||||||
|
&'a self,
|
||||||
|
bytes: &'a [u8],
|
||||||
|
load_context: &'a mut LoadContext,
|
||||||
|
) -> BoxedFuture<'a, Result<(), bevy::asset::Error>> {
|
||||||
|
Box::pin(async move {
|
||||||
|
let s = std::str::from_utf8(bytes)?;
|
||||||
|
let custom_asset = toml::from_str::<Tweakfile>(s)?;
|
||||||
|
load_context.set_default_asset(LoadedAsset::new(custom_asset));
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extensions(&self) -> &[&str] {
|
||||||
|
&["tweak.toml"]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue