Skip to content

Commit

Permalink
Adjust skillbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Dec 30, 2024
1 parent 91159ac commit 62efc08
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 252 deletions.
30 changes: 6 additions & 24 deletions reffect/src/addon/ui/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,49 +76,31 @@ impl Addon {
ui.text("Own skillbar:");
ui.same_line();
debug_result(ui, own_skillbar.as_ref(), |skillbar| {
let passed = skillbar.passed(ctx.now);

if let Some(weapon) = &skillbar.weapon_swap {
ui.text(format!(
"{:<14} = {:.1}/{:.1}s",
"Weapon Swap",
to_secs(weapon.recharge_remaining(ctx.now)),
to_secs(weapon.recharge),
));
}

if let Some(legend) = &skillbar.legend_swap {
ui.text(format!(
"{:<14} = {:.1}/{:.1}s",
"Legend Swap",
to_secs(legend.recharge_remaining(ctx.now)),
to_secs(legend.recharge),
));
}

let now = ctx.now;
ui.text(format!("Bundle: {}", skillbar.has_bundle));
for slot in Slot::iter() {
if let Some(ability) = skillbar.slot(slot) {
ui.text(format!("{slot:<14} = {}x {:>5}", ability.ammo, ability.id));

let recharge = ability.recharge_remaining(passed);
let recharge = ability.recharge_remaining(now);
if recharge > 0 {
ui.same_line();
ui.text(format!(
"{:.1}/{:.1}s {:.1}%",
to_secs(recharge),
to_secs(ability.recharge),
100.0 * ability.recharge_progress(passed)
100.0 * ability.recharge_progress(now)
));
}

let ammo_recharge = ability.ammo_recharge_remaining(passed);
let ammo_recharge = ability.ammo_recharge_remaining(now);
if ammo_recharge > 0 {
ui.same_line();
ui.text(format!(
"Ammo {:.1}/{:.1}s {:.1}%",
to_secs(ammo_recharge),
to_secs(ability.ammo_recharge),
100.0 * ability.ammo_recharge_progress(passed)
100.0 * ability.ammo_recharge_progress(now)
));
}
}
Expand Down
52 changes: 29 additions & 23 deletions reffect/src/trigger/progress/active.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use reffect_internal::{Skillbar, Slot};

use crate::{
fmt::{Time, Unit},
internal::{Ability, Buff, Recharge, Resource, Skillbar},
internal::{Ability, Buff, Resource},
settings::FormatSettings,
};

Expand Down Expand Up @@ -57,47 +59,34 @@ impl ProgressActive {
}
}

/// Creates new timed active progress from a recharge.
pub fn from_recharge(skill: Skill, recharge: &Recharge) -> Self {
let duration = recharge.recharge;
Self::Ability {
skill,
ammo: if duration == 0 { 1 } else { 0 },
recharge: duration,
end: recharge.end(),
ammo_recharge: 0,
ammo_end: 0,
rate: 1.0,
}
}

/// Creates new timed active progress from a skillbar and ability.
pub fn from_ability(skillbar: &Skillbar, ability: &Ability) -> Self {
/// Creates new timed active progress from an ability.
pub fn from_ability(skill: Skill, ability: &Ability) -> Self {
let Ability {
id,
id: _,
ammo,
last_update,
recharge_rate,
recharge,
recharge_remaining,
ammo_recharge,
ammo_recharge_remaining,
} = *ability;
Self::Ability {
skill: id.into(),
skill,
ammo,
recharge,
end: if recharge > 0 {
skillbar.last_update + Self::unscale(recharge_remaining, skillbar.recharge_rate)
last_update + Self::unscale(recharge_remaining, recharge_rate)
} else {
0
},
ammo_recharge,
ammo_end: if ammo_recharge > 0 {
skillbar.last_update
+ Self::unscale(ammo_recharge_remaining, skillbar.recharge_rate)
last_update + Self::unscale(ammo_recharge_remaining, recharge_rate)
} else {
0
},
rate: skillbar.recharge_rate,
rate: recharge_rate,
}
}

Expand Down Expand Up @@ -344,6 +333,23 @@ pub enum Skill {
Id(u32),
}

impl Skill {
pub fn from_slot(skillbar: &Skillbar, slot: Slot) -> Self {
if slot == Slot::WeaponSwap {
if skillbar.has_bundle {
Skill::BundleDrop
} else {
Skill::WeaponSwap
}
} else {
skillbar
.slot(slot)
.map(|ability| ability.id.into())
.unwrap_or_default()
}
}
}

impl From<u32> for Skill {
fn from(id: u32) -> Self {
Self::Id(id)
Expand Down
3 changes: 1 addition & 2 deletions reffect/src/trigger/progress/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
mod active;
mod slot;
mod source;
mod threshold;

pub use self::{active::*, slot::*, source::*, threshold::*};
pub use self::{active::*, source::*, threshold::*};

use crate::{
context::{Context, ContextUpdate},
Expand Down
142 changes: 0 additions & 142 deletions reffect/src/trigger/progress/slot.rs

This file was deleted.

23 changes: 16 additions & 7 deletions reffect/src/trigger/progress/source.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{ProgressActive, Slot};
use super::{ProgressActive, Skill};
use crate::{
action::Action,
context::Context,
internal::{Buff, Category, Error, Interface, Internal, SkillInfo},
internal::{Buff, Category, Error, Interface, Internal, SkillInfo, Slot},
render::RenderOptions,
render_util::{enum_combo, helper, impl_static_variants, input_skill_id, Validation},
};
Expand Down Expand Up @@ -88,11 +88,20 @@ impl ProgressSource {
}
ProgressActive::from_buff(ids.first().copied().unwrap_or(0), &combined)
}),
Self::SkillbarSlot(slot) => slot.get_progress(ctx.own_skillbar()?),
Self::Ability(id) => {
Self::SkillbarSlot(slot) => {
let skillbar = ctx.own_skillbar()?;
let ability = skillbar.ability(id)?;
Some(ProgressActive::from_ability(skillbar, ability))
let ability = skillbar.slot(slot)?;
let skill = Skill::from_slot(skillbar, slot);
Some(ProgressActive::from_ability(skill, ability))
}
Self::Ability(id) => {
if id > 0 {
let skillbar = ctx.own_skillbar()?;
let ability = skillbar.ability(id)?;
Some(ProgressActive::from_ability(ability.id.into(), ability))
} else {
None
}
}
Self::Health => ctx.own_resources()?.health.clone().try_into().ok(),
Self::Barrier => ctx.own_resources()?.barrier.clone().try_into().ok(),
Expand All @@ -115,7 +124,7 @@ impl ProgressSource {
Self::SkillbarSlot(slot) => {
let skill = ctx
.own_skillbar()
.and_then(|skillbar| slot.get_skill(skillbar))
.map(|skillbar| Skill::from_slot(skillbar, slot))
.unwrap_or_default();
ProgressActive::edit_ability(skill, progress, ctx.now)
}
Expand Down
Loading

0 comments on commit 62efc08

Please sign in to comment.