1
+ use super :: ProgressActive ;
1
2
use crate :: {
2
3
action:: Action ,
3
4
colors,
@@ -10,15 +11,12 @@ use nexus::imgui::{ComboBoxFlags, InputTextFlags, Ui};
10
11
use serde:: { Deserialize , Serialize } ;
11
12
use strum:: { AsRefStr , EnumIter , IntoStaticStr } ;
12
13
13
- use super :: ProgressActive ;
14
-
15
- // FIXME: serde does not support flatten aliases, see https://github.com/serde-rs/serde/pull/2387
16
14
#[ derive( Debug , Default , Clone , AsRefStr , IntoStaticStr , EnumIter , Serialize , Deserialize ) ]
17
15
pub enum ProgressSource {
18
16
/// Always active, no associated progress.
19
17
#[ default]
20
- #[ serde( alias = "Always " ) ]
21
- None ,
18
+ #[ serde( alias = "None " ) ]
19
+ Always ,
22
20
23
21
/// Single buff id.
24
22
#[ serde( alias = "Single" ) ]
@@ -44,13 +42,13 @@ impl_static_variants!(ProgressSource);
44
42
45
43
impl ProgressSource {
46
44
pub fn always ( & self ) -> bool {
47
- matches ! ( self , Self :: None )
45
+ matches ! ( self , Self :: Always )
48
46
}
49
47
50
48
pub fn progress ( & self , ctx : & Context ) -> ProgressActive {
51
49
match self {
52
- ProgressSource :: None => ProgressActive :: Resource ( Resource { current : 1 , max : 1 } ) ,
53
- ProgressSource :: Buff ( id) => {
50
+ Self :: Always => ProgressActive :: Resource ( Resource { current : 1 , max : 1 } ) ,
51
+ Self :: Buff ( id) => {
54
52
let stacks = ctx. stacks_of ( * id) . unwrap_or ( 0 ) ;
55
53
let ( apply, runout) = ctx. time_range ( * id) . unwrap_or ( ( 0 , 0 ) ) ;
56
54
ProgressActive :: Buff {
@@ -59,7 +57,7 @@ impl ProgressSource {
59
57
runout,
60
58
}
61
59
}
62
- ProgressSource :: AnyBuff ( ids) => {
60
+ Self :: AnyBuff ( ids) => {
63
61
let stacks = ids. iter ( ) . filter_map ( |id| ctx. stacks_of ( * id) ) . sum ( ) ; // sum of all stacks
64
62
let ( apply, runout) = ids
65
63
. iter ( )
@@ -71,11 +69,25 @@ impl ProgressSource {
71
69
runout,
72
70
}
73
71
}
74
- ProgressSource :: PrimaryResource => {
75
- ProgressActive :: Resource ( ctx. resources . primary . clone ( ) )
72
+ Self :: PrimaryResource => ProgressActive :: Resource ( ctx. resources . primary . clone ( ) ) ,
73
+ Self :: SecondaryResource => ProgressActive :: Resource ( ctx. resources . secondary . clone ( ) ) ,
74
+ }
75
+ }
76
+
77
+ pub fn progress_edit ( & self , ctx : & Context ) -> ProgressActive {
78
+ match self {
79
+ Self :: Always => ProgressActive :: Resource ( Resource { current : 1 , max : 1 } ) ,
80
+ Self :: Buff ( _) | Self :: AnyBuff ( _) => {
81
+ let apply = ctx. now - ( ctx. now % 5000 ) ;
82
+ ProgressActive :: Buff {
83
+ stacks : 1 ,
84
+ apply,
85
+ runout : apply + 5000 ,
86
+ }
76
87
}
77
- ProgressSource :: SecondaryResource => {
78
- ProgressActive :: Resource ( ctx. resources . secondary . clone ( ) )
88
+ Self :: PrimaryResource | Self :: SecondaryResource => {
89
+ let current = ( ctx. now % 5000 ) / 100 ;
90
+ ProgressActive :: Resource ( Resource { current, max : 50 } )
79
91
}
80
92
}
81
93
}
0 commit comments