isaacscript-common 1.0.470 → 1.0.474

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.
@@ -10,10 +10,22 @@ export declare function deployJSONRoomInit(mod: ModUpgraded): void;
10
10
  *
11
11
  * This function is meant to be used in the PostNewRoom callback.
12
12
  *
13
- * @returns The iterated seed, which can be used in subsequent room deployments. (The seed is used
14
- * to spawn every entity contained within the custom room.)
13
+ * @param jsonRoom The JSON room to deploy. In practice, this will be something like:
14
+ * ```
15
+ * import customRooms from "./customRooms";
16
+ *
17
+ * const firstJSONRoom = customRooms.rooms.room[0];
18
+ * deployJSONRoom(firstJSONRoom);
19
+ * ```
20
+ * @param seed Optional. Specifies the seed that will be used for spawning every entity in the room.
21
+ * Equal to `Random()` by default.
22
+ * @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
23
+ * what the function is doing. False by default.
24
+ * @returns Before using the seed for spawning each entity, it is iterated with `nextSeed()`. The
25
+ * function returns the final iterated seed after spawning everything, which can be used in
26
+ * subsequent room deployments.
15
27
  */
16
- export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: number): int;
28
+ export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: number, verbose?: boolean): int;
17
29
  /**
18
30
  * Helper function to deconstruct a vanilla room and set up a custom room in its place.
19
31
  * Specifically, this will clear the current room of all entities and grid entities, and then spawn
@@ -21,15 +33,32 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: number): int;
21
33
  *
22
34
  * This function is meant to be used in the PostNewRoom callback.
23
35
  *
24
- * @returns The iterated seed, which can be used in subsequent room deployments. (The seed is used
25
- * to spawn every entity contained within the custom room.)
36
+ * Note that this function does not simply choose a random element in the provided array; it will
37
+ * properly account for each room weight using the algorithm from:
38
+ * https://stackoverflow.com/questions/1761626/weighted-random-numbers
39
+ *
40
+ * @param jsonRooms An array of JSON rooms to randomly select from. In practice, this will be
41
+ * something like:
42
+ * ```
43
+ * import customRooms from "./customRooms";
44
+ *
45
+ * const jsonRooms = customRooms.rooms.room;
46
+ * deployRandomJSONRoom(jsonRooms);
47
+ * ```
48
+ * @param seed Optional. Specifies the seed that will be used for determining the random room. After
49
+ * that, it is also used for spawning every entity in the room. Equal to `Random()` by default.
50
+ * @param verbose Optional. If specified, will write entries to the "log.txt" file that describe
51
+ * what the function is doing. False by default.
52
+ * @returns Before using the seed for spawning each entity, it is iterated with `nextSeed()`. The
53
+ * function returns the final iterated seed after spawning everything, which can be used in
54
+ * subsequent room deployments.
26
55
  */
