diff --git a/src/jecs.luau b/src/jecs.luau index d739517..4e4b266 100755 --- a/src/jecs.luau +++ b/src/jecs.luau @@ -29,7 +29,7 @@ export type QueryInner = { filter_with: { Component }, filter_without: { Component }, next: () -> (Entity, ...any), - world: World, + -- world: World, } type function ecs_entity_t(ty: type) @@ -72,7 +72,7 @@ type function ecs_id_t(first: type, second: type) return p end -export type Entity = { __T: T } +export type Entity = { __T: T } export type Id = { __T: T } export type Pair = ecs_pair_t, Entity> export type Component = { __T: T } @@ -82,15 +82,12 @@ export type Item = (self: Query) -> (Entity, T...) export type Iter = (query: Query) -> () -> (Entity, T...) export type CachedIter = (query: CachedQuery) -> () -> (Entity, T...) -type TypePack = { - __phantomdata: () -> (T...) -} +type TypePack = (T...) -> never export type CachedQuery = typeof(setmetatable( {} :: { iter: CachedIter, - archetypes: (self: CachedQuery) -> { Archetype }, - cached: (self: CachedQuery) -> CachedQuery, + archetypes: (CachedQuery) -> { Archetype }, has: (CachedQuery, Entity) -> boolean, ids: { Id }, filter_with: { Id }?, @@ -108,8 +105,8 @@ export type Query = typeof(setmetatable( iter: Iter, with: ((Query, ...Component) -> Query), without: ((Query, ...Component) -> Query), - archetypes: (self: Query) -> { Archetype }, - cached: (self: Query) -> CachedQuery, + archetypes: (Query) -> { Archetype }, + cached: (Query) -> CachedQuery, has: (Query, Entity) -> boolean, ids: { Id }, filter_with: { Id }?, @@ -246,14 +243,14 @@ export type World = { component: (self: World) -> Entity, --- Gets the target of an relationship. For example, when a user calls --- `world:target(id, ChildOf(parent), 0)`, you will obtain the parent entity. - target: (self: World, id: Entity, relation: ecs_entity_t, index: number?) -> Entity?, - --- Deletes an entity and all its related components and relationships. + target: (self: World, id: Entity, relation: ecs_entity_t, index: number?) -> Entity?, + --- Deletes an entity and all it's related components and relationships. delete: (self: World, id: Entity) -> (), --- Adds a component to the entity with no value add: ( self: World, - id: ecs_entity_t, + id: ecs_entity_t>, component: Component ) -> (), @@ -267,10 +264,10 @@ export type World = { --- Removes a component from the given entity remove: (self: World, id: Entity, component: Component) -> (), --- Retrieves the value of up to 4 components. These values may be nil. - get: & ((World, Entity, Component) -> a?) - & ((World, Entity, Component, Component) -> (a?, b?)) - & ((World, Entity, Component, Component, Component) -> (a?, b?, c?)) - & ((World, Entity, Component, Component, Component, Component) -> (a?, b?, c?, d?)), + get: & ((World, Entity | number, Component) -> a?) + & ((World, Entity | number, Component, Component) -> (a?, b?)) + & ((World, Entity | number, Component, Component, Component) -> (a?, b?, c?)) + & ((World, Entity | number, Component, Component, Component, Component) -> (a?, b?, c?, d?)), --- Returns whether the entity has the ID. has: ((World, Entity, Component) -> boolean) @@ -1704,7 +1701,7 @@ local function query_cached(query: QueryInner) local compatible_archetypes = archetypes :: { Archetype } - local world = query.world + local world = (query :: { world: World }).world -- Only need one observer for EcsArchetypeCreate and EcsArchetypeDelete respectively -- because the event will be emitted for all components of that Archetype. local observable = world.observable @@ -2128,7 +2125,7 @@ local function query_cached(query: QueryInner) end local function query_has(query: QueryInner, entity: i53) - local world = query.world :: world + local world = (query::any).world :: world local r = entity_index_try_get(world.entity_index, entity) if not r then return false @@ -3457,7 +3454,7 @@ return { archetype_append_to_records = archetype_append_to_records, id_record_ensure = id_record_ensure :: (World, Component) -> ComponentRecord, component_record = id_record_get :: (World, Component) -> ComponentRecord?, - record = ecs_entity_record :: (World, Entity) -> Record, + record = ecs_entity_record :: (World, Entity) -> Record, archetype_create = archetype_create :: (World, { Component }, string) -> Archetype, archetype_ensure = archetype_ensure :: (World, { Component }) -> Archetype,