-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
425 additions
and
204 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,18 @@ | ||
//! In this example we will create an action | ||
//! and then combine it with some built-in actions to run a behavior. | ||
use beet::prelude::*; | ||
use beet_examples::prelude::*; | ||
use bevy::prelude::*; | ||
mod scenes; | ||
|
||
fn main() { | ||
let mut app = App::new(); | ||
|
||
app.add_plugins(( | ||
ExamplePluginText::default(), | ||
DefaultBeetPlugins::default(), | ||
)) | ||
.add_systems(Startup, scenes::hello_world) | ||
.add_systems(PostStartup, save_scene("target/scenes/hello_world.ron")) | ||
.run(); | ||
} |
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 @@ | ||
pub mod scenes; |
17 changes: 17 additions & 0 deletions
17
crates/beet_examples/examples/basics/scenes/hello_world.rs
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,17 @@ | ||
use beet::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
pub fn hello_world(mut commands: Commands) { | ||
commands | ||
.spawn((SequenceSelector::default(), Running)) | ||
.with_children(|parent| { | ||
parent.spawn(( | ||
LogOnRun("Hello".into()), | ||
InsertOnRun(RunResult::Success), | ||
)); | ||
parent.spawn(( | ||
LogOnRun("World".into()), | ||
InsertOnRun(RunResult::Success), | ||
)); | ||
}); | ||
} |
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,3 @@ | ||
pub mod hello_world; | ||
#[allow(unused_imports)] | ||
pub use self::hello_world::*; |
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
crates/beet_examples/src/bundles.rs → ...s/beet_examples/src/components/bundles.rs
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use crate::prelude::*; | ||
use beet::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
pub fn bee_bundle() -> impl Bundle { | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,67 @@ | ||
use crate::prelude::DoNotSerialize; | ||
use beet::prelude::LogOnRun; | ||
use beet::prelude::Running; | ||
use bevy::prelude::*; | ||
|
||
#[derive(Debug, Default, Component)] | ||
pub struct LogToUi; | ||
|
||
|
||
|
||
pub fn log_to_ui( | ||
actions: Query<&LogOnRun, Added<Running>>, | ||
mut query: Query<&mut Text, With<LogToUi>>, | ||
) { | ||
for mut text in query.iter_mut() { | ||
for log in actions.iter() { | ||
text.sections[0].value.push_str(&log.0); | ||
text.sections[0].value.push_str("\n"); | ||
} | ||
} | ||
} | ||
|
||
const TEST: &str = r#" | ||
val 1 | ||
val 2 | ||
val 3 | ||
val 4 | ||
val 5 | ||
val 6 | ||
val 7 | ||
val 8 | ||
val 9 | ||
val 10 | ||
val 11 | ||
"#; | ||
|
||
|
||
pub fn spawn_log_to_ui(mut commands: Commands) { | ||
commands | ||
.spawn(( | ||
NodeBundle { | ||
style: Style { | ||
flex_direction: FlexDirection::ColumnReverse, | ||
// align_items: AlignItems::Center, | ||
..default() | ||
}, | ||
..default() | ||
}, | ||
// ScrollingList::default(), | ||
// AccessibilityNode(NodeBuilder::new(Role::List)), | ||
)) | ||
.with_children(|parent| { | ||
parent.spawn(( | ||
DoNotSerialize, | ||
LogToUi, | ||
TextBundle::from_sections([TextSection::new( | ||
TEST, | ||
TextStyle { | ||
// This font is loaded and will be used instead of the default font. | ||
// font: asset_server.load("fonts/FiraSans-Bold.ttf"), | ||
font_size: 60.0, | ||
..default() | ||
}, | ||
)]), | ||
)); | ||
}); | ||
} |
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,30 @@ | ||
pub mod auto_spawn; | ||
#[allow(unused_imports)] | ||
pub use self::auto_spawn::*; | ||
pub mod beet_finished_loading; | ||
#[allow(unused_imports)] | ||
pub use self::beet_finished_loading::*; | ||
pub mod bundles; | ||
#[allow(unused_imports)] | ||
pub use self::bundles::*; | ||
pub mod camera_distance; | ||
#[allow(unused_imports)] | ||
pub use self::camera_distance::*; | ||
pub mod dialog_panel; | ||
#[allow(unused_imports)] | ||
pub use self::dialog_panel::*; | ||
pub mod follow_cursor; | ||
#[allow(unused_imports)] | ||
pub use self::follow_cursor::*; | ||
pub mod log_to_ui; | ||
#[allow(unused_imports)] | ||
pub use self::log_to_ui::*; | ||
pub mod randomize_position; | ||
#[allow(unused_imports)] | ||
pub use self::randomize_position::*; | ||
pub mod render_text; | ||
#[allow(unused_imports)] | ||
pub use self::render_text::*; | ||
pub mod wrap_around; | ||
#[allow(unused_imports)] | ||
pub use self::wrap_around::*; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,28 +1,19 @@ | ||
// #![allow(unused, dead_code)] | ||
mod beet_finished_loading; | ||
mod camera_distance; | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
mod postmessage_input; | ||
pub mod wasm; | ||
#[cfg(target_arch = "wasm32")] | ||
pub use postmessage_input::*; | ||
pub use wasm::*; | ||
pub mod serde_utils; | ||
|
||
pub mod components; | ||
pub mod plugins; | ||
|
||
|
||
mod example_plugin; | ||
mod example_plugin_2d; | ||
mod example_plugin_3d; | ||
pub use example_plugin::*; | ||
pub use example_plugin_2d::*; | ||
pub use example_plugin_3d::*; | ||
mod dialog_panel; | ||
pub use beet_finished_loading::*; | ||
pub use camera_distance::*; | ||
pub use dialog_panel::*; | ||
mod auto_spawn; | ||
pub use auto_spawn::*; | ||
mod follow_cursor; | ||
pub use follow_cursor::*; | ||
mod randomize_position; | ||
pub use randomize_position::*; | ||
mod render_text; | ||
pub use render_text::*; | ||
mod wrap_around; | ||
pub use wrap_around::*; | ||
pub mod prelude { | ||
pub use crate::components::*; | ||
pub use crate::plugins::*; | ||
pub use crate::serde_utils::*; | ||
#[cfg(target_arch = "wasm32")] | ||
pub use wasm::*; | ||
} |
2 changes: 1 addition & 1 deletion
2
crates/beet_examples/src/example_plugin.rs → ...et_examples/src/plugins/example_plugin.rs
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
3 changes: 1 addition & 2 deletions
3
...es/beet_examples/src/example_plugin_2d.rs → ...examples/src/plugins/example_plugin_2d.rs
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
2 changes: 1 addition & 1 deletion
2
...es/beet_examples/src/example_plugin_3d.rs → ...examples/src/plugins/example_plugin_3d.rs
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,23 @@ | ||
use crate::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
pub struct ExamplePluginText {} | ||
|
||
|
||
|
||
impl Default for ExamplePluginText { | ||
fn default() -> Self { Self {} } | ||
} | ||
|
||
|
||
impl Plugin for ExamplePluginText { | ||
fn build(&self, app: &mut App) { | ||
app.add_plugins(ExamplePlugin) | ||
.add_systems(Startup, (setup, spawn_log_to_ui)) | ||
.add_systems(Update, log_to_ui); | ||
} | ||
} | ||
|
||
fn setup(mut commands: Commands) { | ||
commands.spawn((DoNotSerialize, Camera2dBundle::default())); | ||
} |
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,12 @@ | ||
pub mod example_plugin; | ||
#[allow(unused_imports)] | ||
pub use self::example_plugin::*; | ||
pub mod example_plugin_2d; | ||
#[allow(unused_imports)] | ||
pub use self::example_plugin_2d::*; | ||
pub mod example_plugin_3d; | ||
#[allow(unused_imports)] | ||
pub use self::example_plugin_3d::*; | ||
pub mod example_plugin_text; | ||
#[allow(unused_imports)] | ||
pub use self::example_plugin_text::*; |
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,3 @@ | ||
pub mod save_scene; | ||
#[allow(unused_imports)] | ||
pub use self::save_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use bevy::ecs::schedule::SystemConfigs; | ||
use bevy::prelude::*; | ||
use bevy::tasks::IoTaskPool; | ||
use std::fs::File; | ||
use std::fs::{ | ||
self, | ||
}; | ||
use std::io::Write; | ||
|
||
|
||
#[derive(Component)] | ||
pub struct DoNotSerialize; | ||
|
||
fn entities_to_serialize(world: &World) -> Vec<Entity> { | ||
world | ||
.iter_entities() | ||
.map(|entity| entity.id()) | ||
.filter(|entity| world.get::<DoNotSerialize>(*entity).is_none()) | ||
.collect() | ||
} | ||
|
||
|
||
pub fn save_scene(filename: &'static str) -> SystemConfigs { | ||
(move |world: &mut World| { | ||
let scene = DynamicSceneBuilder::from_world(world) | ||
.extract_entities(entities_to_serialize(world).into_iter()) | ||
.build(); | ||
|
||
// Scenes can be serialized like this: | ||
let type_registry = world.resource::<AppTypeRegistry>(); | ||
let type_registry = type_registry.read(); | ||
let serialized_scene = scene.serialize(&type_registry).unwrap(); | ||
|
||
// Showing the scene in the console | ||
info!("{}", serialized_scene); | ||
|
||
// Writing the scene to a new file. Using a task to avoid calling the filesystem APIs in a system | ||
// as they are blocking | ||
// This can't work in WASM as there is no filesystem access | ||
#[cfg(not(target_arch = "wasm32"))] | ||
IoTaskPool::get() | ||
.spawn(async move { | ||
let dir_path = std::path::Path::new(filename).parent().unwrap(); | ||
fs::create_dir_all(dir_path) | ||
.expect("Error while creating directory"); | ||
|
||
// Write the scene RON data to file | ||
File::create(filename) | ||
.and_then(|mut file| { | ||
file.write(serialized_scene.as_bytes()) | ||
}) | ||
.expect("Error while writing scene to file"); | ||
}) | ||
.detach(); | ||
}) | ||
.into_configs() | ||
} |
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,3 @@ | ||
pub mod postmessage_input; | ||
#[allow(unused_imports)] | ||
pub use self::postmessage_input::*; |
2 changes: 1 addition & 1 deletion
2
...es/beet_examples/src/postmessage_input.rs → ...et_examples/src/wasm/postmessage_input.rs
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
Oops, something went wrong.