import {System} from '@/ecs/index.js'; export default class SpriteDirection extends System { static queries() { return { default: ['Sprite'], }; } tick() { for (const [Sprite, entityId] of this.select('default')) { const entity = this.ecs.get(entityId); const parts = []; if (entity.Controlled) { const {moveUp, moveRight, moveDown, moveLeft} = entity.Controlled; if (moveUp > 0 || moveRight > 0 || moveDown > 0 || moveLeft > 0) { parts.push('moving'); } else { parts.push('idle'); } } if (entity.Direction) { const name = { 0: 'up', 1: 'right', 2: 'down', 3: 'left', }; parts.push(name[entity.Direction.direction]); } if (parts.length > 0) { Sprite.animation = parts.join(':'); } } } }