Skip to content

Commit

Permalink
Adjust internal api
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Dec 20, 2024
1 parent cfccd63 commit b69cefa
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 93 deletions.
17 changes: 8 additions & 9 deletions reffect/src/addon/ui/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use super::Addon;
use crate::{
context::Context,
internal::Resources,
internal::{BuffInfoMap, BuffMap, Error, Interface, Internal},
internal::{BuffMap, Error, Interface, Internal},
render::colors::{Colored, GREEN, RED},
};
use nexus::imgui::{StyleColor, Ui, Window};
use reffect_internal::{Slot, State};
use reffect_internal::{SkillInfo, Slot, State};
use std::fmt;
use strum::IntoEnumIterator;

Expand All @@ -18,7 +18,6 @@ impl Addon {
.opened(&mut self.debug)
.build(ui, || {
let ctx = &self.context;
let infos = Internal::get_buff_infos().as_ref().ok();

ui.text(format!("Show elements: {}", ctx.ui.should_show()));

Expand Down Expand Up @@ -129,20 +128,20 @@ impl Addon {
ui.text("Own buffs:");
ui.same_line();
debug_result(ui, own_buffs.as_ref(), |buffs| {
buffs_tooltip(ui, ctx, infos, buffs)
buffs_tooltip(ui, ctx, buffs)
});

ui.text("Target buffs:");
ui.same_line();
debug_result(ui, target_buffs.as_ref(), |buffs| {
buffs_tooltip(ui, ctx, infos, buffs)
buffs_tooltip(ui, ctx, buffs)
});

for i in 0..4 {
ui.text(format!("Group Member {} buffs:", i + 1));
ui.same_line();
debug_result(ui, group_buffs.as_ref().map(|group| &group[i]), |buffs| {
buffs_tooltip(ui, ctx, infos, buffs)
buffs_tooltip(ui, ctx, buffs)
});
}

Expand Down Expand Up @@ -196,12 +195,12 @@ fn debug_result<T>(ui: &Ui, result: Result<&T, &Error>, tooltip: impl FnOnce(&T)
}
}

fn buffs_tooltip(ui: &Ui, ctx: &Context, infos: Option<&BuffInfoMap>, buffs: &BuffMap) {
fn buffs_tooltip(ui: &Ui, ctx: &Context, buffs: &BuffMap) {
for (id, buff) in buffs {
ui.text(format!("{:>2}x {id:>5}", buff.stacks));
if let Some(info) = infos.and_then(|infos| infos.get(id)) {
if let Ok(SkillInfo::Buff { category, stacking }) = Internal::get_skill_info(*id) {
ui.same_line();
ui.text(format!("{:?} {:?}", info.category, info.stacking));
ui.text(format!("{category} {stacking}"));
}
if !buff.is_infinite() {
ui.same_line();
Expand Down
19 changes: 9 additions & 10 deletions reffect/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ mod edit_state;
mod links;
mod map;
mod player;
mod settings;
mod ui;

pub use self::{edit_state::*, links::*, map::*, player::*, settings::*, ui::*};
pub use self::{edit_state::*, links::*, map::*, player::*, ui::*};

use crate::{
internal::{BuffMap, Interface, Internal, Resources, State},
Expand All @@ -17,10 +16,6 @@ use enumflags2::{bitflags, BitFlags};
use reffect_internal::Skillbar;
use windows::Win32::Media::timeGetTime;

const OWN_INTERVAL: u32 = 100;

const PLAYER_INTERVAL: u32 = 1_000;

#[derive(Debug, Clone)]
pub struct Context {
/// Current system time.
Expand Down Expand Up @@ -58,6 +53,10 @@ pub struct Context {
}

impl Context {
pub const DEFAULT_STATE_INTERVAL: u32 = 100;

pub const DEFAULT_PLAYER_INTERVAL: u32 = 1_000;

/// Updates the context.
pub fn update(&mut self) {
self.updates = BitFlags::empty();
Expand Down Expand Up @@ -113,8 +112,8 @@ impl Context {

/// Resets the intervals for all updates.
pub fn reset_intervals(&mut self) {
self.state_interval.frequency = OWN_INTERVAL;
self.player_interval.frequency = PLAYER_INTERVAL;
self.state_interval.frequency = Self::DEFAULT_STATE_INTERVAL;
self.player_interval.frequency = Self::DEFAULT_PLAYER_INTERVAL;
}

/// Returns the [`Resources`] for the own character, if present.
Expand Down Expand Up @@ -144,8 +143,8 @@ impl Default for Context {
map: MapContext::empty(),
state: State::disabled(),
links: Links::load(),
state_interval: Interval::new(OWN_INTERVAL),
player_interval: Interval::new(PLAYER_INTERVAL),
state_interval: Interval::new(Self::DEFAULT_STATE_INTERVAL),
player_interval: Interval::new(Self::DEFAULT_PLAYER_INTERVAL),
save_on_unload: true,
font: LoadedFont::empty(),
icon_settings: IconSettings::default(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{Context, OWN_INTERVAL, PLAYER_INTERVAL};
use crate::settings::icon::IconSettings;
use super::icon::IconSettings;
use crate::context::Context;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -27,8 +27,8 @@ impl Default for ContextSettings {
edit_during_combat: false,
edit_show_all: false,
font: None,
state_interval: OWN_INTERVAL,
player_interval: PLAYER_INTERVAL,
state_interval: Context::DEFAULT_STATE_INTERVAL,
player_interval: Context::DEFAULT_PLAYER_INTERVAL,
icon: IconSettings::default(),
}
}
Expand Down
4 changes: 3 additions & 1 deletion reffect/src/settings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
mod context;
pub mod icon;

use self::context::ContextSettings;
use super::Addon;
use crate::context::{Context, ContextSettings};
use crate::context::Context;
use serde::{Deserialize, Serialize};
use std::{
fs::File,
Expand Down
22 changes: 13 additions & 9 deletions reffect/src/trigger/progress/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
render_util::{enum_combo, helper, impl_static_variants, input_skill_id, Validation},
};
use nexus::imgui::{ComboBoxFlags, InputTextFlags, Ui};
use reffect_internal::{Buff, Category, Slot};
use reffect_internal::{Buff, Category, Error, SkillInfo, Slot};
use serde::{Deserialize, Serialize};
use strum::{AsRefStr, EnumIter, IntoStaticStr};

Expand Down Expand Up @@ -164,18 +164,22 @@ impl ProgressSource {
}

fn buff_validate(id: u32) -> Validation<impl AsRef<str>> {
if let Ok(infos) = Internal::get_buff_infos() {
if let Some(info) = infos.get(&id) {
if info.category == Category::ScreenBorder {
Validation::Warn(format!("{} {id} is only valid for yourself", info.category))
match Internal::get_skill_info(id) {
Ok(SkillInfo::Buff {
category,
stacking: _,
}) => {
if category == Category::ScreenBorder {
Validation::Warn(format!("{category} {id} is only valid for yourself"))
} else {
Validation::Confirm(format!("{} {id} is valid", info.category))
Validation::Confirm(format!("{category} {id} is valid"))
}
} else {
}
Ok(SkillInfo::Ability) => Validation::Error(format!("Effect {id} is an ability")),
Err(Error::SkillNotFound) => {
Validation::Error(format!("Effect {id} is invalid or hidden"))
}
} else {
Validation::Ok
Err(_) => Validation::Ok,
}
}

Expand Down
3 changes: 1 addition & 2 deletions reffect/src/trigger/progress/threshold/threshold_type.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt;

use serde::{Deserialize, Serialize};
use std::fmt;
use strum::{AsRefStr, EnumIter, IntoStaticStr, VariantArray};

#[derive(
Expand Down
2 changes: 1 addition & 1 deletion reffect_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ enumflags2 = "0.7.10"
serde = { version = "1.0.214", features = ["derive"] }
strum = { version = "0.26.3", features = ["derive"] }
thiserror = "2.0.5"
windows = { workspace = true }
windows = { workspace = true, features = ["Win32_Graphics_Direct3D11"] }
52 changes: 1 addition & 51 deletions reffect_api/src/buff.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::{BTreeMap, HashMap};
use strum::{AsRefStr, Display, IntoStaticStr};
use std::collections::BTreeMap;

pub type BuffMap = BTreeMap<u32, Buff>;

Expand Down Expand Up @@ -58,52 +57,3 @@ impl Buff {
self.remaining(now) as f32 / self.duration() as f32
}
}

pub type BuffInfoMap = HashMap<u32, BuffInfo>;

/// Information about a buff.
#[derive(Debug, Clone)]
pub struct BuffInfo {
/// Id of the buff.
pub id: u32,

/// Category of the buff.
pub category: Category,

/// Stacking behavior of the buff.
pub stacking: Stacking,
}

/// Category of the buff.
///
/// Any category except for Boon and Condition is mapped to [`Category::Effect`].
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display, AsRefStr, IntoStaticStr,
)]
pub enum Category {
/// Buff is a Boon.
Boon = 0,

/// Buff is an uncategorized effect.
Effect = 1,

/// Buff is a Condition.
Condition = 2,

/// Buff is hidden but gives a screen border.
#[strum(serialize = "Screen Border")]
ScreenBorder = 3,
}

/// Stacking behavior of the buff.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Display, AsRefStr, IntoStaticStr)]
pub enum Stacking {
// Other/unknown stacking type.
Other,

/// Buff stacks in intenstity.
Intensity,

/// Buff stacks in duration.
Duration,
}
14 changes: 11 additions & 3 deletions reffect_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ mod buff;
mod error;
mod player;
mod resource;
mod skill;
mod state;

pub use self::{ability::*, buff::*, error::*, player::*, resource::*, state::*};
use windows::Win32::Graphics::Direct3D11::ID3D11ShaderResourceView;

pub use self::{ability::*, buff::*, error::*, player::*, resource::*, skill::*, state::*};

pub type Texture = ID3D11ShaderResourceView;

/// Interface for API.
pub trait Interface {
Expand All @@ -18,6 +23,9 @@ pub trait Interface {
/// Retrieves player information.
fn get_player_info() -> Result<PlayerInfo>;

/// Retrives buff information.
fn get_buff_infos() -> &'static Result<BuffInfoMap>;
/// Retrieves skill information.
fn get_skill_info(id: u32) -> Result<SkillInfo>;

/// Retrieves skill icon.
fn get_skill_icon(id: u32) -> Option<Texture>;
}
53 changes: 53 additions & 0 deletions reffect_api/src/skill.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use strum::{AsRefStr, Display, IntoStaticStr};

/// Information about a skill.
#[derive(Debug, Clone)]
pub enum SkillInfo {
/// Ability.
Ability,

/// Buff.
Buff {
/// Category of the buff.
category: Category,

/// Stacking behavior of the buff.
stacking: Stacking,
},
}

/// Category of the buff.
///
/// Any category except for Boon and Condition is mapped to [`Category::Effect`].
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display, AsRefStr, IntoStaticStr,
)]
pub enum Category {
/// Buff is a Boon.
Boon = 0,

/// Buff is an uncategorized effect.
Effect = 1,

/// Buff is a Condition.
Condition = 2,

/// Buff is hidden but gives a screen border.
#[strum(serialize = "Screen Border")]
ScreenBorder = 3,
}

/// Stacking behavior of the buff.
#[derive(
Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Display, AsRefStr, IntoStaticStr,
)]
pub enum Stacking {
// Other/unknown stacking type.
Other,

/// Buff stacks in intenstity.
Intensity,

/// Buff stacks in duration.
Duration,
}
9 changes: 6 additions & 3 deletions reffect_internal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ impl Interface for Dummy {
}

#[inline]
fn get_buff_infos() -> &'static Result<BuffInfoMap> {
static BUFF_INFOS: Result<BuffInfoMap> = Err(Error::Disabled);
fn get_skill_info(id: u32) -> Result<SkillInfo> {
Err(Error::Disabled)
}

&BUFF_INFOS
#[inline]
fn get_skill_icon(id: u32) -> Option<Texture> {
None
}
}

0 comments on commit b69cefa

Please sign in to comment.