File tree Expand file tree Collapse file tree 6 files changed +27
-11
lines changed Expand file tree Collapse file tree 6 files changed +27
-11
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ glam = '0.29.0'
65
65
heapless = ' 0.8.0'
66
66
heed = ' 0.20.5'
67
67
hex = ' 0.4.3'
68
+ humantime = " 2.1.0"
68
69
itertools = ' 0.13.0'
69
70
kanal = ' 0.1.0-pre8'
70
71
libc = ' 0.2.155'
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ geometry = {workspace = true}
25
25
glam = {workspace = true , features = [" serde" ]}
26
26
heapless = {workspace = true }
27
27
heed = {workspace = true }
28
+ humantime = {workspace = true }
28
29
hyperion-crafting = {workspace = true }
29
30
hyperion-event-macros = {workspace = true }
30
31
hyperion-inventory = {workspace = true }
Original file line number Diff line number Diff line change 1
- use std:: time:: { Duration , SystemTime } ;
1
+ use std:: {
2
+ fmt:: Display ,
3
+ time:: { Duration , SystemTime } ,
4
+ } ;
2
5
3
6
use flecs_ecs:: prelude:: * ;
7
+ use humantime:: format_duration;
4
8
5
9
#[ derive( Component , Debug ) ]
6
10
pub struct BowCharging {
7
11
pub start_time : SystemTime ,
8
12
}
9
13
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 ) )
15
19
}
16
20
}
17
21
18
22
impl BowCharging {
19
23
#[ must_use]
20
- pub fn new ( ) -> Self {
21
- Self :: default ( )
24
+ pub fn now ( ) -> Self {
25
+ Self {
26
+ start_time : SystemTime :: now ( ) ,
27
+ }
22
28
}
23
29
24
30
#[ must_use]
Original file line number Diff line number Diff line change @@ -348,7 +348,7 @@ pub fn player_interact_item(
348
348
if charging. is_some ( ) {
349
349
return ;
350
350
}
351
- entity. set ( BowCharging :: new ( ) ) ;
351
+ entity. set ( BowCharging :: now ( ) ) ;
352
352
} ) ;
353
353
}
354
354
}
Original file line number Diff line number Diff line change @@ -571,6 +571,8 @@ impl Module for SimModule {
571
571
fn module ( world : & World ) {
572
572
component ! ( world, VarInt ) . member :: < i32 > ( "x" ) ;
573
573
574
+ component ! ( world, EntitySize ) . opaque_func ( meta_ser_stringify_type_display :: < EntitySize > ) ;
575
+
574
576
component ! ( world, IVec3 {
575
577
x: i32 ,
576
578
y: i32 ,
@@ -590,8 +592,6 @@ impl Module for SimModule {
590
592
591
593
component ! ( world, BlockState ) . member :: < u16 > ( "id" ) ;
592
594
593
- component ! ( world, EntitySize ) . opaque_func ( meta_ser_stringify_type_display :: < EntitySize > ) ;
594
-
595
595
world. component :: < Velocity > ( ) . meta ( ) ;
596
596
world. component :: < Player > ( ) ;
597
597
world. component :: < Visible > ( ) ;
@@ -637,6 +637,7 @@ impl Module for SimModule {
637
637
world. component :: < hyperion_inventory:: PlayerInventory > ( ) ;
638
638
639
639
world. component :: < BowCharging > ( ) ;
640
+ component ! ( world, BowCharging ) . opaque_func ( meta_ser_stringify_type_display :: < BowCharging > ) ;
640
641
641
642
observer ! (
642
643
world,
You can’t perform that action at this time.
0 commit comments