27
- export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seed?: number): int;
56
+ export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seed?: number, verbose?: boolean): int;
28
57
  /**
29
58
  * Helper function to remove all naturally spawning entities and grid entities from a room. Notably,
30
59
  * this will not remove players (1), tears (2), familiars (3), lasers (7), knives (8),
31
60
  * projectiles (9), blacklisted NPCs such as Dark Esau, charmed NPCs, friendly NPCs, persistent
32
- * NPCs, doors, and walls.
61
+ * NPCs, most effects (1000), doors, and walls.
33
62
  *
34
63
  * @param fillWithDecorations Optional. Set to true to fill every grid tile with an invisible
35
64
  * decoration, which prevents vanilla entities in the room from respawning the next time that the
@@ -1,7 +1,7 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  require("lualib_bundle");
3
3
  local ____exports = {}
4
- local postNewRoom, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntity, spawnNormalEntity, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPCS_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, initialized, v
4
+ local postNewRoom, setDecorationsInvisible, respawnPersistentEntities, removeSpecificNPCs, fillRoomWithDecorations, spawnAllEntities, spawnGridEntity, spawnNormalEntity, storePersistentEntity, fixPitGraphics, getPitMap, getPitFrame, FEATURE_NAME, NPC_TYPES_TO_NOT_REMOVE, PERSISTENT_ENTITY_TYPES, initialized, v
5
5
  local ____errors = require("errors")
6
6
  local getUpgradeErrorMsg = ____errors.getUpgradeErrorMsg
7
7
  local ____entity = require("functions.entity")
@@ -15,6 +15,8 @@ local removeAllGridEntitiesExceptFor = ____gridEntity.removeAllGridEntitiesExcep
15
15
  local setGridEntityInvisible = ____gridEntity.setGridEntityInvisible
16
16
  local ____jsonRoom = require("functions.jsonRoom")
17
17
  local getRandomJSONRoom = ____jsonRoom.getRandomJSONRoom
18
+ local ____log = require("functions.log")
19
+ local log = ____log.log
18
20
  local ____npc = require("functions.npc")
19
21
  local getNPCs = ____npc.getNPCs
20
22
  local ____random = require("functions.random")
@@ -75,6 +77,8 @@ function ____exports.emptyRoom(self, fillWithDecorations)
75
77
  removeAllPickups(nil)
76
78
  removeAllMatchingEntities(nil, EntityType.ENTITY_SLOT)
77
79
  removeSpecificNPCs(nil)
80
+ removeAllMatchingEntities(nil, EntityType.ENTITY_EFFECT, EffectVariant.DEVIL)
81
+ removeAllMatchingEntities(nil, EntityType.ENTITY_EFFECT, EffectVariant.ANGEL)
78
82
  removeAllGridEntitiesExceptFor(nil, GridEntityType.GRID_WALL, GridEntityType.GRID_DOOR)
79
83
  setRoomCleared(nil)
80
84
  if fillWithDecorations then
@@ -88,11 +92,11 @@ function removeSpecificNPCs(self)
88
92
  getNPCs(nil)
89
93
  ) do
90
94
  do
91
- if NPCS_TO_NOT_REMOVE:has(npc.Type) then
92
- goto __continue20
95
+ if NPC_TYPES_TO_NOT_REMOVE:has(npc.Type) then
96
+ goto __continue25
93
97
  end
94
98
  if (npc:HasEntityFlags(EntityFlag.FLAG_CHARM) or npc:HasEntityFlags(EntityFlag.FLAG_FRIENDLY)) or npc:HasEntityFlags(EntityFlag.FLAG_PERSISTENT) then
95
- goto __continue20
99
+ goto __continue25
96
100
  end
97
101
  npc:ClearEntityFlags(EntityFlag.FLAG_APPEAR)
98
102
  npc:Remove()
@@ -101,7 +105,7 @@ function removeSpecificNPCs(self)
101
105
  room:SetGridPath(gridIndex, 0)
102
106
  end
103
107
  end
104
- ::__continue20::
108
+ ::__continue25::
105
109
  end
106
110
  end
107
111
  function fillRoomWithDecorations(self)
@@ -120,19 +124,22 @@ function fillRoomWithDecorations(self)
120
124
  do
121
125
  local existingGridEntity = room:GetGridEntity(gridIndex)
122
126
  if existingGridEntity ~= nil then
123
- goto __continue26
127
+ goto __continue31
124
128
  end
125
129
  local position = room:GetGridPosition(gridIndex)
126
130
  local decoration = Isaac.GridSpawn(GridEntityType.GRID_DECORATION, 0, position, true)
127
131
  setGridEntityInvisible(nil, decoration)
128
132
  __TS__ArrayPush(decorationGridIndexes, gridIndex)
129
133
  end
130
- ::__continue26::
134
+ ::__continue31::
131
135
  gridIndex = gridIndex + 1
132
136
  end
133
137
  end
134
138
  end
135
- function spawnAllEntities(self, jsonRoom, seed)
139
+ function spawnAllEntities(self, jsonRoom, seed, verbose)
140
+ if verbose == nil then
141
+ verbose = false
142
+ end
136
143
  local shouldUnclearRoom = false
137
144
  for ____, spawn in ipairs(jsonRoom.spawn) do
138
145
  local xString = spawn["$"].x
@@ -169,9 +176,19 @@ function spawnAllEntities(self, jsonRoom, seed)
169
176
  )
170
177
  end
171
178
  if entityType >= 1000 then
179
+ if verbose then
180
+ log(
181
+ ((((((("Spawning a grid entity " .. tostring(entityType)) .. ".") .. tostring(variant)) .. " at: (") .. tostring(x)) .. ", ") .. tostring(y)) .. ")"
182
+ )
183
+ end
172
184
  spawnGridEntity(nil, entityType, variant, x, y)
173
185
  else
174
186
  seed = nextSeed(nil, seed)
187
+ if verbose then
188
+ log(
189
+ ((((((((("Spawning a normal entity " .. tostring(entityType)) .. ".") .. tostring(variant)) .. ".") .. tostring(subType)) .. " at: (") .. tostring(x)) .. ", ") .. tostring(y)) .. ")"
190
+ )
191
+ end
175
192
  local entity = spawnNormalEntity(nil, entityType, variant, subType, x, y, seed)
176
193
  local npc = entity:ToNPC()
177
194
  if (npc ~= nil) and npc.CanShutDoors then
@@ -180,6 +197,9 @@ function spawnAllEntities(self, jsonRoom, seed)
180
197
  end
181
198
  end
182
199
  if shouldUnclearRoom then
200
+ if verbose then
201
+ log("Setting the room to be uncleared since there were one or more battle NPCs spawned.")
202
+ end
183
203
  setRoomUncleared(nil)
184
204
  end
185
205
  return seed
@@ -348,7 +368,7 @@ function getPitFrame(self, L, R, U, D, UL, UR, DL, DR)
348
368
  return F
349
369
  end
350
370
  FEATURE_NAME = "JSON room deployer"
351
- NPCS_TO_NOT_REMOVE = __TS__New(Set, {EntityType.ENTITY_DARK_ESAU})
371
+ NPC_TYPES_TO_NOT_REMOVE = __TS__New(Set, {EntityType.ENTITY_DARK_ESAU})
352
372
  PERSISTENT_ENTITY_TYPES = __TS__New(Set, {EntityType.ENTITY_WALL_HUGGER})
353
373
  initialized = false
354
374
  v = {
@@ -363,29 +383,50 @@ function ____exports.deployJSONRoomInit(self, mod)
363
383
  saveDataManager(nil, "deployJSONRoom", v)
364
384
  mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, postNewRoom)
365
385
  end
366
- function ____exports.deployJSONRoom(self, jsonRoom, seed)
386
+ function ____exports.deployJSONRoom(self, jsonRoom, seed, verbose)
367
387
  if seed == nil then
368
388
  seed = Random()
369
389
  end
390
+ if verbose == nil then
391
+ verbose = false
392
+ end
370
393
  if not initialized then
371
394
  local msg = getUpgradeErrorMsg(nil, FEATURE_NAME)
372
395
  error(msg)
373
396
  end
397
+ if verbose then
398
+ log("Starting to empty the room of entities and grid entities.")
399
+ end
374
400
  ____exports.emptyRoom(nil, false)
375
- local newSeed = spawnAllEntities(nil, jsonRoom, seed)
401
+ if verbose then
402
+ log("Finished emptying the room of entities and grid entities.")
403
+ end
404
+ if verbose then
405
+ log("Starting to spawn all of the new entities and grid entities.")
406
+ end
407
+ local newSeed = spawnAllEntities(nil, jsonRoom, seed, verbose)
408
+ if verbose then
409
+ log("Finished spawning all of the new entities and grid entities.")
410
+ end
376
411
  fixPitGraphics(nil)
377
412
  fillRoomWithDecorations(nil)
378
413
  return newSeed
379
414
  end
380
- function ____exports.deployRandomJSONRoom(self, jsonRooms, seed)
415
+ function ____exports.deployRandomJSONRoom(self, jsonRooms, seed, verbose)
381
416
  if seed == nil then
382
417
  seed = Random()
383
418
  end
419
+ if verbose == nil then
420
+ verbose = false
421
+ end
384
422
  if not initialized then
385
423
  local msg = getUpgradeErrorMsg(nil, FEATURE_NAME)
386
424
  error(msg)
387
425
  end
388
- local randomJSONRoom = getRandomJSONRoom(nil, jsonRooms, seed)
389
- return ____exports.deployJSONRoom(nil, randomJSONRoom, seed)
426
+ local randomJSONRoom = getRandomJSONRoom(nil, jsonRooms, seed, verbose)
427
+ if verbose then
428
+ log((((((("Randomly chose JSON room " .. randomJSONRoom["$"].type) .. ".") .. randomJSONRoom["$"].variant) .. ".") .. randomJSONRoom["$"].subtype) .. " with name: ") .. randomJSONRoom["$"].name)
429
+ end
430
+ return ____exports.deployJSONRoom(nil, randomJSONRoom, seed, verbose)
390
431
  end
391
432
  return ____exports
@@ -8,14 +8,8 @@ function ____exports.removeGridEntity(self, gridEntity)
8
8
  local room = game:GetRoom()
9
9
  local gridIndex = gridEntity:GetGridIndex()
10
10
  room:RemoveGridEntity(gridIndex, 0, false)
11
- ____exports.setGridEntityInvisible(nil, gridEntity)
12
11
  room:Update()
13
12
  end
14
- function ____exports.setGridEntityInvisible(self, gridEntity)
15
- local sprite = gridEntity:GetSprite()
16
- sprite:ReplaceSpritesheet(0, "gfx/none.png")
17
- sprite:LoadGraphics()
18
- end
19
13
  function ____exports.spawnGridEntityWithVariant(self, gridEntityType, variant, gridIndex)
20
14
  local game = Game()
21
15
  local room = game:GetRoom()
@@ -129,6 +123,11 @@ function ____exports.removeAllMatchingGridEntities(self, gridEntityType)
129
123
  ____exports.removeGridEntity(nil, gridEntity)
130
124
  end
131
125
  end
126
+ function ____exports.setGridEntityInvisible(self, gridEntity)
127
+ local sprite = gridEntity:GetSprite()
128
+ sprite:ReplaceSpritesheet(0, "gfx/none.png")
129
+ sprite:LoadGraphics()
130
+ end
132
131
  function ____exports.spawnGiantPoop(self, topLeftGridIndex)
133
132
  local game = Game()
134
133
  local room = game:GetRoom()
@@ -1,5 +1,12 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  import { JSONRoom } from "../types/JSONRoom";
3
- export declare function getJSONRoomOfVariant(jsonRooms: JSONRoom[], variant: int): JSONRoom | null;
3
+ export declare function getJSONRoomOfVariant(jsonRooms: JSONRoom[], variant: int): JSONRoom | undefined;
4
4
  export declare function getJSONRoomsOfSubType(jsonRooms: JSONRoom[], subType: int): JSONRoom[];
5
- export declare function getRandomJSONRoom(jsonRooms: JSONRoom[], seed?: number): JSONRoom;
5
+ /**
6
+ * Helper function to get a random JSON room from an array of JSON rooms.
7
+ *
8
+ * Note that this function does not simply choose a random element in the provided array; it will
9
+ * properly account for each room weight using the algorithm from:
10
+ * https://stackoverflow.com/questions/1761626/weighted-random-numbers
11
+ */
12
+ export declare function getRandomJSONRoom(jsonRooms: JSONRoom[], seed?: number, verbose?: boolean): JSONRoom;
@@ -2,6 +2,8 @@
2
2
  require("lualib_bundle");
