diff --git a/src/diagnostic/entitycount.js b/src/diagnostic/entitycount.js new file mode 100644 index 00000000..4520c7e1 --- /dev/null +++ b/src/diagnostic/entitycount.js @@ -0,0 +1,42 @@ +import { App, AppSchedule } from '../app/index.js' +import { World, Entity, Query } from '../ecs/index.js' + +export class EntityCountDiagnosticPlugin { + + /** + * @param {App} app + */ + register(app) { + app + .registerSystem(AppSchedule.Startup, setUpUI) + .registerSystem(AppSchedule.Update, updateEntityCount) + } +} + +/** + * + */ +function setUpUI() { + const container = document.body.appendChild(document.createElement('div')) + + container.id = 'entity-count-container' + container.style.position = 'absolute' + container.style.top = '34px' + container.style.right = '0px' + container.style.width = '100px' + container.style.height = '20px' + container.style.background = 'black' + container.style.textAlign = 'center' + container.style.color = 'white' +} + +/** + * @param {World} world + */ +function updateEntityCount(world) { + const entities = new Query(world, [Entity]) + const num = entities.count() + const container = document.querySelector('#entity-count-container') + + if (container) container.innerHTML = `${num} entities` +} \ No newline at end of file diff --git a/src/diagnostic/index.js b/src/diagnostic/index.js index 1064546b..2b3c58ee 100644 --- a/src/diagnostic/index.js +++ b/src/diagnostic/index.js @@ -1 +1,2 @@ -export * from './fpsdebugger.js' \ No newline at end of file +export * from './fpsdebugger.js' +export * from '././entitycount.js' \ No newline at end of file