1
0
Fork 0
This commit is contained in:
Pabloader 2026-04-29 12:24:00 +00:00
parent c2e9a597fa
commit 26e1fb2675
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import { component } from "../core/registry";
import { Component } from "../core/world";
import { action, variable } from "../utils/decorators";
@component
export class Cooldown extends Component<{
remaining: number;
duration: number;
}> {
constructor(duration: number) {
super({ remaining: duration, duration });
}
@variable('.')
get ready(): boolean {
return this.state.remaining <= 0;
}
@action
reset(duration?: number): void {
if (duration != null) this.state.duration = duration;
this.state.remaining = this.state.duration;
}
@action
clear(): void {
if (this.state.remaining <= 0) return;
this.state.remaining = 0;
this.emit('ready');
}
@action
update(dt: number): void {
if (this.state.remaining <= 0) return;
this.state.remaining -= dt;
if (this.state.remaining <= 0) {
this.state.remaining = 0;
this.emit('ready');
}
}
}

View File

@ -0,0 +1,10 @@
import { Cooldown } from "../components/cooldown";
import { System, type World } from "../core/world";
export class CooldownSystem extends System {
override update(world: World, dt: number): void {
for (const [, , cooldown] of world.query(Cooldown)) {
cooldown.update(dt);
}
}
}