Skip to content
Snippets Groups Projects
Commit c847117f authored by Evy Storozhenko's avatar Evy Storozhenko
Browse files

Merge branch 'assets' into 'main'

moved assets to plugin

See merge request smjlstor/bevyjam!18
parents 9f597260 1329d0ba
No related branches found
No related tags found
1 merge request!18moved assets to plugin
Pipeline #103497 passed
use bevy::{prelude::*, sprite::TextureAtlas};
use crate::{
audio::AudioAssets, grid::GridTextures, gridcursor::GridCursorTexture, machine::MachineTextures,
};
// textures
pub const GRIDCURSOR_TEXTURE: TextureInfo =
TextureInfo::new("cursor_select_64x64.png", Vec2::new(64., 64.));
pub const GRID_TEXTURE: TextureInfo = TextureInfo::new("ferris.png", Vec2::new(1024., 1024.));
// atlases
pub const WALL_ATLAS: TextureAtlasInfo = TextureAtlasInfo::new("wall.png", Vec2::new(8., 8.), 1, 1);
pub const TURBINE_ATLAS: TextureAtlasInfo =
TextureAtlasInfo::new("turbine.png", Vec2::new(8., 8.), 1, 1);
pub const CABLE_JOINT_ATLAS: TextureAtlasInfo =
TextureAtlasInfo::new("cable_joint.png", Vec2::new(8., 8.), 1, 10);
pub const CABLE_SIDE_ATLAS: TextureAtlasInfo =
TextureAtlasInfo::new("cable_side.png", Vec2::new(8., 8.), 1, 2);
// audio
pub const THEME_AUDIO: AudioInfo = AudioInfo::new("theme.ogg");
pub struct AssetLoadingPlugin;
impl Plugin for AssetLoadingPlugin {
fn build(&self, app: &mut bevy::prelude::App) {
app.add_startup_system(asset_loading_system);
}
}
// loading logic
fn asset_loading_system(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
) {
// machine texture
let machine_textures = MachineTextures {
wall: texture_atlases.add(WALL_ATLAS.to_texture_atlas(asset_server.as_ref())),
turbine: texture_atlases.add(TURBINE_ATLAS.to_texture_atlas(asset_server.as_ref())),
cable_joint: texture_atlases.add(CABLE_JOINT_ATLAS.to_texture_atlas(asset_server.as_ref())),
cable_side: texture_atlases.add(CABLE_SIDE_ATLAS.to_texture_atlas(asset_server.as_ref())),
};
commands.insert_resource(machine_textures);
// grid textures
let grid_stack_textures = GridTextures {
handles: Vec::from([asset_server.load(GRID_TEXTURE.path)]),
};
commands.insert_resource(grid_stack_textures);
// marker texture
let marker_texture = GridCursorTexture {
handle: asset_server.load(GRIDCURSOR_TEXTURE.path),
};
commands.insert_resource(marker_texture);
// audio assets
let audio_assets = AudioAssets {
theme_handle: asset_server.load(THEME_AUDIO.path),
};
commands.insert_resource(audio_assets);
}
// asset structs
pub struct TextureInfo<'a> {
pub path: &'a str,
pub size: Vec2,
}
impl<'a> TextureInfo<'a> {
pub const fn new(path: &'a str, size: Vec2) -> Self {
Self { path, size }
}
}
pub struct TextureAtlasInfo<'a> {
pub path: &'a str,
pub size: Vec2,
pub columns: usize,
pub rows: usize,
}
impl<'a> TextureAtlasInfo<'a> {
pub const fn new(path: &'a str, size: Vec2, columns: usize, rows: usize) -> Self {
Self {
size,
path,
columns,
rows,
}
}
pub fn to_texture_atlas(self, asset_server: &AssetServer) -> TextureAtlas {
TextureAtlas::from_grid(
asset_server.load(self.path),
self.size,
self.columns,
self.rows,
)
}
}
pub struct AudioInfo<'a> {
pub path: &'a str,
}
impl<'a> AudioInfo<'a> {
pub const fn new(path: &'a str) -> Self {
Self { path }
}
}
use crate::{
assets::GRID_TEXTURE,
components::{GridLayer, GridPos, Side},
error::Error,
GRID_TEXTURE, RENDER_ORDER,
RENDER_ORDER,
};
use bevy::prelude::*;
......
use crate::{
assets::GRIDCURSOR_TEXTURE,
components::{GridCursor, GridPos},
machine::{Machine, MACHINE_SIZE},
GRIDCURSOR_TEXTURE, RENDER_ORDER,
RENDER_ORDER,
};
use bevy::prelude::*;
......
use crate::{
assets::CABLE_JOINT_ATLAS,
components::{Cable, GridPos, Side},
grid::Grid,
power::{Drain, Resistance, Source},
CABLE_JOINT_ATLAS, RENDER_ORDER,
RENDER_ORDER,
};
use bevy::{ecs::query::WorldQuery, prelude::*};
......@@ -126,7 +127,8 @@ fn populate_cable_sides(
let to_side_index: usize;
if cable.2.output.contains(&side)
&& matches!(drains_query.get(neigh), Ok(v) if v.1.input.contains(&side.opposite())) // is_ok_and() would be so much prettier, "let's be stable mimimi"
&& matches!(drains_query.get(neigh), Ok(v) if v.1.input.contains(&side.opposite()))
// is_ok_and() would be so much prettier, "let's be stable mimimi"
{
from_side_index = 1;
to_side_index = 0;
......
use crate::{
components::{Ghost, GridPos, Cable},
assets::{TURBINE_ATLAS, WALL_ATLAS},
components::{Cable, Ghost, GridPos},
grid::{Grid, GRID_SIZE},
{RENDER_ORDER, TURBINE_ATLAS, WALL_ATLAS},
RENDER_ORDER,
};
use bevy::prelude::*;
......@@ -133,11 +134,14 @@ fn add_gridpos_system(
});
}
Machine::Cable => {
commands.entity(entity).insert_bundle(MachineBundle {
commands
.entity(entity)
.insert_bundle(MachineBundle {
position: *grid_pos,
machine: *machine,
..default()
}).insert(Cable);
})
.insert(Cable);
}
}
}
......
mod assets;
mod audio;
mod components;
mod error;
......@@ -8,79 +9,18 @@ mod machine;
mod power;
use crate::{
audio::{AudioAssets, AudioPlugin},
audio::AudioPlugin,
components::GridPos,
grid::{GridPlugin, GridTextures},
gridcursor::{GridCursorPlugin, GridCursorTexture},
grid::GridPlugin,
gridcursor::GridCursorPlugin,
lighting::{LightEmitter, LightingPlugin},
machine::{MachinePlugin, MachineTextures},
machine::MachinePlugin,
power::PowerPlugin,
};
use assets::AssetLoadingPlugin;
use bevy::{prelude::*, render::texture::ImageSettings};
pub const GRIDCURSOR_TEXTURE: TextureInfo =
TextureInfo::new("cursor_select_64x64.png", Vec2::new(64., 64.));
pub const GRID_TEXTURE: TextureInfo = TextureInfo::new("ferris.png", Vec2::new(1024., 1024.));
pub const WALL_ATLAS: TextureAtlasInfo = TextureAtlasInfo::new("wall.png", Vec2::new(8., 8.), 1, 1);
pub const TURBINE_ATLAS: TextureAtlasInfo =
TextureAtlasInfo::new("turbine.png", Vec2::new(8., 8.), 1, 1);
pub const CABLE_JOINT_ATLAS: TextureAtlasInfo =
TextureAtlasInfo::new("cable_joint.png", Vec2::new(8., 8.), 1, 10);
pub const CABLE_SIDE_ATLAS: TextureAtlasInfo =
TextureAtlasInfo::new("cable_side.png", Vec2::new(8., 8.), 1, 2);
pub struct TextureInfo<'a> {
pub path: &'a str,
pub size: Vec2,
}
impl<'a> TextureInfo<'a> {
pub const fn new(path: &'a str, size: Vec2) -> Self {
Self { path, size }
}
}
pub struct TextureAtlasInfo<'a> {
pub path: &'a str,
pub size: Vec2,
pub columns: usize,
pub rows: usize,
}
impl<'a> TextureAtlasInfo<'a> {
pub const fn new(path: &'a str, size: Vec2, columns: usize, rows: usize) -> Self {
Self {
size,
path,
columns,
rows,
}
}
pub fn to_texture_atlas(self, asset_server: &AssetServer) -> TextureAtlas {
TextureAtlas::from_grid(
asset_server.load(self.path),
self.size,
self.columns,
self.rows,
)
}
}
pub const THEME_AUDIO: AudioInfo = AudioInfo::new("theme.ogg");
pub struct AudioInfo<'a> {
pub path: &'a str,
}
impl<'a> AudioInfo<'a> {
pub const fn new(path: &'a str) -> Self {
Self { path }
}
}
pub const RENDER_ORDER: RenderOrder = RenderOrder {
grid: 0.0,
machine: 1.0,
......@@ -106,6 +46,7 @@ fn main() {
.insert_resource(ImageSettings::default_nearest())
.insert_resource(Msaa { samples: 1 })
.add_plugins(DefaultPlugins)
.add_plugin(AssetLoadingPlugin)
.add_startup_system(main_setup_system)
.add_plugin(MachinePlugin)
.add_plugin(GridPlugin)
......@@ -116,42 +57,11 @@ fn main() {
.run();
}
fn main_setup_system(
mut commands: Commands,
asset_server: Res<AssetServer>,
mut texture_atlases: ResMut<Assets<TextureAtlas>>,
) {
fn main_setup_system(mut commands: Commands) {
// camera
commands.spawn_bundle(Camera2dBundle::default());
// machine texture
//asset_server.load(WALL_TEXTURE.path),
let machine_textures = MachineTextures {
wall: texture_atlases.add(WALL_ATLAS.to_texture_atlas(asset_server.as_ref())),
turbine: texture_atlases.add(TURBINE_ATLAS.to_texture_atlas(asset_server.as_ref())),
cable_joint: texture_atlases.add(CABLE_JOINT_ATLAS.to_texture_atlas(asset_server.as_ref())),
cable_side: texture_atlases.add(CABLE_SIDE_ATLAS.to_texture_atlas(asset_server.as_ref())),
};
commands.insert_resource(machine_textures);
// grid textures
let grid_stack_textures = GridTextures {
handles: Vec::from([asset_server.load(GRID_TEXTURE.path)]),
};
commands.insert_resource(grid_stack_textures);
// marker texture
let marker_texture = GridCursorTexture {
handle: asset_server.load(GRIDCURSOR_TEXTURE.path),
};
commands.insert_resource(marker_texture);
// audio assets
let audio_assets = AudioAssets {
theme_handle: asset_server.load("theme.ogg"),
};
commands.insert_resource(audio_assets);
// light
commands
.spawn()
.insert(LightEmitter {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment