-
-
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
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
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,57 @@ | ||
//! This module implements a Bevy plugin for drafting new objects on the map. | ||
//! An entity marked with a component [`Draft`] is automatically handled and | ||
//! visualized by the plugin. | ||
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)); | ||
} | ||
} | ||
|
||
/// Bundle to spawn a construction draft. | ||
#[derive(Bundle)] | ||
pub struct DraftBundle { | ||
object_type: ObjectType, | ||
transform: Transform, | ||
global_transform: GlobalTransform, | ||
draft: Draft, | ||
} | ||
|
||
impl DraftBundle { | ||
pub fn new(object_type: ObjectType, transform: Transform) -> Self { | ||
Self { | ||
object_type, | ||
transform, | ||
global_transform: transform.into(), | ||
draft: Draft, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Component)] | ||
pub struct Draft; | ||
|
||
#[derive(Component)] | ||
struct Ready; | ||
|
||
type NonReadyDrafts<'w, 's> = | ||
Query<'w, 's, (Entity, &'static ObjectType), (With<Draft>, Without<Ready>)>; | ||
|
||
fn new_draft(mut commands: Commands, drafts: NonReadyDrafts, cache: Res<ObjectCache>) { | ||
for (entity, object_type) in drafts.iter() { | ||
commands | ||
.entity(entity) | ||
.insert(Ready) | ||
.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