mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Fix types in export
This commit is contained in:
parent
f2d6d76686
commit
f302fad3b6
7 changed files with 39 additions and 25 deletions
|
@ -1,13 +1,22 @@
|
|||
local jecs = require(game:GetService("ReplicatedStorage").ecs)
|
||||
local world = require(script.Parent.world)
|
||||
|
||||
local components = {
|
||||
type Entity<T=nil> = jecs.Entity<T>
|
||||
local components: {
|
||||
Character: Entity<Model>,
|
||||
Mob: Entity,
|
||||
Model: Entity<Model>,
|
||||
Player: Entity,
|
||||
Target: Entity,
|
||||
Transform: Entity<CFrame>,
|
||||
Velocity: Entity<number>,
|
||||
} = {
|
||||
Character = world:component(),
|
||||
Mob = world:component(),
|
||||
Model = world:component() :: jecs.Entity<Model>,
|
||||
Model = world:component(),
|
||||
Player = world:component(),
|
||||
Target = world:component(),
|
||||
Transform = world:component() :: jecs.Entity<CFrame>,
|
||||
Transform = world:component(),
|
||||
Velocity = world:component(),
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local jecs = require(game:GetService("ReplicatedStorage").ecs)
|
||||
local world = require(script.world)
|
||||
|
||||
local world = require(script.world) :: jecs.World
|
||||
export type World = jecs.World
|
||||
local std = {
|
||||
ChangeTracker = require(script.changetracker),
|
||||
Scheduler = require(script.scheduler),
|
||||
|
@ -11,7 +11,7 @@ local std = {
|
|||
handle = require(script.handle),
|
||||
interval = require(script.interval),
|
||||
ref = require(script.ref),
|
||||
world = world,
|
||||
world = world :: World,
|
||||
pair = jecs.pair,
|
||||
__ = jecs.w,
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
local jecs = require(game:GetService("ReplicatedStorage").ecs)
|
||||
export type World = jecs.t_world
|
||||
|
||||
-- I like the idea of only having the world be a singleton.
|
||||
return jecs.World.new()
|
||||
return jecs.World.new() :: jecs.World
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
--!strict
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local blink = require(game:GetService("ServerScriptService").net)
|
||||
local jecs = require(ReplicatedStorage.ecs)
|
||||
local pair = jecs.pair
|
||||
local __ = jecs.Wildcard
|
||||
|
||||
local std = require(ReplicatedStorage.std)
|
||||
local world = std.world
|
||||
|
||||
local world: std.World = std.world
|
||||
local cts = std.components
|
||||
|
||||
local Mob = cts.Mob
|
||||
|
@ -14,7 +13,6 @@ local Transform = cts.Transform
|
|||
local Velocity = cts.Velocity
|
||||
local Player = cts.Player
|
||||
local Character = cts.Character
|
||||
print("client Model", cts.Model)
|
||||
|
||||
local function mobsMove(dt: number)
|
||||
local players = world:query(Character):with(Player)
|
||||
|
@ -23,15 +21,18 @@ local function mobsMove(dt: number)
|
|||
local p = cf.Position
|
||||
|
||||
local target
|
||||
for playerId, character in players do
|
||||
local pos = character.PrimaryPart.Position
|
||||
|
||||
for playerId, character in players:iter() do
|
||||
local pos = (character.PrimaryPart::Part).Position
|
||||
if true then
|
||||
target = pos
|
||||
break
|
||||
end
|
||||
if not target then
|
||||
target = pos
|
||||
elseif (p - pos).Magnitude < (p - target) then
|
||||
elseif (p - pos).Magnitude
|
||||
< (p - target).Magnitude
|
||||
then
|
||||
target = pos
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,14 +11,16 @@ local Character = cts.Character
|
|||
|
||||
local playersAdded = collect(Players.PlayerAdded)
|
||||
local playersRemoved = collect(Players.PlayerRemoving)
|
||||
local world: std.World = std.world
|
||||
|
||||
local conn = {}
|
||||
|
||||
local function players()
|
||||
for _, player in playersAdded do
|
||||
std.world:set(
|
||||
world:set(
|
||||
std.world:entity(),
|
||||
std.world:entity())
|
||||
cts.Transform
|
||||
)
|
||||
|
||||
local e = ref(player.UserId):set(Player, player)
|
||||
local characterAdd = player.CharacterAdded
|
||||
|
|
|
@ -3,5 +3,4 @@ wally = "upliftgames/wally@0.3.2"
|
|||
rojo = "rojo-rbx/rojo@7.4.1"
|
||||
stylua = "johnnymorganz/stylua@0.19.1"
|
||||
selene = "kampfkarren/selene@0.26.1"
|
||||
wally-patch-package = "Barocena/wally-patch-package@1.2.1"
|
||||
Blink = "1Axen/Blink@0.14.1"
|
|
@ -1442,9 +1442,9 @@ end
|
|||
|
||||
export type Pair = number
|
||||
|
||||
type Item = () -> (number, ...any)
|
||||
type Item<T...> = (self: Query<T...>) -> (Entity, T...)
|
||||
|
||||
export type Entity<T = nil> = number & {__DO_NOT_USE_OR_YOU_WILL_BE_FIRED: T }
|
||||
export type Entity<T = nil> = number & {__T: T }
|
||||
|
||||
type Iter<T...> = (query: Query<T...>) -> () -> (Entity, T...)
|
||||
|
||||
|
@ -1452,14 +1452,14 @@ type Query<T...> = typeof(setmetatable({}, {
|
|||
__iter = (nil :: any) :: Iter<T...>
|
||||
})) & {
|
||||
iter: Iter<T...>,
|
||||
next: Item,
|
||||
with: (Query<T...>) -> Query<T...>,
|
||||
without: (Query<T...>, ...i53) -> Query<T...>,
|
||||
replace: (Query<T...>, <U...>(T...) -> (U...)) -> (),
|
||||
next: Item<T...>,
|
||||
with: (self: Query<T...>, ...i53) -> Query<T...>,
|
||||
without: (self: Query<T...>, ...i53) -> Query<T...>,
|
||||
replace: (self: Query<T...>, <U...>(T...) -> (U...)) -> (),
|
||||
archetypes: () -> { Archetype },
|
||||
}
|
||||
|
||||
type World = {
|
||||
export type World = {
|
||||
archetypeIndex: { [string]: Archetype },
|
||||
archetypes: Archetypes,
|
||||
componentIndex: ComponentIndex,
|
||||
|
@ -1496,6 +1496,10 @@ type World = {
|
|||
& (<A, B, C>(self: World, id: Entity, Entity<A>, Entity<B>, Entity<C>) -> (A, B, C))
|
||||
& <A, B, C, D>(self: World, id: Entity, Entity<A>, Entity<B>, Entity<C>, Entity<D>) -> (A, B, C, D),
|
||||
|
||||
has: (self: World, ...Entity) -> boolean,
|
||||
|
||||
parent: (self: World, entity: Entity) -> Entity,
|
||||
|
||||
--- Searches the world for entities that match a given query
|
||||
query: (<A>(self: World, Entity<A>) -> Query<A>)
|
||||
& (<A, B>(self: World, Entity<A>, Entity<B>) -> Query<A, B>)
|
||||
|
|
Loading…
Reference in a new issue