diff --git a/main_game_lib/src/rscn.rs b/main_game_lib/src/rscn.rs index 071aa173..17ecabbb 100644 --- a/main_game_lib/src/rscn.rs +++ b/main_game_lib/src/rscn.rs @@ -147,6 +147,8 @@ pub struct SpriteTexture { pub animation: Option, /// If the texture should be flipped horizontally. pub flip_horizontally: bool, + /// If the texture should be flipped vertically. + pub flip_vertically: bool, } /// Atlas animation. diff --git a/main_game_lib/src/rscn/intermediate_repr.rs b/main_game_lib/src/rscn/intermediate_repr.rs index c9daf167..3477dc1e 100644 --- a/main_game_lib/src/rscn/intermediate_repr.rs +++ b/main_game_lib/src/rscn/intermediate_repr.rs @@ -71,6 +71,8 @@ pub(crate) enum SectionKey { Visibility(bool), /// A texture should be flipped horizontally. FlipHorizontally(bool), + /// A texture should be flipped vertically. + FlipVertically(bool), /// RGBa SelfModulateColor(Number, Number, Number, Number), } diff --git a/main_game_lib/src/rscn/spawner.rs b/main_game_lib/src/rscn/spawner.rs index 4734ebc6..8905ff2c 100644 --- a/main_game_lib/src/rscn/spawner.rs +++ b/main_game_lib/src/rscn/spawner.rs @@ -126,12 +126,14 @@ fn node_to_entity( visible, color, flip_horizontally, + flip_vertically, }) = texture { let texture = spawner.load_texture(&path); cmd.entity(entity).insert(texture).insert(Sprite { color: color.unwrap_or(Color::WHITE), flip_x: flip_horizontally, + flip_y: flip_vertically, ..default() }); diff --git a/main_game_lib/src/rscn/token.rs b/main_game_lib/src/rscn/token.rs index a62f7da9..f85c4b26 100644 --- a/main_game_lib/src/rscn/token.rs +++ b/main_game_lib/src/rscn/token.rs @@ -288,14 +288,18 @@ fn parse_with_state( Expecting::HeadingOrSectionKey } - Expecting::SectionKey(SectionKeyBuilder::FlipHorizontally) => { + Expecting::SectionKey( + dir @ (SectionKeyBuilder::FlipHorizontally + | SectionKeyBuilder::FlipVertically), + ) => { let visible = matches!(token, TscnToken::True); - state - .nodes - .last_mut() - .unwrap() - .section_keys - .push(SectionKey::FlipHorizontally(visible)); + state.nodes.last_mut().unwrap().section_keys.push( + if matches!(dir, SectionKeyBuilder::FlipHorizontally) { + SectionKey::FlipHorizontally(visible) + } else { + SectionKey::FlipVertically(visible) + }, + ); Expecting::HeadingOrSectionKey } @@ -371,6 +375,8 @@ enum SectionKeyBuilder { Visibility, /// true or false FlipHorizontally, + /// true or false + FlipVertically, /// e.g. `self_modulate = Color(1, 1, 1, 0.823529)` SelfModulate(ColorExpecting), } diff --git a/main_game_lib/src/rscn/token/string.rs b/main_game_lib/src/rscn/token/string.rs index 7f20aed7..1283632c 100644 --- a/main_game_lib/src/rscn/token/string.rs +++ b/main_game_lib/src/rscn/token/string.rs @@ -45,6 +45,9 @@ pub(super) fn parse( "flip_h" => { Expecting::SectionKey(SectionKeyBuilder::FlipHorizontally) } + "flip_v" => { + Expecting::SectionKey(SectionKeyBuilder::FlipVertically) + } s if s.starts_with("metadata/") => { Expecting::SectionKey(SectionKeyBuilder::StringMetadata( s["metadata/".len()..].to_ascii_lowercase(), diff --git a/main_game_lib/src/rscn/tree.rs b/main_game_lib/src/rscn/tree.rs index 37ad2600..5b871c28 100644 --- a/main_game_lib/src/rscn/tree.rs +++ b/main_game_lib/src/rscn/tree.rs @@ -18,6 +18,7 @@ struct Properties { visible: bool, color: Option, flip_horizontally: bool, + flip_vertically: bool, } pub(crate) fn from_state( @@ -88,6 +89,7 @@ pub(crate) fn from_state( visible, color, flip_horizontally, + flip_vertically, } = properties; let in_2d = match parsed_node.kind { @@ -103,6 +105,7 @@ pub(crate) fn from_state( animation }, flip_horizontally, + flip_vertically, }), }), ParsedNodeKind::Sprite2D => Some(In2D { @@ -117,6 +120,7 @@ pub(crate) fn from_state( None }, flip_horizontally, + flip_vertically, }), }), ParsedNodeKind::Node2D => Some(In2D { @@ -184,6 +188,7 @@ fn apply_section_key( visible, color, flip_horizontally, + flip_vertically, }: &mut Properties, ) { use intermediate_repr::{Number, SectionKey, X}; @@ -213,6 +218,9 @@ fn apply_section_key( SectionKey::FlipHorizontally(flip) => { *flip_horizontally = flip; } + SectionKey::FlipVertically(flip) => { + *flip_vertically = flip; + } SectionKey::Visibility(visibility) => { *visible = visibility; } @@ -379,6 +387,7 @@ impl Default for Properties { visible: true, color: None, flip_horizontally: false, + flip_vertically: false, } } } diff --git a/wiki/src/devtools_godot.md b/wiki/src/devtools_godot.md index c7c8e75b..ea6357ec 100644 --- a/wiki/src/devtools_godot.md +++ b/wiki/src/devtools_godot.md @@ -78,6 +78,7 @@ This hierarchical arrangement allows for precise control over the rendering orde - Visibility / Self Modulate color - Ordering / Z Index - Offset / Flip H +- Offset / Flip V ## Components