Skip to content

Commit

Permalink
Merge pull request #356 from AnthonyTornetta/354-add-basic-fabricator
Browse files Browse the repository at this point in the history
354 add basic fabricator
  • Loading branch information
AnthonyTornetta authored Dec 4, 2024
2 parents 289a545 + f814ec8 commit b9450a6
Show file tree
Hide file tree
Showing 48 changed files with 1,725 additions and 36 deletions.
24 changes: 24 additions & 0 deletions cosmos_client/assets/cosmos/blocks/basic_fabricator.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"texture": {
"Sides": {
"right": {
"Single": "cosmos:basic_fabricator_sides"
},
"left": {
"Single": "cosmos:basic_fabricator_sides"
},
"front": {
"Single": "cosmos:basic_fabricator_sides"
},
"back": {
"Single": "cosmos:basic_fabricator_sides"
},
"top": {
"Single": "cosmos:basic_fabricator_top_bottom"
},
"bottom": {
"Single": "cosmos:basic_fabricator_top_bottom"
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion cosmos_client/assets/cosmos/lang/blocks/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ cosmos:cactus=Cactus
cosmos:build_block=Build Block
cosmos:door=Door
cosmos:door_open=Door
cosmos:basic_fabricator=Basic Fabricator
cosmos:iron_ore=Iron Ore

cosmos:ship_hull_grey=Grey Ship Hull
cosmos:ship_hull_black=Black Ship Hull
Expand Down Expand Up @@ -107,4 +109,4 @@ cosmos:logic_wire_red=Red Logic Wire
cosmos:logic_wire_dark_red=Dark Red Logic Wire
cosmos:logic_wire_yellow=Yellow Logic Wire
cosmos:logic_wire_dark_yellow=Dark Yellow Logic Wire
cosmos:logic_wire_mint=Mint Logic Wire
cosmos:logic_wire_mint=Mint Logic Wire
3 changes: 2 additions & 1 deletion cosmos_client/assets/cosmos/lang/items/en_us.lang
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cosmos:test_crystal=Test Crystal
cosmos:test_crystal=Test Crystal
cosmos:iron_bar=Iron Bar
70 changes: 70 additions & 0 deletions cosmos_client/src/crafting/blocks/basic_fabricator/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use bevy::{
app::Update,
core::Name,
log::error,
prelude::{
in_state, App, Commands, Component, Entity, EventReader, IntoSystemConfigs, IntoSystemSetConfigs, Query, Res, SystemSet, With,
},
reflect::Reflect,
};
use cosmos_core::{
crafting::blocks::basic_fabricator::OpenBasicFabricatorEvent,
ecs::NeedsDespawned,
netty::{
sync::{
events::client_event::NettyEventReceived,
mapping::{Mappable, NetworkMapping},
},
system_sets::NetworkingSystemsSet,
},
prelude::StructureBlock,
state::GameState,
};

mod ui;

#[derive(Component, Debug, Reflect)]
struct OpenBasicFabricatorMenu(StructureBlock);

fn open_menu(
q_open_menu: Query<Entity, With<OpenBasicFabricatorMenu>>,
mut commands: Commands,
mut nevr: EventReader<NettyEventReceived<OpenBasicFabricatorEvent>>,
network_mapping: Res<NetworkMapping>,
) {
let Some(ev) = nevr.read().last() else {
return;
};

if let Ok(ent) = q_open_menu.get_single() {
commands.entity(ent).insert(NeedsDespawned);
}

let Ok(s_block) = ev.0.map(&network_mapping) else {
error!("Bad network mapping - {:?}", ev.0);
return;
};

commands.spawn((OpenBasicFabricatorMenu(s_block), Name::new("Open Basic Fabricator Menu")));
}

#[derive(Debug, Hash, PartialEq, Eq, Clone, SystemSet)]
enum FabricatorMenuSet {
OpenMenu,
PopulateMenu,
}

pub(super) fn register(app: &mut App) {
ui::register(app);

app.configure_sets(Update, (FabricatorMenuSet::OpenMenu, FabricatorMenuSet::PopulateMenu).chain());

app.add_systems(
Update,
open_menu
.in_set(NetworkingSystemsSet::Between)
.in_set(FabricatorMenuSet::OpenMenu)
.run_if(in_state(GameState::Playing)),
)
.register_type::<OpenBasicFabricatorMenu>();
}
Loading

0 comments on commit b9450a6

Please sign in to comment.