import { Sprite } from "@common/rpg/components/sprite";
import { System, World } from "@common/rpg/core/world";

export class SpriteSystem extends System {
    override update(world: World, dt: number) {
        for (const [, , sprite] of world.query(Sprite)) {
            sprite.state.animationCounter += dt;
            if (sprite.state.animationCounter >= sprite.state.animationDelay) {
                const frameDiff = Math.floor(sprite.state.animationCounter / sprite.state.animationDelay);
                sprite.state.animationCounter = sprite.state.animationCounter % sprite.state.animationDelay;
                sprite.state.currentFrame = (sprite.state.currentFrame + frameDiff) % sprite.state.frames.length;
            }
        }
    }
}
