262 lines
7.0 KiB
Rust
262 lines
7.0 KiB
Rust
mod abilities;
|
|
mod ai;
|
|
mod aim;
|
|
mod alien;
|
|
mod backpack;
|
|
mod camera;
|
|
mod cash;
|
|
mod cash_heal;
|
|
mod control;
|
|
mod cutscene;
|
|
mod debug;
|
|
mod gates;
|
|
mod head;
|
|
mod heads;
|
|
mod hitpoints;
|
|
mod keys;
|
|
mod loading_assets;
|
|
mod loading_map;
|
|
mod movables;
|
|
mod npc;
|
|
mod physics_layers;
|
|
mod platforms;
|
|
mod player;
|
|
mod sounds;
|
|
mod tb_entities;
|
|
mod utils;
|
|
mod water;
|
|
|
|
use avian3d::prelude::*;
|
|
use bevy::{
|
|
audio::{PlaybackMode, Volume},
|
|
core_pipeline::tonemapping::Tonemapping,
|
|
prelude::*,
|
|
render::view::ColorGrading,
|
|
};
|
|
use bevy_polyline::PolylinePlugin;
|
|
use bevy_sprite3d::Sprite3dPlugin;
|
|
use bevy_steamworks::{FriendFlags, SteamworksClient, SteamworksPlugin};
|
|
use bevy_trenchbroom::prelude::*;
|
|
use bevy_ui_gradients::UiGradientsPlugin;
|
|
use camera::MainCamera;
|
|
use control::controller::CharacterControllerPlugin;
|
|
use loading_assets::AudioAssets;
|
|
use std::io::{Read, Write};
|
|
use utils::{billboards, sprite_3d_animation, squish_animation};
|
|
|
|
#[derive(Resource, Reflect, Debug)]
|
|
#[reflect(Resource)]
|
|
struct DebugVisuals {
|
|
pub unlit: bool,
|
|
pub tonemapping: Tonemapping,
|
|
pub exposure: f32,
|
|
pub shadows: bool,
|
|
pub cam_follow: bool,
|
|
}
|
|
|
|
#[derive(States, Default, Clone, Eq, PartialEq, Debug, Hash)]
|
|
enum GameState {
|
|
#[default]
|
|
AssetLoading,
|
|
MapLoading,
|
|
Playing,
|
|
}
|
|
|
|
fn main() {
|
|
let mut app = App::new();
|
|
|
|
app.register_type::<DebugVisuals>();
|
|
app.insert_resource(DebugVisuals {
|
|
unlit: false,
|
|
tonemapping: Tonemapping::None,
|
|
exposure: 1.,
|
|
shadows: true,
|
|
cam_follow: true,
|
|
});
|
|
|
|
app.add_plugins(
|
|
DefaultPlugins
|
|
.set(WindowPlugin {
|
|
primary_window: Some(Window {
|
|
title: "HEDZ Reloaded".into(),
|
|
resolution: (1024., 768.).into(),
|
|
..default()
|
|
}),
|
|
..default()
|
|
})
|
|
.set(bevy::log::LogPlugin {
|
|
filter: "info".into(),
|
|
level: bevy::log::Level::INFO,
|
|
// provide custom log layer to receive logging events
|
|
custom_layer: bevy_debug_log::log_capture_layer,
|
|
}),
|
|
);
|
|
|
|
match SteamworksPlugin::init_app(1603000) {
|
|
Ok(plugin) => {
|
|
app.add_plugins(plugin);
|
|
}
|
|
Err(e) => {
|
|
warn!("steam init error: {e:?}");
|
|
}
|
|
};
|
|
|
|
app.add_plugins(bevy_debug_log::LogViewerPlugin::default());
|
|
app.add_plugins(PhysicsPlugins::default());
|
|
app.add_plugins(CharacterControllerPlugin);
|
|
app.add_plugins(PolylinePlugin);
|
|
app.add_plugins(Sprite3dPlugin);
|
|
app.add_plugins(TrenchBroomPlugin(TrenchBroomConfig::new("hedz")));
|
|
app.add_plugins(UiGradientsPlugin);
|
|
|
|
#[cfg(feature = "dbg")]
|
|
{
|
|
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
|
app.add_plugins(WorldInspectorPlugin::new());
|
|
app.add_plugins(PhysicsDebugPlugin::default());
|
|
|
|
// app.add_plugins(bevy::pbr::wireframe::WireframePlugin)
|
|
// .insert_resource(bevy::pbr::wireframe::WireframeConfig {
|
|
// global: true,
|
|
// default_color: bevy::color::palettes::css::WHITE.into(),
|
|
// });
|
|
}
|
|
|
|
app.add_plugins(ai::plugin);
|
|
app.add_plugins(alien::plugin);
|
|
app.add_plugins(cash::plugin);
|
|
app.add_plugins(player::plugin);
|
|
app.add_plugins(gates::plugin);
|
|
app.add_plugins(platforms::plugin);
|
|
app.add_plugins(movables::plugin);
|
|
app.add_plugins(billboards::plugin);
|
|
app.add_plugins(aim::plugin);
|
|
app.add_plugins(npc::plugin);
|
|
app.add_plugins(keys::plugin);
|
|
app.add_plugins(squish_animation::plugin);
|
|
app.add_plugins(cutscene::plugin);
|
|
app.add_plugins(control::plugin);
|
|
app.add_plugins(sounds::plugin);
|
|
app.add_plugins(camera::plugin);
|
|
app.add_plugins(backpack::plugin);
|
|
app.add_plugins(loading_assets::LoadingPlugin);
|
|
app.add_plugins(loading_map::plugin);
|
|
app.add_plugins(sprite_3d_animation::plugin);
|
|
app.add_plugins(abilities::plugin);
|
|
app.add_plugins(heads::plugin);
|
|
app.add_plugins(hitpoints::plugin);
|
|
app.add_plugins(cash_heal::plugin);
|
|
app.add_plugins(debug::plugin);
|
|
app.add_plugins(utils::observers::plugin);
|
|
app.add_plugins(water::plugin);
|
|
|
|
app.init_state::<GameState>();
|
|
|
|
app.insert_resource(AmbientLight {
|
|
color: Color::WHITE,
|
|
brightness: 400.,
|
|
});
|
|
app.insert_resource(ClearColor(Color::BLACK));
|
|
|
|
app.add_systems(
|
|
Startup,
|
|
(
|
|
write_trenchbroom_config,
|
|
steam_system.run_if(resource_exists::<SteamworksClient>),
|
|
),
|
|
);
|
|
app.add_systems(OnEnter(GameState::Playing), music);
|
|
app.add_systems(Update, (set_materials_unlit, set_tonemapping, set_shadows));
|
|
|
|
app.run();
|
|
}
|
|
|
|
fn steam_system(steam_client: Res<SteamworksClient>) {
|
|
for friend in steam_client.friends().get_friends(FriendFlags::IMMEDIATE) {
|
|
info!(
|
|
"Steam Friend: {:?} - {}({:?})",
|
|
friend.id(),
|
|
friend.name(),
|
|
friend.state()
|
|
);
|
|
}
|
|
|
|
steam_client
|
|
.remote_storage()
|
|
.set_cloud_enabled_for_app(true);
|
|
let f = steam_client.remote_storage().file("hedz_data.dat");
|
|
if f.exists() {
|
|
let mut buf = String::new();
|
|
if let Err(e) = f.read().read_to_string(&mut buf) {
|
|
error!("File read error: {}", e);
|
|
} else {
|
|
info!("File content: {}", buf);
|
|
}
|
|
} else {
|
|
info!("File does not exist");
|
|
|
|
if let Err(e) = f.write().write_all(String::from("hello world").as_bytes()) {
|
|
error!("steam cloud error: {}", e);
|
|
} else {
|
|
info!("steam cloud saved");
|
|
}
|
|
}
|
|
}
|
|
|
|
fn music(assets: Res<AudioAssets>, mut commands: Commands) {
|
|
commands.spawn((
|
|
Name::new("sfx-music"),
|
|
AudioPlayer::new(assets.music.clone()),
|
|
PlaybackSettings {
|
|
mode: PlaybackMode::Loop,
|
|
volume: Volume::new(0.4),
|
|
..default()
|
|
},
|
|
));
|
|
|
|
commands.spawn((
|
|
Name::new("sfx-ambient"),
|
|
AudioPlayer::new(assets.ambient.clone()),
|
|
PlaybackSettings {
|
|
mode: PlaybackMode::Loop,
|
|
volume: Volume::new(0.8),
|
|
..default()
|
|
},
|
|
));
|
|
}
|
|
|
|
fn write_trenchbroom_config(server: Res<TrenchBroomServer>) {
|
|
if let Err(e) = server.config.write_folder("trenchbroom/hedz") {
|
|
warn!("Failed to write trenchbroom config: {}", e);
|
|
}
|
|
}
|
|
|
|
fn set_tonemapping(
|
|
mut cams: Query<(&mut Tonemapping, &mut ColorGrading), With<MainCamera>>,
|
|
visuals: Res<DebugVisuals>,
|
|
) {
|
|
for (mut tm, mut color) in cams.iter_mut() {
|
|
*tm = visuals.tonemapping;
|
|
color.global.exposure = visuals.exposure;
|
|
}
|
|
}
|
|
|
|
fn set_materials_unlit(
|
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
|
visuals: Res<DebugVisuals>,
|
|
) {
|
|
if !materials.is_changed() {
|
|
return;
|
|
}
|
|
|
|
for (_, material) in materials.iter_mut() {
|
|
material.unlit = visuals.unlit;
|
|
}
|
|
}
|
|
|
|
fn set_shadows(mut lights: Query<&mut DirectionalLight>, visuals: Res<DebugVisuals>) {
|
|
for mut l in lights.iter_mut() {
|
|
l.shadows_enabled = visuals.shadows;
|
|
}
|
|
}
|