Skip to content

Commit

Permalink
Add some funky remake transitions in!
Browse files Browse the repository at this point in the history
Twilio: burst-blended-bounce.
Spinitron: random ones with random durations too (and cool intermediate textures as well).
  • Loading branch information
CaspianA1 committed Dec 19, 2024
1 parent 4a275e6 commit 4d122fe
Show file tree
Hide file tree
Showing 29 changed files with 241 additions and 38 deletions.
Binary file added assets/bird.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/bird_boots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/brock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/business_expert.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/deer_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/deer_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/dog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/horse_cop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/house_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/house_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/lobster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/monks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/polar_board.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/putin_kim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/waltuh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/willem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
126 changes: 126 additions & 0 deletions src/dashboard_defs/funky_remake_transitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
use rand::Rng;
use std::borrow::Cow;

use crate::{
utility_types::{
time::Duration,
generic_result::*
},

texture::{
TexturePool,
TextureCreationInfo,
RemakeTransitionInfo,
TextureTransitionOpacityEaser,
TextureTransitionAspectRatioEaser
},

dashboard_defs::easing_fns,
window_tree::WindowContents
};

pub struct IntermediateTextureTransitionInfo {
pub percent_chance_to_show_rand_intermediate_texture: f64,
pub rand_duration_range_for_intermediate: (f64, f64),
pub max_random_transitions: usize
}

fn pick_from_slice<'a, T>(choices: &'a [T], rand_generator: &mut rand::rngs::ThreadRng) -> &'a T {
&choices[rand_generator.gen_range(0..choices.len())]
}

fn pick_random_easing_pair(rand_generator: &mut rand::rngs::ThreadRng)
-> (TextureTransitionOpacityEaser, TextureTransitionAspectRatioEaser) {

use easing_fns::transition::{opacity, aspect_ratio};

let easing_pairs = [
(opacity::LINEAR_BLENDED_FADE, aspect_ratio::LINEAR),
(opacity::BURST_BLENDED_FADE, aspect_ratio::LINEAR),
(opacity::FADE_OUT_THEN_FADE_IN, aspect_ratio::LINEAR),

(opacity::LINEAR_BLENDED_BOUNCE, aspect_ratio::BOUNCE),
(opacity::BURST_BLENDED_BOUNCE, aspect_ratio::BOUNCE),

(opacity::STRAIGHT_WAVY, aspect_ratio::STRAIGHT_WAVY),
(opacity::JITTER_WAVY, aspect_ratio::JITTER_WAVY)
];

*pick_from_slice(&easing_pairs, rand_generator)
}

pub fn update_as_texture_with_funky_remake_transition(
window_contents: &mut WindowContents,
texture_pool: &mut TexturePool,
texture_creation_info: &TextureCreationInfo,
duration: Duration,
rand_generator: &mut rand::rngs::ThreadRng,
get_fallback_texture_creation_info: fn() -> TextureCreationInfo<'static>,
mut intermediate_info: IntermediateTextureTransitionInfo) -> MaybeError {

//////////

let path = |base| TextureCreationInfo::Path(Cow::Borrowed(base));

let all_intermediate_texture_creation_info = [
path("assets/business_expert.jpg"),
path("assets/house_1.jpg"),
path("assets/house_2.jpg"),

path("assets/bird.jpg"),
path("assets/brock.png"),
path("assets/dog.png"),
path("assets/horse_cop.png"),
path("assets/monks.png"),
path("assets/polar_board.png"),
path("assets/putin_kim.png"),

path("assets/willem.png"),
path("assets/deer_1.png"),
path("assets/deer_2.png"),
path("assets/waltuh.png"),
path("assets/bird_boots.png"),
path("assets/lobster.png")
];

//////////

// Randomly recurring to show intermediate textures before the final one
if intermediate_info.max_random_transitions != 0 &&
rand_generator.gen_range(0.0..1.0) < intermediate_info.percent_chance_to_show_rand_intermediate_texture {

let intermediate_texture_creation_info = pick_from_slice(&all_intermediate_texture_creation_info, rand_generator);

let range = intermediate_info.rand_duration_range_for_intermediate;
let rand_duration_secs = rand_generator.gen_range(range.0..range.1);
let rand_duration_ms = (rand_duration_secs * 1000.0) as i64;

intermediate_info.max_random_transitions -= 1;

update_as_texture_with_funky_remake_transition(
window_contents, texture_pool, intermediate_texture_creation_info,
Duration::milliseconds(rand_duration_ms),
rand_generator,
get_fallback_texture_creation_info,
intermediate_info
)?;
}

////////// Making a remake transition

let easers = pick_random_easing_pair(rand_generator);

let remake_transition_info = RemakeTransitionInfo::new(
duration, easers.0, easers.1
);

////////// Updating

window_contents.update_as_texture(
true,
texture_pool,
texture_creation_info,
Some(&remake_transition_info),
get_fallback_texture_creation_info
)
}
1 change: 1 addition & 0 deletions src/dashboard_defs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod spinitron;
mod easing_fns;
mod shared_window_state;
mod updatable_text_pattern;
mod funky_remake_transitions;

