Skip to content

Commit

Permalink
stains seem to work?
Browse files Browse the repository at this point in the history
  • Loading branch information
bgkillas committed Jan 16, 2025
1 parent a55074e commit c5edb7a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
34 changes: 23 additions & 11 deletions ewext/noita_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ impl EntityID {
}

pub fn set_game_effects(self, game_effect: &Option<Vec<GameEffectData>>) {
if !self.is_alive() {
return;
}
fn set_frames(ent: EntityID) -> eyre::Result<()> {
if let Some(effect) =
ent.try_get_first_component_including_disabled::<GameEffectComponent>(None)?
Expand Down Expand Up @@ -320,16 +317,27 @@ impl EntityID {
let _ = raw::entity_add_child(self.0.get() as i32, child.0.get() as i32);
}

pub fn get_current_stains(self) -> u64 {
//todo!()
0
pub fn get_current_stains(self) -> eyre::Result<u64> {
let mut current = 0;
if let Ok(Some(status)) = self.try_get_first_component::<StatusEffectDataComponent>(None) {
for (i, v) in status.0.stain_effects()?.iter().enumerate() {
if *v >= 0.15 {
current += 1 << i
}
}
}
Ok(current)
}

pub fn set_current_stains(self, _current_stains: u64) {
/*if !self.is_alive() {
return;
}*/
//todo!()
pub fn set_current_stains(self, current_stains: u64) -> eyre::Result<()> {
if let Ok(Some(status)) = self.try_get_first_component::<StatusEffectDataComponent>(None) {
for (i, v) in status.0.stain_effects()?.iter().enumerate() {
if *v >= 0.15 && current_stains & (1 << i) == 0 {
raw::entity_remove_stain_status_effect(self.0.get() as i32, i.to_string().into(), None)?
}
}
}
Ok(())
}

pub fn set_components_with_tag_enabled(
Expand Down Expand Up @@ -374,6 +382,10 @@ impl ComponentID {
self, object, key, value)?;
Ok(())
}

pub fn stain_effects(self) -> eyre::Result<Vec<f32>> {
raw::component_get_value(self, "stain_effects")
}
}

pub fn game_print(value: impl AsRef<str>) {
Expand Down
3 changes: 3 additions & 0 deletions ewext/noita_api_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum Typ {
StdString,
#[serde(rename = "vec2")]
Vec2,
#[serde(rename = "vec_float")]
VectorFloat,
EntityID,
#[serde(rename = "int64")]
Int64,
Expand All @@ -40,6 +42,7 @@ impl Typ {
Typ::Bool => quote!(bool),
Typ::StdString => quote!(Cow<'_, str>),
Typ::Vec2 => quote! {(f32, f32)},
Typ::VectorFloat => quote! {Vec<f32>},
Typ::EntityID => quote! { Option<EntityID> },
Typ::Int64 => quote! { i64 },
Typ::GameEffectEnum => quote! { GameEffectEnum },
Expand Down
4 changes: 2 additions & 2 deletions ewext/src/modules/entity_sync/diff_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl LocalDiffModelTracker {
.collect::<Vec<GameEffectData>>()
});

info.current_stains = entity.get_current_stains();
info.current_stains = entity.get_current_stains()?;

if let Ok(sprites) = entity.iter_all_components_of_type::<SpriteComponent>(None) {
info.animations = sprites
Expand Down Expand Up @@ -998,7 +998,7 @@ impl RemoteDiffModel {

entity.set_game_effects(&entity_info.game_effects);

entity.set_current_stains(entity_info.current_stains);
entity.set_current_stains(entity_info.current_stains)?;

if let Ok(sprites) = entity.iter_all_components_of_type::<SpriteComponent>(None)
{
Expand Down

0 comments on commit c5edb7a

Please sign in to comment.