Skip to content

Commit

Permalink
Display team roster in shop
Browse files Browse the repository at this point in the history
  • Loading branch information
makscee committed Feb 9, 2025
1 parent 6994e17 commit 834f8ad
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 54 deletions.
12 changes: 8 additions & 4 deletions schema/src/macro_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,18 @@ pub fn table_conversions(
vec_link_types: &Vec<TokenStream>,
) -> TokenStream {
quote! {
fn from_table(c: &Context, domain: NodeDomain, id: u64) -> Option<Self> {
fn from_table_no_children(c: &Context, domain: NodeDomain, id: u64) -> Option<Self> {
let data = domain.tnode_find_by_key(c, &Self::kind_s().key(id))?.data;
let mut d = Self::default();
d.inject_data(&data);
d.id = Some(id);
#(
d.#option_link_fields = #option_link_types::from_table(c, domain, id);
)*
Some(d)
}
fn from_table(c: &Context, domain: NodeDomain, id: u64) -> Option<Self> {
let mut d = Self::from_table_no_children(c, domain, id)?;
let children = c
.rc
.db
Expand All @@ -178,9 +185,6 @@ pub fn table_conversions(
.filter(id)
.map(|r| r.id)
.collect_vec();
#(
d.#option_link_fields = #option_link_types::from_table(c, domain, id);
)*
#(
d.#vec_link_fields = children
.iter()
Expand Down
1 change: 1 addition & 0 deletions server/src/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub trait Node: Default + Sized {
fn get_data(&self) -> String;
fn from_strings(i: usize, strings: &Vec<String>) -> Option<Self>;
fn to_strings(&self, parent: usize, field: &str, strings: &mut Vec<String>);
fn from_table_no_children(c: &Context, domain: NodeDomain, id: u64) -> Option<Self>;
fn from_table(c: &Context, domain: NodeDomain, id: u64) -> Option<Self>;
fn to_table(self, c: &Context, domain: NodeDomain, parent: u64);
}
Expand Down
5 changes: 2 additions & 3 deletions server/src/nodes_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,11 @@ impl NodeDomainExt for NodeDomain {
.collect()
}
fn node_parent<T: Node + GetNodeKindSelf>(self, c: &Context, id: u64) -> Option<T> {
let kind = T::kind_s();
let mut id = id;
while let Some(parent) = id.parent(c.rc) {
id = parent;
if let Some(node) = self.tnode_find_by_key(c, &kind.key(id)) {
return Some(node.to_node());
if let Some(node) = T::from_table_no_children(c, self, id) {
return Some(node);
}
}
None
Expand Down
115 changes: 68 additions & 47 deletions src/plugins/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl MatchPlugin {
pub fn load_match_data(id: u64, world: &mut World) {
let m = Match::from_table(NodeDomain::Match, id).unwrap();
let mut team_world = World::new();
dbg!(&m);
m.team
.unwrap()
.unpack(team_world.spawn_empty().id(), &mut team_world);
Expand All @@ -44,62 +45,82 @@ impl MatchPlugin {
Window::new("Match", move |ui, world| {
let mut md = world.remove_resource::<MatchData>().unwrap();
let shop_slots = md.shop_case.len();
ui.columns(shop_slots, |ui| {
for i in 0..shop_slots {
let ui = &mut ui[i];
ui.with_layout(
Layout::bottom_up(Align::Center).with_cross_justify(true),
|ui| {
let sc = &md.shop_case[i];
let full_rect = ui.available_rect_before_wrap();
ui.horizontal(|ui| {
ui.vertical(|ui| {
for unit in md.team_world.query::<&Unit>().iter(&md.team_world) {
TagWidget::new_text(
&unit.name,
Context::new_world(&md.team_world)
.set_owner(unit.entity())
.get_color(VarName::color)
.unwrap(),
)
.ui(ui);
}
ui.expand_to_include_y(full_rect.bottom());
});
ui.columns(shop_slots, |ui| {
for i in 0..shop_slots {
let ui = &mut ui[i];
ui.with_layout(
Layout::bottom_up(Align::Center).with_cross_justify(true),
|ui| {
let sc = &md.shop_case[i];

if "buy"
.cstr_s(CstrStyle::Bold)
.as_button()
.enabled(!sc.sold)
.ui(ui)
.clicked()
{
cn().reducers.match_buy(i as u8).unwrap();
}
let entity = md.core_world.get_id_link(sc.unit_id).unwrap();
let context =
&Context::new_world(&md.core_world).set_owner(entity).take();
let name = context.get_string(VarName::name).unwrap();
let color = context.get_color(VarName::color).unwrap();
TagWidget::new_text(name, color).ui(ui);
let size = ui.available_size();
let size = size.x.at_most(size.y);
let rect = ui
.allocate_ui_at_rect(
Rect::from_center_size(
ui.available_rect_before_wrap().center(),
egui::vec2(size, size),
),
|ui| show_slot(i, 1, false, ui).rect,
)
.inner
.shrink(10.0);
if !sc.sold {
RepresentationPlugin::paint_rect(
rect,
context,
&unit_rep().material,
ui,
if "buy"
.cstr_s(CstrStyle::Bold)
.as_button()
.enabled(!sc.sold)
.ui(ui)
.clicked()
{
cn().reducers.match_buy(i as u8).unwrap();
}
let entity = md.core_world.get_id_link(sc.unit_id).unwrap();
let context =
&Context::new_world(&md.core_world).set_owner(entity).take();
let name = context.get_string(VarName::name).unwrap();
let color = context.get_color(VarName::color).unwrap();
TagWidget::new_text(
name,
if sc.sold { VISIBLE_DARK } else { color },
)
.log();
if let Some(rep) = md.core_world.get::<Representation>(entity) {
.ui(ui);
let size = ui.available_size();
let size = size.x.at_most(size.y);
let rect = ui
.allocate_ui_at_rect(
Rect::from_center_size(
ui.available_rect_before_wrap().center(),
egui::vec2(size, size),
),
|ui| show_slot(i, 1, false, ui).rect,
)
.inner
.shrink(10.0);
if !sc.sold {
RepresentationPlugin::paint_rect(
rect,
context,
&rep.material,
&unit_rep().material,
ui,
)
.log();
if let Some(rep) = md.core_world.get::<Representation>(entity) {
RepresentationPlugin::paint_rect(
rect,
context,
&rep.material,
ui,
)
.log();
}
}
}
},
);
}
},
);
}
});
});
for (entity, slot) in md
.team_world
Expand Down

0 comments on commit 834f8ad

Please sign in to comment.