// src/Component.ts
import { mapObject, uuid } from "@mud-classic/utils";

// src/constants.ts
var OptionalTypes = [
  10 /* OptionalEntity */,
  12 /* OptionalEntityArray */,
  2 /* OptionalNumber */,
  6 /* OptionalNumberArray */,
  4 /* OptionalString */,
  8 /* OptionalStringArray */,
  14 /* OptionalT */
];

// src/Component.ts
function setComponent(component, entity, value) {
  const prevValue = getComponentValue(component, entity);
  for (const [key, val] of Object.entries(value)) {
    component.values[key].set(entity, val);
  }
  component.update$.next({ entity, value: [value, prevValue], component });
}
function getComponentValue(component, entity) {
  const value = {};
  const schemaKeys = Object.keys(component.schema);
  for (const key of schemaKeys) {
    const val = component.values[key].get(entity);
    if (val === void 0 && !OptionalTypes.includes(component.schema[key]))
      return void 0;
    value[key] = val;
  }
  return value;
}

// src/Entity.ts
function createEntity(world, components, options) {
  const entity = world.registerEntity(options != null ? options : {});
  if (components) {
    for (const [component, value] of components) {
      setComponent(component, entity, value);
    }
  }
  return entity;
}
export {
  createEntity
};
//# sourceMappingURL=Entity.js.map