structure project

using ui layout to ensure pieces work together
This commit is contained in:
sorrel 2024-04-21 23:19:47 -04:00
parent b4f34ec038
commit 8f38a07c67
11 changed files with 336 additions and 35 deletions

71
Cargo.lock generated
View file

@ -68,7 +68,7 @@ dependencies = [
"accesskit", "accesskit",
"accesskit_macos", "accesskit_macos",
"accesskit_windows", "accesskit_windows",
"raw-window-handle 0.6.0", "raw-window-handle 0.6.1",
"winit", "winit",
] ]
@ -169,6 +169,15 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "app"
version = "0.1.0"
dependencies = [
"bevy",
"bevy-inspector-egui",
"game",
]
[[package]] [[package]]
name = "approx" name = "approx"
version = "0.5.1" version = "0.5.1"
@ -1089,7 +1098,7 @@ dependencies = [
"bevy_math", "bevy_math",
"bevy_reflect", "bevy_reflect",
"bevy_utils", "bevy_utils",
"raw-window-handle 0.6.0", "raw-window-handle 0.6.1",
"smol_str", "smol_str",
] ]
@ -1112,7 +1121,7 @@ dependencies = [
"bevy_utils", "bevy_utils",
"bevy_window", "bevy_window",
"crossbeam-channel", "crossbeam-channel",
"raw-window-handle 0.6.0", "raw-window-handle 0.6.1",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
"winit", "winit",
@ -1307,12 +1316,13 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.94" version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b"
dependencies = [ dependencies = [
"jobserver", "jobserver",
"libc", "libc",
"once_cell",
] ]
[[package]] [[package]]
@ -1658,6 +1668,15 @@ dependencies = [
"bytemuck", "bytemuck",
] ]
[[package]]
name = "editor"
version = "0.1.0"
dependencies = [
"bevy",
"bevy-inspector-egui",
"game",
]
[[package]] [[package]]
name = "egui" name = "egui"
version = "0.27.2" version = "0.27.2"
@ -1935,6 +1954,14 @@ dependencies = [
"thread_local", "thread_local",
] ]
[[package]]
name = "game"
version = "0.1.0"
dependencies = [
"bevy",
"bevy-inspector-egui",
]
[[package]] [[package]]
name = "gethostname" name = "gethostname"
version = "0.4.3" version = "0.4.3"
@ -2597,7 +2624,7 @@ dependencies = [
"log", "log",
"ndk-sys", "ndk-sys",
"num_enum", "num_enum",
"raw-window-handle 0.6.0", "raw-window-handle 0.6.1",
"thiserror", "thiserror",
] ]
@ -3044,9 +3071,9 @@ checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
[[package]] [[package]]
name = "raw-window-handle" name = "raw-window-handle"
version = "0.6.0" version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42a9830a0e1b9fb145ebb365b8bc4ccd75f290f98c0247deafbbe2c75cefb544" checksum = "8cc3bcbdb1ddfc11e700e62968e6b4cc9c75bb466464ad28fb61c5b2c964418b"
[[package]] [[package]]
name = "rectangle-pack" name = "rectangle-pack"
@ -3152,9 +3179,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]] [[package]]
name = "rustix" name = "rustix"
version = "0.38.32" version = "0.38.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" checksum = "e3cc72858054fcff6d7dea32df2aeaee6a7c24227366d7ea429aada2f26b16ad"
dependencies = [ dependencies = [
"bitflags 2.5.0", "bitflags 2.5.0",
"errno", "errno",
@ -3411,28 +3438,20 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "that-has-no-name"
version = "0.1.0"
dependencies = [
"bevy",
"bevy-inspector-egui",
]
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.58" version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
dependencies = [ dependencies = [
"thiserror-impl", "thiserror-impl",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "1.0.58" version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -3942,7 +3961,7 @@ dependencies = [
"naga", "naga",
"parking_lot", "parking_lot",
"profiling", "profiling",
"raw-window-handle 0.6.0", "raw-window-handle 0.6.1",
"smallvec", "smallvec",
"static_assertions", "static_assertions",
"wasm-bindgen", "wasm-bindgen",
@ -3970,7 +3989,7 @@ dependencies = [
"once_cell", "once_cell",
"parking_lot", "parking_lot",
"profiling", "profiling",
"raw-window-handle 0.6.0", "raw-window-handle 0.6.1",
"rustc-hash", "rustc-hash",
"smallvec", "smallvec",
"thiserror", "thiserror",
@ -4013,7 +4032,7 @@ dependencies = [
"parking_lot", "parking_lot",
"profiling", "profiling",
"range-alloc", "range-alloc",
"raw-window-handle 0.6.0", "raw-window-handle 0.6.1",
"renderdoc-sys", "renderdoc-sys",
"rustc-hash", "rustc-hash",
"smallvec", "smallvec",
@ -4385,7 +4404,7 @@ dependencies = [
"once_cell", "once_cell",
"orbclient", "orbclient",
"percent-encoding", "percent-encoding",
"raw-window-handle 0.6.0", "raw-window-handle 0.6.1",
"redox_syscall 0.3.5", "redox_syscall 0.3.5",
"rustix", "rustix",
"sctk-adwaita", "sctk-adwaita",

View file

@ -1,11 +1,9 @@
[package] [workspace]
name = "that-has-no-name" members = ["app", "editor", "game"]
version = "0.1.0" # default-members = ["app", "game"]
edition = "2021" resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace.dependencies]
[dependencies]
bevy = "0.13.2" bevy = "0.13.2"
bevy-inspector-egui = "0.24.0" bevy-inspector-egui = "0.24.0"

View file

@ -4,3 +4,18 @@ original concept sketched out for QGJam, 2023 Oct -- [beginning of godot impleme
building with [bevy](https://bevyengine.org/) building with [bevy](https://bevyengine.org/)
## developing
this project is structured with two binaries:
- an app entrypoint in which to run the game
- an editor entrypoint in which to edit assets to be included in the game
and one library:
- a game lib that contains most of the game logic, data and assets
### running
```sh
cargo run # launches from "app" binary
```
```sh
cargo run --bin editor # launches from "editor" binary
```

11
app/Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "app"
version = "0.1.0"
edition = "2021"
# it is strange to me that this lives in the bin and not the workspace virtual manifest
default-run = "app"
[dependencies]
bevy = "0.13.2"
bevy-inspector-egui = "0.24.0"
game = { version = "0.1.0", path = "../game" }

View file

@ -1,5 +1,12 @@
use bevy::prelude::* use bevy::{
prelude::*,
input::{common_conditions::input_toggle_active, keyboard::KeyboardInput},
window::{ReceivedCharacter, WindowResolution},
};
use bevy_inspector_egui::quick::WorldInspectorPlugin; use bevy_inspector_egui::quick::WorldInspectorPlugin;
use game::{camera, ui};
const VERSION: &str = "0.1.0"; const VERSION: &str = "0.1.0";
// display constants // display constants
const WINDOW_WIDTH: f32 = 1024.0; const WINDOW_WIDTH: f32 = 1024.0;
@ -12,6 +19,10 @@ enum AppState {
InGame, InGame,
} }
fn start_game(mut next_state: ResMut<NextState<AppState>>) {
next_state.set(AppState::InGame)
}
fn start_app() { fn start_app() {
println!("starting app!"); println!("starting app!");
} }
@ -31,6 +42,8 @@ fn main() {
primary_window: app_window, primary_window: app_window,
..default() ..default()
}), }),
camera::CameraPlugin,
ui::UIPlugin,
StartAppPlugin, StartAppPlugin,
)) ))
.add_plugins( .add_plugins(
@ -46,4 +59,3 @@ impl Plugin for StartAppPlugin {
app.init_state::<AppState>().add_systems(Startup, start_app); app.init_state::<AppState>().add_systems(Startup, start_app);
} }
} }

