diff --git a/src/time/components/index.js b/src/time/components/index.js new file mode 100644 index 00000000..76d6570a --- /dev/null +++ b/src/time/components/index.js @@ -0,0 +1 @@ +export * from './timer.js' \ No newline at end of file diff --git a/src/time/timer.js b/src/time/components/timer.js similarity index 98% rename from src/time/timer.js rename to src/time/components/timer.js index a45196c6..7870c7b5 100644 --- a/src/time/timer.js +++ b/src/time/components/timer.js @@ -1,4 +1,4 @@ -import { clamp } from '../math/index.js' +import { clamp } from '../../math/index.js' export class Timer { diff --git a/src/time/index.js b/src/time/index.js index 649b3c97..a01d568f 100644 --- a/src/time/index.js +++ b/src/time/index.js @@ -1,4 +1,4 @@ +export * from './components/index.js' export * from './clock.js' -export * from './timer.js' export * from './plugin.js' export * from './resource/index.js' \ No newline at end of file diff --git a/src/time/plugin.js b/src/time/plugin.js index 21dbb603..2d519ac9 100644 --- a/src/time/plugin.js +++ b/src/time/plugin.js @@ -1,18 +1,21 @@ import { World } from '../ecs/index.js' +import { AppSchedule, App, Plugin } from '../app/index.js' +import { updateTimers } from './systems/index.js' import { VirtualClock } from './resource/index.js' -import { App, Plugin } from '../app/app.js' -import { AppSchedule } from '../app/schedules.js' import { Clock } from './clock.js' +import { Timer } from './components/timer.js' -export class TimePlugin extends Plugin{ +export class TimePlugin extends Plugin { /** * @param {App} app */ register(app) { app + .registerType(Timer) .setResource(new VirtualClock()) .registerSystem(AppSchedule.Update, updateVirtualClock) + .registerSystem(AppSchedule.Update, updateTimers) } } diff --git a/src/time/systems/index.js b/src/time/systems/index.js new file mode 100644 index 00000000..76d6570a --- /dev/null +++ b/src/time/systems/index.js @@ -0,0 +1 @@ +export * from './timer.js' \ No newline at end of file diff --git a/src/time/systems/timer.js b/src/time/systems/timer.js new file mode 100644 index 00000000..34d83ca3 --- /dev/null +++ b/src/time/systems/timer.js @@ -0,0 +1,17 @@ +import { Query, World } from '../../ecs/index.js' +import { Timer } from '../components/index.js' +import { VirtualClock } from '../resource/index.js' + + +/** + * @param {World} world + */ +export function updateTimers(world) { + const timers = new Query(world, [Timer]) + const clock = world.getResource(VirtualClock) + const delta = clock.getDelta() + + timers.each(([timer]) => { + timer.update(delta) + }) +} \ No newline at end of file diff --git a/src/time/tests/timer.test.js b/src/time/tests/timer.test.js index 283c6f01..8c3a39ce 100644 --- a/src/time/tests/timer.test.js +++ b/src/time/tests/timer.test.js @@ -1,5 +1,5 @@ import { test, describe } from "node:test"; -import { Timer, TimerMode } from "../timer.js"; +import { Timer, TimerMode } from "../index.js"; import { strictEqual } from "node:assert"; describe("Testing `Timer`", () => {