Skip to content

Commit

Permalink
refactor: multiple changes and fixes 🌻
Browse files Browse the repository at this point in the history
fix: now tilemaps work on web
change: add back embeded assets
this was some troubleshooting session...
  • Loading branch information
eerii committed Dec 3, 2023
1 parent c8baa21 commit eff9b5f
Show file tree
Hide file tree
Showing 16 changed files with 175 additions and 95 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ jobs:
mkdir linux
cp target/x86_64-unknown-linux-gnu/release/${{ env.binary }} linux/
strip linux/${{ env.binary }}
cp -r assets linux/
- name: Package as a zip
working-directory: ./linux
Expand Down Expand Up @@ -168,7 +167,6 @@ jobs:
run: |
mkdir windows
cp target/x86_64-pc-windows-msvc/release/${{ env.binary }}.exe windows/
cp -r assets windows/
- name: Package as a zip
run: |
Expand Down Expand Up @@ -232,7 +230,6 @@ jobs:
mkdir -p ${{ env.binary }}.app/Contents/MacOS
cp target/release/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/
strip ${{ env.binary }}.app/Contents/MacOS/${{ env.binary }}
cp -r assets ${{ env.binary }}.app/Contents/MacOS/
hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ env.binary }}.dmg
- name: Upload binaries to artifacts
Expand Down
19 changes: 19 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ bevy = { version = "0.12", default-features = false, features = [
"tonemapping_luts", "default_font", "webgl2",
]}
bevy_asset_loader = { version = "0.18", features = [ "progress_tracking" ] } # Better asset loader
bevy_embedded_assets = { version = "0.9" } # Embed assets in binary
bevy_kira_audio = { version = "0.18" } # Improved audio library
iyes_progress = { version = "0.10", features = [ "assets" ] } # Track loading and game state
bevy-inspector-egui = { version = "0.21" } # Inspector
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

a game for the bevy jam 4

_work in progress_
TODO: _write readme_
Binary file modified assets/sprites/tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion build/wasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<title>Charon</title>

<link data-trunk rel="copy-dir" href="../../assets"/>
<link data-trunk rel="inline" href="style.css"/>
<link data-trunk rel="rust" href="../../Cargo.toml"/>
</head>
Expand Down
2 changes: 2 additions & 0 deletions src/audio.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use bevy::prelude::*;
use bevy_kira_audio::prelude::AudioPlugin as KiraAudioPlugin;

// TODO: Add sound to the game

// ······
// Plugin
// ······
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::Path;
use bevy::prelude::*;
use serde::{Deserialize, Serialize};

use crate::{input::Bind, GameState};
use crate::input::Bind;

pub use bevy_persistent::prelude::*;

Expand All @@ -18,7 +18,7 @@ pub struct ConfigPlugin;

impl Plugin for ConfigPlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(GameState::Loading), init_persistence);
app.add_systems(Startup, init_persistence);
}
}

Expand Down
47 changes: 47 additions & 0 deletions src/game.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use bevy::{prelude::*, render::view::RenderLayers};

use crate::GameState;

// TODO: Spawn entities, follow pathfinding
// TODO: Collisions between entities (traffic)
// TODO: Multiple spawn points

pub struct CharonPlugin;

impl Plugin for CharonPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
OnEnter(GameState::Play),
(init_game.run_if(run_once()), resume_game),
)
.add_systems(OnExit(GameState::Play), pause_game);
}
}

// ··········
// Components
// ··········

#[derive(Component)]
pub struct GameCam;

// ·······
// Systems
// ·······

pub fn init_game(mut cmd: Commands) {
// Camera
cmd.spawn((Camera2dBundle::default(), RenderLayers::layer(0), GameCam));
}

pub fn resume_game(mut cam: Query<&mut Camera, With<GameCam>>) {
for mut cam in cam.iter_mut() {
cam.is_active = true;
}
}

pub fn pause_game(mut cam: Query<&mut Camera, With<GameCam>>) {
for mut cam in cam.iter_mut() {
cam.is_active = false;
}
}
9 changes: 3 additions & 6 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ impl Plugin for InputPlugin {
.add_systems(
PreUpdate,
(
(
handle_input_keyboard,
handle_input_mouse,
handle_input_gamepad,
)
.run_if(resource_exists::<Persistent<Keybinds>>()),
handle_input_keyboard,
handle_input_mouse,
handle_input_gamepad,
handle_mouse_moved,
),
)
Expand Down
40 changes: 9 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
pub mod audio;
pub mod config;
mod audio;
mod config;
mod debug;
pub mod input;
pub mod load;
mod game;
mod input;
mod load;
mod menu;
pub mod tilemap;
pub mod ui;
mod tilemap;
mod ui;

use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
use bevy_persistent::Persistent;
use config::GameOptions;
use bevy::prelude::*;

// Game state
#[derive(States, Debug, Default, Clone, Eq, PartialEq, Hash)]
Expand All @@ -33,34 +32,13 @@ impl Plugin for GamePlugin {
input::InputPlugin,
audio::AudioPlugin,
tilemap::TilePlugin,
game::CharonPlugin,
));

