Skip to content

Commit e3630ba

Browse files
Merge branch '7111-sdk-add-an-option-in-the-gem-to-interpolate-between-frames-in-step-by-step-mode' into 'master'
feat(SDK): animate viewer when step-by-stepping See merge request codingame/game-engine!225
2 parents bc631ec + 3409b78 commit e3630ba

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

engine/core/src/main/resources/view/core/Drawer.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ModuleError } from './ModuleError.js'
1111
export class Drawer {
1212
constructor (customDemo) {
1313
this.toDestroy = []
14+
this.stepByStepAnimateSpeed = config.stepByStepAnimateSpeed || null
1415

1516
let demo = customDemo || defaultDemo
1617

@@ -434,11 +435,17 @@ export class Drawer {
434435
}
435436
}
436437

437-
updateScene (scope, question, frames, frameNumber, progress, speed, reason) {
438+
updateScene (scope, question, frames, frameNumber, progress, speed, reason, demo, force) {
439+
const parsedFrame = frames[frameNumber]
440+
if (!force && this.checkSteppedToNextFrame(scope, parsedFrame)) {
441+
this.startAsynchronousAnimation(scope, progress, parsedFrame)
442+
return
443+
}
444+
438445
/** ************************************* */
439446
/* SYNCHRONOUS */
440447
/** ************************************* */
441-
var parsedFrame = frames[frameNumber]
448+
442449
scope.currentFrame = parsedFrame
443450
scope.currentProgress = progress
444451
scope.reason = reason
@@ -455,6 +462,16 @@ export class Drawer {
455462
}
456463
}
457464

465+
startAsynchronousAnimation (scope, progress, currentFrame) {
466+
scope.targetProgress = progress
467+
scope.currentProgress = 0
468+
scope.currentFrame = currentFrame
469+
}
470+
471+
checkSteppedToNextFrame (scope, parsedFrame) {
472+
return scope.currentFrame && scope.currentFrame !== parsedFrame && scope.currentFrame === parsedFrame.previous && this.speed === 0
473+
}
474+
458475
initEndScene (scope, failure) {
459476
scope.endSceneViewed = false
460477
}
@@ -495,6 +512,12 @@ export class Drawer {
495512
scope.endTime = 0
496513
}
497514

515+
if (this.stepByStepAnimateSpeed && this.isAsynchronousAnimationOngoing(scope)) {
516+
var p = scope.currentProgress + step / 200 * this.getFrameSpeed(this.currentFrame) * this.stepByStepAnimateSpeed
517+
p = Math.min(scope.targetProgress, p)
518+
this.updateScene(this.scope, this.question, this.frames, this.currentFrame, p, this.speed, this.reasons[this.currentFrame], false, true)
519+
}
520+
498521
for (let moduleName in this.modules) {
499522
const module = this.modules[moduleName]
500523
if (typeof module.animateScene === 'function') {
@@ -508,6 +531,10 @@ export class Drawer {
508531
return true
509532
}
510533

534+
isAsynchronousAnimationOngoing (scope) {
535+
return scope.targetProgress != null && scope.currentProgress !== scope.targetProgress
536+
}
537+
511538
getFrameSpeed (frameNumber) {
512539
return BASE_FRAME_DURATION / this.getFrameDuration(frameNumber)
513540
}
@@ -738,7 +765,7 @@ export class Drawer {
738765
var key
739766
window.PIXI = Drawer.PIXI || window.PIXI
740767
this.oversampling = oversampling || 1
741-
768+
742769
const notifyRenderer = () => {
743770
if (this.currentFrame >= 0) {
744771
this.changed = true

playground/misc/misc-3-release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
The CodinGame SDK is regularly updated and improved. This document lets you know what changed in the latest releases.
44

5+
## Next versions
6+
57
## 3.4.10
68

9+
### 🎁 New features
10+
11+
- Added an optional export to `config.js` called `stepByStepAnimateSpeed` which lets you set whether to animate the view when stepping from one frame to the next
12+
713
### 🐞 Bug fix
814

915
- Fixed Tooltip not showing all texts of stacked sprites below the cursor

0 commit comments

Comments
 (0)