Skip to content

Commit

Permalink
checkpoint: tinkering
Browse files Browse the repository at this point in the history
  • Loading branch information
philiplinden committed Sep 2, 2024
1 parent ca975c6 commit b4b07a8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 37 deletions.
15 changes: 15 additions & 0 deletions docs/devlog/v0.2.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,18 @@ options in the UI, it doesn't propagate back to the Coordinate Time resource.
I'm not sure why this is the case, but it happens for _both_ options: timescale
(which does not involve lofitime) and the date picker (which uses lofitime).
I'm pretty sure lofitime isn't the problem here.

# 2024-08-24
I discovered [`Vinermy/astray`](https://github.com/Vinermy/astray) and found the
terminal UI charming. `astray` uses
[`joshka/bevy_ratatui`](https://github.com/joshka/bevy_ratatui), a Bevy wrapper
for the popular terminal UI crate [ratatui](https://ratatui.rs/).

# 2024-08-31
Another inspiration: [`victorb/dogoap`](https://github.com/victorb/dogoap)
([demo](https://victorb.github.io/dogoap/)) It's a GOAP library. Nothing too
special about it but it looks the way I want this to look with entities spawning
and moving around.

# 2024-09-02
Fresh eyes help. Some refactors today to make the code feel more "natural".
53 changes: 43 additions & 10 deletions spacetime/src/components/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ use avian2d::prelude::*;
use bevy::prelude::*;
use bevy_prototype_lyon::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.add_event::<SpawnPlanetoid>();
app.add_systems(Update, spawn_planetoid);
}

#[derive(Component)]
pub struct Planetoid;

#[derive(Bundle)]
pub struct PlanetoidBundle {
struct CircleBody {
physics_body: RigidBody,
collider_shape: Collider,
graphics_shape: ShapeBundle,
fill: Fill,
}

impl Default for PlanetoidBundle {
fn default() -> Self {
let default_radius = 10.0;
Self::from_radius(default_radius)
}
}

impl PlanetoidBundle {
impl CircleBody {
pub fn from_radius(radius: f32) -> Self {
let points = [
Vec2::new(1.0, -1.0),
Expand All @@ -33,7 +31,7 @@ impl PlanetoidBundle {
radius: radius,
..default()
};
PlanetoidBundle {
CircleBody {
physics_body: RigidBody::Dynamic,
collider_shape: Collider::circle(radius),
graphics_shape: ShapeBundle {
Expand All @@ -44,3 +42,38 @@ impl PlanetoidBundle {
}
}
}


#[derive(Event)]
pub struct SpawnPlanetoid {
pub position: Vec2,
pub velocity: Vec2,
pub mass: f32,
pub radius: f32,
}

fn spawn_planetoid(mut commands: Commands, mut events: EventReader<SpawnPlanetoid>) {
let text_style = TextStyle {
font_size: 18.0,
..default()
};
for e in events.read(){
commands
.spawn((
Name::new("Hello"),
Planetoid,
CircleBody::from_radius(e.radius)
))
.with_children(|subcommands| {
subcommands.spawn((
Text2dBundle {
transform: Transform::from_translation(Vec3::new(10.0, -10.0, 10.0)),
text: Text::from_section("", text_style.clone())
.with_justify(JustifyText::Left),
text_anchor: bevy::sprite::Anchor::TopLeft,
..default()
},
));
});
}
}
5 changes: 4 additions & 1 deletion spacetime/src/components/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ use bevy_prototype_lyon::plugin::ShapePlugin;
pub mod bodies;

pub(super) fn plugin(app: &mut App) {
app.add_plugins(ShapePlugin);
app.add_plugins((
ShapePlugin,
bodies::plugin,
));
}
7 changes: 2 additions & 5 deletions spacetime/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
mod physics;
mod ui;
pub mod components;
pub mod spawners;
pub mod palette;

use bevy::prelude::*;
use spawners::SpawnPlanetoid;
pub struct AppPlugin;

impl Plugin for AppPlugin {
Expand All @@ -31,7 +29,6 @@ impl Plugin for AppPlugin {
// Add custom plugins.
app.add_plugins((
ui::UserInterfacePlugins,
spawners::plugin,
physics::plugin,
components::plugin,
));
Expand All @@ -55,9 +52,9 @@ pub enum AppState {
Running,
}

fn initialize(mut events: EventWriter<SpawnPlanetoid>) {
fn initialize(mut events: EventWriter<components::bodies::SpawnPlanetoid>) {
// spawn center body
events.send(spawners::SpawnPlanetoid {
events.send(components::bodies::SpawnPlanetoid {
position: Vec2::new(0.0, 0.0),
velocity: Vec2::new(0.0, 0.0),
mass: 100_000.0,
Expand Down
21 changes: 0 additions & 21 deletions spacetime/src/spawners/mod.rs

This file was deleted.

0 comments on commit b4b07a8

Please sign in to comment.