Skip to content

Commit

Permalink
Fusion edit;
Browse files Browse the repository at this point in the history
Fusion display in Shop;
  • Loading branch information
makscee committed Feb 12, 2025
1 parent 2044b09 commit bdd5f99
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 102 deletions.
40 changes: 8 additions & 32 deletions macro-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,41 +158,17 @@ pub fn node(_: TokenStream, item: TokenStream) -> TokenStream {
} else {
default()
};
let common = common_node_fns(
struct_ident,
&all_data_fields,
&all_data_types,
&component_link_fields,
&component_link_types,
);
quote! {
#[derive(Component, Clone, Default, Debug)]
#input
impl #struct_ident {
pub fn new(
#(
#all_data_fields: #all_data_types,
)*
) -> Self {
Self {
#(
#all_data_fields,
)*
..default()
}
}
pub fn new_full(
#(
#all_data_fields: #all_data_types,
)*
#(
#component_link_fields: #component_link_types,
)*
) -> Self {
Self {
#(
#all_data_fields,
)*
#(
#component_link_fields: Some(#component_link_fields),
)*
..default()
}
}
}
#common
impl std::fmt::Display for #struct_ident {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.kind())
Expand Down
17 changes: 9 additions & 8 deletions macro-server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn node(_: TokenStream, item: TokenStream) -> TokenStream {
data_types: _,
data_type_ident,
all_data_fields,
all_data_types: _,
all_data_types,
} = parse_node_fields(fields);
let strings_conversions = strings_conversions(
&component_link_fields,
Expand All @@ -52,16 +52,17 @@ pub fn node(_: TokenStream, item: TokenStream) -> TokenStream {
.unwrap(),
);
}
let common = common_node_fns(
struct_ident,
&all_data_fields,
&all_data_types,
&component_link_fields,
&component_link_types,
);
quote! {
#[derive(Default, Debug, Clone)]
#input
impl #struct_ident {
#(
pub fn #component_link_fields(&self) -> &#component_link_types {
self.#component_link_fields.as_ref().unwrap()
}
)*
}
#common
impl Node for #struct_ident {
#strings_conversions
#table_conversions
Expand Down
47 changes: 47 additions & 0 deletions schema/src/macro_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,50 @@ pub fn table_conversions(
}
}
}
pub fn common_node_fns(
struct_ident: &Ident,
all_data_fields: &Vec<Ident>,
all_data_types: &Vec<Type>,
component_link_fields: &Vec<Ident>,
component_link_types: &Vec<TokenStream>,
) -> TokenStream {
quote! {
impl #struct_ident {
pub fn new(
#(
#all_data_fields: #all_data_types,
)*
) -> Self {
Self {
#(
#all_data_fields,
)*
..default()
}
}
pub fn new_full(
#(
#all_data_fields: #all_data_types,
)*
#(
#component_link_fields: #component_link_types,
)*
) -> Self {
Self {
#(
#all_data_fields,
)*
#(
#component_link_fields: Some(#component_link_fields),
)*
..default()
}
}
#(
pub fn #component_link_fields(&self) -> &#component_link_types {
self.#component_link_fields.as_ref().unwrap()
}
)*
}
}
}
12 changes: 2 additions & 10 deletions server/src/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,12 @@ fn match_edit_fusions(ctx: &ReducerContext, fusions: Vec<Vec<String>>) -> Result
.into_iter()
.map(|u| (u.name.clone(), u.clone())),
);
// let fusions_units = fusions.iter().flat_map(|f| &f.unit).collect_vec();
// if !fusions_units.iter().all_unique() {
// return Err("Each unit can be fused only once".into());
// }
// for unit in fusions_units {
// if !roster_units.contains_key(unit) {
// return Err(format!("Unit {unit} is not in roster"));
// }
// }
info!("{fusions:?}");
for fusion in &m.team().fusions {
NodeDomain::Match.delete_by_id_recursive(c, fusion.id());
}
for fusion in fusions {
for (i, mut fusion) in fusions.into_iter().enumerate() {
fusion.slot = Some(UnitSlot::new(i as i32));
fusion.to_table(c, NodeDomain::Match, m.team().id());
}
m.save(c);
Expand Down
9 changes: 2 additions & 7 deletions server/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ pub trait Node: Default + Sized {
fn to_table(self, c: &Context, domain: NodeDomain, parent: u64);
}

impl Hero {
pub fn new(name: String) -> Self {
Self { name, ..default() }
}
}
impl Mover {
pub fn new() -> Self {
Self {
pub fn new_empty() -> Self {
Mover {
start_ts: now_seconds(),
..default()
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/nodes_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ fn node_spawn_hero(ctx: &ReducerContext, name: String) -> Result<(), String> {
let c = &ctx.wrap()?;
let id = c.next_id();
let mut hero = Hero::new(name);
let mut mover = Mover::new();
let mut mover = Mover::new_empty();
hero.id = Some(id);
mover.id = Some(id);
NodeDomain::World.node_insert(c, &hero);
Expand Down
4 changes: 1 addition & 3 deletions src/nodes/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ impl OnUnpack for NodeKind {
.get_mut::<NodeState>()
.unwrap()
};
for (var, value) in vars {
ns.init(var, value);
}
ns.init_vars(vars);
match self {
NodeKind::House => {
ns.init(VarName::visible, false.into());
Expand Down
Loading

0 comments on commit bdd5f99

Please sign in to comment.