Skip to content

Commit

Permalink
Implements rewind support (#10)
Browse files Browse the repository at this point in the history
* Implements rewind support

Allows configs to specify if produced icon states should rewind
themselves or not.

Compatability with byond, someone asked me for it
  • Loading branch information
LemonInTheDark authored Jul 12, 2024
1 parent abc9004 commit 268e553
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions examples/bitmask-slice.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ y = 16
# If you do not provide a delay for each frame (ie, two delays for 4 frames,) the delay values
# will cycle until the list is full. ie, 10,20 for 5 frames becomes 10,20,10,20,10 and so on.
delays = [10, 20]
# Rewind is a boolean that maps directly to byond, if it's true animations will play,
# then animate "backwards" to the start.
# Defaults to false
rewind = false

# Settings for generating a unique map icon for each icon_state
# This entire section is optional
Expand Down
1 change: 1 addition & 0 deletions hypnagogic_core/src/config/blocks/cutters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ impl<'de> Deserialize<'de> for PrefabOverlays {
#[derive(Clone, PartialEq, Debug, Default, Serialize, Deserialize)]
pub struct Animation {
pub delays: Vec<f32>,
pub rewind: Option<bool>,
}

#[derive(Clone, Eq, PartialEq, Debug)]
Expand Down
4 changes: 4 additions & 0 deletions hypnagogic_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#![allow(clippy::cast_sign_loss)]
// error we can't do anything about because of dependancies
#![allow(clippy::multiple_crate_versions)]
// map makes less sense in some contexts
#![allow(clippy::bind_instead_of_map)]
// throws in cases where `` obfuscates what's going on (code links)
#![allow(clippy::doc_markdown)]

pub mod config;
pub mod generation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,17 @@ impl IconOperationConfig for BitmaskDirectionalVis {
possible_states,
);

let delay = self
let delay: Option<Vec<f32>> = self
.bitmask_slice_config
.animation
.clone()
.map(|x| repeat_for(&x.delays, num_frames as usize));
let rewind = self
.bitmask_slice_config
.animation
.as_ref()
.and_then(|animation| animation.rewind)
.unwrap_or(false);

let mut icon_states = vec![];

Expand Down Expand Up @@ -111,6 +117,7 @@ impl IconOperationConfig for BitmaskDirectionalVis {
frames: num_frames,
images: icon_state_frames,
delay: delay.clone(),
rewind,
..Default::default()
}));
}
Expand Down Expand Up @@ -153,6 +160,7 @@ impl IconOperationConfig for BitmaskDirectionalVis {
frames: num_frames,
images: icon_state_frames,
delay: delay.clone(),
rewind,

..Default::default()
}));
Expand Down
6 changes: 6 additions & 0 deletions hypnagogic_core/src/operations/cutters/bitmask_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ impl IconOperationConfig for BitmaskSlice {
.animation
.clone()
.map(|x| repeat_for(&x.delays, num_frames as usize));
let rewind = self
.animation
.as_ref()
.and_then(|animation| animation.rewind)
.unwrap_or(false);

let states_to_gen = (0..possible_states)
.map(|x| Adjacency::from_bits(x as u8).unwrap())
Expand All @@ -138,6 +143,7 @@ impl IconOperationConfig for BitmaskSlice {
frames: num_frames,
images: icon_state_frames,
delay: delay.clone(),
rewind,
..Default::default()
}));
}
Expand Down
7 changes: 7 additions & 0 deletions hypnagogic_core/src/operations/cutters/bitmask_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ impl IconOperationConfig for BitmaskWindows {
.animation
.clone()
.map(|x| repeat_for(&x.delays, num_frames as usize));
let rewind = self
.animation
.as_ref()
.and_then(|animation| animation.rewind)
.unwrap_or(false);

let mut states = vec![];

Expand Down Expand Up @@ -132,6 +137,7 @@ impl IconOperationConfig for BitmaskWindows {
frames: num_frames,
images: upper_frames,
delay: delay.clone(),
rewind,
..Default::default()
}));
states.push(dedupe_frames(IconState {
Expand All @@ -140,6 +146,7 @@ impl IconOperationConfig for BitmaskWindows {
frames: num_frames,
images: lower_frames,
delay: delay.clone(),
rewind,
..Default::default()
}));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl IconOperationConfig for BitmaskSliceReconstruct {
.clone()
.into_iter()
.filter_map(|(mut state, suffix)| {
state.name = suffix.clone();
state.name.clone_from(&suffix);
if bespoke.get(suffix.as_str()).is_some() {
bespoke_found.push(suffix);
Some(state)
Expand Down Expand Up @@ -161,6 +161,10 @@ impl IconOperationConfig for BitmaskSliceReconstruct {
let delays: Option<Vec<f32>> = trimmed_frames
.first()
.and_then(|first_frame| first_frame.delay.clone());
let rewind = trimmed_frames
.first()
.and_then(|first_frame| Some(first_frame.rewind))
.unwrap_or(false);

let mut problem_states: Vec<InconsistentDelay> = vec![];
for (x, state) in trimmed_frames.into_iter().enumerate() {
Expand Down Expand Up @@ -211,6 +215,9 @@ impl IconOperationConfig for BitmaskSliceReconstruct {
if let Some(actual_delay) = delays {
config.push("[animation]".to_string());
config.push(format!("delays = {}", text_delays(&actual_delay, "")));
if rewind {
config.push(format!("rewind = {rewind}"));
}
config.push(String::new());
};
config.push("[icon_size]".to_string());
Expand Down

0 comments on commit 268e553

Please sign in to comment.