Skip to content

Commit

Permalink
Fix map history arbitrary lookup
Browse files Browse the repository at this point in the history
There was a bug that meant the get_date function didn't work for non-i-frames. Fixed that, so we can now properly lookup any date in the game's timespan
  • Loading branch information
2kai2kai2 committed Jun 16, 2024
1 parent 1ce2c4c commit 3f829cb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,10 @@ pub async fn do_webgl(history: &str, base_url: &str) -> Result<JsValue, JsValue>
let Ok(date) = date.parse::<EU4Date>() else {
return Err(JsError::new("Invalid date.").into());
};

current_date = date;
let Some(frame) = history.get_date(&date) else {
return Err(JsError::new("Unable to resolve the map state at this date. It may be outside the game's timespan.").into());
};
current_date = date;

current_frame = frame;
log!("{current_date}");
Expand Down
2 changes: 1 addition & 1 deletion src/map_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl ColorMapManager {
}

let (mut iter_date, mut i_frame) =
EU4Date::iter_range_inclusive_reversed(*date, date.with_year(date.year - 1))
EU4Date::iter_range_inclusive_reversed(date.with_year(date.year - 1), *date)
.find_map(|d| Some((d, self.i_frames.get(&d)?.clone())))?;
while iter_date < *date {
self.apply_diffs(&iter_date, &mut i_frame);
Expand Down

0 comments on commit 3f829cb

Please sign in to comment.