From 54e3b56b2e9610195879f78e5f7e1fcb4896ee70 Mon Sep 17 00:00:00 2001 From: waynemwashuma <94756970+waynemwashuma@users.noreply.github.com> Date: Thu, 18 Sep 2025 07:46:42 +0300 Subject: [PATCH 1/4] Move `Timer` into components --- src/time/components/index.js | 1 + src/time/{ => components}/timer.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 src/time/components/index.js rename src/time/{ => components}/timer.js (98%) 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 { From 7eff16e5828c19df009d88ebc11db9d982034fe9 Mon Sep 17 00:00:00 2001 From: waynemwashuma <94756970+waynemwashuma@users.noreply.github.com> Date: Thu, 18 Sep 2025 07:46:57 +0300 Subject: [PATCH 2/4] Add `updateTimers` system --- src/time/systems/index.js | 1 + src/time/systems/timer.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 src/time/systems/index.js create mode 100644 src/time/systems/timer.js 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 From 9d6ab98bcd63a59a2f438aa4ca0a02370a408ebb Mon Sep 17 00:00:00 2001 From: waynemwashuma <94756970+waynemwashuma@users.noreply.github.com> Date: Thu, 18 Sep 2025 07:47:09 +0300 Subject: [PATCH 3/4] Update importers of `Timer` --- src/time/index.js | 2 +- src/time/tests/timer.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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`", () => { From ad7b15110d3bc40f5bd2edc0d710dbb69644ef8e Mon Sep 17 00:00:00 2001 From: waynemwashuma <94756970+waynemwashuma@users.noreply.github.com> Date: Thu, 18 Sep 2025 07:47:21 +0300 Subject: [PATCH 4/4] Register `Timer` and its systems to `TimePlugin` --- src/time/plugin.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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) } }