3
3
  local ____exports = {}
4
4
  local getTotalWeightOfJSONRooms, getJSONRoomWithChosenWeight
5
+ local ____log = require("functions.log")
6
+ local log = ____log.log
5
7
  local ____random = require("functions.random")
6
8
  local getRandomFloat = ____random.getRandomFloat
7
9
  function getTotalWeightOfJSONRooms(self, jsonRooms)
@@ -54,12 +56,25 @@ function ____exports.getJSONRoomsOfSubType(self, jsonRooms, subType)
54
56
  end
55
57
  return jsonRoomsOfSubType
56
58
  end
57
- function ____exports.getRandomJSONRoom(self, jsonRooms, seed)
59
+ function ____exports.getRandomJSONRoom(self, jsonRooms, seed, verbose)
58
60
  if seed == nil then
59
61
  seed = Random()
60
62
  end
63
+ if verbose == nil then
64
+ verbose = false
65
+ end
61
66
  local totalWeight = getTotalWeightOfJSONRooms(nil, jsonRooms)
67
+ if verbose then
68
+ log(
69
+ "Total weight of the JSON rooms provided: " .. tostring(totalWeight)
70
+ )
71
+ end
62
72
  local chosenWeight = getRandomFloat(nil, 0, totalWeight, seed)
73
+ if verbose then
74
+ log(
75
+ "Randomly chose weight: " .. tostring(chosenWeight)
76
+ )
77
+ end
63
78
  return getJSONRoomWithChosenWeight(nil, jsonRooms, chosenWeight)
