Skip to content

Commit

Permalink
fix: Type fixes for sapphire + chore: Started working on sapphire-ecr…
Browse files Browse the repository at this point in the history
… types
  • Loading branch information
Mark-Marks committed Jul 31, 2024
1 parent 16a5ec6 commit 14481ee
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 10 deletions.
42 changes: 42 additions & 0 deletions crates/sapphire-ecr/lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { Handle, Entity } from "@rbxts/ecr";
import type { singleton } from "@rbxts/sapphire";

declare type loop_type = "Stepped" | "Heartbeat" | "RenderStepped";
declare interface system {
/** Fires every `RunService.Stepped` */
runner(delta_time: number): void;
/** 1 = lowest priority */
priority?: number;
/** Defaults to "Stepped" */
loop_type?: loop_type;
}

declare interface spawner<T> {
/**
* Creates an entity with the given components.
* @param components T[]
* @return ecr.entity
*/
spawn(...components: T[]): ecr.entity;
/**
* Creates an entity with the given components and returns a handle to it.
* @param components T[]
* @return @ecr.Handle
*/
spawn_with_handle(...components: T[]): ecr.Handle;
}

declare interface World {
readonly identifier: "sapphire-ecr";
readonly methods: Map<string, (singleton: singleton) => void>;

registry: ecr.registry;
readonly stepped_systems: system[];
readonly heartbeat_systems: system[];
readonly render_stepped_systems: system[];

extension(): void;
create_spawner<T>(...components: T[]): spawner<T>;
spawn_entity(): ecr.entity;
spawn_entity_with_handle(): ecr.Handle;
}
8 changes: 4 additions & 4 deletions crates/sapphire-ecr/lib/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ end
export type spawner<T...> = {
--- Creates an entity with the given components.
--- @param ... T...
--- @return ecr.entity
--- @returns ecr.entity
spawn: (T...) -> ecr.entity,
--- Creates an entity with the given components and returns a handle to it.
--- @param ... T...
--- @return ecr.Handle
--- @returns ecr.Handle
spawn_with_handle: (T...) -> ecr.Handle,
}

Expand All @@ -64,7 +64,7 @@ local function create_spawner(...)
local passed = { ... }
local entity = World.spawn_entity()

for index, _ in components do
for index in components do
World.registry:add(entity, passed[index])
end

Expand All @@ -75,7 +75,7 @@ local function create_spawner(...)
local passed = { ... }
local entity = World.spawn_entity_with_handle()

for index, _ in components do
for index in components do
entity:add(passed[index])
end

Expand Down
24 changes: 24 additions & 0 deletions crates/sapphire-ecr/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@rbxts/sapphire-ecr",
"version": "0.1.1-ts.1",
"description": "A lightweight ECR scheduler for sapphire",
"main": "lib/init.luau",
"types": "lib/index.d.ts",
"files": [
"lib"
],
"repository": {
"type": "git",
"url": "git+https://github.com/Mark-Marks/sapphire.git"
},
"publishConfig": {
"access": "public"
},
"author": "Mark-Marks",
"license": "MIT",
"homepage": "https://github.com/Mark-Marks/sapphire#readme",
"dependencies": {
"@rbxts/ecr": "^0.8.0-ts.2",
"@rbxts/sapphire": "^0.1.1-ts.1"
}
}
2 changes: 2 additions & 0 deletions crates/sapphire-net/lib/init.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--!strict
local squash = require(script.Parent.squash)
8 changes: 3 additions & 5 deletions crates/sapphire/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare interface Signal<T> {
/**
* Registerable singleton.
*/
declare interface singleton {
export interface singleton {
/**
* The name of the ModuleScript which holds the singleton. Overwritten by sapphire.
*/
Expand Down Expand Up @@ -47,7 +47,7 @@ declare interface singleton {
* Sapphire extension.
* Extensions are in their simplest form singletons that are instantly ran.
*/
declare interface extension {
export interface extension {
/**
* What to identify the extension by.
*/
Expand Down Expand Up @@ -145,8 +145,6 @@ declare interface SapphireObject {

declare function sapphire(): SapphireObject;

declare namespace sapphire {
export namespace sapphire {
export { SapphireObject as sapphire };
}

export = sapphire;
2 changes: 1 addition & 1 deletion crates/sapphire/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rbxts/sapphire",
"version": "0.1.1-ts.1",
"version": "0.1.2-ts.1",
"description": "A lightweight module loader or a batteries included framework",
"main": "lib/init.luau",
"types": "lib/index.d.ts",
Expand Down
Empty file added dev/server/test.ts
Empty file.

0 comments on commit 14481ee

Please sign in to comment.