Skip to content

Commit

Permalink
fix: replay reset animations (#475)
Browse files Browse the repository at this point in the history
chore: fix json format
  • Loading branch information
leanmendoza authored Oct 29, 2024
1 parent c102cc9 commit 7320c48
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 41 deletions.
10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
"useTabs": false,
"semi": false
}
},
{
"files": "*.json",
"options": {
"tabWidth": 2,
"printWidth": 80,
"useTabs": false
}
}
]
}
}
52 changes: 15 additions & 37 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
"program": "${workspaceFolder}/.bin/godot/godot4_bin",
"args": [
"--path",
"${workspaceFolder}/godot"
"${workspaceFolder}/godot",
"--skip-lobby",
"--realm",
"http://localhost:8000",
"--preview"
],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/godot",
"environment": [
{
"name": "RUST_LOG",
"value": "debug"
"value": "dclgodot=debug"
}
],
"externalConsole": true,
"preLaunchTask": "Build GDExtension Lib",
"sourceFileMap": {
"/rustc/cc66ad468955717ab92600c770da8c1601a4ff33": "${env:HOME}${env:USERPROFILE}\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\src\\rust"
"/rustc/129f3b9964af4d4a709d1383930ade12dfe7c081": "${env:HOME}${env:USERPROFILE}\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\src\\rust"
}
},
{
"name": "(Windows) Run Test",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/.bin/godot/godot4_bin",
"args": [
"--path",
"${workspaceFolder}/godot",
"--test"
],
"args": ["--path", "${workspaceFolder}/godot", "--test"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/godot",
"environment": [
Expand All @@ -50,11 +50,7 @@
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/.bin/godot/godot4_bin",
"args": [
"--path",
"${workspaceFolder}/godot",
"-e"
],
"args": ["--path", "${workspaceFolder}/godot", "-e"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/godot",
"environment": [],
Expand All @@ -66,11 +62,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/.bin/godot/godot4_bin",
"args": [
"--path",
"${workspaceFolder}/godot",
"-e"
],
"args": ["--path", "${workspaceFolder}/godot", "-e"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/godot",
"environment": [],
Expand All @@ -82,10 +74,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/.bin/godot/godot4_bin",
"args": [
"--path",
"${workspaceFolder}/godot"
],
"args": ["--path", "${workspaceFolder}/godot"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/godot",
"environment": [
Expand All @@ -111,11 +100,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/.bin/godot/godot4_bin",
"args": [
"--path",
"${workspaceFolder}/godot",
"--test"
],
"args": ["--path", "${workspaceFolder}/godot", "--test"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/godot",
"environment": [],
Expand All @@ -136,11 +121,7 @@
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/.bin/godot/godot4_bin",
"args": [
"--path",
"${workspaceFolder}/godot",
"-e"
],
"args": ["--path", "${workspaceFolder}/godot", "-e"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/godot",
"environment": [],
Expand All @@ -153,10 +134,7 @@
"request": "launch",
"targetArchitecture": "arm64",
"program": "${workspaceFolder}/.bin/godot/godot4_bin",
"args": [
"--path",
"${workspaceFolder}/godot"
],
"args": ["--path", "${workspaceFolder}/godot"],
"stopAtEntry": false,
"cwd": "${workspaceRoot}/godot",
"environment": [],
Expand All @@ -172,4 +150,4 @@
]
}
]
}
}
1 change: 1 addition & 0 deletions godot/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.godot/

/android/
/addons/**/~*.dll

# Godot-specific ignores
.import/
Expand Down
2 changes: 1 addition & 1 deletion godot/src/test/avatar/avatar_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,4 @@
"urn:decentraland:matic:collections-v2:0xbada8a315e84e4d78e3b6914003647226d9b4001:11",
"urn:decentraland:matic:collections-v2:0x0c956c74518ed34afb7b137d9ddfdaea7ca13751:0"
]
}
}
29 changes: 27 additions & 2 deletions lib/src/godot_classes/animator_controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};

use godot::{
bind::{godot_api, GodotClass},
Expand Down Expand Up @@ -35,6 +35,8 @@ pub struct MultipleAnimationController {

current_time: HashMap<String, f32>,
playing_anims: HashMap<String, AnimationItem>,

finished_animations: HashSet<String>,
}

#[godot_api]
Expand Down Expand Up @@ -77,6 +79,7 @@ impl MultipleAnimationController {
if !looping {
self.base
.set(anim_item.speed_param_ref_str.clone(), 0_f32.to_variant());
self.finished_animations.insert(anim_name.clone());
}
} else {
tracing::error!("finished animation {} not found!", anim_name);
Expand All @@ -92,6 +95,7 @@ impl MultipleAnimationController {
current_time: HashMap::new(),
playing_anims: HashMap::new(),
existing_anims_duration,
finished_animations: HashSet::new(),
})
}

Expand Down Expand Up @@ -149,6 +153,22 @@ impl MultipleAnimationController {
.unwrap_or(&0.0)
};

self.base.set(
anim_state.time_param_ref_str.clone(),
playing_time.to_variant(),
);
} else if self.finished_animations.contains(&new_state.clip) {
self.finished_animations.remove(&new_state.clip);

let playing_time = if !anim_state.value.playing_backward() {
0.0
} else {
*self
.existing_anims_duration
.get(&anim_state.value.clip)
.unwrap_or(&0.0)
};

self.base.set(
anim_state.time_param_ref_str.clone(),
playing_time.to_variant(),
Expand Down Expand Up @@ -237,7 +257,12 @@ impl MultipleAnimationController {
);

let playing_time = if let Some(playing_time) = self.current_time.remove(&anim.clip) {
playing_time
if self.finished_animations.contains(&anim.clip) {
self.finished_animations.remove(&anim.clip);
0.0
} else {
playing_time
}
} else if !anim_item.value.playing_backward() {
0.0
} else {
Expand Down

0 comments on commit 7320c48

Please sign in to comment.