Skip to content
Snippets Groups Projects
Verified Commit e4e9e905 authored by Louis's avatar Louis :fire:
Browse files

Configure app scaffold

parents
No related branches found
No related tags found
No related merge requests found
Showing with 348 additions and 0 deletions
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"]
\ No newline at end of file
/target
\ No newline at end of file
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/game_core/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ComposerSettings">
<execution />
</component>
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/KenneyJamExplore.iml" filepath="$PROJECT_DIR$/.idea/KenneyJamExplore.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/game_core" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
[workspace]
resolver = "2"
members = [
"game_core",
]
[profile.dev]
opt-level = 1
[profile.dev.package."*"]
opt-level = 3
[workspace.dependencies]
bevy = "0.11.0"
bevy_embedded_assets = "0.8.0"
micro_bevy_world_utils = "0.3.0"
micro_bevy_web_utils = "0.3.0"
micro_ldtk = { version = "0.6.1", default-features = false, features = ["ldtk_1_3_0", "autotile"] }
micro_banimate = { git = "https://lab.lcr.gr/microhacks/micro-banimate.git", rev = "33e56278471f32cbcd1a843aca83298c8b80c7e3" }
micro_musicbox = "0.7.0"
/target
[package]
name = "game_core"
version = "0.1.0"
edition = "2021"
[features]
default = []
embed = ["dep:bevy_embedded_assets"]
[dependencies]
bevy.workspace = true
bevy_embedded_assets = { workspace = true, optional = true }
micro_bevy_world_utils.workspace = true
micro_bevy_web_utils.workspace = true
micro_ldtk.workspace = true
micro_banimate.workspace = true
micro_musicbox.workspace = true
pub mod system;
use bevy::prelude::App;
fn main() {
App::new()
.add_plugins(game_core::system::SystemPluginSet)
.run();
}
use bevy::prelude::*;
/// An enum representing the current set of systems that should be running
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, States, Default)]
pub enum AppState {
/// During the preload state, embedded resources will be registered with Bevy.
/// Embedded resources will be attached to the asset system with the path
/// `internal:{resource-name}`
#[default]
Preload,
/// During the setup state, external resources will be registered by reading from
/// the filesystem or the network. Progress can be displayed using the embedded
/// resources loaded in the previous state
Setup,
/// The splash state exists solely to render attributions & logos before starting
/// the game
Splash,
/// An initial landing page that will present players with options
Menu,
/// The in game state runs all of the actual gameplay logic. Most of the runtime
/// will be spent here.
InGame,
}
pub fn run_in_game(state: Res<State<AppState>>) -> bool {
**state == AppState::InGame
}
pub fn run_in_menu(state: Res<State<AppState>>) -> bool {
**state == AppState::Menu
}
pub fn run_in_splash(state: Res<State<AppState>>) -> bool {
**state == AppState::Splash
}
pub fn run_in_setup(state: Res<State<AppState>>) -> bool {
**state == AppState::Setup
}
pub struct FlowPlugin;
impl Plugin for FlowPlugin {
fn build(&self, app: &mut App) {
app.add_state::<AppState>();
}
}
mod flow;
mod resource_config;
mod resources;
mod web;
mod _plugin {
use crate::system::resources::InitAppPlugins;
use bevy::app::PluginGroupBuilder;
use bevy::prelude::PluginGroup;
pub struct SystemPluginSet;
impl PluginGroup for SystemPluginSet {
fn build(self) -> PluginGroupBuilder {
InitAppPlugins.build().add(super::flow::FlowPlugin)
}
}
}
pub use _plugin::SystemPluginSet;
pub use flow::{run_in_game, run_in_menu, run_in_setup, run_in_splash, AppState};
pub use resource_config::{get_asset_path_string, initial_size, virtual_size};
pub use resources::configure_default_plugins;
const WINDOW_SCALER: f32 = 2.0;
#[cfg(not(target_arch = "wasm32"))]
mod setup {
use crate::system::resource_config::WINDOW_SCALER;
pub fn get_asset_path_string() -> String {
std::env::current_dir()
.unwrap()
.join("assets")
.to_str()
.unwrap()
.to_string()
}
pub fn initial_size() -> (f32, f32) {
(1920.0, 1080.0)
}
pub fn virtual_size() -> (f32, f32) {
(1280.0 / WINDOW_SCALER, 720.0 / WINDOW_SCALER)
}
}
#[cfg(target_arch = "wasm32")]
mod setup {
use crate::system::load_config::WINDOW_SCALER;
pub fn get_asset_path_string() -> String {
String::from("assets")
}
pub fn virtual_size() -> (f32, f32) {
(1280.0 / WINDOW_SCALER, 720.0 / WINDOW_SCALER)
}
#[cfg(feature = "no_aspect")]
pub fn initial_size() -> (f32, f32) {
static default_width: f32 = 1280.0;
static default_height: f32 = 720.0;
web_sys::window()
.and_then(|window: web_sys::Window| {
let w = window
.inner_width()
.ok()
.and_then(|val| val.as_f64().map(|v| v as f32))
.unwrap_or(default_width);
let h = window
.inner_height()
.ok()
.and_then(|val| val.as_f64().map(|v| v as f32))
.unwrap_or(default_height);
Some((w, h))
})
.unwrap_or((default_width, default_height))
}
#[cfg(not(feature = "no_aspect"))]
pub fn initial_size() -> (f32, f32) {
static default_width: f32 = 1280.0;
static default_height: f32 = 720.0;
static ratio: f32 = 1280.0 / 720.0;
web_sys::window()
.and_then(|window: web_sys::Window| {
let w = window
.inner_width()
.ok()
.and_then(|val| val.as_f64().map(|v| v as f32))
.unwrap_or(default_width);
let h = window
.inner_height()
.ok()
.and_then(|val| val.as_f64().map(|v| v as f32))
.unwrap_or(default_height);
Some((w, h / ratio))
})
.unwrap_or((default_width, default_height))
}
}
pub use setup::*;
use bevy::app::PluginGroupBuilder;
use bevy::asset::ChangeWatcher;
use bevy::log::{Level, LogPlugin};
use bevy::prelude::*;
use bevy::window::{PresentMode, WindowMode, WindowResolution};
use std::time::Duration;
use crate::system::{get_asset_path_string, initial_size};
pub struct DefaultResourcesPlugin;
impl Plugin for DefaultResourcesPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(Msaa::Off)
.insert_resource(ClearColor(Color::hex("040720").unwrap()));
}
}
pub fn configure_default_plugins() -> PluginGroupBuilder {
let (width, height) = initial_size();
let plugin_set = DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(width, height),
resizable: true,
mode: WindowMode::Windowed,
title: String::from("KJ: Explore"),
present_mode: PresentMode::AutoNoVsync,
fit_canvas_to_parent: true,
..Default::default()
}),
..Default::default()
})
.set(AssetPlugin {
asset_folder: get_asset_path_string(),
watch_for_changes: ChangeWatcher::with_delay(Duration::from_secs(1)),
})
.set(ImagePlugin::default_nearest())
.set(LogPlugin {
filter: String::from(
"info,game_core=debug,symphonia_core=warn,symphonia_format_ogg=warn,winit=warn,symphonia_bundle_mp3=warn,wgpu_core=warn,wgpu_hal=warn",
),
level: Level::DEBUG,
});
#[cfg(feature = "embed")]
{
plugin_set.add_before::<AssetPlugin, _>(bevy_embedded_assets::EmbeddedAssetPlugin)
}
#[cfg(not(feature = "embed"))]
{
plugin_set
}
}
pub struct InitAppPlugins;
impl PluginGroup for InitAppPlugins {
fn build(self) -> PluginGroupBuilder {
configure_default_plugins()
.add(DefaultResourcesPlugin)
.add(super::web::WebPlugin)
}
}
#[cfg(target_arch = "wasm32")]
mod _plugin {
use bevy::prelude::*;
pub fn handle_startup_fullscreen() {
if micro_bevy_web_utils::bindings::is_touch_device() {
micro_bevy_web_utils::bindings::make_selector_fullscreen("canvas".to_string());
micro_bevy_web_utils::bindings::bind_selector_touch_events("canvas".to_string());
micro_bevy_web_utils::bindings::orientation_lock("landscape".to_string());
}
}
pub struct WebPlugin;
impl Plugin for WebPlugin {
fn build(&self, app: &mut App) {
app.add_startup_system(handle_startup_fullscreen)
.add_system(
micro_bevy_web_utils::bevy::emit_touch_events.in_base_set(CoreSet::First),
);
}
}
}
#[cfg(not(target_arch = "wasm32"))]
mod _plugin {
use bevy::app::{App, Plugin};
pub struct WebPlugin;
impl Plugin for WebPlugin {
fn build(&self, _app: &mut App) {}
}
}
pub use _plugin::WebPlugin;
hard_tabs = true
use_field_init_shorthand = true
use_try_shorthand = true
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment