rbxts-chrono 2.0.0-experimental.1 → 2.0.0-experimental.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -1
- package/package.json +1 -1
- package/src/index.d.ts +69 -44
- package/src/init.lua +39 -2
package/README.md
CHANGED
|
@@ -1,2 +1,38 @@
|
|
|
1
1
|
# rbxts-chrono
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for [Chrono](https://github.com/Parihsz/Chrono) - a custom character replication library for Roblox.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install rbxts-chrono
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import Chrono from "rbxts-chrono";
|
|
15
|
+
|
|
16
|
+
// Start Chrono
|
|
17
|
+
Chrono.Start();
|
|
18
|
+
|
|
19
|
+
// Create an entity
|
|
20
|
+
const entity = new Chrono.Entity("default", model);
|
|
21
|
+
|
|
22
|
+
// Set entity CFrame
|
|
23
|
+
entity.SetCFrame(new CFrame(0, 10, 0));
|
|
24
|
+
|
|
25
|
+
// Listen for events
|
|
26
|
+
Chrono.Events.EntityAdded.Connect((entity) => {
|
|
27
|
+
print("Entity added:", entity.GetModel());
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Links
|
|
32
|
+
|
|
33
|
+
- [Chrono Repository](https://github.com/Parihsz/Chrono)
|
|
34
|
+
- [Chrono Documentation](https://parihsz.github.io/Chrono/)
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
MIT
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
type ModelReplicationMode = "NATIVE" | "NATIVE_WITH_LOCK" | "CUSTOM";
|
|
9
9
|
|
|
10
10
|
// Player replication modes
|
|
11
|
-
type PlayerReplicationMode = "AUTOMATIC" | "
|
|
11
|
+
type PlayerReplicationMode = "AUTOMATIC" | "CUSTOM";
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
type
|
|
13
|
+
// Replication filter modes (used for REPLICATE_DEATHS and REPLICATE_CFRAME_SETTERS)
|
|
14
|
+
type ReplicationFilterMode = "NONE" | "PLAYER_ENTITIES" | "PLAYER_CHARACTERS";
|
|
15
15
|
|
|
16
16
|
// Configuration option names
|
|
17
17
|
type ConfigName =
|
|
@@ -26,7 +26,8 @@ type ConfigName =
|
|
|
26
26
|
| "PLAYER_REPLICATION"
|
|
27
27
|
| "REPLICATE_DEATHS"
|
|
28
28
|
| "REPLICATE_CFRAME_SETTERS"
|
|
29
|
-
| "MAX_TOTAL_BYTES_PER_FRAME_PER_PLAYER"
|
|
29
|
+
| "MAX_TOTAL_BYTES_PER_FRAME_PER_PLAYER"
|
|
30
|
+
| "SEND_FULL_ROTATION";
|
|
30
31
|
|
|
31
32
|
// Event system types
|
|
32
33
|
interface Connection {
|
|
@@ -35,14 +36,14 @@ interface Connection {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
interface ChronoEvent<T extends Callback = Callback> {
|
|
38
|
-
Connect(callback: T): Connection;
|
|
39
|
-
Once(callback: T): Connection;
|
|
40
|
-
Wait(): LuaTuple<Parameters<T>>;
|
|
39
|
+
Connect(callback: T, defer?: boolean): Connection;
|
|
40
|
+
Once(callback: T, defer?: boolean): Connection;
|
|
41
|
+
Wait(defer?: boolean): LuaTuple<Parameters<T>>;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
// Snapshot types
|
|
44
45
|
interface SnapshotData<Value, Velocity> {
|
|
45
|
-
|
|
46
|
+
t: number;
|
|
46
47
|
value: Value;
|
|
47
48
|
velocity: Velocity;
|
|
48
49
|
}
|
|
@@ -56,18 +57,15 @@ interface Snapshot<Value, Velocity> {
|
|
|
56
57
|
|
|
57
58
|
// Entity configuration input
|
|
58
59
|
interface EntityConfigInput {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
BUFFER?: {
|
|
65
|
-
MIN?: number;
|
|
66
|
-
MAX?: number;
|
|
67
|
-
};
|
|
60
|
+
BUFFER: number;
|
|
61
|
+
TICK_RATE: number;
|
|
62
|
+
FULL_ROTATION?: boolean;
|
|
63
|
+
AUTO_UPDATE_POSITION?: boolean;
|
|
64
|
+
STORE_SNAPSHOTS?: boolean;
|
|
68
65
|
MODEL_REPLICATION_MODE?: ModelReplicationMode;
|
|
69
66
|
NORMAL_TICK_DISTANCE?: number;
|
|
70
67
|
HALF_TICK_DISTANCE?: number;
|
|
68
|
+
CUSTOM_INTERPOLATION?: boolean;
|
|
71
69
|
}
|
|
72
70
|
|
|
73
71
|
// Stats interfaces
|
|
@@ -99,19 +97,41 @@ interface ServerStats {
|
|
|
99
97
|
|
|
100
98
|
// Entity event names
|
|
101
99
|
type EntityEventName =
|
|
102
|
-
| "
|
|
103
|
-
| "
|
|
104
|
-
| "
|
|
105
|
-
| "
|
|
106
|
-
| "
|
|
107
|
-
| "
|
|
108
|
-
| "
|
|
109
|
-
| "
|
|
110
|
-
| "OnReplicationPaused"
|
|
111
|
-
| "OnReplicationResumed";
|
|
100
|
+
| "Destroying"
|
|
101
|
+
| "NetworkOwnerChanged"
|
|
102
|
+
| "PushedSnapShot"
|
|
103
|
+
| "TickChanged"
|
|
104
|
+
| "DataChanged"
|
|
105
|
+
| "Ticked"
|
|
106
|
+
| "ModelChanged"
|
|
107
|
+
| "LockChanged";
|
|
112
108
|
|
|
113
109
|
// Entity interface
|
|
114
110
|
interface Entity {
|
|
111
|
+
/** Unique identifier for this entity */
|
|
112
|
+
readonly id: number;
|
|
113
|
+
|
|
114
|
+
/** Whether this entity is registered with the system */
|
|
115
|
+
readonly registered: boolean;
|
|
116
|
+
|
|
117
|
+
/** Whether this entity has been destroyed */
|
|
118
|
+
readonly destroyed: boolean;
|
|
119
|
+
|
|
120
|
+
/** The player who owns this entity (controls its movement) */
|
|
121
|
+
readonly networkOwner: Player | undefined;
|
|
122
|
+
|
|
123
|
+
/** Whether the current context (client/server) is the network owner */
|
|
124
|
+
readonly isContextOwner: boolean;
|
|
125
|
+
|
|
126
|
+
/** The model associated with this entity */
|
|
127
|
+
readonly model: Model | BasePart | undefined;
|
|
128
|
+
|
|
129
|
+
/** Whether replication is paused for this entity */
|
|
130
|
+
readonly paused: boolean;
|
|
131
|
+
|
|
132
|
+
/** The most recent CFrame value */
|
|
133
|
+
readonly latestCFrame: CFrame | undefined;
|
|
134
|
+
|
|
115
135
|
/** Sets or changes the model for this entity */
|
|
116
136
|
SetModel(
|
|
117
137
|
model?: Model | BasePart | string,
|
|
@@ -183,16 +203,20 @@ interface Entity {
|
|
|
183
203
|
Destroy(): void;
|
|
184
204
|
|
|
185
205
|
/** Gets an event by name */
|
|
186
|
-
GetEvent(name: "
|
|
187
|
-
GetEvent(
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
GetEvent(
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
GetEvent(name: "
|
|
194
|
-
GetEvent(name: "
|
|
195
|
-
GetEvent(name: "
|
|
206
|
+
GetEvent(name: "Destroying"): ChronoEvent<(entity: Entity) => void>;
|
|
207
|
+
GetEvent(
|
|
208
|
+
name: "NetworkOwnerChanged",
|
|
209
|
+
): ChronoEvent<(entity: Entity, newOwner: Player | undefined, prevOwner: Player | undefined) => void>;
|
|
210
|
+
GetEvent(
|
|
211
|
+
name: "PushedSnapShot",
|
|
212
|
+
): ChronoEvent<(entity: Entity, time: number, value: CFrame, isNewest: boolean) => void>;
|
|
213
|
+
GetEvent(name: "TickChanged"): ChronoEvent<(entity: Entity, newTickType: "NONE" | "HALF" | "NORMAL") => void>;
|
|
214
|
+
GetEvent(name: "DataChanged"): ChronoEvent<(entity: Entity, data: unknown) => void>;
|
|
215
|
+
GetEvent(name: "Ticked"): ChronoEvent<(entity: Entity, dt: number) => void>;
|
|
216
|
+
GetEvent(
|
|
217
|
+
name: "ModelChanged",
|
|
218
|
+
): ChronoEvent<(entity: Entity, newModel: Model | BasePart | undefined, oldModel: Model | BasePart | undefined) => void>;
|
|
219
|
+
GetEvent(name: "LockChanged"): ChronoEvent<(entity: Entity, isLocked: boolean) => void>;
|
|
196
220
|
GetEvent(name: EntityEventName): ChronoEvent;
|
|
197
221
|
}
|
|
198
222
|
|
|
@@ -249,8 +273,8 @@ declare namespace Chrono {
|
|
|
249
273
|
/** Gets the entity associated with a model */
|
|
250
274
|
function GetEntityFromModel(model: Model): Entity | undefined;
|
|
251
275
|
|
|
252
|
-
/** Map of entity IDs to entities */
|
|
253
|
-
const idMap:
|
|
276
|
+
/** Map of entity IDs to entities (Lua table, use .get() to access) */
|
|
277
|
+
const idMap: ReadonlyMap<number, Entity>;
|
|
254
278
|
}
|
|
255
279
|
|
|
256
280
|
/** Global events */
|
|
@@ -286,9 +310,10 @@ declare namespace Chrono {
|
|
|
286
310
|
function SetConfig(name: "DEFAULT_HALF_TICK_DISTANCE", value: number): void;
|
|
287
311
|
function SetConfig(name: "DEFAULT_MODEL_REPLICATION_MODE", value: ModelReplicationMode): void;
|
|
288
312
|
function SetConfig(name: "PLAYER_REPLICATION", value: PlayerReplicationMode): void;
|
|
289
|
-
function SetConfig(name: "REPLICATE_DEATHS", value:
|
|
290
|
-
function SetConfig(name: "REPLICATE_CFRAME_SETTERS", value:
|
|
313
|
+
function SetConfig(name: "REPLICATE_DEATHS", value: ReplicationFilterMode): void;
|
|
314
|
+
function SetConfig(name: "REPLICATE_CFRAME_SETTERS", value: ReplicationFilterMode): void;
|
|
291
315
|
function SetConfig(name: "MAX_TOTAL_BYTES_PER_FRAME_PER_PLAYER", value: number): void;
|
|
316
|
+
function SetConfig(name: "SEND_FULL_ROTATION", value: boolean): void;
|
|
292
317
|
function SetConfig(name: ConfigName, value: unknown): void;
|
|
293
318
|
|
|
294
319
|
/** Registers a custom entity type configuration */
|
|
@@ -300,14 +325,14 @@ declare namespace Chrono {
|
|
|
300
325
|
|
|
301
326
|
/** Replication rules for controlling entity visibility */
|
|
302
327
|
namespace ReplicationRules {
|
|
303
|
-
/** Sets a replication rule for a target */
|
|
328
|
+
/** Sets a replication rule for a target. Pass undefined to clear the rule. */
|
|
304
329
|
function SetReplicationRule(
|
|
305
330
|
target: Player | Model | number | Entity,
|
|
306
|
-
rule: ReplicationRule | RuleFn,
|
|
331
|
+
rule: ReplicationRule | RuleFn | undefined,
|
|
307
332
|
): void;
|
|
308
333
|
|
|
309
334
|
/** Checks if an entity should be replicated to a viewer */
|
|
310
|
-
function Allows(entity: Entity, viewer: Player
|
|
335
|
+
function Allows(entity: Entity, viewer: Player): boolean;
|
|
311
336
|
|
|
312
337
|
/** Creates a rule that only includes specified players */
|
|
313
338
|
function Include(players: Player[]): RuleFn;
|
package/src/init.lua
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
-- rbxts-chrono: TypeScript types for Chrono
|
|
2
|
-
-- Re-exports the chrono-lua dependency
|
|
2
|
+
-- Re-exports the chrono-lua dependency with all sub-modules
|
|
3
|
+
|
|
4
|
+
local RunService = game:GetService("RunService")
|
|
5
|
+
local IS_SERVER = RunService:IsServer()
|
|
3
6
|
|
|
4
7
|
local Packages = script.Parent.Parent.Parent
|
|
5
|
-
|
|
8
|
+
local ChronoSrc = Packages["chrono-lua"].src
|
|
9
|
+
local Shared = ChronoSrc.Shared
|
|
10
|
+
|
|
11
|
+
-- Main module (contains Start)
|
|
12
|
+
local Main = require(ChronoSrc)
|
|
13
|
+
|
|
14
|
+
-- Shared modules (available on both client and server)
|
|
15
|
+
local Entity = require(Shared.Entity)
|
|
16
|
+
local Holder = require(Shared.Holder)
|
|
17
|
+
local Events = require(Shared.Events)
|
|
18
|
+
local Config = require(Shared.Config)
|
|
19
|
+
local ReplicationRules = require(Shared.ReplicationRules)
|
|
20
|
+
local Stats = require(Shared.Stats)
|
|
21
|
+
local Snapshots = require(Shared.Snapshots)
|
|
22
|
+
|
|
23
|
+
-- Build the export table
|
|
24
|
+
local Chrono = {
|
|
25
|
+
Start = Main.Start,
|
|
26
|
+
Entity = Entity,
|
|
27
|
+
Holder = Holder,
|
|
28
|
+
Events = Events,
|
|
29
|
+
Config = Config,
|
|
30
|
+
ReplicationRules = ReplicationRules,
|
|
31
|
+
Stats = Stats,
|
|
32
|
+
Snapshots = { New = Snapshots },
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
-- Server-only modules
|
|
36
|
+
if IS_SERVER then
|
|
37
|
+
local Server = ChronoSrc.Server
|
|
38
|
+
Chrono.Receiver = require(Server.Receiver)
|
|
39
|
+
Chrono.ServerClock = require(Server.ServerClock)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
return Chrono
|