-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Relates to #23.
- Loading branch information
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! This module implements a Bevy plugin for drafting new objects on the map. | ||
//! This serves mostly as a visual guide for the user to correctly place new | ||
//! structures on the map. | ||
use bevy::prelude::*; | ||
use de_core::{objects::ObjectType, state::GameState}; | ||
use iyes_loopless::prelude::*; | ||
|
||
use crate::ObjectCache; | ||
|
||
pub(crate) struct DraftPlugin; | ||
|
||
impl Plugin for DraftPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_system(new_draft.run_in_state(GameState::Playing)); | ||
} | ||
} | ||
|
||
/// This is a marker component. | ||
/// | ||
/// An entity with this component is considered to be a (construction) draft. | ||
/// Its model will be automatically spawned by a system in this module. | ||
/// | ||
/// An entity marked as a draft must have components | ||
/// [`bevy::transform::components::Transform`] and | ||
/// [`de_core::objects::ObjectType`]. | ||
#[derive(Component)] | ||
pub struct Draft; | ||
|
||
fn new_draft( | ||
mut commands: Commands, | ||
drafts: Query<(Entity, &ObjectType), With<Draft>>, | ||
cache: Res<ObjectCache>, | ||
) { | ||
for (entity, object_type) in drafts.iter() { | ||
commands | ||
.entity(entity) | ||
.remove::<Draft>() | ||
.with_children(|parent| { | ||
parent.spawn_scene(cache.get(*object_type).scene()); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters