Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data from Files #71

Merged
merged 13 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- bevy_common_assets allowing certain data to be loaded from asset files
- Allow window mode and master volume to be set via config file

### Changed

- Gravitable component added allowing dynamic_orbit system to be applied to any entity
- Load credits from asset file

### Fixed

Expand Down
22 changes: 18 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ edition = "2021"
bevy = "0.11.3"
bevy-inspector-egui = "0.20.0"
bevy_asset_loader = { version = "0.17.0", features = ["2d"] }
bevy_common_assets = { version = "0.7.0", features = ["ron"] }
bevy_rapier2d = "0.22.0"
bevy_spatial = "0.6.0"
bevy_tiling_background = { git = "https://github.com/rparrett/bevy_tiling_background.git", branch = "tex-typo" }
image = "0.24.7"
leafwing-input-manager = "0.10.0"
serde = "1.0.190"
winit = "0.28.7"

# Enable a small amount of optimization in debug mode
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
4 changes: 4 additions & 0 deletions assets/verse.config.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GameConfig(
window_mode: Windowed, // Windowed, Fullscreen, BorderlessFullscreen, SizedFullscreen
master_volume: 1.0,
)
67 changes: 67 additions & 0 deletions assets/verse.credits.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
([
(
section_title: "Developed by",
credits: [(credit_title: "Thom Bruce")]
),
(
section_title: "Title Font",
credits: [(
credit_title: "Edge of the Galaxy by Quinn Davis Type",
credit_meta: Some("FontSpace, Public Domain")
)]
),
(
section_title: "Art",
credits: [
(
credit_title: "Space Shooter Redux by Kenney",
credit_meta: Some("kenney.nl, CC0")
),
(
credit_title: "Ship Mixer by Kenney",
credit_meta: Some("kenney.nl")
),
(
credit_title: "Pixel Planets by Deep-Fold",
credit_meta: Some("itch.io, MIT")
),
(
credit_title: "Xolonium Typeface by Severin Meyer",
credit_meta: Some("Font Library, OFL (SIL Open Font License)")
),
]
),
(
section_title: "Music",
credits: [
(
credit_title: "Lightspeed by Beat Mekanik",
credit_meta: Some("Free Music Archive, CC BY")
),
(
credit_title: "Space Dust by Kirk Osamayo",
credit_meta: Some("Free Music Archive, CC BY")
),
]
),
(
section_title: "Audio",
credits: [
(
credit_title: "Impact Sounds by Kenney",
credit_meta: Some("kenney.nl, CC0")
),
]
),
// (
// section_title: "Become a Supporter",
// credits: [
// (
// credit_title: "ko-fi.com/thombruce"
// ),
// (
// credit_title: "patreon.com/thombruce"
// ),
// ]
// ),
])
15 changes: 14 additions & 1 deletion src/core/resources/assets.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
use bevy::prelude::*;
use bevy_asset_loader::prelude::*;

use crate::ui::menus::credits::Credits;

use super::config::GameConfig;

#[derive(AssetCollection, Resource)]
pub struct DataAssets {
#[asset(path = "verse.config.ron")]
pub config: Handle<GameConfig>,

#[asset(path = "verse.credits.ron")]
pub credits: Handle<Credits>,
}

#[derive(AssetCollection, Resource)]
pub struct SpriteAssets {
#[asset(path = "space/ships/player.png")]
Expand Down Expand Up @@ -72,6 +85,6 @@ pub struct UiAssets {
#[asset(path = "fonts/Xolonium/Xolonium-Bold.ttf")]
pub font: Handle<Font>,

#[asset(path = "verse.png")]
#[asset(path = "images/verse.png")]
pub title: Handle<Image>,
}
38 changes: 38 additions & 0 deletions src/core/resources/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use bevy::prelude::*;
use bevy::reflect::{TypePath, TypeUuid};
use bevy::window::WindowMode;
use bevy_common_assets::ron::RonAssetPlugin;

use super::{assets::DataAssets, state::GameState};

pub struct ConfigPlugin;
impl Plugin for ConfigPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(RonAssetPlugin::<GameConfig>::new(&["config.ron"]));

app.insert_resource(GameConfig {
window_mode: WindowMode::Fullscreen,
master_volume: 1.0,
});

app.add_systems(OnExit(GameState::Loading), load_config);
}
}

#[derive(serde::Deserialize, TypeUuid, TypePath, Resource)]
#[uuid = "bdb624ed-62bc-447f-9f89-f361ed58748c"]
pub struct GameConfig {
pub(crate) window_mode: WindowMode,
pub(crate) master_volume: f32,
}

