@rbxts/covenant 3.5.1 → 3.6.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/covenant",
3
- "version": "3.5.1",
3
+ "version": "3.6.0",
4
4
  "main": "src/init.luau",
5
5
  "scripts": {
6
6
  "build": "rbxtsc",
package/src/covenant.d.ts CHANGED
@@ -4,8 +4,9 @@ import { Remove, Delete } from "./stringEnums";
4
4
  export * from "@rbxts/jecs";
5
5
  export type WorldChangesForReplication = Map<string, Delete | Map<string, defined | Remove>>;
6
6
  export type WorldChangesForPrediction = Map<string, Map<string, defined | Remove>>;
7
+ export type LoggingOption = "FORCE_ON" | "FORCE_OFF" | "COMPONENT_CONTROLLED";
7
8
  export interface CovenantProps {
8
- logging: boolean;
9
+ logging: LoggingOption;
9
10
  requestPayloadSend: () => void;
10
11
  requestPayloadConnect: (callback: (player: Player) => void) => void;
11
12
  replicationSend: (player: Player, worldChanges: WorldChangesForReplication) => void;
@@ -25,6 +26,7 @@ export declare class Covenant {
25
26
  private undefinedStringifiedComponents;
26
27
  private replicatedStringifiedComponents;
27
28
  private predictedStringifiedComponents;
29
+ private loggingStringfiedComponents;
28
30
  private stringfiedComponentsToNameMap;
29
31
  private started;
30
32
  private stringifiedComponentSubscribers;
@@ -41,9 +43,7 @@ export declare class Covenant {
41
43
  constructor({ logging, requestPayloadSend, requestPayloadConnect, replicationSend, replicationConnect, replicationSendAll, predictionSend, predictionConnect, }: CovenantProps);
42
44
  getClientEntity(entity: Entity): Entity | undefined;
43
45
  getServerEntity(entity: Entity): Entity | undefined;
44
- private logging;
45
- enableLogging(): void;
46
- disableLogging(): void;
46
+ private loggingOption;
47
47
  private setupPredictionClient;
48
48
  private forEachComponentChanges;
49
49
  private setupPredictionServer;
@@ -63,14 +63,16 @@ export declare class Covenant {
63
63
  worldTag(): Entity<undefined>;
64
64
  private checkComponentDefined;
65
65
  private defineComponentNetworkBehavior;
66
- defineComponent<T extends defined>({ component, queriedComponents, recipe, replicated, predictionValidator, }: {
66
+ defineComponent<T extends defined>({ logging, component, queriedComponents, recipe, replicated, predictionValidator, }: {
67
+ logging?: true;
67
68
  replicated: boolean;
68
69
  predictionValidator: ComponentPredictionValidator | false;
69
70
  component: Entity<T>;
70
71
  queriedComponents: Entity[][];
71
72
  recipe: (entity: Entity, lastState: T | undefined, updateId: number, hooks: CovenantHooks) => T | undefined;
72
73
  }): void;
73
- defineIdentity<T extends defined>({ identityComponent, replicated, lifetime, factory, }: {
74
+ defineIdentity<T extends defined>({ logging, identityComponent, replicated, lifetime, factory, }: {
75
+ logging?: true;
74
76
  identityComponent: Entity<T>;
75
77
  replicated: boolean;
76
78
  lifetime: (entity: Entity, state: T, despawn: () => void) => (() => void) | undefined;
package/src/covenant.luau CHANGED
@@ -46,13 +46,14 @@ do
46
46
  self.undefinedStringifiedComponents = {}
47
47
  self.replicatedStringifiedComponents = {}
48
48
  self.predictedStringifiedComponents = {}
49
+ self.loggingStringfiedComponents = {}
49
50
  self.stringfiedComponentsToNameMap = {}
50
51
  self.started = false
51
52
  self.stringifiedComponentSubscribers = {}
52
53
  self.stringifiedComponentValidators = {}
53
54
  self.clientToServerEntityMap = {}
54
55
  self.serverToClientEntityMap = {}
55
- self.logging = logging
56
+ self.loggingOption = logging
56
57
  self.requestPayloadSend = requestPayloadSend
57
58
  self.requestPayloadConnect = requestPayloadConnect
58
59
  self.replicationSend = replicationSend
@@ -73,12 +74,6 @@ do
73
74
  local _arg0 = tostring(entity)
74
75
  return _clientToServerEntityMap[_arg0]
75
76
  end
76
- function Covenant:enableLogging()
77
- self.logging = true
78
- end
79
- function Covenant:disableLogging()
80
- self.logging = false
81
- end
82
77
  function Covenant:setupPredictionClient()
83
78
  self:schedule(RunService.Heartbeat, function()
84
79
  if next(self.worldChangesForPrediction) == nil then
@@ -378,7 +373,17 @@ do
378
373
  else
379
374
  self._world:set(entity, component, newState)
380
375
  end
381
- if self.logging and RunService:IsStudio() then
376
+ local _condition = RunService:IsStudio() and self.loggingOption ~= "FORCE_OFF"
377
+ if _condition then
378
+ local _condition_1 = self.loggingOption == "FORCE_ON"
379
+ if not _condition_1 then
380
+ local _loggingStringfiedComponents = self.loggingStringfiedComponents
381
+ local _arg0 = tostring(component)
382
+ _condition_1 = _loggingStringfiedComponents[_arg0] ~= nil
383
+ end
384
+ _condition = _condition_1
385
+ end
386
+ if _condition then
382
387
  print(`{self:getComponentName(component)}.{entity}.[{if doNotReconcile then "remote" else "local"}]:{tableToString(lastState)}->{tableToString(newState)}`)
383
388
  end
384
389
  local _stringifiedComponentSubscribers = self.stringifiedComponentSubscribers
@@ -397,13 +402,13 @@ do
397
402
  if doNotReconcile then
398
403
  return nil
399
404
  end
400
- local _condition = RunService:IsServer()
401
- if _condition then
405
+ local _condition_1 = RunService:IsServer()
406
+ if _condition_1 then
402
407
  local _replicatedStringifiedComponents = self.replicatedStringifiedComponents
403
408
  local _arg0_1 = tostring(component)
404
- _condition = _replicatedStringifiedComponents[_arg0_1] ~= nil
409
+ _condition_1 = _replicatedStringifiedComponents[_arg0_1] ~= nil
405
410
  end
406
- if _condition then
411
+ if _condition_1 then
407
412
  local _worldChangesForReplication = self.worldChangesForReplication
408
413
  local _arg0_1 = tostring(entity)
409
414
  local entityChanges = _worldChangesForReplication[_arg0_1]
@@ -421,13 +426,13 @@ do
421
426
  _entityChanges[_arg0_2] = _arg1
422
427
  end
423
428
  end
424
- local _condition_1 = RunService:IsClient()
425
- if _condition_1 then
429
+ local _condition_2 = RunService:IsClient()
430
+ if _condition_2 then
426
431
  local _predictedStringifiedComponents = self.predictedStringifiedComponents
427
432
  local _arg0_1 = tostring(component)
428
- _condition_1 = _predictedStringifiedComponents[_arg0_1] ~= nil
433
+ _condition_2 = _predictedStringifiedComponents[_arg0_1] ~= nil
429
434
  end
430
- if _condition_1 then
435
+ if _condition_2 then
431
436
  local _worldChangesForPrediction = self.worldChangesForPrediction
432
437
  local _arg0_1 = tostring(component)
433
438
  local componentChanges = _worldChangesForPrediction[_arg0_1]
@@ -553,6 +558,7 @@ do
553
558
  end
554
559
  end
555
560
  function Covenant:defineComponent(_param)
561
+ local logging = _param.logging
556
562
  local component = _param.component
557
563
  local queriedComponents = _param.queriedComponents
558
564
  local recipe = _param.recipe
@@ -560,6 +566,11 @@ do
560
566
  local predictionValidator = _param.predictionValidator
561
567
  self:checkComponentDefined(component)
562
568
  self:defineComponentNetworkBehavior(component, replicated, predictionValidator)
569
+ if logging then
570
+ local _loggingStringfiedComponents = self.loggingStringfiedComponents
571
+ local _arg0 = tostring(component)
572
+ _loggingStringfiedComponents[_arg0] = true
573
+ end
563
574
  local queryThisComponent = self:worldQuery(component):cached()
564
575
  local willUpdate = true
565
576
  local function indicateUpdate()
@@ -681,11 +692,17 @@ do
681
692
  end)
682
693
  end
683
694
  function Covenant:defineIdentity(_param)
695
+ local logging = _param.logging
684
696
  local identityComponent = _param.identityComponent
685
697
  local replicated = _param.replicated
686
698
  local lifetime = _param.lifetime
687
699
  local factory = _param.factory
688
700
  self:checkComponentDefined(identityComponent)
701
+ if logging then
702
+ local _loggingStringfiedComponents = self.loggingStringfiedComponents
703
+ local _arg0 = tostring(identityComponent)
704
+ _loggingStringfiedComponents[_arg0] = true
705
+ end
689
706
  self:defineComponentNetworkBehavior(identityComponent, replicated, false)
690
707
  factory(function(state)
691
708
  local entity = self:worldEntity()