Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Commit

Permalink
feat: unit s and ms
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed May 14, 2024
1 parent bf8a299 commit 26f262f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class App {
) {
this.setBackgroundColor(Color.BLACK)
this.config = defineConfig({
unit: 'frame',
unit: 's',
})
if (element === void 0) {
console.warn(
Expand Down Expand Up @@ -73,8 +73,8 @@ export class App {
*/
checkout(scene: Scene): this {
for (const plugin of this.plugins) plugin.beforeCheckout(this, scene)

this.scene = scene
this.scene.startTime = performance.now()
this.last = this.scene.root
for (const plugin of this.plugins) plugin.onCheckout(this, this.scene)
// if (!scene.root.hasSet)
Expand Down Expand Up @@ -117,7 +117,12 @@ export class App {
for (const plugin of app.plugins) plugin.onUpdate(app, app.scene.elapsed)

if (app.playing) {
app.scene.elapsed += 1
if (app.config.unit === 'frame')
app.scene.elapsed += 1
else if (app.config.unit === 'ms')
app.scene.elapsed = performance.now() - app.scene.startTime
else if (app.config.unit === 's')
app.scene.elapsed = (performance.now() - app.scene.startTime) / 1000
app.surface.requestAnimationFrame((canvas: Canvas) => {
App.update(app, canvas)
})
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/scene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Widget } from './widget'

export class Scene {
elapsed = 0
startTime: number

constructor(public root: Widget) {}
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export class Widget {
}
break
}
// TODO: Align and Baseline
}
index += 1
}
Expand Down

0 comments on commit 26f262f

Please sign in to comment.