concinnity_world/schema/engine_defaults.rs
1//! Engine-injected default opt-out schema.
2
3/// Opts a world out of individual engine-injected defaults.
4///
5/// A world is completed at build time with standard assets it does not declare
6/// itself: the [DebugHud](#debughud) with its chip [TextLabel](#textlabel)s
7/// and font, the [StatHud](#stathud) and its chips when the world declares a
8/// [MainMenu](#mainmenu), the [PhysicsConfig](#physicsconfig) a world with
9/// physics content simulates on, and, when an
10/// [EnvironmentMap](#environmentmap) is present, the sky mesh that displays
11/// it. Declaring the same asset yourself replaces the injected one; declaring
12/// `EngineDefaults` with a flag set to `false` removes it entirely.
13///
14/// The build records every injected asset in `world-lock.json`; copy an entry
15/// from there (or from `cn explain <name>`) into `world.jsonl` to override it.
16///
17/// ```rust
18/// # use concinnity_world::registry::build_only::EngineDefaults;
19/// EngineDefaults {
20/// debug_hud: false,
21/// sky: false,
22/// ..Default::default()
23/// };
24/// ```
25#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
26#[serde(default)]
27pub struct EngineDefaults {
28 /// Inject the [StatHud](#stathud) with its chip labels and font when the
29 /// world declares a [MainMenu](#mainmenu) but no `StatHud`.
30 pub hud: bool,
31 /// Inject the [DebugHud](#debughud) with its chip labels when the world
32 /// declares no `DebugHud`.
33 pub debug_hud: bool,
34 /// Inject the sky mesh (a skybox [ProceduralMesh](#proceduralmesh),
35 /// [Material](#material), and [Prop](#prop)) when the world has an
36 /// [EnvironmentMap](#environmentmap) but no skybox mesh. Disable to use an
37 /// `EnvironmentMap` for image-based lighting only, with the background
38 /// left to `clear_color` or your own geometry.
39 pub sky: bool,
40 /// Inject an Escape-toggled pause [MainMenu](#mainmenu) when the world
41 /// plays a [Story](#story) but declares no `MainMenu`: Resume, Save, Load,
42 /// a trimmed Settings screen, and Quit to the story's title. Disable to
43 /// leave a story with no pause menu, or declare your own `MainMenu` to
44 /// replace it.
45 pub story_pause_menu: bool,
46 /// Inject the [LoadingOverlay](#loadingoverlay) with its screen, backdrop,
47 /// progress bar, and label when the world declares [Scene](#scene)s and a
48 /// [StreamingConfig](#streamingconfig) but no `LoadingOverlay`. Disable to
49 /// jump between scenes with no loading screen while their content streams
50 /// in.
51 pub loading_overlay: bool,
52 /// Inject a [PhysicsConfig](#physicsconfig) with the engine's own values
53 /// when the world has physics content -- a [RigidBody](#rigidbody), a
54 /// [PropBody](#propbody), a [TriggerVolume](#triggervolume), or a
55 /// [SkinnedMesh](#skinnedmesh) with a `capsule` -- but declares no
56 /// `PhysicsConfig`. Physics runs on those values either way; the injected
57 /// asset is what makes them visible in `world-lock.json` and editable,
58 /// `spawn_headroom` above all. Disable to leave them implicit.
59 pub physics_config: bool,
60}
61
62impl Default for EngineDefaults {
63 fn default() -> Self {
64 Self {
65 hud: true,
66 debug_hud: true,
67 sky: true,
68 story_pause_menu: true,
69 loading_overlay: true,
70 physics_config: true,
71 }
72 }
73}
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
80 fn every_injected_default_is_on_until_opted_out_of() {
81 // This asset exists only to turn injection off, so declaring it without
82 // saying which one must change nothing.
83 let d = EngineDefaults::default();
84 assert!(d.hud);
85 assert!(d.debug_hud);
86 assert!(d.sky);
87 assert!(d.story_pause_menu);
88 assert!(d.loading_overlay);
89 assert!(d.physics_config);
90
91 let declared: EngineDefaults = serde_json::from_str("{}").unwrap();
92 assert!(declared.hud && declared.debug_hud && declared.sky);
93 assert!(declared.story_pause_menu && declared.loading_overlay);
94 assert!(declared.physics_config);
95 }
96
97 #[test]
98 fn opting_out_of_one_default_leaves_the_rest_alone() {
99 let d: EngineDefaults = serde_json::from_str(r#"{"sky":false}"#).unwrap();
100 assert!(!d.sky);
101 assert!(d.hud && d.debug_hud && d.story_pause_menu && d.loading_overlay);
102 assert!(d.physics_config);
103
104 let bytes = postcard::to_allocvec(&d).unwrap();
105 let back: EngineDefaults = postcard::from_bytes(&bytes).unwrap();
106 assert!(!back.sky);
107 assert!(back.hud);
108 }
109}