Skip to content

Commit

Permalink
Merge branch 'main' into fix/guard_is_complete
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalz authored Mar 12, 2024
2 parents d8b4a90 + 07f957c commit 52f0fe5
Show file tree
Hide file tree
Showing 18 changed files with 26,561 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ define CREATE_FRAMEWORK
-c "Add :CFBundleShortVersionString string 1.0.0" \
-c "Add :CFBundlePackageType string FMWK" \
-c "Add :CFBundleExecutable string $(DOTLOTTIE_PLAYER_MODULE)" \
-c "Add :MinimumOSVersion string 16.4" \
-c "Add :MinimumOSVersion string 13" \
-c "Add :CFBundleSupportedPlatforms array" \
$(foreach platform,$(PLIST_DISABLE),-c "Add :CFBundleSupportedPlatforms:0 string $(platform)" ) \
$(foreach platform,$(PLIST_ENABLE),-c "Add :CFBundleSupportedPlatforms:1 string $(platform)" ) \
Expand Down
90 changes: 76 additions & 14 deletions demo-player/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,34 +116,51 @@ fn main() {
let base_path = env::var("CARGO_MANIFEST_DIR").unwrap();

let mut path = path::PathBuf::from(base_path);
path.push("src/cartoon.json");
path.push("src/markers.json");

let mut lottie_player: DotLottiePlayer = DotLottiePlayer::new(Config {
mode: Mode::ReverseBounce,
mode: Mode::Forward,
loop_animation: true,
speed: 1.0,
use_frame_interpolation: true,
autoplay: true,
segments: vec![10.0, 45.0],
segments: vec![],
background_color: 0xffffffff,
marker: "feather".to_string(),
});

// read dotlottie in to vec<u8>
let mut f = File::open("src/emoji.lottie").expect("no file found");
let metadata = fs::metadata("src/emoji.lottie").expect("unable to read metadata");
let mut f =
File::open(
// "src/emoji.lottie"
"src/theming_example.lottie",
)
.expect("no file found");
let metadata =
fs::metadata(
// "src/emoji.lottie"
"src/theming_example.lottie",
)
.expect("unable to read metadata");

let mut buffer = vec![0; metadata.len() as usize];
f.read(&mut buffer).expect("buffer overflow");

let mut cartoon = File::open("src/cartoon.json").expect("no file found");
let metadataCartoon = fs::metadata("src/cartoon.json").expect("unable to read metadata");
let mut cartoonBuffer = vec![0; metadataCartoon.len() as usize];
cartoon.read(&mut cartoonBuffer).expect("buffer overflow");
let string = String::from_utf8(cartoonBuffer.clone()).unwrap();
let mut markers = File::open("src/markers.json").expect("no file found");
let metadatamarkers = fs::metadata("src/markers.json").expect("unable to read metadata");
let mut markersBuffer = vec![0; metadatamarkers.len() as usize];
markers.read(&mut markersBuffer).expect("buffer overflow");
let string = String::from_utf8(markersBuffer.clone()).unwrap();
// lottie_player.load_animation_data(string.as_str(), WIDTH as u32, HEIGHT as u32);
// println!("{:?}", Some(lottie_player.manifest()));

lottie_player.load_dotlottie_data(&buffer, WIDTH as u32, HEIGHT as u32);
lottie_player.load_animation_path(
path.as_path().to_str().unwrap(),
WIDTH as u32,
HEIGHT as u32,
);

// lottie_player.load_dotlottie_data(&buffer, WIDTH as u32, HEIGHT as u32);
// lottie_player.load_animation("confused", WIDTH as u32, HEIGHT as u32);

let observer1: Arc<dyn Observer + 'static> = Arc::new(DummyObserver { id: 1 });
Expand Down Expand Up @@ -202,6 +219,16 @@ fn main() {
lottie_player.set_config(config)
}

if window.is_key_pressed(Key::T, KeyRepeat::No) {
if let Some(manifest) = lottie_player.manifest() {
if let Some(themes) = manifest.themes {
let theme = &themes[0];

lottie_player.load_theme(&theme.id.as_str());
}
}
}

if window.is_key_pressed(Key::Right, KeyRepeat::No) {
if let Some(manifest) = lottie_player.manifest() {
println!("{:?}", i);
Expand All @@ -218,11 +245,22 @@ fn main() {
}
}

if window.is_key_down(Key::L) {
lottie_player.load_animation_data(string.as_str(), WIDTH as u32, HEIGHT as u32);
if window.is_key_pressed(Key::L, KeyRepeat::No) {
lottie_player = DotLottiePlayer::new(Config {
mode: Mode::ReverseBounce,
loop_animation: true,
speed: 1.0,
use_frame_interpolation: true,
autoplay: true,
segments: vec![10.0, 45.0],
background_color: 0xffffffff,
marker: "".to_string(),
});

lottie_player.load_animation_data(&string, WIDTH as u32, HEIGHT as u32);
}

if window.is_key_down(Key::R) {
if window.is_key_pressed(Key::R, KeyRepeat::No) {
lottie_player.load_dotlottie_data(&buffer, WIDTH as u32, HEIGHT as u32);
}

Expand All @@ -234,6 +272,30 @@ fn main() {
lottie_player.unsubscribe(&observer2);
}

if window.is_key_pressed(Key::Q, KeyRepeat::No) {
let mut config = lottie_player.config();

config.marker = "bird".to_string();

lottie_player.set_config(config);
}

if window.is_key_pressed(Key::W, KeyRepeat::No) {
let mut config = lottie_player.config();

config.marker = "explosion".to_string();

lottie_player.set_config(config);
}

if window.is_key_pressed(Key::E, KeyRepeat::No) {
let mut config = lottie_player.config();

config.marker = "feather".to_string();

lottie_player.set_config(config);
}

if cpu_memory_monitor_timer.elapsed().as_secs() >= 1 {
cpu_memory_monitor_timer = Instant::now();
}
Expand Down
Loading

0 comments on commit 52f0fe5

Please sign in to comment.