refactor: normalize createMany

This commit is contained in:
cha0s 2022-09-17 06:46:55 -05:00
parent bbf11c0b63
commit ee566e7c70
3 changed files with 3 additions and 17 deletions

View File

@ -25,14 +25,7 @@ export default class ArbitraryComponent extends BaseComponent {
if (entries.length > 0) {
const allocated = this.allocateMany(entries.length);
for (let i = 0; i < entries.length; ++i) {
let entity;
let values = {};
if (Array.isArray(entries[i])) {
[entity, values] = entries[i];
}
else {
entity = entries[i];
}
const [entity, values = {}] = entries[i];
this.map[entity] = allocated[i];
this.data[allocated[i]].entity = entity;
for (const j in values) {

View File

@ -47,14 +47,7 @@ export default class FlatComponent extends BaseComponent {
const window = new this.Window(this.data, this);
const {defaultValues} = this.schema;
for (let i = 0; i < entries.length; ++i) {
let entity;
let values = {};
if (Array.isArray(entries[i])) {
[entity, values] = entries[i];
}
else {
entity = entries[i];
}
const [entity, values = {}] = entries[i];
this.map[entity] = allocated[i];
window.cursor = allocated[i] * this.constructor.width;
window.entity = entity;

View File

@ -96,7 +96,7 @@ export default class Ecs {
if (!creating[component]) {
creating[component] = [];
}
creating[component].push(components[component] ? [entity, components[component]] : entity);
creating[component].push([entity, components[component]]);
}
}
for (const i in creating) {