64
79
  end
65
80
  return ____exports
@@ -102,6 +102,7 @@ export declare function inCrawlspace(): boolean;
102
102
  * area.
103
103
  */
104
104
  export declare function inDeathCertificateArea(): boolean;
105
+ export declare function isDevilsCrownTreasureRoom(): boolean;
105
106
  export declare function inDimension(dimension: Dimension): boolean;
106
107
  /** Helper function to see if the current room shape is one of the four L room shapes. */
107
108
  export declare function inLRoom(): boolean;
@@ -11,6 +11,8 @@ local ____doors = require("functions.doors")
11
11
  local closeAllDoors = ____doors.closeAllDoors
12
12
  local getDoors = ____doors.getDoors
13
13
  local isHiddenSecretRoomDoor = ____doors.isHiddenSecretRoomDoor
14
+ local ____flag = require("functions.flag")
15
+ local hasFlag = ____flag.hasFlag
14
16
  function ____exports.getRoomIndex(self)
15
17
  local game = Game()
16
18
  local level = game:GetLevel()
@@ -164,6 +166,12 @@ function ____exports.inDeathCertificateArea(self)
164
166
  local roomSubType = ____exports.getRoomSubType(nil)
165
167
  return (roomStageID == 35) and ((roomSubType == 33) or (roomSubType == 33))
