-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
346 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::rc::Rc; | ||
use rand::Rng; | ||
use slint::{Timer, TimerMode, VecModel}; | ||
use crate::ui::*; | ||
|
||
struct SnowflakeModel { | ||
x: f32, | ||
y: f32, | ||
x_velocity: f32, | ||
y_velocity: f32 | ||
} | ||
|
||
impl From<&mut SnowflakeModel> for Snowflake { | ||
fn from(val: &mut SnowflakeModel) -> Snowflake { | ||
Snowflake{ | ||
x: val.x.into(), | ||
y: val.y.into() | ||
} | ||
} | ||
} | ||
|
||
|
||
pub fn setup_snow(main_window: &MainWindow) -> Timer { | ||
|
||
let snow_timer = Timer::default(); | ||
let mut rng = rand::thread_rng(); | ||
|
||
let snow_handle = main_window.as_weak(); | ||
let width = main_window.window().size().width; | ||
let height = main_window.window().size().height; | ||
|
||
|
||
let mut flurry = vec!(); | ||
for _ in 0..100 { | ||
let snowflake = SnowflakeModel { | ||
x: rng.gen_range(0.0..width as f32), | ||
y: rng.gen_range(0.0..height as f32), | ||
x_velocity: rng.gen_range(-1.0..1.0), | ||
y_velocity: rng.gen_range(0.5..2.0) | ||
}; | ||
flurry.push(snowflake); | ||
} | ||
|
||
snow_timer.start(TimerMode::Repeated, std::time::Duration::from_millis(10), move || { | ||
let snowflakes : VecModel<Snowflake> = VecModel::default(); | ||
for flake in &mut flurry { | ||
flake.x += flake.x_velocity; | ||
flake.y += flake.y_velocity; | ||
|
||
// bounce snowflake if out of bounds | ||
if flake.x < -15.0 { | ||
flake.x = -15.0; | ||
flake.x_velocity = -flake.x_velocity; | ||
} else if flake.x > width as f32 { | ||
flake.x = width as f32; | ||
flake.x_velocity = -flake.x_velocity; | ||
} | ||
|
||
// move flake to top when exiting bottom | ||
if flake.y > height as f32 { | ||
flake.y = 0.0; | ||
} | ||
snowflakes.push(flake.into()); | ||
} | ||
snow_handle.unwrap().set_snowflakes(Rc::new(snowflakes).into()); | ||
}); | ||
|
||
snow_timer | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
use crate::{ui::*, StaticAssets}; | ||
use rand::Rng; | ||
use slint::{Image, LogicalPosition, Rgba8Pixel, SharedPixelBuffer, Timer, TimerMode}; | ||
|
||
pub fn setup_halloween_spooky_face(main_window: &MainWindow) -> Timer { | ||
let halloween_timer = Timer::default(); | ||
let halloween_handle = main_window.as_weak(); | ||
|
||
let width = main_window.window().size().width; | ||
let height = main_window.window().size().height; | ||
let mut rng = rand::thread_rng(); | ||
|
||
halloween_timer.start( | ||
TimerMode::Repeated, | ||
std::time::Duration::from_secs(10), | ||
move || { | ||
let mut current_spooky = halloween_handle.unwrap().get_spooky_face(); | ||
if current_spooky.hidden { | ||
let face_width = rng.gen_range(100..500); | ||
let x_pos = rng.gen_range(0..width - (face_width + 20)); | ||
let y_pos = rng.gen_range(0..height - (face_width + 20)); | ||
let spooky_face = SpookyFace { | ||
pos: LogicalPosition { | ||
x: x_pos as f32, | ||
y: y_pos as f32, | ||
}, | ||
size: face_width as f32, | ||
hidden: false, | ||
}; | ||
halloween_handle.unwrap().set_spooky_face(spooky_face); | ||
} else { | ||
current_spooky.hidden = true; | ||
halloween_handle.unwrap().set_spooky_face(current_spooky); | ||
} | ||
}, | ||
); | ||
|
||
halloween_timer | ||
} | ||
|
||
pub fn setup_halloween_bat(main_window: &MainWindow) -> Timer { | ||
let width = main_window.window().size().width; | ||
let height = main_window.window().size().height; | ||
|
||
let timer = Timer::default(); | ||
let mut rng = rand::thread_rng(); | ||
let frames = read_bat_frames(); | ||
let handle = main_window.as_weak(); | ||
let mut frame_number = 0; | ||
let mut current_pos = LogicalPosition { x: 0.0, y: 0.0 }; | ||
|
||
timer.start( | ||
TimerMode::Repeated, | ||
std::time::Duration::from_millis(100), | ||
move || { | ||
let frame = &frames.clone()[frame_number % 9]; | ||
let bat = Bat { | ||
frame: frame.clone(), | ||
pos: current_pos, | ||
size: 200 as f32, | ||
}; | ||
|
||
if frame_number % 200 == 0 { | ||
current_pos = LogicalPosition { | ||
x: rng.gen_range(0.0..width as f32), | ||
y: rng.gen_range(0.0..height as f32), | ||
}; | ||
} | ||
|
||
frame_number += 1; | ||
|
||
handle.unwrap().set_bat(bat) | ||
}, | ||
); | ||
|
||
timer | ||
} | ||
|
||
fn read_bat_frames() -> Vec<Image> { | ||
let mut frames = vec![]; | ||
|
||
for i in 0..9 { | ||
let bat_frame_path = std::format!("seasons/halloween/bat-{}.png", i); | ||
let frame_data = match StaticAssets::get(&bat_frame_path) { | ||
Some(icon_data) => icon_data.data.into_owned(), | ||
None => StaticAssets::get("not-found.png") | ||
.unwrap() | ||
.data | ||
.into_owned(), | ||
}; | ||
|
||
let bat_frame = image::load_from_memory_with_format(&frame_data, image::ImageFormat::Png) | ||
.unwrap() | ||
.into_rgba8(); | ||
|
||
let buffer = SharedPixelBuffer::<Rgba8Pixel>::clone_from_slice( | ||
bat_frame.as_raw(), | ||
bat_frame.width(), | ||
bat_frame.height(), | ||
); | ||
|
||
frames.push(Image::from_rgba8(buffer)) | ||
} | ||
frames | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
This module adds seasonal fluff: | ||
Halloween bats and sppoky face in late october | ||
Snow effect in December | ||
....more? :D | ||
*/ | ||
|
||
use crate::ui::*; | ||
use chrono::{Datelike, Local}; | ||
use slint::Timer; | ||
mod december; | ||
mod halloween; | ||
use december::setup_snow; | ||
use halloween::{setup_halloween_bat, setup_halloween_spooky_face}; | ||
|
||
pub fn setup_seasons(main_window: &MainWindow) -> Vec<Timer> { | ||
let mut season_timers = vec![]; | ||
|
||
if Local::now().month() == 12 { | ||
let snow_timer = setup_snow(main_window); | ||
season_timers.push(snow_timer); | ||
} | ||
|
||
let now = Local::now(); | ||
if now.month() == 10 && now.day() >= 10 && now.day() <= 31 { | ||
let face_timer = setup_halloween_spooky_face(main_window); | ||
let bat_timer = setup_halloween_bat(main_window); | ||
|
||
season_timers.push(face_timer); | ||
season_timers.push(bat_timer); | ||
} | ||
|
||
season_timers | ||
} |
Oops, something went wrong.