fn load_config(
data: Res<DataAssets>,
mut configs: ResMut<Assets<GameConfig>>,
mut game_config: ResMut<GameConfig>,
) {
if let Some(config) = configs.remove(data.config.id()) {
game_config.window_mode = config.window_mode;
game_config.master_volume = config.master_volume;
}
}
1 change: 1 addition & 0 deletions src/core/resources/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod assets;
pub mod config;
pub mod despawn_timer;
pub mod game_time;
pub mod state;
2 changes: 1 addition & 1 deletion src/core/resources/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn game_setup(
source: audios.ambience.clone(),
settings: PlaybackSettings {
mode: PlaybackMode::Loop,
volume: Volume::new_absolute(0.5),
volume: Volume::new_relative(0.5),
..default()
},
},
Expand Down
21 changes: 14 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[allow(unused_imports)]
use bevy::{
audio::{AudioPlugin, VolumeLevel},
prelude::*,
window::{Cursor, PrimaryWindow, WindowMode},
winit::WinitWindows,
Expand All @@ -19,7 +20,8 @@ mod world;

use crate::{
core::resources::{
assets::{AudioAssets, SpriteAssets, UiAssets},
assets::{AudioAssets, DataAssets, SpriteAssets, UiAssets},
config::{ConfigPlugin, GameConfig},
state::GameState,
},
core::CorePlugin,
Expand Down Expand Up @@ -53,7 +55,7 @@ fn main() {
.set(ImagePlugin::default_nearest()),
);

app.add_plugins((CorePlugin, ShipsPlugin, WorldPlugin, UiPlugin));
app.add_plugins((ConfigPlugin, CorePlugin, ShipsPlugin, WorldPlugin, UiPlugin));

#[cfg(debug_assertions)]
app.add_plugins((
Expand All @@ -66,7 +68,8 @@ fn main() {
)
.add_collection_to_loading_state::<_, SpriteAssets>(GameState::Loading)
.add_collection_to_loading_state::<_, AudioAssets>(GameState::Loading)
.add_collection_to_loading_state::<_, UiAssets>(GameState::Loading);
.add_collection_to_loading_state::<_, UiAssets>(GameState::Loading)
.add_collection_to_loading_state::<_, DataAssets>(GameState::Loading);

app.insert_resource(ClearColor(Color::rgb(0., 0., 0.)));

Expand All @@ -84,9 +87,13 @@ fn main() {
}

/// The setup function
fn setup() {
// Good place to put window setup configs, like whether or not
// the player has suggested the game be played fullscreen.
fn setup(
config: Res<GameConfig>,
mut window: Query<&mut Window>,
mut volume: ResMut<GlobalVolume>,
) {
window.single_mut().mode = config.window_mode;
volume.volume = VolumeLevel::new(config.master_volume);
}

// Documented:
Expand All @@ -104,7 +111,7 @@ fn set_window_icon(
// here we use the `image` crate to load our icon data from a png file
// this is not a very bevy-native solution, but it will do
let (icon_rgba, icon_width, icon_height) = {
let image = image::open("assets/VerseSquircle-256.png")
let image = image::open("assets/images/VerseSquircle-256.png")
.expect("Failed to open icon path")
.into_rgba8();
let (width, height) = image.dimensions();
Expand Down
15 changes: 13 additions & 2 deletions src/ships/bullet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use bevy::prelude::*;
use bevy::{
audio::{PlaybackMode, Volume},
prelude::*,
};
use bevy_rapier2d::prelude::*;

use crate::core::resources::{
Expand Down Expand Up @@ -89,7 +92,15 @@ fn spawn_bullet(
ActiveEvents::COLLISION_EVENTS,
AudioBundle {
source: audios.gun.clone(),
..default()
settings: PlaybackSettings {
mode: PlaybackMode::Remove,
// TODO: This should be relative to an SFX Volume setting
// which should in turn be relative to the master volume.
// Right now, this is just being set relative to the
// GlobalVolume (which is configurable as master_volume).
volume: Volume::new_relative(1.0),
..default()
},
},
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/hud/indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn setup(
for (entity, indicated) in entities_query.iter() {
parent.spawn((
ImageBundle {
image: UiImage::new(asset_server.load("grey_arrowUpWhite.png")),
image: UiImage::new(asset_server.load("images/grey_arrowUpWhite.png")),
style: Style {
position_type: PositionType::Absolute,
width: Val::Px(15.0),
Expand Down
Loading