Fix types issues

This commit is contained in:
Ukendio 2025-07-24 02:24:25 +02:00
parent 666a3ef6de
commit 7b43748f18
5 changed files with 48 additions and 51 deletions

View file

@ -2,42 +2,46 @@
local jecs = require("@jecs")
type Description<T...> = jecs.Query<T...>
export type Iter<T...> = (query: Query<T...>) -> () -> (jecs.Entity, T...)
type ObserverArm = (<a>(
PatchedWorld,
{
query: jecs.Query<a>,
callback: ((jecs.Entity) -> ())?
type Id<T=any> = jecs.Id<T>
type Query<T...> = typeof(setmetatable(
{} :: {
iter: Iter<T...>,
with: (<a>(Query<T...>, Id<a>) -> Query<T...>)
& (<a, b>(Query<T...>, Id<a>, Id<b>) -> Query<T...>)
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
& (<a, b, c, d>(Query<T...>, Id<a>, Id<b>, Id<c>, Id) -> Query<T...>),
without: (<a>(Query<T...>, Id<a>) -> Query<T...>)
& (<a, b>(Query<T...>, Id<a>, Id<b>) -> Query<T...>)
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
& (<a, b, c>(Query<T...>, Id<a>, Id<b>, Id<c>) -> Query<T...>)
& (<a, b, c, d>(Query<T...>, Id<a>, Id<b>, Id<c>, Id) -> Query<T...>),
archetypes: (self: Query<T...>) -> { jecs.Archetype },
cached: (self: Query<T...>) -> Query<T...>,
},
{} :: {
__iter: Iter<T...>,
}
) -> () -> () -> (jecs.Entity)) & (<a, b>(
PatchedWorld,
{
query: jecs.Query<a, b>,
callback: ((jecs.Entity) -> ())?
}
) -> () -> () -> (jecs.Entity)) & (<a, b, c>(
PatchedWorld,
{
query: jecs.Query<a, b, c>,
callback: ((jecs.Entity) -> ())?
}
) -> () -> () -> (jecs.Entity))
))
export type PatchedWorld = jecs.World & {
added: <T>(PatchedWorld, jecs.Id<T>, <e>(e: jecs.Entity<e>, id: jecs.Id<T>, value: T?) -> ()) -> () -> (),
removed: <T>(PatchedWorld, jecs.Id<T>, (e: jecs.Entity, id: jecs.Id) -> ()) -> () -> (),
changed: <T>(PatchedWorld, jecs.Id<T>, <e>(e: jecs.Entity<e>, id: jecs.Id<T>, value: T) -> ()) -> () -> (),
observer: ObserverArm & any,
monitor: ObserverArm & any
observer: <T...>(PatchedWorld, Query<T...>, callback: ((jecs.Entity, jecs.Id, any?) -> ())?) -> () -> () -> (jecs.Entity),
monitor: <T...>(PatchedWorld, Query<T...>, callback: ((jecs.Entity, jecs.Id, any?) -> ())?) -> () -> () -> (jecs.Entity)
}
local function observers_new(
local function observers_new<T...>(
world: PatchedWorld,
query: any,
query: Query<T...>,
callback: (<T, a>(jecs.Entity<T>, jecs.Id<a>, value: a?) -> ())?
)
query = query:cached()
callback = callback
local archetypes = {}
local terms = query.ids

View file

@ -1,13 +1,11 @@
local function collect<T...>(
signal: {
Connect: (RBXScriptSignal<T...>, fn: (T...) -> ()) -> RBXScriptConnection
}
): () -> (T...)
--!strict
local function collect(signal)
local enqueued = {}
local i = 0
local connection = (signal :: any):Connect(function(...)
local connection = signal:Connect(function(...)
table.insert(enqueued, { ... })
i += 1
end)
@ -25,4 +23,11 @@ local function collect<T...>(
end, connection
end
return collect
type Signal<T... = ...any> = {
Connect: (self: Signal<T...>, callback: (T...) -> ()) -> RBXScriptConnection,
ConnectParallel: (self: Signal<T...>, callback: (T...) -> ()) -> RBXScriptConnection,
Once: (self: Signal<T...>, callback: (T...) -> ()) -> RBXScriptConnection,
Wait: (self: Signal<T...>) -> (T...)
}
return collect :: <T...>(Signal<T...>) -> (() -> (T...), RBXScriptConnection)

View file

@ -1,40 +1,32 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local types = require("../ReplicatedStorage/types")
type Signal<T...> = {
Connect: (Signal<T...>, fn: (T...) -> ()) -> RBXScriptConnection
}
type Remote<T...> = {
FireClient: (Remote<T...>, T...) -> (),
FireClient: (Remote<T...>, Player, T...) -> (),
FireAllClients: (Remote<T...>, T...) -> (),
FireServer: (Remote<T...>) -> (),
OnServerEvent: {
Connect: (any, fn: (Player, T...) -> () ) -> ()
},
OnClientEvent: {
Connect: (any, fn: (T...) -> () ) -> ()
FireServer: (Remote<T...>, T...) -> (),
OnServerEvent: RBXScriptSignal<(Player, T...)>,
OnClientEvent: RBXScriptSignal<T...>
}
}
local function stream_ensure(name): Remote<any>
local function stream_ensure(name)
local remote = ReplicatedStorage:FindFirstChild(name)
if not remote then
remote = Instance.new("RemoteEvent")
remote.Name = name
remote.Parent = ReplicatedStorage
end
return remote :: any
return remote
end
local function datagram_ensure(name): Remote<any>
local function datagram_ensure(name)
local remote = ReplicatedStorage:FindFirstChild(name)
if not remote then
remote = Instance.new("UnreliableRemoteEvent")
remote.Name = name
remote.Parent = ReplicatedStorage
end
return remote :: any
return remote
end
return {

View file

@ -88,9 +88,6 @@ return function(world: types.World)
if removed then
for _, entity in removed do
entity = ecs_ensure_entity(world, entity)
if not world:contains(entity) then
continue
end
world:remove(entity, id)
end
end

View file

@ -1,4 +1,3 @@
--!strict
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
@ -177,7 +176,7 @@ return function(world: ty.World)
set_n += 1
set_ids[set_n] = e
set_values[set_n] = v or true
elseif not world:contains(e) then
elseif world:contains(e) then
removed_n += 1
removed_ids[removed_n] = e
end