fix: Bugs + temp push for bugfixing

This commit is contained in:
Mark Marks 2024-09-22 00:05:15 +02:00
parent 88ca58df9b
commit d34edf8d70
21 changed files with 2317 additions and 73 deletions

View file

@ -61,7 +61,9 @@ local function collect<D, T...>(event: signal_like<D, T...>): (() -> (number, T.
end
end
local disconnect = event:Connect(function(...)
local connect = event.Connect or event.connect
assert(connect ~= nil, "Signal is missing a Connect function - is it really a signal?")
local disconnect = connect(event, function(...)
table.insert(storage, { ... })
mt.__iter = iter :: any
end)

View file

@ -1,10 +1,10 @@
--!strict
--!optimize 2
local jecs = require("@pkg/jecs")
local jecs = require("./jecs")
type entity<T = nil> = jecs.Entity<T>
type id<T = nil> = jecs.Id<T>
local world = require("./world").get()
local WORLD = require("./world").get
--- `map<component_id, array<entity_id>>`
local add_commands: { [id]: { entity } } = {}
@ -15,7 +15,7 @@ local remove_commands: { [id]: { entity } } = {}
--- `array<entity_id>`
local delete_commands: { entity } = {}
type command_buffer = {
export type command_buffer = {
--- Execute all buffered commands and clear the buffer
flush: () -> (),
@ -30,48 +30,46 @@ type command_buffer = {
}
local function flush()
local adds = add_commands
local sets = set_commands
local removes = remove_commands
local deletes = delete_commands
local world = WORLD()
for _, entity in delete_commands do
world:delete(entity)
end
for component, entities in add_commands do
for _, entity in entities do
if delete_commands[entity] then
continue
end
world:add(entity, component)
end
end
table.clear(add_commands)
for component, entities in set_commands do
for entity, value in entities do
if delete_commands[entity] then
continue
end
world:set(entity, component, value)
end
end
table.clear(set_commands)
for component, entities in remove_commands do
for _, entity in entities do
if delete_commands[entity] then
continue
end
world:remove(entity, component)
end
end
table.clear(remove_commands)
table.clear(delete_commands)
for _, id in deletes do
world:delete(id)
end
for component, ids in adds do
for _, id in ids do
if deletes[id] then
continue
end
world:add(id, component)
end
end
for component, ids in sets do
for id, value in ids do
if deletes[id] then
continue
end
world:set(id, component, value)
end
end
for component, ids in removes do
for _, id in ids do
if deletes[id] then
continue
end
world:remove(id, component)
end
end
end
local function add(entity: entity, component: id)

View file

@ -1,10 +1,10 @@
--!strict
--!optimize 2
local jecs = require("@pkg/jecs")
export type entity<T = nil> = jecs.Entity<T>
export type id<T = nil> = entity<T> | jecs.Pair
local jecs = require("./jecs")
type entity<T = nil> = jecs.Entity<T>
type id<T = nil> = entity<T> | jecs.Pair
local world = require("./world").get()
local world = require("./world").get
type interface = {
__index: interface,
@ -44,34 +44,34 @@ function handle.new(entity: entity)
end
function handle:has(...: id): boolean
return world:has(self.entity, ...)
return world():has(self.entity, ...)
end
handle.get = function(self: handle, a: id, b: id?, c: id?, d: id?)
return world:get(self.entity, a, b :: any, c :: any, d :: any)
return world():get(self.entity, a, b :: any, c :: any, d :: any)
end :: any
function handle:add<T>(id: id<T>): handle
world:add(self.entity, id)
world():add(self.entity, id)
return self
end
function handle:set<T>(id: id<T>, value: T): handle
world:set(self.entity, id, value)
world():set(self.entity, id, value)
return self
end
function handle:remove(id: id): handle
world:remove(self.entity, id)
world():remove(self.entity, id)
return self
end
function handle:delete()
world:delete(self.entity)
world():delete(self.entity)
end
function handle:id(): entity
return self.entity
end
return handle
return handle.new

View file

@ -1,12 +1,19 @@
--!strict
--!optimize 2
local jecs = require("./jecs")
local WORLD = require("./world")
local collect = require("./collect")
export type collect_signal_like<T...> = collect.signal_like<any, T...>
export type collect_verbose_signal_like<D, T...> = collect.signal_like<D, T...>
local command_buffer = require("./command_buffer")
export type command_buffer = command_buffer.command_buffer
local handle = require("./handle")
local jecs = require("@pkg/jecs")
export type handle = handle.handle
local ref = require("./ref")
local replicator = require("./replicator")
export type replicator = replicator.replicator
export type changes = replicator.changes
--- Set the world for all utilities.
--- Should be called once per context before any utility is used.

1895
lib/jecs.luau Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
--!strict
--!optimize 2
local handle = require("./handle")
local world = require("./world").get()
local WORLD = require("./world").get
local refs = {}
@ -11,8 +11,9 @@ local refs = {}
--- @param key any
--- @return handle
local function ref(key: any): handle.handle
local world = WORLD()
if not key then
return handle.new(world:entity())
return handle(world:entity())
end
local entity = refs[key]
@ -21,7 +22,7 @@ local function ref(key: any): handle.handle
refs[key] = entity
end
return handle.new(entity)
return handle(entity)
end
return ref

View file

@ -1,11 +1,11 @@
--!strict
--!optimize 2
local jecs = require("@pkg/jecs")
local jecs = require("./jecs")
type entity<T = nil> = jecs.Entity<T>
type i53 = number
local ref = require("./ref")
local world = require("./world").get()
local WORLD = require("./world").get
--- A replicator keeps track of all entities with the passed components and their values -
--- whenever a component is changed (add, change, remove) and the replicator listens to it, it's also changed within the contained raw data.\
@ -122,6 +122,7 @@ export type changes = {
--- @param ... entity
--- @return replicator
local function replicator(...: entity): replicator
local world = WORLD()
local components = { ... }
-- don't index a changes table start

View file

@ -1,6 +1,6 @@
--!strict
--!optimize 2
local jecs = require("@pkg/jecs")
local jecs = require("./jecs")
local WORLD: jecs.World