Rollback types
Some checks are pending
analysis / Run Luau Analyze (push) Waiting to run
deploy-docs / build (push) Waiting to run
deploy-docs / Deploy (push) Blocked by required conditions
publish-npm / publish (push) Waiting to run
unit-testing / Run Luau Tests (push) Waiting to run

This commit is contained in:
Ukendio 2025-03-26 04:59:11 +01:00
parent 59e7fd1f41
commit 045408af37
2 changed files with 14 additions and 12 deletions

View file

@ -2374,9 +2374,10 @@ end
World.new = world_new World.new = world_new
export type Entity<T = unknown> = { __nominal_entity: "Tag", __phantom_data: T } export type Entity<T = nil> = { __T: T }
export type Id<T = unknown> = { __phantom_data: T } export type Id<T = unknown> = { __T: T }
export type Pair<P, O> = { __phantom_data: P } export type Pair<P, O> = Id<P>
type ecs_id_t<T=unknown> = Id<T> | Pair<T, "Tag"> | Pair<"Tag", T>
export type Item<T...> = (self: Query<T...>) -> (Entity, T...) export type Item<T...> = (self: Query<T...>) -> (Entity, T...)
export type Iter<T...> = (query: Query<T...>) -> () -> (Entity, T...) export type Iter<T...> = (query: Query<T...>) -> () -> (Entity, T...)
@ -2500,7 +2501,7 @@ return {
Name = EcsName :: Entity<string>, Name = EcsName :: Entity<string>,
Rest = EcsRest :: Entity, Rest = EcsRest :: Entity,
pair = (ECS_PAIR :: any) :: <P, O>(first: P, second: O) -> Pair<P, O>, pair = (ECS_PAIR :: any) :: <P, O>(first: Id<P>, second: Id<O>) -> Pair<P, O>,
-- Inwards facing API for testing -- Inwards facing API for testing
ECS_ID = ECS_ENTITY_T_LO, ECS_ID = ECS_ENTITY_T_LO,

View file

@ -242,9 +242,9 @@ end)
TEST("world:cleanup()", function() TEST("world:cleanup()", function()
local world = world_new() local world = world_new()
local A = world:component() local A = world:component() :: jecs.Id<boolean>
local B = world:component() local B = world:component() :: jecs.Id<boolean>
local C = world:component() local C = world:component() :: jecs.Id<boolean>
local e1 = world:entity() local e1 = world:entity()
local e2 = world:entity() local e2 = world:entity()
@ -355,7 +355,7 @@ TEST("world:entity()", function()
do CASE "Recycling max generation" do CASE "Recycling max generation"
local world = world_new() local world = world_new()
local pin = jecs.Rest::number + 1 local pin = (jecs.Rest :: any) :: number + 1
for i = 1, 2^16-1 do for i = 1, 2^16-1 do
local e = world:entity() local e = world:entity()
world:delete(e) world:delete(e)
@ -569,21 +569,22 @@ TEST("world:query()", function()
do CASE "pairs" do CASE "pairs"
local world = jecs.World.new() local world = jecs.World.new()
local C1 = world:component() local C1 = world:component() :: jecs.Id<boolean>
local C2 = world:component() local C2 = world:component() :: jecs.Id<boolean>
local T1 = world:entity() local T1 = world:entity()
local T2 = world:entity() local T2 = world:entity()
local e = world:entity() local e = world:entity()
world:set(e, pair(C1, C2), true) local C1_C2 = pair(C1, C2)
world:set(e, C1_C2, true)
world:set(e, pair(C1, T1), true) world:set(e, pair(C1, T1), true)
world:set(e, pair(T1, C1), true) world:set(e, pair(T1, C1), true)
CHECK_EXPECT_ERR(function() CHECK_EXPECT_ERR(function()
world:set(e, pair(T1, T2), true :: any) world:set(e, pair(T1, T2), true :: any)
end) end)
for id, a, b, c, d in world:query(pair(C1, C2), pair(C1, T1), pair(T1, C1), pair(T1, T2)) :: any do for id, a, b, c, d in world:query(pair(C1, C2), pair(C1, T1), pair(T1, C1), pair(T1, T2)):iter() do
CHECK(a == true) CHECK(a == true)
CHECK(b == true) CHECK(b == true)
CHECK(c == true) CHECK(c == true)