@rbxts/prototype 0.0.5 → 0.0.7

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.
@@ -59,6 +59,11 @@ export declare class PrototypeHandler {
59
59
  /** @metadata macro */
60
60
  TryIndex<T extends IPrototype>(prototypeId: string, kindName?: Modding.Generic<T, "text"> | string): [success: false] | [success: true, prototype: T];
61
61
  TryIndex(prototypeId: string, kindName: string): [success: false] | [success: true, prototype: IPrototype];
62
+ /** @metadata macro */
63
+ Index<T extends IPrototype>(prototypeId: string, kindName?: Modding.Generic<T, "text"> | string): T;
64
+ Index(prototypeId: string, kindName: string): IPrototype;
65
+ /** @metadata macro */
66
+ IndexAll<T extends IPrototype>(kindName?: Modding.Generic<T, "text"> | string): T[];
62
67
  Compile(): void;
63
68
  RegisterPrototype(prototype: IPrototype, kindName: string): void;
64
69
  }
package/out/prototype.lua CHANGED
@@ -390,6 +390,42 @@ do
390
390
  local _prototypeId_1 = prototypeId
391
391
  return { true, _instances_1[_prototypeId_1].Instance }
392
392
  end
393
+ function PrototypeHandler:Index(prototypeId, kindName)
394
+ local _prototypes = self.prototypes
395
+ local _kindName = kindName
396
+ local kind = _prototypes[_kindName]
397
+ if not kind then
398
+ error(`Prototype with kind key: {kindName} does not exist. PrototypeId: {prototypeId}`)
399
+ end
400
+ local _instances = kind.Instances
401
+ local _prototypeId = prototypeId
402
+ local _condition = not (_instances[_prototypeId] ~= nil)
403
+ if not _condition then
404
+ local _instances_1 = kind.Instances
405
+ local _prototypeId_1 = prototypeId
406
+ _condition = not _instances_1[_prototypeId_1].Instance
407
+ end
408
+ if _condition then
409
+ error(`Prototype with id: {prototypeId} does not exist`)
410
+ end
411
+ local _instances_1 = kind.Instances
412
+ local _prototypeId_1 = prototypeId
413
+ return _instances_1[_prototypeId_1].Instance
414
+ end
415
+ function PrototypeHandler:IndexAll(kindName)
416
+ local _prototypes = self.prototypes
417
+ local _kindName = kindName
418
+ local kind = _prototypes[_kindName]
419
+ if not kind then
420
+ error(`Prototype with kind key: {kindName} does not exist`)
421
+ end
422
+ local instances = {}
423
+ for _, instanceData in pairs(kind.Instances) do
424
+ local _instance = instanceData.Instance
425
+ table.insert(instances, _instance)
426
+ end
427
+ return instances
428
+ end
393
429
  function PrototypeHandler:Compile()
394
430
  local ids = {}
395
431
  for id, Kind in self.allRegisteredPrototypes do
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/prototype",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {