code sharing for steam setup
+ strip server a bit more
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
mod debug;
|
||||
mod steam;
|
||||
mod ui;
|
||||
|
||||
use crate::utils::{auto_rotate, explosions};
|
||||
@@ -11,14 +12,12 @@ use bevy::{
|
||||
};
|
||||
use bevy_common_assets::ron::RonAssetPlugin;
|
||||
use bevy_sprite3d::Sprite3dPlugin;
|
||||
use bevy_steamworks::{Client, FriendFlags, SteamworksEvent, SteamworksPlugin};
|
||||
use bevy_trenchbroom::prelude::*;
|
||||
use bevy_ui_gradients::UiGradientsPlugin;
|
||||
use camera::MainCamera;
|
||||
use heads_database::HeadDatabaseAsset;
|
||||
use loading_assets::AudioAssets;
|
||||
use shared::*;
|
||||
use std::io::{Read, Write};
|
||||
use utils::{billboards, sprite_3d_animation, squish_animation, trail};
|
||||
|
||||
fn main() {
|
||||
@@ -52,22 +51,7 @@ fn main() {
|
||||
}),
|
||||
);
|
||||
|
||||
let app_id = 1603000;
|
||||
// should only be done in production builds
|
||||
#[cfg(not(debug_assertions))]
|
||||
if steamworks::restart_app_if_necessary(app_id.into()) {
|
||||
info!("Restarting app via steam");
|
||||
return;
|
||||
}
|
||||
|
||||
match SteamworksPlugin::init_app(app_id) {
|
||||
Ok(plugin) => {
|
||||
app.add_plugins(plugin);
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("steam init error: {e:?}");
|
||||
}
|
||||
};
|
||||
app.add_plugins(steam::plugin);
|
||||
|
||||
app.add_plugins(
|
||||
bevy_debug_log::LogViewerPlugin::default()
|
||||
@@ -143,81 +127,13 @@ fn main() {
|
||||
//TODO: let user control this
|
||||
app.insert_resource(GlobalVolume::new(Volume::Linear(0.4)));
|
||||
|
||||
app.add_systems(
|
||||
Startup,
|
||||
(
|
||||
write_trenchbroom_config,
|
||||
(steam_system, steam_events)
|
||||
.chain()
|
||||
.run_if(resource_exists::<Client>),
|
||||
),
|
||||
);
|
||||
app.add_systems(Startup, write_trenchbroom_config);
|
||||
app.add_systems(OnEnter(GameState::Playing), music);
|
||||
app.add_systems(Update, (set_materials_unlit, set_tonemapping, set_shadows));
|
||||
|
||||
app.run();
|
||||
}
|
||||
|
||||
fn steam_events(mut events: EventReader<SteamworksEvent>) {
|
||||
for e in events.read() {
|
||||
info!("steam ev: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn steam_system(steam_client: Res<Client>) {
|
||||
steam_client.matchmaking().request_lobby_list(|list| {
|
||||
let Ok(list) = list else { return };
|
||||
|
||||
info!("lobby list: [{}]", list.len());
|
||||
for (i, l) in list.iter().enumerate() {
|
||||
info!("lobby [{i}]: {:?}", l);
|
||||
}
|
||||
});
|
||||
|
||||
steam_client
|
||||
.matchmaking()
|
||||
.create_lobby(
|
||||
steamworks::LobbyType::FriendsOnly,
|
||||
4,
|
||||
|result| match result {
|
||||
Ok(lobby_id) => {
|
||||
info!("Created lobby with ID: {:?}", lobby_id);
|
||||
}
|
||||
Err(e) => error!("Failed to create lobby: {}", e),
|
||||
},
|
||||
);
|
||||
|
||||
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"),
|
||||
|
||||
Reference in New Issue
Block a user