9
editor/Cargo.toml Normal file
View file

@ -0,0 +1,9 @@
[package]
name = "editor"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = "0.13.2"
bevy-inspector-egui = "0.24.0"
game = { version = "0.1.0", path = "../game" }

26
editor/src/main.rs Normal file
View file

@ -0,0 +1,26 @@
use bevy::{input::common_conditions::input_toggle_active, prelude::*, window::WindowResolution};
use bevy_inspector_egui::quick::WorldInspectorPlugin;
const VERSION: &str = "0.1.0";
// display constants
const WINDOW_WIDTH: f32 = 1024.0;
const WINDOW_HEIGHT: f32 = 768.0;
fn main() {
let app_window = Some(Window {
title: format!("that-has-no-name--EDITOR:{}", VERSION).into(),
resolution: WindowResolution::new(WINDOW_WIDTH, WINDOW_HEIGHT),
resizable: true,
..default()
});
App::new()
.add_plugins((DefaultPlugins.set(WindowPlugin {
primary_window: app_window,
..default()
}),))
.add_plugins(
WorldInspectorPlugin::default().run_if(input_toggle_active(true, KeyCode::Escape)),
)
.run();
}

8
game/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "game"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = "0.13.2"
bevy-inspector-egui = "0.24.0"

16
game/src/camera.rs Normal file
View file

