Skip to content

Commit e272fa0

Browse files
feat: show BowCharging data in flecs panel (#669)
1 parent f300855 commit e272fa0

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ glam = '0.29.0'
6565
heapless = '0.8.0'
6666
heed = '0.20.5'
6767
hex = '0.4.3'
68+
humantime = "2.1.0"
6869
itertools = '0.13.0'
6970
kanal = '0.1.0-pre8'
7071
libc = '0.2.155'

crates/hyperion/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ geometry = {workspace = true}
2525
glam = {workspace = true, features = ["serde"]}
2626
heapless = {workspace = true}
2727
heed = {workspace = true}
28+
humantime = {workspace = true}
2829
hyperion-crafting = {workspace = true}
2930
hyperion-event-macros = {workspace = true}
3031
hyperion-inventory = {workspace = true}

crates/hyperion/src/simulation/bow.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
use std::time::{Duration, SystemTime};
1+
use std::{
2+
fmt::Display,
3+
time::{Duration, SystemTime},
4+
};
25

36
use flecs_ecs::prelude::*;
7+
use humantime::format_duration;
48

59
#[derive(Component, Debug)]
610
pub struct BowCharging {
711
pub start_time: SystemTime,
812
}
913

10-
impl Default for BowCharging {
11-
fn default() -> Self {
12-
Self {
13-
start_time: SystemTime::now(),
14-
}
14+
impl Display for BowCharging {
15+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16+
let duration = self.start_time.elapsed().unwrap_or_default();
17+
18+
write!(f, "{}", format_duration(duration))
1519
}
1620
}
1721

1822
impl BowCharging {
1923
#[must_use]
20-
pub fn new() -> Self {
21-
Self::default()
24+
pub fn now() -> Self {
25+
Self {
26+
start_time: SystemTime::now(),
27+
}
2228
}
2329

2430
#[must_use]

crates/hyperion/src/simulation/handlers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ pub fn player_interact_item(
348348
if charging.is_some() {
349349
return;
350350
}
351-
entity.set(BowCharging::new());
351+
entity.set(BowCharging::now());
352352
});
353353
}
354354
}

crates/hyperion/src/simulation/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ impl Module for SimModule {
571571
fn module(world: &World) {
572572
component!(world, VarInt).member::<i32>("x");
573573

574+
component!(world, EntitySize).opaque_func(meta_ser_stringify_type_display::<EntitySize>);
575+
574576
component!(world, IVec3 {
575577
x: i32,
576578
y: i32,
@@ -590,8 +592,6 @@ impl Module for SimModule {
590592

591593
component!(world, BlockState).member::<u16>("id");
592594

593-
component!(world, EntitySize).opaque_func(meta_ser_stringify_type_display::<EntitySize>);
594-
595595
world.component::<Velocity>().meta();
596596
world.component::<Player>();
597597
world.component::<Visible>();
@@ -637,6 +637,7 @@ impl Module for SimModule {
637637
world.component::<hyperion_inventory::PlayerInventory>();
638638

639639
world.component::<BowCharging>();
640+
component!(world, BowCharging).opaque_func(meta_ser_stringify_type_display::<BowCharging>);
640641

641642
observer!(
642643
world,

0 commit comments

Comments
 (0)