#[cfg(debug_assertions)]
{
app.add_plugins(debug::DebugPlugin);
debug::save_schedule(app);
}

app.add_systems(OnEnter(GameState::Play), init_game.run_if(run_once()));
}
}

// TODO: Move this somewhere where it makes sense

#[derive(Component)]
pub struct GameCamera;

fn init_game(
mut cmd: Commands,
opts: Res<Persistent<GameOptions>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
// Background
cmd.spawn(MaterialMesh2dBundle {
mesh: meshes.add(Mesh::from(shape::Quad::default())).into(),
transform: Transform::from_xyz(0., 0., -10.).with_scale(Vec3::new(1080., 720., 1.)),
material: materials.add(ColorMaterial::from(opts.color.dark)),
..default()
});
}
73 changes: 40 additions & 33 deletions src/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bevy_persistent::Persistent;
use iyes_progress::prelude::*;

#[cfg(debug_assertions)]
pub const SPLASH_TIME: f32 = 2.;
pub const SPLASH_TIME: f32 = 0.1;
#[cfg(not(debug_assertions))]
pub const SPLASH_TIME: f32 = 2.;

Expand All @@ -26,14 +26,11 @@ impl Plugin for LoadPlugin {
.add_plugins((ProgressPlugin::new(GameState::Loading)
.continue_to(GameState::Menu)
.track_assets(),))
.add_systems(OnEnter(GameState::Loading), init_splash)
.add_systems(OnExit(GameState::Loading), clear_loading)
.add_systems(
Update,
(
init_splash,
check_splash_finished.track_progress(),
check_progress,
)
(check_splash_finished.track_progress(), check_progress)
.run_if(in_state(GameState::Loading))
.after(LoadingStateSet(GameState::Loading)),
);
Expand Down Expand Up @@ -88,17 +85,20 @@ fn init_splash(
if let Ok(node) = node.get_single() {
if let Some(mut node) = cmd.get_entity(node) {
node.with_children(|parent| {
parent.spawn((ImageBundle {
image: UiImage {
texture: assets.bevy_icon.clone(),
..default()
},
style: Style {
width: Val::Px(128.),
parent.spawn((
ImageBundle {
image: UiImage {
texture: assets.bevy_icon.clone(),
..default()
},
style: Style {
width: Val::Px(128.),
..default()
},
..default()
},
..default()
},));
UI_LAYER,
));
});

*has_init = true;
Expand Down Expand Up @@ -148,29 +148,35 @@ fn check_progress(
if let Some(mut entity) = cmd.get_entity(node) {
entity.with_children(|parent| {
// Loading text
parent.spawn((TextBundle {
text: Text::from_section(
"Loading",
TextStyle {
font: assets.font.clone(),
font_size: 48.,
color: opts.color.mid,
},
),
..default()
},));
parent.spawn((
TextBundle {
text: Text::from_section(
"Loading",
TextStyle {
font: assets.font.clone(),
font_size: 48.,
color: opts.color.mid,
},
),
..default()
},
UI_LAYER,
));

// Progress bar
parent
.spawn((NodeBundle {
style: Style {
width: Val::Percent(70.),
height: Val::Px(32.),
.spawn((
NodeBundle {
style: Style {
width: Val::Percent(70.),
height: Val::Px(32.),
..default()
},
background_color: opts.color.dark.into(),
..default()
},
background_color: opts.color.dark.into(),
..default()
},))
UI_LAYER,
))
.with_children(|parent| {
parent.spawn((
NodeBundle {
Expand All @@ -185,6 +191,7 @@ fn check_progress(
background_color: opts.color.light.into(),
..default()
},
UI_LAYER,
ProgressBar,
));
});
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use bevy::{asset::AssetMetaCheck, prelude::*, window::WindowResolution};
use bevy_embedded_assets::{EmbeddedAssetPlugin, PluginMode};
use charon::GamePlugin;

fn main() {
App::new()
.insert_resource(AssetMetaCheck::Never)
.add_plugins((
EmbeddedAssetPlugin {
mode: PluginMode::ReplaceDefault,
},
DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Charon".to_string(),
Expand Down
11 changes: 3 additions & 8 deletions src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,10 @@ enum MenuButton {
// Systems
// ·······

fn init_menu(
mut cmd: Commands,
style: Res<UIStyle>,
mut node: Query<(Entity, &mut BackgroundColor), With<UiNode>>,
opts: Res<Persistent<GameOptions>>,
) {
if let Ok((node, mut bg)) = node.get_single_mut() {
fn init_menu(mut cmd: Commands, style: Res<UIStyle>, mut node: Query<Entity, With<UiNode>>) {
// Main menu layout
if let Ok(node) = node.get_single_mut() {
cmd.insert_resource(MenuStarting);
*bg = opts.color.dark.into();
layout_main(cmd, node, &style);
}
}
Expand Down
Loading

0 comments on commit eff9b5f

Please sign in to comment.