/
RaskolnickOFF
/
3D
Обзор
Документация
Войти
/
RaskolnickOFF
/
3D
Код
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
js/source/core/Entity.js
57 строк
2 KB
RaskolnickOFF
Structure update
06 июн 2026, 03:18
06 июн 2026, 03:18
9bc1c25
Код
Авторство
О чём код?
// js/source/core/Entity.js export class Entity { constructor(id) { this.id = id; this.components = new Map(); } add(name, data) { this.components.set(name, data); return this; } get(name) { return this.components.get(name); } has(name) { return this.components.has(name); } remove(name) { this.components.delete(name); return this; } // УЛУЧШЕНИЯ ДЛЯ ТЕСТИРОВАНИЯ: // 1. hasAll(...names) — проверка наличия всех компонентов сразу. // entity.hasAll(Component.POSITION, Component.HEALTH) → boolean // hasAll(...names) { // return names.every(name => this.components.has(name)); // } // 2. hasAny(...names) — проверка наличия хотя бы одного. // entity.hasAny(Component.PLAYER, Component.ENEMY) → boolean // hasAny(...names) { // return names.some(name => this.components.has(name)); // } // 3. toJSON() — сериализация для сохранений. // Чтобы не лазить в entity.components напрямую в Engine.serializeAll(). // toJSON() { // const data = { id: this.id, components: {} }; // for (const [key, value] of this.components) { // data.components[key] = value; // } // return data; // } // 4. toString() — для отладки. // console.log(entity.toString()) → "Entity#42 [player, health, transform]" // toString() { // const names = [...this.components.keys()].join(', '); // return `Entity#${this.id} [${names}]`; // } }