pub mod error;
pub mod themes;
30 changes: 23 additions & 7 deletions src/dashboard_defs/spinitron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use std::borrow::Cow;
use crate::{
dashboard_defs::{
easing_fns,
funky_remake_transitions,
shared_window_state::SharedWindowState
},

spinitron::model::{SpinitronModelName, NUM_SPINITRON_MODEL_TYPES},

texture::{
DisplayText,
TextDisplayInfo,
TextureCreationInfo
},

utility_types::{
time::*,
vec2f::Vec2f,
generic_result::*,
update_rate::UpdateRate,
Expand All @@ -27,7 +27,9 @@ use crate::{
WindowContents,
WindowUpdaterParams,
PossibleWindowUpdater
}
},

spinitron::model::{SpinitronModelName, NUM_SPINITRON_MODEL_TYPES}
};

struct SpinitronModelWindowState {
Expand Down Expand Up @@ -87,7 +89,6 @@ pub fn make_spinitron_windows(

//////////


let texture_creation_info = if is_text_window {
let model_text = spinitron_state.model_to_string(model_name);

Expand All @@ -112,11 +113,26 @@ pub fn make_spinitron_windows(
spinitron_state.get_cached_texture_creation_info(model_name)
};

params.window.get_contents_mut().update_as_texture(
true,
//////////

let default_duration = Duration::seconds(2);

let intermediate_info = funky_remake_transitions::IntermediateTextureTransitionInfo {
percent_chance_to_show_rand_intermediate_texture: 0.3,
rand_duration_range_for_intermediate: (0.4, 1.2),
max_random_transitions: 10
};

//////////

funky_remake_transitions::update_as_texture_with_funky_remake_transition(
params.window.get_contents_mut(),
params.texture_pool,
&texture_creation_info,
inner_shared_state.get_fallback_texture_creation_info
default_duration,
&mut inner_shared_state.rand_generator,
inner_shared_state.get_fallback_texture_creation_info,
intermediate_info
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/dashboard_defs/surprise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub async fn make_surprise_window(
local_hour >= surprise_info.local_hours_24_start.into()
&& local_hour <= surprise_info.local_hours_24_end.into();

use rand::Rng; // TODO: can I use the system's rand generator instead? Less dependencies that way...
use rand::Rng;
let rand_num = rand_generator.gen::<SurpriseAppearanceChance>();

in_acceptable_hour_range && rand_num < surprise_info.chance_of_appearing_when_updating
Expand Down
13 changes: 10 additions & 3 deletions src/dashboard_defs/themes/barebones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use sdl2::{render::BlendMode, ttf::{FontStyle, Hinting}};

use crate::{
themes::shared_utils::*,
texture::{FontInfo, TextureCreationInfo, TexturePool},
spinitron::{model::SpinitronModelName, state::SpinitronState},
texture::{FontInfo, TextureCreationInfo, TexturePool, RemakeTransitionInfo},

utility_types::{
file_utils,
Expand All @@ -21,6 +21,7 @@ use crate::{
},

dashboard_defs::{
easing_fns,
credit::make_credit_window,
weather::make_weather_window,
error::{make_error_window, ErrorState},
Expand Down Expand Up @@ -64,7 +65,7 @@ pub async fn make_dashboard(
let main_windows_gap_size = 0.01;

let theme_color_1 = ColorSDL::RGB(255, 133, 133);
let shared_update_rate = update_rate_creator.new_instance(15.0);
let shared_update_rate = update_rate_creator.new_instance(10.0);
let api_keys: ApiKeys = file_utils::load_json_from_file("assets/api_keys.json").await?;

////////// Defining the Spinitron window extents
Expand Down Expand Up @@ -313,7 +314,13 @@ pub async fn make_dashboard(
&api_keys.twilio_auth_token,
11,
Duration::days(5),
false
false,

Some(RemakeTransitionInfo::new(
Duration::seconds(2),
easing_fns::transition::opacity::BURST_BLENDED_BOUNCE,
easing_fns::transition::aspect_ratio::BOUNCE
))
),

make_creation_info_for_static_texture_set(&background_static_texture_info),
Expand Down
11 changes: 9 additions & 2 deletions src/dashboard_defs/themes/retro_room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use sdl2::{render::BlendMode, ttf::{FontStyle, Hinting}};

use crate::{
themes::shared_utils::*,
texture::{FontInfo, TextureCreationInfo, TexturePool},
spinitron::{model::SpinitronModelName, state::SpinitronState},
texture::{FontInfo, TextureCreationInfo, TexturePool, RemakeTransitionInfo},

utility_types::{
file_utils,
Expand All @@ -21,6 +21,7 @@ use crate::{
},

dashboard_defs::{
easing_fns,
credit::make_credit_window,
weather::make_weather_window,
error::{make_error_window, ErrorState},
Expand Down Expand Up @@ -309,7 +310,13 @@ pub async fn make_dashboard(
&api_keys.twilio_auth_token,
3,
Duration::days(5),
false
false,

Some(RemakeTransitionInfo::new(
Duration::seconds(2),
easing_fns::transition::opacity::BURST_BLENDED_BOUNCE,
easing_fns::transition::aspect_ratio::BOUNCE
))
),

TextureCreationInfo::from_path_async("assets/alternative_text_bubble.png"),
Expand Down
11 changes: 9 additions & 2 deletions src/dashboard_defs/themes/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use sdl2::{render::BlendMode, ttf::{FontStyle, Hinting}};

use crate::{
themes::shared_utils::*,
texture::{FontInfo, TextureCreationInfo, TexturePool},
spinitron::{model::SpinitronModelName, state::SpinitronState},
texture::{FontInfo, TextureCreationInfo, TexturePool, RemakeTransitionInfo},

utility_types::{
file_utils,
Expand All @@ -21,6 +21,7 @@ use crate::{
},

dashboard_defs::{
easing_fns,
credit::make_credit_window,
weather::make_weather_window,
error::{make_error_window, ErrorState},
Expand Down Expand Up @@ -315,7 +316,13 @@ pub async fn make_dashboard(
&api_keys.twilio_auth_token,
6,
Duration::days(5),
false
false,

Some(RemakeTransitionInfo::new(
Duration::seconds(2),
easing_fns::transition::opacity::BURST_BLENDED_BOUNCE,
easing_fns::transition::aspect_ratio::BOUNCE
))
),

TextureCreationInfo::from_path_async("assets/text_bubble.png"),
Expand Down
Loading

0 comments on commit 4d122fe

Please sign in to comment.