Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many things #395

Merged
merged 32 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
031de6b
Merge pull request #392 from AnthonyTornetta/main
AnthonyTornetta Dec 23, 2024
81ddf1a
Enabling more persistent component serialization customization
AnthonyTornetta Dec 23, 2024
e11373b
Renaming stuff to be more obvious
AnthonyTornetta Dec 23, 2024
1069ffc
Moving utiltiy type to common folder
AnthonyTornetta Dec 23, 2024
1ee9a6f
Reworking location architecture
AnthonyTornetta Dec 23, 2024
7636726
Rewrote location systems to be less buggy
AnthonyTornetta Jan 2, 2025
99a8b95
Removing old location systems
AnthonyTornetta Jan 2, 2025
19075ec
Quicksave
AnthonyTornetta Jan 2, 2025
52c8cc7
Location syncing working for parent child relationships
AnthonyTornetta Jan 2, 2025
548e7eb
Kinda works if world doesnt move
AnthonyTornetta Jan 3, 2025
44b187c
Quicksave
AnthonyTornetta Jan 3, 2025
0587aec
Fixed incorrect set_parent and remove_parent calls not updating posit…
AnthonyTornetta Jan 3, 2025
b837c2c
Parent child stuff works on client even with changing world position
AnthonyTornetta Jan 4, 2025
518c53d
Fixed player never getting transform
AnthonyTornetta Jan 4, 2025
5a5ef05
Debugging
AnthonyTornetta Jan 4, 2025
ea986aa
Locations are working again
AnthonyTornetta Jan 5, 2025
d543f1d
Warnings be gone
AnthonyTornetta Jan 5, 2025
a271d0e
Docs
AnthonyTornetta Jan 5, 2025
8bd48c7
Loading more things during the LoadingWorld state
AnthonyTornetta Jan 5, 2025
057e394
Players now respect their parent on the client when joining
AnthonyTornetta Jan 5, 2025
4b6fd30
Client now has 1 sec delay between loading world and playing
AnthonyTornetta Jan 6, 2025
d67197a
Making player joining more reliable on client side
AnthonyTornetta Jan 11, 2025
23df6fc
cargo clippy --fix
AnthonyTornetta Jan 11, 2025
d87048b
Adding recipes
AnthonyTornetta Jan 12, 2025
e12753e
Adding all recipes
AnthonyTornetta Jan 12, 2025
3676b56
Fixed location drift of children
AnthonyTornetta Jan 15, 2025
db4bb25
Log be gone
AnthonyTornetta Jan 15, 2025
a356e8e
Removing useless garbage
AnthonyTornetta Jan 15, 2025
4760454
Fixing warning
AnthonyTornetta Jan 15, 2025
bd8fe2d
Fixing clippy lints
AnthonyTornetta Jan 15, 2025
4fde5e1
Clippy fix
AnthonyTornetta Jan 15, 2025
3a85f9a
I should really update my clippy version
AnthonyTornetta Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cosmos_client/assets/cosmos/lang/blocks/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cosmos:redwood_log=Redwood Log
cosmos:redwood_leaf=Redwood Leaf
cosmos:ship_core=Ship Core
cosmos:energy_cell=Energy Cell
cosmos:reactor=Reactor
cosmos:passive_generator=Passive Generator
cosmos:thruster=Thruster
cosmos:light=Light
cosmos:glass=Glass
Expand Down
2 changes: 1 addition & 1 deletion cosmos_client/assets/cosmos/lang/items/en_us.lang
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cosmos:test_crystal=Test Crystal
cosmos:photonium_crystal=Test Crystal
cosmos:iron_bar=Iron Bar
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,7 @@ pub(super) fn register(app: &mut App) {
(
respond_to_remove_materails_event.in_set(MaterialsSystemSet::ProcessRemoveMaterialsEvents),
respond_to_add_materials_event.in_set(MaterialsSystemSet::ProcessAddMaterialsEvents),
)
.run_if(in_state(GameState::Playing)),
),
)
.add_systems(
Update,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ pub(super) fn register(app: &mut App) {
(
respond_to_remove_materails_event.in_set(MaterialsSystemSet::ProcessRemoveMaterialsEvents),
respond_to_add_materials_event.in_set(MaterialsSystemSet::ProcessAddMaterialsEvents),
)
.run_if(in_state(GameState::Playing)),
),
)
.add_systems(
Update,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ pub(super) fn register(app: &mut App) {
(
respond_to_remove_materails_event.in_set(MaterialsSystemSet::ProcessRemoveMaterialsEvents),
respond_to_add_materials_event.in_set(MaterialsSystemSet::ProcessAddMaterialsEvents),
)
.run_if(in_state(GameState::Playing)),
),
)
.add_systems(
Update,
Expand Down
1 change: 1 addition & 0 deletions cosmos_client/src/asset/materials/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ pub(super) fn register(app: &mut App) {
MaterialsSystemSet::ProcessAddMaterialsEvents,
)
.in_set(AssetsSet::AssetsReady)
.run_if(in_state(GameState::Playing).or(in_state(GameState::LoadingWorld)))
.chain(),
);

