Skip to content

Commit

Permalink
Fix progress value
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Dec 24, 2024
1 parent ee85eeb commit 2031bca
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
3 changes: 1 addition & 2 deletions reffect/src/elements/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use crate::{
id::Id,
render::{colors, ComponentWise, RenderDebug, RenderOptions},
render_util::{
debug_optional, helper_slider, input_pos, push_alpha_change, slider_percent,
EnumStaticVariants, Rect,
helper_slider, input_pos, push_alpha_change, slider_percent, EnumStaticVariants, Rect,
},
trigger::ProgressTrigger,
};
Expand Down
5 changes: 2 additions & 3 deletions reffect/src/elements/icon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl Icon {

// render duration text
if self.duration_text {
if let Some(remain) = active.current(ProgressValue::PreferPrimary, ctx.now) {
if let Some(remain) = active.current(ProgressValue::Primary, ctx.now) {
let DurationTextSettings {
max_remain,
scale,
Expand All @@ -157,8 +157,7 @@ impl Icon {
} = ctx.settings.icon.duration_text;

if remain < max_remain {
let text =
active.current_text(ProgressValue::PreferPrimary, ctx.now, false);
let text = active.current_text(ProgressValue::Primary, ctx.now, false);

let font_size = scale * small_size;
let font_scale = font_size / ui.current_font_size();
Expand Down
16 changes: 6 additions & 10 deletions reffect/src/trigger/progress/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,13 @@ impl ProgressActive {
Self::Fixed { current, .. } => Some(current),
Self::Buff { end, .. } => (end != u32::MAX).then(|| Self::time_between(now, end)),
Self::Ability {
ammo,
end,
ammo_end,
rate,
..
} => Some(Self::time_between_scaled(
now,
value.pick(ammo, end, ammo_end),
value.pick(end, ammo_end),
rate,
)),
}
Expand All @@ -225,14 +224,13 @@ impl ProgressActive {
}
}
Self::Ability {
ammo,
end,
ammo_end,
rate,
..
} => Self::duration_text(Self::time_between_scaled(
now,
value.pick(ammo, end, ammo_end),
value.pick(end, ammo_end),
rate,
)),
}
Expand All @@ -244,11 +242,10 @@ impl ProgressActive {
Self::Fixed { max, .. } => max,
Self::Buff { duration, .. } => duration,
Self::Ability {
ammo,
duration,
ammo_duration,
..
} => value.pick(ammo, duration, ammo_duration),
} => value.pick(duration, ammo_duration),
}
}

Expand All @@ -264,11 +261,10 @@ impl ProgressActive {
}
}
Self::Ability {
ammo,
duration,
ammo_duration,
..
} => Self::format_seconds(value.pick(ammo, duration, ammo_duration)),
} => Self::format_seconds(value.pick(duration, ammo_duration)),
}
}

Expand Down Expand Up @@ -319,12 +315,12 @@ pub enum ProgressValue {
}

impl ProgressValue {
pub fn pick(&self, intensity: u32, primary: u32, secondary: u32) -> u32 {
pub fn pick(&self, primary: u32, secondary: u32) -> u32 {
match self {
Self::Primary => primary,
Self::Secondary => secondary,
Self::PreferPrimary => {
if intensity > 0 {
if primary > 0 {
primary
} else {
secondary
Expand Down
4 changes: 2 additions & 2 deletions reffect/src/trigger/progress/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ impl ProgressSource {
Validation::Confirm(format!("{category} {id} is valid"))
}
}
Ok(SkillInfo::Ability) => Validation::Error(format!("Id {id} is an ability")),
Ok(SkillInfo::Ability { .. }) => Validation::Error(format!("Id {id} is an ability")),
Err(Error::SkillNotFound) => Validation::Error(format!("Id {id} is invalid or hidden")),
Err(_) => Validation::Ok,
}
}

fn ability_validate(id: u32) -> Validation<impl AsRef<str>> {
match Internal::get_skill_info(id) {
Ok(SkillInfo::Ability) => Validation::Confirm(format!("Ability {id} is valid")),
Ok(SkillInfo::Ability { .. }) => Validation::Confirm(format!("Ability {id} is valid")),
Ok(SkillInfo::Buff { .. }) => Validation::Error(format!("Id {id} is an effect")),
Err(Error::SkillNotFound) => Validation::Error(format!("Id {id} is invalid or hidden")),
Err(_) => Validation::Ok,
Expand Down
5 changes: 4 additions & 1 deletion reffect_api/src/skill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use strum::{AsRefStr, Display, IntoStaticStr};
#[derive(Debug, Clone)]
pub enum SkillInfo {
/// Ability.
Ability,
Ability {
/// Whether the ability is an ammunition skill.
is_ammo: bool,
},

/// Buff.
Buff {
Expand Down

0 comments on commit 2031bca

Please sign in to comment.