isaacscript-common 15.1.0 → 15.2.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.
Files changed (39) hide show
  1. package/dist/index.d.ts +74 -5
  2. package/dist/isaacscript-common.lua +121 -11
  3. package/dist/src/classes/ModFeature.d.ts +10 -0
  4. package/dist/src/classes/ModFeature.d.ts.map +1 -1
  5. package/dist/src/classes/ModFeature.lua +53 -7
  6. package/dist/src/functions/arrayLua.d.ts +1 -1
  7. package/dist/src/functions/arrayLua.lua +1 -1
  8. package/dist/src/functions/decorators.d.ts.map +1 -1
  9. package/dist/src/functions/decorators.lua +10 -0
  10. package/dist/src/functions/entities.d.ts +27 -2
  11. package/dist/src/functions/entities.d.ts.map +1 -1
  12. package/dist/src/functions/entities.lua +63 -1
  13. package/dist/src/functions/gridEntities.d.ts +5 -2
  14. package/dist/src/functions/gridEntities.d.ts.map +1 -1
  15. package/dist/src/functions/gridEntities.lua +20 -2
  16. package/dist/src/functions/tears.d.ts +10 -0
  17. package/dist/src/functions/tears.d.ts.map +1 -1
  18. package/dist/src/functions/tears.lua +10 -0
  19. package/dist/src/index.d.ts +2 -0
  20. package/dist/src/index.d.ts.map +1 -1
  21. package/dist/src/indexLua.d.ts +171 -0
  22. package/dist/src/indexLua.d.ts.map +1 -0
  23. package/dist/src/indexLua.lua +1042 -0
  24. package/dist/src/types/EntityID.d.ts +10 -0
  25. package/dist/src/types/EntityID.d.ts.map +1 -0
  26. package/dist/src/types/EntityID.lua +2 -0
  27. package/dist/src/types/GridEntityID.d.ts +10 -0
  28. package/dist/src/types/GridEntityID.d.ts.map +1 -0
  29. package/dist/src/types/GridEntityID.lua +2 -0
  30. package/package.json +1 -1
  31. package/src/classes/ModFeature.ts +74 -6
  32. package/src/functions/arrayLua.ts +1 -1
  33. package/src/functions/decorators.ts +23 -8
  34. package/src/functions/entities.ts +76 -4
  35. package/src/functions/gridEntities.ts +35 -4
  36. package/src/functions/tears.ts +10 -0
  37. package/src/index.ts +2 -0
  38. package/src/types/EntityID.ts +7 -0
  39. package/src/types/GridEntityID.ts +7 -0