@ -0,0 +1,16 @@
use bevy::prelude::*;
pub struct CameraPlugin;
impl Plugin for CameraPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup);
}
}
#[derive(Component)]
struct MainCamera;
fn setup(mut commands: Commands) {
commands.spawn((Camera2dBundle::default(), MainCamera));
}

2
game/src/lib.rs Normal file
View file

@ -0,0 +1,2 @@
pub mod ui;
pub mod camera;

185
game/src/ui/mod.rs Normal file
View file

@ -0,0 +1,185 @@
use bevy::prelude::*;
pub struct UIPlugin;
impl Plugin for UIPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, spawn_ui);
}
}
fn spawn_ui(mut commands: Commands) {
commands
.spawn((
NodeBundle {
style: Style { ..default() },
..default()
},
Name::new("UI Root"),
))
.with_children(|commands| {
commands.spawn((
NodeBundle {
background_color: BackgroundColor(Color::Rgba {
red: 255.0,
green: 0.0,
blue: 0.0,
alpha: 200.0,
}),
style: Style {
position_type: PositionType::Absolute,
min_width: Val::Px(216.0),
min_height: Val::Px(288.0),
..default()
},
..default()
},
Name::new("Visual Container"),
VisualContainer,
));
commands.spawn((
NodeBundle {
background_color: BackgroundColor(Color::Rgba {
red: 0.0,
green: 255.0,
blue: 255.0,
alpha: 200.0,
}),
style: Style {
position_type: PositionType::Absolute,
left: Val::Px(216.0),
min_width: Val::Px(504.0),
min_height: Val::Px(480.0),
..default()
},
..default()
},
Name::new("Main Container"),
MainContainer,
));
commands.spawn((
NodeBundle {
background_color: BackgroundColor(Color::Rgba {
red: 255.0,
green: 255.0,
blue: 0.0,
alpha: 200.0,
}),
style: Style {
position_type: PositionType::Absolute,
left: Val::Px(720.0),
min_width: Val::Px(304.0),
min_height: Val::Px(384.0),
..default()
},
..default()
},
Name::new("Overlay Container"),
OverlayContainer,
));
commands.spawn((
NodeBundle {
background_color: BackgroundColor(Color::Rgba {
red: 255.0,
green: 0.0,
blue: 255.0,
alpha: 200.0,
}),
style: Style {
position_type: PositionType::Absolute,
top: Val::Px(288.0),
min_width: Val::Px(216.0),
min_height: Val::Px(192.0),
..default()
},
..default()
},
Name::new("Help Container"),
HelpContainer,
));
commands.spawn((
NodeBundle {
background_color: BackgroundColor(Color::Rgba {
red: 0.0,
green: 0.0,
blue: 255.0,
alpha: 200.0,
}),
style: Style {
position_type: PositionType::Absolute,
top: Val::Px(384.0),
left: Val::Px(720.0),
min_width: Val::Px(394.0),
min_height: Val::Px(96.0),
..default()
},
..default()
},
Name::new("Input Container"),
InputContainer,
));
commands.spawn((
NodeBundle {
background_color: BackgroundColor(Color::Rgba {
red: 0.0,
green: 255.0,
blue: 0.0,
alpha: 200.0,
}),
style: Style {
position_type: PositionType::Absolute,
top: Val::Px(512.0),
min_width: Val::Px(720.0),
min_height: Val::Px(256.0),
..default()
},
..default()
},
Name::new("Jumper Container"),
JumperContainer,
));
commands.spawn((
NodeBundle {
background_color: BackgroundColor(Color::Rgba {
red: 127.0,
green: 127.0,
blue: 127.0,
alpha: 200.0,
}),
style: Style {
position_type: PositionType::Absolute,
left: Val::Px(720.0),
top: Val::Px(512.0),
min_width: Val::Px(394.0),
min_height: Val::Px(256.0),
..default()
},
..default()
},
Name::new("Id Container"),
IdContainer,
));
});
}
#[derive(Component)]
pub struct VisualContainer;
#[derive(Component)]
pub struct MainContainer;
#[derive(Component)]
pub struct OverlayContainer;
#[derive(Component)]
pub struct HelpContainer;
#[derive(Component)]
pub struct InputContainer;
#[derive(Component)]
pub struct JumperContainer;
#[derive(Component)]
pub struct IdContainer;
//