Skip to content

Commit

Permalink
Fix old threshold migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Jul 25, 2024
1 parent ff08d58 commit 32c64e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "reffect"
version = "0.2.2"
version = "0.2.3"
authors = ["Zerthox"]
edition = "2021"
description = "Customizable effect & resource displays"
Expand Down
18 changes: 17 additions & 1 deletion src/trigger/progress/threshold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use nexus::imgui::{ComboBoxFlags, Ui};
use serde::{Deserialize, Serialize};

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct ProgressThreshold {
/// Threshold type.
pub threshold_type: ThresholdType,

/// Amount type.
#[serde(default)] // TODO: move up after migration period
pub amount_type: AmountType,
}

Expand Down Expand Up @@ -72,3 +72,19 @@ impl RenderOptions for ProgressThreshold {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::serde_migrate::Migrate;

#[test]
fn migrate() {
let old_json = "{ \"Between\": [1, 23] }";

let result = serde_json::from_str::<Migrate<ProgressThreshold, ThresholdType>>(&old_json);
assert!(result.is_ok());
let threshold = result.unwrap().inner;
assert_eq!(threshold.threshold_type, ThresholdType::Between(1.0, 23.0));
}
}
4 changes: 3 additions & 1 deletion src/trigger/progress/threshold/threshold_type.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use serde::{Deserialize, Serialize};
use strum::{AsRefStr, EnumIter, IntoStaticStr, VariantArray};

#[derive(Debug, Default, Clone, AsRefStr, IntoStaticStr, EnumIter, Serialize, Deserialize)]
#[derive(
Debug, Default, Clone, PartialEq, AsRefStr, IntoStaticStr, EnumIter, Serialize, Deserialize,
)]
pub enum ThresholdType {
/// Always met.
Always,
Expand Down

0 comments on commit 32c64e2

Please sign in to comment.