Skip to content

Commit 45c303e

Browse files
committed
Update animationExporter.ts
- Cleaned up a bit - Added Move Function to satisfy #69
1 parent 3b469ab commit 45c303e

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/exporters/animationExporter.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -734,10 +734,6 @@ async function createMCFile(
734734

735735
{
736736
//? Animation Loop function
737-
const animationRunCommand = `execute if entity @s[tag=aj.${projectName}.anim.%animationName] at @s run function ${projectName}:animations/%animationName/next_frame`
738-
const animationRunCommands = Object.values(animations).map((v) =>
739-
format(animationRunCommand, { animationName: v.name })
740-
)
741737
// prettier-ignore
742738
FILE.push(`
743739
function animation_loop {
@@ -749,7 +745,11 @@ async function createMCFile(
749745
scoreboard players set .aj.animation ${scoreboards.animatingFlag} 0
750746
# Run animations that are active on the entity
751747
execute as @e[type=${entityTypes.root},tag=${tags.root}] run{
752-
${animationRunCommands.join('\n')}
748+
749+
${Object.values(animations).map((animation) =>
750+
`execute if entity @s[tag=aj.${projectName}.anim.${animation.name}] at @s run function ${projectName}:animations/${animation.name}/next_frame`
751+
).join('\n')}
752+
753753
scoreboard players operation @s ${scoreboards.animatingFlag} = .aj.animation ${scoreboards.animatingFlag}
754754
}
755755
# Stop the anim_loop clock if no models are animating
@@ -764,6 +764,31 @@ async function createMCFile(
764764
}
765765

766766
{
767+
// Move Function
768+
FILE.push(`function move {
769+
# Make sure this function has been ran as the root entity
770+
execute(if entity @s[tag=${tags.root}] at @s rotated ~ 0) {
771+
tp @e[type=${entityTypes.boneRoot}] ~ ~ ~ ~ ~
772+
773+
scoreboard players set # aj.i 0
774+
${Object.values(animations).map(animation => `execute if entity @s[tag=aj.${projectName}.anim.${animation.name}] run {
775+
function ${projectName}:animations/${animation.name}/next_frame
776+
scoreboard players set # aj.i 1
777+
}`).join('\n')}
778+
execute if score # aj.i matches 0 run function ${projectName}:reset
779+
780+
# If this entity is not the root
781+
} else {
782+
tellraw @s ${rootExeErrorJsonText.replace(
783+
'%functionName',
784+
`${projectName}:move`
785+
)}
786+
}
787+
}`)
788+
}
789+
790+
{
791+
//? Animations
767792
if (!Object.keys(animations).length) {
768793
throw new CustomError('No Animations Error', {
769794
intentional: true,
@@ -783,9 +808,10 @@ async function createMCFile(
783808
})
784809
}
785810
console.groupCollapsed('Animations')
786-
//? Animation Dir
811+
787812
FILE.push(`dir animations {`)
788813

814+
// TODO Frame deduplication
789815
for (const animation of Object.values(animations)) {
790816
if (animation.frames.length <= 1) {
791817
throw new CustomError('Zero Length Animation Error', {

0 commit comments

Comments
 (0)