package/dist/index.d.ts CHANGED
@@ -641,6 +641,16 @@ export declare function addSetsToSet<T>(mainSet: Set<T>, ...setsToAdd: Array<Set
641
641
  * adds it to the player.
642
642
  * - This function should only be used inside the `EVALUATE_CACHE` callback.
643
643
  * - In this context, the "tears stat" represents what is shown on the in-game stat UI.
644
+ *
645
+ * For example:
646
+ *
647
+ * ```ts
648
+ * function evaluateCacheTears(player: EntityPlayer) {
649
+ * const numFoo = player.GetNumCollectible(CollectibleTypeCustom.FOO);
650
+ * const tearsStat = numFoo * FOO_TEARS_STAT;
651
+ * addTearsStat(player, tearsStat);
652
+ * }
653
+ * ```
644
654
  */
645
655
  export declare function addTearsStat(player: EntityPlayer, tearsStat: float): void;
646
656
 
@@ -3427,6 +3437,16 @@ export declare function emptyArray<T>(array: T[]): void;
3427
3437
  */
3428
3438
  export declare function emptyRoom(): void;
3429
3439
 
3440
+ /**
3441
+ * A string that represents an entity. This is the entity type, variant, and sub-type, all separated
3442
+ * by periods.
3443
+ *
3444
+ * This type is branded for extra type safety.
3445
+ */
3446
+ export declare type EntityID = string & {
3447
+ readonly __entityIDBrand: symbol;
3448
+ };
3449
+
3430
3450
  /**
3431
3451
  * Helper function to return an array of integers with the specified range, inclusive on the lower
3432
3452
  * end and exclusive on the high end. (The "e" stands for exclusive.)
@@ -4351,6 +4371,12 @@ export declare function getCollidingEntitiesWithGridEntity(gridEntity: GridEntit
4351
4371
  */
4352
4372
  export declare function getCombinedBossSet(stage: int): ReadonlySet<string> | undefined;
4353
4373
 
4374
+ /** Helper function to get the entity type, variant, and sub-type from an `EntityID`. */
4375
+ export declare function getConstituentsFromEntityID(entityID: EntityID): [entityType: EntityType, variant: int, subType: int];
4376
+
4377
+ /** Helper function to get the grid entity type and variant from a `GridEntityID`. */
4378
+ export declare function getConstituentsFromGridEntityID(gridEntityID: GridEntityID): [gridEntityType: GridEntityType, variant: int];
4379
+
4354
4380
  /**
4355
4381
  * Helper function to get all of the grid entities of type `GridEntityType.CRAWL_SPACE` (18) in the
4356
4382
  * room.
@@ -4518,12 +4544,12 @@ export declare function getEntityFields(entity: Entity): LuaMap<string, boolean
4518
4544
  export declare function getEntityFromPtrHash(ptrHash: PtrHash): Entity | undefined;
4519
4545
 
4520
4546
  /** Helper function to get a string containing the entity's type, variant, and sub-type. */
4521
- export declare function getEntityID(entity: Entity): string;
4547
+ export declare function getEntityID(entity: Entity): EntityID;
4522
4548
 
4523
4549
  /**
4524
4550
  * Helper function to get a formatted string in the format returned by the `getEntityID` function.
4525
4551
  */
4526
- export declare function getEntityIDFromConstituents(entityType: EntityType, variant: int, subType: int): string;
4552
+ export declare function getEntityIDFromConstituents(entityType: EntityType, variant: int, subType: int): EntityID;
4527
4553
 
4528
4554
  /**
4529
4555
  * Helper function to get a map containing the positions of every entity in the current room.
@@ -4732,13 +4758,13 @@ export declare function getGridEntitiesMap(...gridEntityTypes: GridEntityType[])
4732
4758
  export declare function getGridEntityCollisionPoints(gridEntity: GridEntity): [topLeft: Vector, bottomRight: Vector];
4733
4759
 
4734
4760
  /** Helper function to get a string containing the grid entity's type and variant. */
4735
- export declare function getGridEntityID(gridEntity: GridEntity): string;
4761
+ export declare function getGridEntityID(gridEntity: GridEntity): GridEntityID;
4736
4762
 
4737
4763
  /**
4738
4764
  * Helper function to get a formatted string in the format returned by the `getGridEntityID`
4739
4765
  * function.
4740
4766
  */
4741
- export declare function getGridEntityIDFromConstituents(gridEntityType: GridEntityType, variant: int): string;
4767
+ export declare function getGridEntityIDFromConstituents(gridEntityType: GridEntityType, variant: int): GridEntityID;
4742
4768
 
4743
4769
  /**
4744
4770
  * Helper function to get the grid index delta that a door out of the given room shape would lead
@@ -6474,6 +6500,16 @@ export declare interface GridEntityCustomData {
6474
6500
  defaultAnimation?: string;
6475
6501
  }
6476
6502
 
6503
+ /**
6504
+ * A string that represents a grid entity. This is the entity type and variant separated by a
6505
+ * period.
6506
+ *
6507
+ * This type is branded for extra type safety.
6508
+ */
6509
+ export declare type GridEntityID = string & {
6510
+ readonly __gridEntityIDBrand: symbol;
6511
+ };
6512
+
6477
6513
  declare class GridEntityRenderDetection extends Feature {
6478
6514
  private postGridEntityRender;
6479
6515
  private postGridEntityCustomRender;
@@ -6701,7 +6737,7 @@ export declare function inBossRoomOf(bossID: BossID): boolean;
6701
6737
  /**
6702
6738
  * Helper function for non-TypeScript users to check if an element is in an array.
6703
6739
  *
6704
- * Since this takes O(N) time, using this function is usually a mistake, since you can use a `Map`
6740
+ * Since this takes O(N) time, using this function is usually a mistake, since you can use a `Set`
6705
6741
  * data structure to get O(1) lookups.
6706
6742
  *
6707
6743
  * Internally, this just calls `array.includes`.
@@ -10647,10 +10683,20 @@ declare class ModdedElementSets extends Feature {
10647
10683
  * mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
10648
10684
  * that automatically subscribe to callbacks.
10649
10685
  *
10686
+ * If your feature has variables that are managed by the save data manager, put them as a `v` class
10687
+ * member and they will automatically be registered with the save data manager when the class is
10688
+ * instantiated.
10689
+ *
10650
10690
  * For example:
10651
10691
  *
10652
10692
  * ```ts
10653
10693
  * export class MyFeature extends ModFeature {
10694
+ * v = {
10695
+ * run: {
10696
+ * foo: 123,
10697
+ * }
10698
+ * }
10699
+ *
10654
10700
  * @Callback(ModCallback.POST_GAME_STARTED)
10655
10701
  * postGameStarted(isContinued: boolean): void {
10656
10702
  * Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
@@ -13347,6 +13393,16 @@ export declare type SoulHeartType = HeartSubType.SOUL | HeartSubType.BLACK | Hea
13347
13393
  * need to specify the velocity or spawner.
13348
13394
  *
13349
13395
  * Also see the `spawnWithSeed` helper function.
13396
+ *
13397
+ * @param entityType The `EntityType` of the entity to spawn.
13398
+ * @param variant The variant of the entity to spawn.
13399
+ * @param subType The sub-type of the entity to spawn.
13400
+ * @param position The position of the entity to spawn.
13401
+ * @param velocity Optional. The velocity of the entity to spawn. Default is `VectorZero`.
13402
+ * @param spawner Optional. The entity that will be the `SpawnerEntity`. Default is undefined.
13403
+ * @param seedOrRNG Optional. The seed or RNG object to use to generate the `InitSeed` of the
13404
+ * entity. Default is undefined, which will make the entity spawn with a random
13405
+ * seed using the `Isaac.Spawn` method.
13350
13406
  */
13351
13407
  export declare function spawn(entityType: EntityType, variant: int, subType: int, position: Vector, velocity?: Vector, spawner?: Entity | undefined, seedOrRNG?: Seed | RNG | undefined): Entity;
13352
13408
 
@@ -13517,6 +13573,19 @@ export declare function spawnEffectWithSeed(effectVariant: EffectVariant, subTyp
13517
13573
  */
13518
13574
  export declare function spawnEmptyCollectible(position: Vector, seedOrRNG?: Seed | RNG): EntityPickup;
13519
13575
 
13576
+ /**
13577
+ * Helper function to spawn the entity corresponding to an `EntityID`.
13578
+ *
13579
+ * @param entityID The `EntityID` of the entity to spawn.
13580
+ * @param position The position of the entity to spawn.
13581
+ * @param velocity Optional. The velocity of the entity to spawn. Default is `VectorZero`.
13582
+ * @param spawner Optional. The entity that will be the `SpawnerEntity`. Default is undefined.
13583
+ * @param seedOrRNG Optional. The seed or RNG object to use to generate the `InitSeed` of the
13584
+ * entity. Default is undefined, which will make the entity spawn with a random
13585
+ * seed using the `Isaac.Spawn` method.
13586
+ */
13587
+ export declare function spawnEntityID(entityID: EntityID, position: Vector, velocity?: Vector, spawner?: Entity | undefined, seedOrRNG?: Seed | RNG | undefined): Entity;
13588
+
13520
13589
  /**
13521
13590
  * Helper function to spawn a `EntityType.FAMILIAR` (3).
13522
13591
  *
@@ -1,6 +1,6 @@
1
1
  --[[
2
2
 
3
- isaacscript-common 15.1.0
3
+ isaacscript-common 15.2.0
4
4
 
5
5
  This is the "isaacscript-common" library, which was created with the IsaacScript tool.
6
6
 
@@ -19088,15 +19088,19 @@ return ____exports
19088
19088
  end,
19089
19089
  ["src.types.AnyEntity"] = function(...)
19090
19090
  local ____exports = {}
19091
+ return ____exports
19092
+ end,
19093
+ ["src.types.EntityID"] = function(...)
19094
+ local ____exports = {}
19091
19095
  return ____exports
19092
19096
  end,
19093
19097
  ["src.functions.entities"] = function(...)
19094
19098
  local ____lualib = require("lualib_bundle")
19095
19099
  local Set = ____lualib.Set
19100
+ local __TS__StringSplit = ____lualib.__TS__StringSplit
19096
19101
  local __TS__ArrayFind = ____lualib.__TS__ArrayFind
19097
19102
  local __TS__New = ____lualib.__TS__New
19098
19103
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
19099
- local __TS__StringSplit = ____lualib.__TS__StringSplit
19100
19104
  local ____exports = {}
19101
19105
  local setPrimitiveEntityFields
19102
19106
  local ____cachedClasses = require("src.core.cachedClasses")
@@ -19217,6 +19221,26 @@ function ____exports.getClosestEntityTo(self, referenceEntity, entities)
19217
19221
  end
19218
19222
  return closestEntity
19219
19223
  end
19224
+ function ____exports.getConstituentsFromEntityID(self, entityID)
19225
+ local parts = __TS__StringSplit(entityID, ".")
19226
+ if #parts ~= 3 then
19227
+ error("Failed to get the constituents from entity ID: " .. entityID)
19228
+ end
19229
+ local entityTypeString, variantString, subTypeString = table.unpack(parts)
19230
+ local entityType = tonumber(entityTypeString)
19231
+ if entityType == nil then
19232
+ error("Failed to convert the entity type to a number: " .. tostring(entityTypeString))
19233
+ end
19234
+ local variant = tonumber(variantString)
19235
+ if variant == nil then
19236
+ error("Failed to convert the entity variant to a number: " .. tostring(variantString))
19237
+ end
19238
+ local subType = tonumber(subTypeString)
19239
+ if subType == nil then
19240
+ error("Failed to convert the entity sub-type to a number: " .. tostring(subTypeString))
19241
+ end
19242
+ return {entityType, variant, subType}
19243
+ end
19220
19244
  function ____exports.getEntities(self, entityType, variant, subType, ignoreFriendly)
19221
19245
  if entityType == nil then
19222
19246
  entityType = -1
@@ -19411,6 +19435,28 @@ function ____exports.spawn(self, entityType, variant, subType, position, velocit
19411
19435
  seed
19412
19436
  )
19413
19437
  end
19438
+ function ____exports.spawnEntityID(self, entityID, position, velocity, spawner, seedOrRNG)
19439
+ if velocity == nil then
19440
+ velocity = VectorZero
19441
+ end
19442
+ if spawner == nil then
19443
+ spawner = nil
19444
+ end
19445
+ if seedOrRNG == nil then
19446
+ seedOrRNG = nil
19447
+ end
19448
+ local entityType, variant, subType = table.unpack(____exports.getConstituentsFromEntityID(nil, entityID))
19449
+ return ____exports.spawn(
19450
+ nil,
19451
+ entityType,
19452
+ variant,
19453
+ subType,
19454
+ position,
19455
+ velocity,
19456
+ spawner,
19457
+ seedOrRNG
19458
+ )
19459
+ end
19414
19460
  function ____exports.spawnWithSeed(self, entityType, variant, subType, position, seedOrRNG, velocity, spawner)
19415
19461
  if velocity == nil then
19416
19462
  velocity = VectorZero
@@ -24658,6 +24704,10 @@ return ____exports
24658
24704
  end,
24659
24705
  ["src.types.AnyGridEntity"] = function(...)
24660
24706
  local ____exports = {}
24707
+ return ____exports
24708
+ end,
24709
+ ["src.types.GridEntityID"] = function(...)
24710
+ local ____exports = {}
24661
24711
  return ____exports
24662
24712
  end,
24663
24713
  ["src.objects.roomTypeNames"] = function(...)
@@ -25424,6 +25474,7 @@ local ____lualib = require("lualib_bundle")
25424
25474
  local Set = ____lualib.Set
25425
25475
  local __TS__New = ____lualib.__TS__New
25426
25476
  local __TS__ArrayFilter = ____lualib.__TS__ArrayFilter
25477
+ local __TS__StringSplit = ____lualib.__TS__StringSplit
25427
25478
  local Map = ____lualib.Map
25428
25479
  local ____exports = {}
25429
25480
  local getAllGridEntities
@@ -25592,6 +25643,22 @@ function ____exports.getCollidingEntitiesWithGridEntity(self, gridEntity)
25592
25643
  ) end
25593
25644
  )
25594
25645
  end
25646
+ function ____exports.getConstituentsFromGridEntityID(self, gridEntityID)
25647
+ local parts = __TS__StringSplit(gridEntityID, ".")
25648
+ if #parts ~= 2 then
25649
+ error("Failed to get the constituents from grid entity ID: " .. gridEntityID)
25650
+ end
25651
+ local gridEntityTypeString, variantString = table.unpack(parts)
25652
+ local gridEntityType = tonumber(gridEntityTypeString)
25653
+ if gridEntityType == nil then
25654
+ error("Failed to convert the grid entity type to a number: " .. tostring(gridEntityTypeString))
25655
+ end
25656
+ local variant = tonumber(variantString)
25657
+ if variant == nil then
25658
+ error("Failed to convert the grid entity variant to a number: " .. tostring(variantString))
25659
+ end
25660
+ return {gridEntityType, variant}
25661
+ end
25595
25662
  function ____exports.getGridEntities(self, ...)
25596
25663
  local gridEntityTypes = {...}
25597
25664
  local gridEntities = getAllGridEntities(nil)
@@ -25639,7 +25706,7 @@ function ____exports.getGridEntitiesInRadius(self, targetPosition, radius)
25639
25706
  local gridIndex = room:GetGridIndex(position)
25640
25707
  local gridEntity = room:GetGridEntityFromPos(position)
25641
25708
  if gridEntity == nil or registeredGridIndexes:has(gridIndex) then
25642
- goto __continue20
25709
+ goto __continue24
25643
25710
  end
25644
25711
  registeredGridIndexes:add(gridIndex)
25645
25712
  local topLeft, bottomRight = table.unpack(____exports.getGridEntityCollisionPoints(nil, gridEntity))
@@ -25653,7 +25720,7 @@ function ____exports.getGridEntitiesInRadius(self, targetPosition, radius)
25653
25720
  gridEntities[#gridEntities + 1] = gridEntity
25654
25721
  end
25655
25722
  end
25656
- ::__continue20::
25723
+ ::__continue24::
25657
25724
  end
25658
25725
  end
25659
25726
  return gridEntities
@@ -48279,7 +48346,6 @@ return ____exports
48279
48346
  ["src.classes.ModFeature"] = function(...)
48280
48347
  local ____lualib = require("lualib_bundle")
48281
48348
  local __TS__Class = ____lualib.__TS__Class
48282
- local __TS__Spread = ____lualib.__TS__Spread
48283
48349
  local ____exports = {}
48284
48350
  local checkAddDecoratedCallbacks, checkAddDecoratedCallbacksCustom, checkRegisterSaveDataManager
48285
48351
  local ____tstlClass = require("src.functions.tstlClass")
@@ -48287,22 +48353,56 @@ local getTSTLClassConstructor = ____tstlClass.getTSTLClassConstructor
48287
48353
  local getTSTLClassName = ____tstlClass.getTSTLClassName
48288
48354
  local ____types = require("src.functions.types")
48289
48355
  local isTable = ____types.isTable
48290
- function checkAddDecoratedCallbacks(self, mod, modFeatureConstructor)
48356
+ function checkAddDecoratedCallbacks(self, mod, modFeatureConstructor, modFeature)
48291
48357
  local addCallbackArgs = modFeatureConstructor[____exports.ADD_CALLBACK_ARGS_KEY]
48292
48358
  if addCallbackArgs == nil then
48293
48359
  return
48294
48360
  end
48361
+ local tstlClassName = getTSTLClassName(nil, modFeatureConstructor) or "Unknown"
48295
48362
  for ____, args in ipairs(addCallbackArgs) do
48296
- mod:AddCallback(__TS__Spread(args))
48363
+ local parameters = args
48364
+ local modCallback = table.remove(parameters, 1)
48365
+ if modCallback == nil then
48366
+ error("Failed to get the ModCallback from the parameters for class: " .. tstlClassName)
48367
+ end
48368
+ local callback = table.remove(parameters, 1)
48369
+ if callback == nil then
48370
+ error("Failed to get the callback from the parameters for class: " .. tstlClassName)
48371
+ end
48372
+ local function newCallback(____, ...)
48373
+ callback(modFeature, ...)
48374
+ end
48375
+ mod:AddCallback(
48376
+ modCallback,
48377
+ newCallback,
48378
+ table.unpack(parameters)
48379
+ )
48297
48380
  end
48298
48381
  end
48299
- function checkAddDecoratedCallbacksCustom(self, mod, modFeatureConstructor)
48382
+ function checkAddDecoratedCallbacksCustom(self, mod, modFeatureConstructor, modFeature)
48300
48383
  local addCallbackCustomArgs = modFeatureConstructor[____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY]
48301
48384
  if addCallbackCustomArgs == nil then
48302
48385
  return
48303
48386
  end
48387
+ local tstlClassName = getTSTLClassName(nil, modFeatureConstructor) or "Unknown"
48304
48388
  for ____, args in ipairs(addCallbackCustomArgs) do
48305
- mod:AddCallbackCustom(__TS__Spread(args))
48389
+ local parameters = args
48390
+ local modCallbackCustom = table.remove(parameters, 1)
48391
+ if modCallbackCustom == nil then
48392
+ error("Failed to get the ModCallbackCustom from the parameters for class: " .. tstlClassName)
48393
+ end
48394
+ local callback = table.remove(parameters, 1)
48395
+ if callback == nil then
48396
+ error("Failed to get the callback from the parameters for class: " .. tstlClassName)
48397
+ end
48398
+ local function newCallback(____, ...)
48399
+ callback(modFeature, ...)
48400
+ end
48401
+ mod:AddCallbackCustom(
48402
+ modCallbackCustom,
48403
+ newCallback,
48404
+ table.unpack(parameters)
48405
+ )
48306
48406
  end
48307
48407
  end
48308
48408
  function checkRegisterSaveDataManager(self, mod, modFeature)
@@ -48333,8 +48433,8 @@ function ModFeature.prototype.____constructor(self, mod)
48333
48433
  error("Failed to get the TSTL class constructor for a mod feature.")
48334
48434
  end
48335
48435
  local modFeatureConstructor = constructor
48336
- checkAddDecoratedCallbacks(nil, mod, modFeatureConstructor)
48337
- checkAddDecoratedCallbacksCustom(nil, mod, modFeatureConstructor)
48436
+ checkAddDecoratedCallbacks(nil, mod, modFeatureConstructor, self)
48437
+ checkAddDecoratedCallbacksCustom(nil, mod, modFeatureConstructor, self)
48338
48438
  checkRegisterSaveDataManager(nil, mod, self)
48339
48439
  end
48340
48440
  return ____exports
@@ -48712,6 +48812,8 @@ local ____exports = {}
48712
48812
  local ____ModFeature = require("src.classes.ModFeature")
48713
48813
  local ADD_CALLBACK_ARGS_KEY = ____ModFeature.ADD_CALLBACK_ARGS_KEY
48714
48814
  local ADD_CALLBACK_CUSTOM_ARGS_KEY = ____ModFeature.ADD_CALLBACK_CUSTOM_ARGS_KEY
48815
+ local ____tstlClass = require("src.functions.tstlClass")
48816
+ local getTSTLClassName = ____tstlClass.getTSTLClassName
48715
48817
  function ____exports.Callback(self, modCallback, ...)
48716
48818
  local optionalArgs = {...}
48717
48819
  return function(____, target, propertyKey, _descriptor)
@@ -48723,6 +48825,10 @@ function ____exports.Callback(self, modCallback, ...)
48723
48825
  __TS__Spread(optionalArgs)
48724
48826
  }
48725
48827
  local constructor = target.constructor
48828
+ if constructor == nil then
48829
+ local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
48830
+ error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods, because the \"Mod\" object is not present before the class is instantiated.")
48831
+ end
48726
48832
  if not (constructor[ADD_CALLBACK_ARGS_KEY] ~= nil) then
48727
48833
  constructor[ADD_CALLBACK_ARGS_KEY] = {}
48728
48834
  end
@@ -48741,6 +48847,10 @@ function ____exports.CallbackCustom(self, modCallbackCustom, ...)
48741
48847
  __TS__Spread(optionalArgs)
48742
48848
  }
48743
48849
  local constructor = target.constructor
48850
+ if constructor == nil then
48851
+ local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
48852
+ error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods, because the \"Mod\" object is not present before the class is instantiated.")
48853
+ end
48744
48854
  if not (constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY] ~= nil) then
48745
48855
  constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY] = {}
48746
48856
  end
@@ -6,10 +6,20 @@ export declare const ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs";
6
6
  * mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
7
7
  * that automatically subscribe to callbacks.
8
8
  *
9
+ * If your feature has variables that are managed by the save data manager, put them as a `v` class
10
+ * member and they will automatically be registered with the save data manager when the class is
11
+ * instantiated.
12
+ *
9
13
  * For example:
10
14
  *
11
15
  * ```ts
12
16
  * export class MyFeature extends ModFeature {
17
+ * v = {
18
+ * run: {
19
+ * foo: 123,
20
+ * }
21
+ * }
22
+ *
13
23
  * @Callback(ModCallback.POST_GAME_STARTED)
14
24
  * postGameStarted(isContinued: boolean): void {
15
25
  * Isaac.DebugString(`Callback fired: POST_GAME_STARTED`);
@@ -1 +1 @@
1
- {"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AAOtE;;;;;;;;;;;;;;;GAeG;AAEH,qBAAa,UAAU;gBACT,GAAG,EAAE,eAAe;CAWjC"}
1
+ {"version":3,"file":"ModFeature.d.ts","sourceRoot":"","sources":["../../../src/classes/ModFeature.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,eAAO,MAAM,qBAAqB,sBAAsB,CAAC;AACzD,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AAOtE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,qBAAa,UAAU;gBACT,GAAG,EAAE,eAAe;CAWjC"}
@@ -1,6 +1,5 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
- local __TS__Spread = ____lualib.__TS__Spread
4
3
  local ____exports = {}
5
4
  local checkAddDecoratedCallbacks, checkAddDecoratedCallbacksCustom, checkRegisterSaveDataManager
6
5
  local ____tstlClass = require("src.functions.tstlClass")
@@ -8,22 +7,60 @@ local getTSTLClassConstructor = ____tstlClass.getTSTLClassConstructor
8
7
  local getTSTLClassName = ____tstlClass.getTSTLClassName
9
8
  local ____types = require("src.functions.types")
10
9
  local isTable = ____types.isTable
11
- function checkAddDecoratedCallbacks(self, mod, modFeatureConstructor)
10
+ function checkAddDecoratedCallbacks(self, mod, modFeatureConstructor, modFeature)
12
11
  local addCallbackArgs = modFeatureConstructor[____exports.ADD_CALLBACK_ARGS_KEY]
13
12
  if addCallbackArgs == nil then
14
13
  return
15
14
  end
15
+ local tstlClassName = getTSTLClassName(nil, modFeatureConstructor) or "Unknown"
16
16
  for ____, args in ipairs(addCallbackArgs) do
17
- mod:AddCallback(__TS__Spread(args))
17
+ local parameters = args
18
+ local modCallback = table.remove(parameters, 1)
19
+ if modCallback == nil then
20
+ error("Failed to get the ModCallback from the parameters for class: " .. tstlClassName)
21
+ end
22
+ local callback = table.remove(parameters, 1)
23
+ if callback == nil then
24
+ error("Failed to get the callback from the parameters for class: " .. tstlClassName)
25
+ end
26
+ --- We need to wrap the callback in a new function so that we can explicitly pass the class as
27
+ -- the first argument. (Otherwise, the method will not be able to properly access `this`.
28
+ local function newCallback(____, ...)
29
+ callback(modFeature, ...)
30
+ end
31
+ mod:AddCallback(
32
+ modCallback,
33
+ newCallback,
34
+ table.unpack(parameters)
35
+ )
18
36
  end
19
37
  end
20
- function checkAddDecoratedCallbacksCustom(self, mod, modFeatureConstructor)
38
+ function checkAddDecoratedCallbacksCustom(self, mod, modFeatureConstructor, modFeature)
21
39
  local addCallbackCustomArgs = modFeatureConstructor[____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY]
22
40
  if addCallbackCustomArgs == nil then
23
41
  return
24
42
  end
43
+ local tstlClassName = getTSTLClassName(nil, modFeatureConstructor) or "Unknown"
25
44
  for ____, args in ipairs(addCallbackCustomArgs) do
26
- mod:AddCallbackCustom(__TS__Spread(args))
45
+ local parameters = args
46
+ local modCallbackCustom = table.remove(parameters, 1)
47
+ if modCallbackCustom == nil then
48
+ error("Failed to get the ModCallbackCustom from the parameters for class: " .. tstlClassName)
49
+ end
50
+ local callback = table.remove(parameters, 1)
51
+ if callback == nil then
52
+ error("Failed to get the callback from the parameters for class: " .. tstlClassName)
53
+ end
54
+ --- We need to wrap the callback in a new function so that we can explicitly pass the class as
55
+ -- the first argument. (Otherwise, the method will not be able to properly access `this`.
56
+ local function newCallback(____, ...)
57
+ callback(modFeature, ...)
58
+ end
59
+ mod:AddCallbackCustom(
60
+ modCallbackCustom,
61
+ newCallback,
62
+ table.unpack(parameters)
63
+ )
27
64
  end
28
65
  end
29
66
  function checkRegisterSaveDataManager(self, mod, modFeature)
@@ -49,10 +86,19 @@ ____exports.ADD_CALLBACK_CUSTOM_ARGS_KEY = "__addCallbackCustomArgs"
49
86
  -- mod features from this class in order to enable the `@Callback` and `@CustomCallback` decorators
50
87
  -- that automatically subscribe to callbacks.
51
88
  --
89
+ -- If your feature has variables that are managed by the save data manager, put them as a `v` class
90
+ -- member and they will automatically be registered with the save data manager when the class is
91
+ -- instantiated.
92
+ --
52
93
  -- For example:
53
94
  --
54
95
  -- ```ts
55
96
  -- export class MyFeature extends ModFeature {
97
+ -- v = {
98
+ -- run: {
99
+ -- foo: 123,
100
+ -- }
101
+ -- }
56
102
  --
57
103
  -- @Callback (ModCallback.POST_GAME_STARTED)
58
104
  -- postGameStarted(isContinued: boolean): void {
@@ -69,8 +115,8 @@ function ModFeature.prototype.____constructor(self, mod)
69
115
  error("Failed to get the TSTL class constructor for a mod feature.")
70
116
  end
71
117
  local modFeatureConstructor = constructor
72
- checkAddDecoratedCallbacks(nil, mod, modFeatureConstructor)
73
- checkAddDecoratedCallbacksCustom(nil, mod, modFeatureConstructor)
118
+ checkAddDecoratedCallbacks(nil, mod, modFeatureConstructor, self)
119
+ checkAddDecoratedCallbacksCustom(nil, mod, modFeatureConstructor, self)
74
120
  checkRegisterSaveDataManager(nil, mod, self)
75
121
  end
76
122
  return ____exports
@@ -36,7 +36,7 @@ export declare function forEach<T>(array: T[], func: (value: T, index: number, a
36
36
  /**
37
37
  * Helper function for non-TypeScript users to check if an element is in an array.
38
38
  *
39
- * Since this takes O(N) time, using this function is usually a mistake, since you can use a `Map`
39
+ * Since this takes O(N) time, using this function is usually a mistake, since you can use a `Set`
40
40
  * data structure to get O(1) lookups.
41
41
  *
42
42
  * Internally, this just calls `array.includes`.
@@ -36,7 +36,7 @@ function ____exports.forEach(self, array, func)
36
36
  end
37
37
  --- Helper function for non-TypeScript users to check if an element is in an array.
38
38
  --
39
- -- Since this takes O(N) time, using this function is usually a mistake, since you can use a `Map`
39
+ -- Since this takes O(N) time, using this function is usually a mistake, since you can use a `Set`
40
40
  -- data structure to get O(1) lookups.
41
41
  --
42
42
  -- Internally, this just calls `array.includes`.
@@ -1 +1 @@
1
- {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/functions/decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAGL,UAAU,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,WAAW,EAC5C,WAAW,EAAE,CAAC,EACd,GAAG,YAAY,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,kGAIvC,MAAM,+CAElB,IAAI,CAwBR;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,iBAAiB,EACxD,iBAAiB,EAAE,CAAC,EACpB,GAAG,YAAY,EAAE,WAAW,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,wGAO7C,MAAM,+CAElB,IAAI,CA0BR"}
1
+ {"version":3,"file":"decorators.d.ts","sourceRoot":"","sources":["../../../src/functions/decorators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAGL,UAAU,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,2BAA2B,EAAE,MAAM,mDAAmD,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,WAAW,EAC5C,WAAW,EAAE,CAAC,EACd,GAAG,YAAY,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC,kGAIvC,MAAM,+CAElB,IAAI,CA+BR;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,iBAAiB,EACxD,iBAAiB,EAAE,CAAC,EACpB,GAAG,YAAY,EAAE,WAAW,CAAC,2BAA2B,CAAC,CAAC,CAAC,CAAC,wGAO7C,MAAM,+CAElB,IAAI,CAiCR"}
@@ -4,6 +4,8 @@ local ____exports = {}
4
4
  local ____ModFeature = require("src.classes.ModFeature")
5
5
  local ADD_CALLBACK_ARGS_KEY = ____ModFeature.ADD_CALLBACK_ARGS_KEY
6
6
  local ADD_CALLBACK_CUSTOM_ARGS_KEY = ____ModFeature.ADD_CALLBACK_CUSTOM_ARGS_KEY
7
+ local ____tstlClass = require("src.functions.tstlClass")
8
+ local getTSTLClassName = ____tstlClass.getTSTLClassName
7
9
  --- A decorator function that signifies that the decorated class method should be automatically
8
10
  -- registered with `Mod.AddCallback`.
9
11
  --
@@ -19,6 +21,10 @@ function ____exports.Callback(self, modCallback, ...)
19
21
  __TS__Spread(optionalArgs)
20
22
  }
21
23
  local constructor = target.constructor
24
+ if constructor == nil then
25
+ local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
26
+ error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods, because the \"Mod\" object is not present before the class is instantiated.")
27
+ end
22
28
  if not (constructor[ADD_CALLBACK_ARGS_KEY] ~= nil) then
23
29
  constructor[ADD_CALLBACK_ARGS_KEY] = {}
24
30
  end
@@ -41,6 +47,10 @@ function ____exports.CallbackCustom(self, modCallbackCustom, ...)
41
47
  __TS__Spread(optionalArgs)
42
48
  }
43
49
  local constructor = target.constructor
50
+ if constructor == nil then
51
+ local tstlClassName = getTSTLClassName(nil, target) or "Unknown"
52
+ error(("Failed to get the constructor for class \"" .. tstlClassName) .. "\". Did you decorate a static method? You can only decorate non-static class methods, because the \"Mod\" object is not present before the class is instantiated.")
53
+ end
44
54
  if not (constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY] ~= nil) then
45
55
  constructor[ADD_CALLBACK_CUSTOM_ARGS_KEY] = {}
46
56
  end
@@ -1,6 +1,7 @@
1
1
  /// <reference types="@typescript-to-lua/language-extensions" />
2
2
  import { EntityType } from "isaac-typescript-definitions";
3
3
  import { AnyEntity } from "../types/AnyEntity";
4
+ import { EntityID } from "../types/EntityID";
4
5
  /**
5
6
  * Helper function to count the number of entities in room. Use this over the vanilla
6
7
  * `Isaac.CountEntities` method to avoid having to specify a spawner and to handle ignoring charmed
@@ -35,6 +36,8 @@ export declare function doesEntityExist(entityType?: EntityType, variant?: numbe
35
36
  * ```
36
37
  */
37
38
  export declare function getClosestEntityTo<T extends AnyEntity>(referenceEntity: Entity, entities: T[]): T | undefined;
39
+ /** Helper function to get the entity type, variant, and sub-type from an `EntityID`. */
40
+ export declare function getConstituentsFromEntityID(entityID: EntityID): [entityType: EntityType, variant: int, subType: int];
38
41
  /**
39
42
  * Helper function to get all of the entities in the room or all of the entities that match a
40
43
  * specific entity type / variant / sub-type.
@@ -78,11 +81,11 @@ export declare function getEntityFields(entity: Entity): LuaMap<string, boolean
78
81
  */
79
82
  export declare function getEntityFromPtrHash(ptrHash: PtrHash): Entity | undefined;
80
83
  /** Helper function to get a string containing the entity's type, variant, and sub-type. */
81
- export declare function getEntityID(entity: Entity): string;
84
+ export declare function getEntityID(entity: Entity): EntityID;
82
85
  /**
83
86
  * Helper function to get a formatted string in the format returned by the `getEntityID` function.
84
87
  */
85
- export declare function getEntityIDFromConstituents(entityType: EntityType, variant: int, subType: int): string;
88
+ export declare function getEntityIDFromConstituents(entityType: EntityType, variant: int, subType: int): EntityID;
86
89
  /**
87
90
  * Helper function to compare two different arrays of entities. Returns the entities that are in the
88
91
  * second array but not in the first array.
@@ -170,8 +173,30 @@ export declare function setEntityRandomColor(entity: Entity): void;
170
173
  * need to specify the velocity or spawner.
171
174
  *
172
175
  * Also see the `spawnWithSeed` helper function.
176
+ *
177
+ * @param entityType The `EntityType` of the entity to spawn.
178
+ * @param variant The variant of the entity to spawn.
179
+ * @param subType The sub-type of the entity to spawn.
180
+ * @param position The position of the entity to spawn.
181
+ * @param velocity Optional. The velocity of the entity to spawn. Default is `VectorZero`.
182
+ * @param spawner Optional. The entity that will be the `SpawnerEntity`. Default is undefined.
183
+ * @param seedOrRNG Optional. The seed or RNG object to use to generate the `InitSeed` of the
184
+ * entity. Default is undefined, which will make the entity spawn with a random
185
+ * seed using the `Isaac.Spawn` method.
173
186
  */
174
187
  export declare function spawn(entityType: EntityType, variant: int, subType: int, position: Vector, velocity?: Vector, spawner?: Entity | undefined, seedOrRNG?: Seed | RNG | undefined): Entity;
188
+ /**
189
+ * Helper function to spawn the entity corresponding to an `EntityID`.
190
+ *
191
+ * @param entityID The `EntityID` of the entity to spawn.
192
+ * @param position The position of the entity to spawn.
193
+ * @param velocity Optional. The velocity of the entity to spawn. Default is `VectorZero`.
194
+ * @param spawner Optional. The entity that will be the `SpawnerEntity`. Default is undefined.
195
+ * @param seedOrRNG Optional. The seed or RNG object to use to generate the `InitSeed` of the
196
+ * entity. Default is undefined, which will make the entity spawn with a random
197
+ * seed using the `Isaac.Spawn` method.
198
+ */
199
+ export declare function spawnEntityID(entityID: EntityID, position: Vector, velocity?: Vector, spawner?: Entity | undefined, seedOrRNG?: Seed | RNG | undefined): Entity;
175
200
  /**
176
201
  * Helper function to spawn an entity. Use this instead of the `Game.Spawn` method if you do not
177
202
  * need to specify the velocity or spawner.