166
168
  end
169
+ function ____exports.isDevilsCrownTreasureRoom(self)
170
+ local game = Game()
171
+ local level = game:GetLevel()
172
+ local roomDesc = level:GetCurrentRoomDesc()
173
+ return hasFlag(nil, roomDesc.Flags, 2048)
174
+ end
167
175
  function ____exports.inDimension(self, dimension)
168
176
  return dimension == ____exports.getCurrentDimension(nil)
169
177
  end
@@ -202,14 +210,14 @@ function ____exports.setRoomCleared(self)
202
210
  ) do
203
211
  do
204
212
  if isHiddenSecretRoomDoor(nil, door) then
205
- goto __continue37
213
+ goto __continue38
206
214
  end
207
215
  door.State = DoorState.STATE_OPEN
208
216
  local sprite = door:GetSprite()
209
217
  sprite:Play("Opened", true)
210
218
  door.ExtraVisible = false
211
219
  end
212
- ::__continue37::
220
+ ::__continue38::
213
221
  end
214
222
  sfx:Stop(SoundEffect.SOUND_DOOR_HEAVY_OPEN)
215
223
  game:ShakeScreen(0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.0.470",
3
+ "version": "1.0.474",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",
@@ -25,7 +25,7 @@
25
25
  "dist/**/*.d.ts"
26
26
  ],
27
27
  "devDependencies": {
28
- "isaac-typescript-definitions": "^1.0.281",
28
+ "isaac-typescript-definitions": "^1.0.282",
29
29
  "isaacscript-lint": "^1.0.67",
30
30
  "typedoc": "^0.22.10",
31
31
  "typescript": "4.4.4",