Skip to content

Commit

Permalink
Merge branch 'master' of github.com:m00nwtchr/cofd-pc-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
m00nwtchr committed Mar 12, 2024
2 parents d46d575 + f991654 commit 544671a
Show file tree
Hide file tree
Showing 18 changed files with 2,094 additions and 792 deletions.
1,688 changes: 1,022 additions & 666 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion cofd/app/src/component/merits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ impl<Message> Component<Message, iced::Renderer> for MeritComponent<Message> {

vec.push(Merit::_Custom(fl!("custom")));

let attributes = &character.attributes();
let skills = &character.skills();

let vec: Vec<Translated<Merit>> = vec
.iter()
.cloned()
Expand All @@ -91,7 +94,7 @@ impl<Message> Component<Message, iced::Renderer> for MeritComponent<Message> {
.merits
.iter()
.filter(|(merit, _)| *merit == *e)
.count() == 0 && e.is_available(&character)
.count() == 0 && e.is_available(&character, attributes, skills)
})
.map(Into::into)
.collect();
Expand Down
2 changes: 1 addition & 1 deletion cofd/app/src/component/skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<Message> SkillsComponent<Message> {
.on_press(Event::SpecialtySkillChanged(skill)),
);

let v = character.base_skills().get(&skill);
let v = character.base_skills().get(skill);
let val = character._modified(ModifierTarget::BaseSkill(skill));
let mod_ = val - v;

Expand Down
23 changes: 10 additions & 13 deletions cofd/app/src/component/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ use iced_lazy::Component;

use cofd::{character::ArmorStruct, prelude::*};

use crate::{fl, i18n::flt, Element, INPUT_PADDING};
use crate::{
fl,
i18n::flt,
widget::dots::{Shape, SheetDots},
Element, INPUT_PADDING,
};

struct Traits {
size: u16,
Expand Down Expand Up @@ -37,7 +42,7 @@ pub fn traits_component<Message>(
}

#[derive(Clone)]
pub struct Event(String, Trait);
pub struct Event(u16, Trait);

impl<Message> TraitsComponent<Message> {
fn new(character: &Character, on_change: impl Fn(u16, Trait) -> Message + 'static) -> Self {
Expand Down Expand Up @@ -67,22 +72,14 @@ impl<Message> Component<Message, iced::Renderer> for TraitsComponent<Message> {
type Event = Event;

fn update(&mut self, _state: &mut Self::State, event: Self::Event) -> Option<Message> {
if let Ok(val) = event.0.parse() {
Some((self.on_change)(val, event.1))
} else if event.0.is_empty() {
Some((self.on_change)(0, event.1))
} else {
None
}
Some((self.on_change)(event.0, event.1))
}

fn view(&self, _state: &Self::State) -> Element<Self::Event> {
let beats = row![
text(format!("{}:", fl!("beats"))),
text_input("", &format!("{}", self.traits.beats), |val| {
// if let Some(val) = val.parse() {
Event(val, Trait::Beats)
// }
Event(val.parse().unwrap_or(0), Trait::Beats)
})
.padding(INPUT_PADDING)
];
Expand All @@ -94,7 +91,7 @@ impl<Message> Component<Message, iced::Renderer> for TraitsComponent<Message> {
flt(&self.traits.splat, Some("beats")).unwrap()
)),
text_input("", &format!("{}", self.traits.alternate_beats), |val| {
Event(val, Trait::AlternateBeats)
Event(val.parse().unwrap_or(0), Trait::AlternateBeats)
})
.padding(INPUT_PADDING)
]
Expand Down
10 changes: 7 additions & 3 deletions cofd/app/src/view/overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub enum Event {
// YSplatChanged(YSplat),
AbilityValChanged(Ability, u16),
AbilityChanged(Ability, Ability),
NewAbility(Ability),
MeritChanged(usize, Merit, u16),
// CustomAbilityChanged(Ability, String),
HealthChanged(Wound),
Expand Down Expand Up @@ -165,7 +166,7 @@ impl<Message> OverviewTab<Message> {
}

new = new.push(
pick_list(vec, None, |key| Event::AbilityValChanged(key.unwrap(), 0))
pick_list(vec, None, |key| Event::NewAbility(key.unwrap()))
.width(Length::Fill)
.padding(INPUT_PADDING)
.text_size(20),
Expand Down Expand Up @@ -199,7 +200,7 @@ where

match event {
Event::AttrChanged(val, attr) => *character.base_attributes_mut().get_mut(&attr) = val,
Event::SkillChanged(val, skill) => *character.base_skills_mut().get_mut(&skill) = val,
Event::SkillChanged(val, skill) => *character.base_skills_mut().get_mut(skill) = val,
Event::SpecialtyChanged(skill, i, val) => {
if let Some(vec) = character.specialties.get_mut(&skill) {
if val.is_empty() {
Expand All @@ -224,7 +225,10 @@ where
if character.has_ability(&ability) {
let val = character.remove_ability(&ability).unwrap_or_default();
character.add_ability(new, val);
} else {
}
}
Event::NewAbility(ability) => {
if !character.has_ability(&ability) {
character.add_ability(ability, 0);
}
}
Expand Down
Loading

0 comments on commit 544671a

Please sign in to comment.