Skip to content

Commit

Permalink
KID improvements, color cleanup, dead code pruning.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceejbot committed Jan 13, 2024
1 parent afe2145 commit 937d25e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 46 deletions.
11 changes: 4 additions & 7 deletions installer/core/SoulsyHUD_KID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@ Keyword = OCF_InvColorWhite|Armor|0x805~EldenRingLantern.esp

; Effects granted by some minor powers and spells
; Bats vampire lord spell "Bats Effect" [MGEF:0200E654]
Keyword = Soulsy_Power_Bats|Magic Effect|DLC1VQ08BatsEffect|NONE|100
Keyword = Soulsy_Power_Bats|Spell|DLC1VQ08Bats|NONE|100
Keyword = Soulsy_Power_Bats|Spell|DLC1VampireBats|NONE|100
Keyword = Soulsy_Power_Bats|Magic Effect|0x0200E654|NONE|100
Keyword = Soulsy_Power_Vampire|Spell|DLC1VampireChange|NONE|100
Keyword = Soulsy_Power_Vampire|Magic Effect|DLC1VampireChangeEffect|NONE|100
Keyword = Soulsy_Power_RevertForm|Spell|DLC1RevertForm|NONE|100
Keyword = Soulsy_Power_Bats|Magic Effect|DLC1BatsEffect
;Keyword = Soulsy_Power_Vampire|Spell|DLC1VampireChange|NONE|100
;Keyword = Soulsy_Power_Vampire|Magic Effect|DLC1VampireChangeEffect|NONE|100
;Keyword = Soulsy_Power_RevertForm|Spell|DLC1RevertForm|NONE|100

; Spells associated with shouts.
; We can't assign keywords to shouts directly, so we use their spells.
Expand Down
39 changes: 11 additions & 28 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ pub fn hud_item_from_keywords(
Box::new(result)
}

pub fn categorize_shout(
keywords_ffi: &CxxVector<CxxString>,
name: String,
form_string: String,
) -> Box<HudItem> {
let keywords: Vec<String> = keywords_ffi.iter().map(|xs| xs.to_string()).collect();
let kind = BaseType::Shout(ShoutType::new(keywords));
let result = HudItem::preclassified(name, form_string, 1, kind);
Box::new(result)
}

pub fn fill_out_spell_data(
hostile: bool,
resist: i32,
Expand Down Expand Up @@ -87,17 +98,6 @@ pub fn magic_from_spelldata(
Box::new(result)
}

pub fn categorize_shout(
keywords_ffi: &CxxVector<CxxString>,
name: String,
form_string: String,
) -> Box<HudItem> {
let keywords: Vec<String> = keywords_ffi.iter().map(|xs| xs.to_string()).collect();
let kind = BaseType::Shout(ShoutType::new(keywords));
let result = HudItem::preclassified(name, form_string, 1, kind);
Box::new(result)
}

pub fn simple_from_formdata(kind: ItemCategory, name: String, form_string: String) -> Box<HudItem> {
let classification = match kind {
ItemCategory::Book => BaseType::Book,
Expand Down Expand Up @@ -175,23 +175,6 @@ pub trait HasKeywords {
fn classify(name: &str, keywords: Vec<String>, twohanded: bool) -> Self;
}

// A generic convert keywords to enum variants function.
pub fn strings_to_keywords<T: for<'a> TryFrom<&'a str>>(tags: &[String]) -> Vec<T> {
let keywords: Vec<T> = tags
.iter()
.filter_map(|xs| {
if let Ok(subtype) = T::try_from(xs.as_str()) {
Some(subtype)
} else {
log::trace!("Unknown keyword: '{xs}';");

None
}
})
.collect();
keywords
}

// Generic convert keywords to an enum set.
pub fn strings_to_enumset<T: EnumSetType + for<'a> TryFrom<&'a str>>(
tags: &[String],
Expand Down
12 changes: 8 additions & 4 deletions src/data/power.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::color::InvColor;
use super::keywords::*;
use super::{strings_to_enumset, HasIcon};
use crate::data::color::color_from_keywords;
use crate::images::Icon;
use crate::plugin::Color;

Expand All @@ -22,10 +23,13 @@ impl PowerType {
Icon::Power
};

PowerType {
icon,
color: color_for_tagset(&kywds).unwrap_or_default(),
}
let color = if let Some(c) = color_from_keywords(&tags) {
c
} else {
color_for_tagset(&kywds).unwrap_or_default()
};

PowerType { icon, color }
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/data/spell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
use enumset::EnumSet;

use super::color::InvColor;
use super::color::{color_from_keywords, InvColor};
use super::keywords::*;
use super::magic::{School, SpellData};
use super::{strings_to_enumset, strings_to_keywords, HasIcon};
use super::{strings_to_enumset, HasIcon};
use crate::images::icons::Icon;
use crate::plugin::Color;

Expand Down Expand Up @@ -51,11 +51,10 @@ impl SpellType {

// Colors. We base this on damage type, mostly, but first we look to see
// if we have a color keyword.
let color_kwds = strings_to_keywords::<InvColor>(&tags);
let color = if let Some(assigned) = color_kwds.first() {
assigned.clone()
} else if let Some(color) = color_for_tagset(&tagset) {
color
let color = if let Some(c) = color_from_keywords(&tags) {
c
} else if let Some(c) = color_for_tagset(&tagset) {
c
} else {
match data.school {
// TODO identify common colors for magical schools
Expand Down

0 comments on commit 937d25e

Please sign in to comment.