Expand Down
146 changes: 75 additions & 71 deletions cosmos_client/src/crafting/blocks/basic_fabricator/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::{
ui::{
components::{
button::{register_button, Button, ButtonEvent, ButtonStyles},
scollable_container::ScrollBox,
window::GuiWindow,
},
font::DefaultFont,
Expand Down Expand Up @@ -149,93 +150,96 @@ fn populate_menu(
let mut slot_ents = vec![];

ecmds.with_children(|p| {
p.spawn((Node {
flex_grow: 1.0,
flex_direction: FlexDirection::Column,
..Default::default()
},))
.with_children(|p| {
for recipe in crafting_recipes.iter() {
p.spawn((
ScrollBox::default(),
Node {
flex_grow: 1.0,
flex_direction: FlexDirection::Column,
..Default::default()
},
))
.with_children(|p| {
for recipe in crafting_recipes.iter() {
p.spawn((
Node {
height: Val::Px(100.0),
width: Val::Percent(100.0),
justify_content: JustifyContent::SpaceBetween,
..Default::default()
},
Button::<SelectItemEvent>::default(),
Recipe(recipe.clone()),
))
.with_children(|p| {
p.spawn((
Node {
height: Val::Px(100.0),
width: Val::Percent(100.0),
justify_content: JustifyContent::SpaceBetween,
width: Val::Px(64.0),
height: Val::Px(64.0),
margin: UiRect::all(Val::Auto),
..Default::default()
},
RenderItem {
item_id: recipe.output.item,
},
));

let item = items.from_numeric_id(recipe.output.item);
let name = lang.get_name_from_id(item.unlocalized_name()).unwrap_or(item.unlocalized_name());

p.spawn((
Name::new("Item name + inputs display"),
Node {
width: Val::Percent(80.0),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::SpaceEvenly,
..Default::default()
},
Button::<SelectItemEvent>::default(),
Recipe(recipe.clone()),
))
.with_children(|p| {
p.spawn((
Node {
width: Val::Px(64.0),
height: Val::Px(64.0),
margin: UiRect::all(Val::Auto),
width: Val::Percent(100.0),
// margin: UiRect::vertical(Val::Auto),
..Default::default()
},
RenderItem {
item_id: recipe.output.item,
},
Text::new(format!("{}x {}", recipe.output.quantity, name)),
text_style.clone(),
));

let item = items.from_numeric_id(recipe.output.item);
let name = lang.get_name_from_id(item.unlocalized_name()).unwrap_or(item.unlocalized_name());

p.spawn((
Name::new("Item name + inputs display"),
Node {
width: Val::Percent(80.0),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::SpaceEvenly,
..Default::default()
},
))
p.spawn(Node {
flex_direction: FlexDirection::Row,
width: Val::Percent(100.0),
..Default::default()
})
.with_children(|p| {
p.spawn((
Node {
width: Val::Percent(100.0),
// margin: UiRect::vertical(Val::Auto),
..Default::default()
},
Text::new(format!("{}x {}", recipe.output.quantity, name)),
text_style.clone(),
));

p.spawn(Node {
flex_direction: FlexDirection::Row,
width: Val::Percent(100.0),
..Default::default()
})
.with_children(|p| {
for item in recipe.inputs.iter() {
let RecipeItem::Item(item_id) = item.item;

for item in recipe.inputs.iter() {
let RecipeItem::Item(item_id) = item.item;

p.spawn((
Node {
width: Val::Px(64.0),
height: Val::Px(64.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::End,
justify_content: JustifyContent::End,
..Default::default()
},
RenderItem { item_id },
))
.with_children(|p| {
p.spawn((
Node {
width: Val::Px(64.0),
height: Val::Px(64.0),
flex_direction: FlexDirection::Column,
align_items: AlignItems::End,
justify_content: JustifyContent::End,
..Default::default()
},
RenderItem { item_id },
))
.with_children(|p| {
p.spawn((
Name::new("Item recipe qty"),
TextNeedsTopRoot,
Text::new(format!("{}", item.quantity)),
text_style.clone(),
));
});
}
});
Name::new("Item recipe qty"),
TextNeedsTopRoot,
Text::new(format!("{}", item.quantity)),
text_style.clone(),
));
});
}
});
});
}
});
});
}
});

p.spawn((
Name::new("Footer"),
Expand Down
39 changes: 38 additions & 1 deletion cosmos_client/src/entities/player/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
//! Contains systems and components for the player

use bevy::prelude::App;
use bevy::{color::palettes::css, prelude::*};
use bevy_rapier3d::prelude::{ActiveEvents, CoefficientCombineRule, Collider, Friction, LockedAxes, ReadMassProperties, RigidBody};
use cosmos_core::{entities::player::Player, netty::system_sets::NetworkingSystemsSet, persistence::LoadingDistance, state::GameState};

pub mod player_movement;
pub mod render_distance;

fn on_add_player(
mut commands: Commands,
mut materials: ResMut<Assets<StandardMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
q_player: Query<(Entity, &Player), Added<Player>>,
) {
for (ent, player) in q_player.iter() {
commands.entity(ent).insert((
Mesh3d(meshes.add(Capsule3d::default())),
MeshMaterial3d(materials.add(StandardMaterial {
base_color: css::GREEN.into(),
..Default::default()
})),
Collider::capsule_y(0.65, 0.25),
LockedAxes::ROTATION_LOCKED,
Name::new(format!("Player ({})", player.name())),
RigidBody::Dynamic,
Friction {
coefficient: 0.0,
combine_rule: CoefficientCombineRule::Min,
},
LoadingDistance::new(1, 2),
ReadMassProperties::default(),
ActiveEvents::COLLISION_EVENTS,
));
}
}

pub(super) fn register(app: &mut App) {
app.add_systems(
Update,
on_add_player
.in_set(NetworkingSystemsSet::Between)
.run_if(in_state(GameState::Playing).or(in_state(GameState::LoadingWorld))),
);

render_distance::register(app);
player_movement::register(app);
}
7 changes: 5 additions & 2 deletions cosmos_client/src/entities/player/render_distance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Represents how far the player can see entities

use bevy::prelude::{in_state, App, Changed, IntoSystemConfigs, Query, ResMut, Update, With};
use bevy::prelude::{in_state, App, Changed, Condition, IntoSystemConfigs, Query, ResMut, Update, With};
use bevy_renet2::renet2::RenetClient;
use cosmos_core::{
entities::player::render_distance::RenderDistance,
Expand All @@ -20,5 +20,8 @@ fn send_render_distance(query: Query<&RenderDistance, (With<LocalPlayer>, Change
}

pub(super) fn register(app: &mut App) {
app.add_systems(Update, send_render_distance.run_if(in_state(GameState::Playing)));
app.add_systems(
Update,
send_render_distance.run_if(in_state(GameState::Playing).or(in_state(GameState::LoadingWorld))),
);
}
41 changes: 33 additions & 8 deletions cosmos_client/src/inventory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,22 +953,47 @@ enum InventorySet {
MoveWindows,
}

fn rec_make_render_middle_camera(
ent: Entity,
q_mid_cam: &Query<Entity, With<UiTopRoot>>,
q_children: &Query<&Children>,
q_target_cam: &mut Query<(Entity, &mut TargetCamera), (Changed<TargetCamera>, With<TextNeedsTopRoot>)>,
commands: &mut Commands,
) {
let middle_camera_entity = q_mid_cam.single();

if let Ok((_, mut target_camera)) = q_target_cam.get_mut(ent) {
if target_camera.0 != middle_camera_entity {
target_camera.0 = middle_camera_entity;
}
if let Ok(children) = q_children.get(ent) {
for c in children.iter() {
rec_make_render_middle_camera(*c, q_mid_cam, q_children, q_target_cam, commands);
}
}
} else {
commands.entity(ent).insert(TargetCamera(middle_camera_entity));
if let Ok(children) = q_children.get(ent) {
for c in children.iter() {
rec_make_render_middle_camera(*c, q_mid_cam, q_children, q_target_cam, commands);
}
}
}
}

fn make_render_middle_camera(
q_mid_cam: Query<Entity, With<UiTopRoot>>,
mut q_target_cam: Query<&mut TargetCamera, (Changed<TargetCamera>, With<TextNeedsTopRoot>)>,
q_children: Query<&Children>,
mut q_target_cam: Query<(Entity, &mut TargetCamera), (Changed<TargetCamera>, With<TextNeedsTopRoot>)>,
q_needs_target_cam: Query<Entity, (Without<TargetCamera>, With<TextNeedsTopRoot>)>,
mut commands: Commands,
) {
for mut target_camera in q_target_cam.iter_mut() {
let middle_camera_entity = q_mid_cam.single();
if target_camera.0 != middle_camera_entity {
target_camera.0 = middle_camera_entity;
}
for ent in q_target_cam.iter().map(|x| x.0).collect::<Vec<Entity>>() {
rec_make_render_middle_camera(ent, &q_mid_cam, &q_children, &mut q_target_cam, &mut commands);
}

for ent in q_needs_target_cam.iter() {
let middle_camera_entity = q_mid_cam.single();
commands.entity(ent).insert(TargetCamera(middle_camera_entity));
rec_make_render_middle_camera(ent, &q_mid_cam, &q_children, &mut q_target_cam, &mut commands);
}
}

Expand Down
6 changes: 5 additions & 1 deletion cosmos_client/src/loading/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! Responsible for unloading far entities

use bevy::prelude::{App, Commands, Entity, IntoSystemConfigs, Parent, Query, Update, With, Without};
use bevy::{
log::info,
prelude::{App, Commands, Entity, IntoSystemConfigs, Parent, Query, Update, With, Without},
};
use cosmos_core::{
ecs::NeedsDespawned,
entities::player::Player,
Expand All @@ -19,6 +22,7 @@ fn unload_far_entities(
let ul_distance = unload_distance.unload_distance() as SectorUnit;

if (loc.sector() - my_loc.sector()).abs().max_element() > ul_distance {
info!("Unloading {ent:?} - it's too far.");
commands.entity(ent).insert(NeedsDespawned);
}
}
Expand Down
3 changes: 1 addition & 2 deletions cosmos_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ fn main() {
))
// .add_plugins(RapierDebugRenderPlugin::default())
.add_systems(OnEnter(GameState::Connecting), connect::establish_connection)
.add_systems(Update, connect::wait_for_connection.run_if(in_state(GameState::Connecting)))
.add_systems(Update, connect::wait_for_done_loading.run_if(in_state(GameState::LoadingWorld)));
.add_systems(Update, connect::wait_for_connection.run_if(in_state(GameState::Connecting)));

input::register(&mut app);
window::register(&mut app);
Expand Down
Loading
Loading