|
| 1 | +import { afterAll, beforeAll, describe, expect, it } from '@jest/globals' |
| 2 | +import * as fs from 'node:fs' |
| 3 | +import * as path from 'node:path' |
| 4 | +import { type ExportRun, relFiles, runFixtureExport } from './helpers/export' |
| 5 | + |
| 6 | +/** |
| 7 | + * `tween_paused` runs `tween`, then tags the root with `aj.pause_after_tween`. The animation's |
| 8 | + * `zzz/on_tick` pauses it instead of playing once the tween finishes, and `play` / `pause_all` |
| 9 | + * clear the tag so a pending pause can't leak into a later animation. |
| 10 | + */ |
| 11 | + |
| 12 | +const PAUSE_TAG = 'aj.pause_after_tween' |
| 13 | + |
| 14 | +function readMatching(run: ExportRun, files: string[], match: (file: string) => boolean) { |
| 15 | + return files |
| 16 | + .filter(match) |
| 17 | + .map(f => fs.readFileSync(path.join(run.dataPackFolder, f), 'utf-8')) |
| 18 | + .join('\n') |
| 19 | +} |
| 20 | + |
| 21 | +// 1.20.4 is the oldest main.mcb, 26.2 resolves to the newest. |
| 22 | +describe.each(['1.20.4', '26.2'])('tween_paused export (%s)', targetVersion => { |
| 23 | + let run: ExportRun |
| 24 | + let dpFiles: string[] |
| 25 | + const read = (match: (file: string) => boolean) => readMatching(run, dpFiles, match) |
| 26 | + |
| 27 | + beforeAll(async () => { |
| 28 | + run = await runFixtureExport({ |
| 29 | + fixture: 'test_blueprints/Dummy.ajblueprint', |
| 30 | + targetVersion, |
| 31 | + }) |
| 32 | + dpFiles = relFiles(run.dataPackFolder) |
| 33 | + }, 180_000) |
| 34 | + |
| 35 | + afterAll(() => run?.cleanup()) |
| 36 | + |
| 37 | + it('exports', () => { |
| 38 | + expect(run.ok).toBe(true) |
| 39 | + }) |
| 40 | + |
| 41 | + it('tags the root after tweening, so the tween does not clear the tag', () => { |
| 42 | + const tweenPaused = read(f => f.endsWith('/animations/floss/tween_paused.mcfunction')) |
| 43 | + const tweenCall = tweenPaused.indexOf('animations/floss/tween {') |
| 44 | + const tagAdd = tweenPaused.indexOf(`tag @s add ${PAUSE_TAG}`) |
| 45 | + expect(tweenCall).toBeGreaterThan(-1) |
| 46 | + expect(tagAdd).toBeGreaterThan(tweenCall) |
| 47 | + }) |
| 48 | + |
| 49 | + it('pauses the animation once a paused tween finishes', () => { |
| 50 | + const onTick = read( |
| 51 | + f => |
| 52 | + f.includes('/animations/floss/zzz/on_tick') || |
| 53 | + f.endsWith('/animations/floss/zzz/pause_after_tween.mcfunction') |
| 54 | + ) |
| 55 | + expect(onTick).toMatch(/matches \.\.0/) |
| 56 | + expect(onTick).toContain(`if entity @s[tag=${PAUSE_TAG}]`) |
| 57 | + expect(onTick).toContain(`tag @s remove ${PAUSE_TAG}`) |
| 58 | + expect(onTick).toContain('tag @s remove aj_booth_rigs.dummy.animation.floss.playing') |
| 59 | + }) |
| 60 | + |
| 61 | + it('clears a pending pause when playing or pausing every animation', () => { |
| 62 | + expect(read(f => f.endsWith('/animations/floss/play.mcfunction'))).toContain( |
| 63 | + `tag @s remove ${PAUSE_TAG}` |
| 64 | + ) |
| 65 | + expect(read(f => f.endsWith('/animations/pause_all.mcfunction'))).toContain( |
| 66 | + `tag @s remove ${PAUSE_TAG}` |
| 67 | + ) |
| 68 | + }) |
| 69 | +}) |
0 commit comments