Working better, but not intro -> game animation is missing

the game just pops into existance, no bueno.
main
Elijah C. Voigt 2 years ago
parent d5f44b9639
commit ae19a96844

@ -87,14 +87,12 @@ objective = [
]
ownership = [
"""
> When player or AI moves a piece across the canal,
This here line is called the canal. And blow me down if she aint a beaut! See herein lies the kicker of Martian warfare: You control any and only the pieces on your side of the canal. When you move a piece across the canal, your opponent assumes control over it.
""",
"Keep playing and try to score some points!",
]
promotions = [
"""
> When player has either no drones or no Queens
Oh and one last thing: real nerds occasionally employ the field promotions strategy. Here's how it works: If you control no drones, you may combine two pawns to make a drone. Similarly, if you control no Queens, you may combine two drones to make a queen.
""",
]

@ -83,9 +83,11 @@ impl Plugin for Display3dPlugin {
),
setup_capture_piece.run_if(any_component_changed::<Handle<StandardMaterial>>),
capture_piece.run_if(any_with_component::<game::Captured>()),
skip_animation.run_if(|keys: Res<Input<KeyCode>>| -> bool {
keys.just_pressed(KeyCode::Return)
}),
skip_animation
.run_if(|keys: Res<Input<KeyCode>>| -> bool {
keys.just_pressed(KeyCode::Return)
})
.run_if(in_state(GameState::Play)),
),
)
.add_systems(

@ -12,8 +12,12 @@ impl Plugin for IntroPlugin {
.run_if(resource_exists::<tweak::GameTweaks>())
.run_if(run_once()),
)
.add_systems(OnEnter(GameState::Intro), (activate::<Intro>, start_intro))
.add_systems(OnEnter(GameState::Intro), manage_intro)
.add_systems(OnExit(GameState::Intro), deactivate::<Intro>)
.add_systems(
Update,
manage_intro.run_if(any_component_removed::<ui::TextScrollAnimation>()),
)
.add_systems(
Update,
// Started when the TextScrollAnimation component is added to the parent entity
@ -65,8 +69,8 @@ fn init_intro_text(
height: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
position_type: PositionType::Absolute,
padding: UiRect::all(Val::Px(50.0)),
..default()
},
background_color: Color::NONE.into(),
@ -81,14 +85,11 @@ fn init_intro_text(
Intro,
NodeBundle {
style: Style {
width: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_content: AlignContent::Center,
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
justify_items: JustifyItems::Center,
position_type: PositionType::Absolute,
padding: UiRect::all(Val::Px(25.0)),
..default()
},
visibility: Visibility::Hidden,
background_color: Color::hex(&background_hex).unwrap().into(),
..default()
},
@ -97,14 +98,6 @@ fn init_intro_text(
parent.spawn((
Intro,
TextBundle {
style: Style {
// position_type: PositionType::Absolute,
top: Val::Px(0.0),
left: Val::Px(0.0),
justify_self: JustifySelf::Center,
align_self: AlignSelf::Center,
..default()
},
text: Text {
sections: text
.chars()
@ -129,13 +122,16 @@ fn init_intro_text(
});
}
fn start_intro(
// Hack, this way of "finding" the Node with our animated Text is precarious
query: Query<Entity, (With<Node>, With<Intro>, With<Children>, Without<Parent>)>,
fn manage_intro(
// Hack, this way of "finding" the root Node containing our paragraphs is precarious
query: Query<Entity, (With<Node>, With<Intro>, Without<Parent>)>,
mut commands: Commands,
) {
query.iter().for_each(|e| {
commands.entity(e).insert(ui::TextScrollAnimation);
commands
.entity(e)
.insert(ui::TextScrollAnimation)
.insert(Visibility::Inherited);
});
}
@ -143,9 +139,11 @@ fn manage_scroll_text_animation(
roots: Query<Entity, With<ui::TextScrollAnimation>>,
texts: Query<Entity, (With<Text>, With<Intro>)>,
animated_texts: Query<&ui::TextScroll>,
parents: Query<&Parent>,
children: Query<&Children>,
time: Res<Time>,
framecount: Res<FrameCount>,
mut next_state: ResMut<NextState<GameState>>,
mut curr: Local<Option<Entity>>,
mut commands: Commands,
) {
@ -164,6 +162,9 @@ fn manage_scroll_text_animation(
if curr.is_some() {
// Hide the last active entity
if let Some(e) = *curr {
let p = parents.get(e).unwrap();
commands.entity(p.get()).insert(Visibility::Hidden);
commands.entity(e).insert(Visibility::Hidden);
}
// Locate the last entity we were operating with
@ -186,6 +187,7 @@ fn manage_scroll_text_animation(
});
} else {
commands.entity(r).remove::<ui::TextScrollAnimation>();
next_state.set(GameState::Play);
}
}
});
@ -197,6 +199,7 @@ fn scroll_text(
tweaks: Res<Assets<tweak::Tweaks>>,
time: Res<Time>,
keys: Res<Input<KeyCode>>,
parents: Query<&Parent>,
mut commands: Commands,
) {
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
@ -207,6 +210,10 @@ fn scroll_text(
// If the animation just started, make visible
if text_scroll.progress == 0 {
let p = parents.get(entity).unwrap();
commands.entity(p.get()).insert(Visibility::Inherited);
// Make the text visible as well
*vis = Visibility::Inherited;
}

Loading…
Cancel
Save