isaacscript-common 1.0.471 → 1.0.475
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/dist/features/deployJSONRoom.d.ts +35 -6
- package/dist/features/deployJSONRoom.lua +53 -14
- package/dist/functions/jsonRoom.d.ts +9 -2
- package/dist/functions/jsonRoom.lua +16 -1
- package/dist/functions/playerHealth.lua +4 -4
- package/dist/functions/rooms.d.ts +1 -0
- package/dist/functions/rooms.lua +10 -2
- package/package.json +2 -2
|
@@ -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
|
-
* @
|
|
14
|
-
*
|
|
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,10 +33,27 @@ 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
|
-
*
|
|
25
|
-
*
|
|
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),
|
|
@@ -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,
|
|
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")
|
|
@@ -90,11 +92,11 @@ function removeSpecificNPCs(self)
|
|
|
90
92
|
getNPCs(nil)
|
|
91
93
|
) do
|
|
92
94
|
do
|
|
93
|
-
if
|
|
94
|
-
goto
|
|
95
|
+
if NPC_TYPES_TO_NOT_REMOVE:has(npc.Type) then
|
|
96
|
+
goto __continue25
|
|
95
97
|
end
|
|
96
98
|
if (npc:HasEntityFlags(EntityFlag.FLAG_CHARM) or npc:HasEntityFlags(EntityFlag.FLAG_FRIENDLY)) or npc:HasEntityFlags(EntityFlag.FLAG_PERSISTENT) then
|
|
97
|
-
goto
|
|
99
|
+
goto __continue25
|
|
98
100
|
end
|
|
99
101
|
npc:ClearEntityFlags(EntityFlag.FLAG_APPEAR)
|
|
100
102
|
npc:Remove()
|
|
@@ -103,7 +105,7 @@ function removeSpecificNPCs(self)
|
|
|
103
105
|
room:SetGridPath(gridIndex, 0)
|
|
104
106
|
end
|
|
105
107
|
end
|
|
106
|
-
::
|
|
108
|
+
::__continue25::
|
|
107
109
|
end
|
|
108
110
|
end
|
|
109
111
|
function fillRoomWithDecorations(self)
|
|
@@ -122,19 +124,22 @@ function fillRoomWithDecorations(self)
|
|
|
122
124
|
do
|
|
123
125
|
local existingGridEntity = room:GetGridEntity(gridIndex)
|
|
124
126
|
if existingGridEntity ~= nil then
|
|
125
|
-
goto
|
|
127
|
+
goto __continue31
|
|
126
128
|
end
|
|
127
129
|
local position = room:GetGridPosition(gridIndex)
|
|
128
130
|
local decoration = Isaac.GridSpawn(GridEntityType.GRID_DECORATION, 0, position, true)
|
|
129
131
|
setGridEntityInvisible(nil, decoration)
|
|
130
132
|
__TS__ArrayPush(decorationGridIndexes, gridIndex)
|
|
131
133
|
end
|
|
132
|
-
::
|
|
134
|
+
::__continue31::
|
|
133
135
|
gridIndex = gridIndex + 1
|
|
134
136
|
end
|
|
135
137
|
end
|
|
136
138
|
end
|
|
137
|
-
function spawnAllEntities(self, jsonRoom, seed)
|
|
139
|
+
function spawnAllEntities(self, jsonRoom, seed, verbose)
|
|
140
|
+
if verbose == nil then
|
|
141
|
+
verbose = false
|
|
142
|
+
end
|
|
138
143
|
local shouldUnclearRoom = false
|
|
139
144
|
for ____, spawn in ipairs(jsonRoom.spawn) do
|
|
140
145
|
local xString = spawn["$"].x
|
|
@@ -171,9 +176,19 @@ function spawnAllEntities(self, jsonRoom, seed)
|
|
|
171
176
|
)
|
|
172
177
|
end
|
|
173
178
|
if entityType >= 1000 then
|
|
179
|
+
if verbose then
|
|
180
|
+
log(
|
|
181
|
+
((((((("Spawning grid entity " .. tostring(entityType)) .. ".") .. tostring(variant)) .. " at: (") .. tostring(x)) .. ", ") .. tostring(y)) .. ")"
|
|
182
|
+
)
|
|
183
|
+
end
|
|
174
184
|
spawnGridEntity(nil, entityType, variant, x, y)
|
|
175
185
|
else
|
|
176
186
|
seed = nextSeed(nil, seed)
|
|
187
|
+
if verbose then
|
|
188
|
+
log(
|
|
189
|
+
((((((((("Spawning normal entity " .. tostring(entityType)) .. ".") .. tostring(variant)) .. ".") .. tostring(subType)) .. " at: (") .. tostring(x)) .. ", ") .. tostring(y)) .. ")"
|
|
190
|
+
)
|
|
191
|
+
end
|
|
177
192
|
local entity = spawnNormalEntity(nil, entityType, variant, subType, x, y, seed)
|
|
178
193
|
local npc = entity:ToNPC()
|
|
179
194
|
if (npc ~= nil) and npc.CanShutDoors then
|
|
@@ -182,6 +197,9 @@ function spawnAllEntities(self, jsonRoom, seed)
|
|
|
182
197
|
end
|
|
183
198
|
end
|
|
184
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
|
|
185
203
|
setRoomUncleared(nil)
|
|
186
204
|
end
|
|
187
205
|
return seed
|
|
@@ -350,7 +368,7 @@ function getPitFrame(self, L, R, U, D, UL, UR, DL, DR)
|
|
|
350
368
|
return F
|
|
351
369
|
end
|
|
352
370
|
FEATURE_NAME = "JSON room deployer"
|
|
353
|
-
|
|
371
|
+
NPC_TYPES_TO_NOT_REMOVE = __TS__New(Set, {EntityType.ENTITY_DARK_ESAU})
|
|
354
372
|
PERSISTENT_ENTITY_TYPES = __TS__New(Set, {EntityType.ENTITY_WALL_HUGGER})
|
|
355
373
|
initialized = false
|
|
356
374
|
v = {
|
|
@@ -365,29 +383,50 @@ function ____exports.deployJSONRoomInit(self, mod)
|
|
|
365
383
|
saveDataManager(nil, "deployJSONRoom", v)
|
|
366
384
|
mod:AddCallback(ModCallbacks.MC_POST_NEW_ROOM, postNewRoom)
|
|
367
385
|
end
|
|
368
|
-
function ____exports.deployJSONRoom(self, jsonRoom, seed)
|
|
386
|
+
function ____exports.deployJSONRoom(self, jsonRoom, seed, verbose)
|
|
369
387
|
if seed == nil then
|
|
370
388
|
seed = Random()
|
|
371
389
|
end
|
|
390
|
+
if verbose == nil then
|
|
391
|
+
verbose = false
|
|
392
|
+
end
|
|
372
393
|
if not initialized then
|
|
373
394
|
local msg = getUpgradeErrorMsg(nil, FEATURE_NAME)
|
|
374
395
|
error(msg)
|
|
375
396
|
end
|
|
397
|
+
if verbose then
|
|
398
|
+
log("Starting to empty the room of entities and grid entities.")
|
|
399
|
+
end
|
|
376
400
|
____exports.emptyRoom(nil, false)
|
|
377
|
-
|
|
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
|
|
378
411
|
fixPitGraphics(nil)
|
|
379
412
|
fillRoomWithDecorations(nil)
|
|
380
413
|
return newSeed
|
|
381
414
|
end
|
|
382
|
-
function ____exports.deployRandomJSONRoom(self, jsonRooms, seed)
|
|
415
|
+
function ____exports.deployRandomJSONRoom(self, jsonRooms, seed, verbose)
|
|
383
416
|
if seed == nil then
|
|
384
417
|
seed = Random()
|
|
385
418
|
end
|
|
419
|
+
if verbose == nil then
|
|
420
|
+
verbose = false
|
|
421
|
+
end
|
|
386
422
|
if not initialized then
|
|
387
423
|
local msg = getUpgradeErrorMsg(nil, FEATURE_NAME)
|
|
388
424
|
error(msg)
|
|
389
425
|
end
|
|
390
|
-
local randomJSONRoom = getRandomJSONRoom(nil, jsonRooms, seed)
|
|
391
|
-
|
|
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)
|
|
392
431
|
end
|
|
393
432
|
return ____exports
|
|
@@ -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 |
|
|
3
|
+
export declare function getJSONRoomOfVariant(jsonRooms: JSONRoom[], variant: int): JSONRoom | undefined;
|
|
4
4
|
export declare function getJSONRoomsOfSubType(jsonRooms: JSONRoom[], subType: int): JSONRoom[];
|
|
5
|
-
|
|
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
|
|
@@ -76,10 +76,10 @@ function ____exports.setPlayerHealth(self, player, playerHealth)
|
|
|
76
76
|
player:AddEternalHearts(playerHealth.eternalHearts)
|
|
77
77
|
local soulHeartsRemaining = playerHealth.soulHearts
|
|
78
78
|
do
|
|
79
|
-
local i =
|
|
80
|
-
while i
|
|
81
|
-
local heartType = playerHealth.soulHeartTypes[i]
|
|
82
|
-
local isHalf = (playerHealth.soulHearts + (playerHealth.boneHearts * 2)) < (i * 2)
|
|
79
|
+
local i = 0
|
|
80
|
+
while i < #playerHealth.soulHeartTypes do
|
|
81
|
+
local heartType = playerHealth.soulHeartTypes[i + 1]
|
|
82
|
+
local isHalf = (playerHealth.soulHearts + (playerHealth.boneHearts * 2)) < ((i + 1) * 2)
|
|
83
83
|
local addAmount = 2
|
|
84
84
|
if (isHalf or (heartType == HeartSubType.HEART_BONE)) or (soulHeartsRemaining < 2) then
|
|
85
85
|
addAmount = 1
|
|
@@ -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;
|
package/dist/functions/rooms.lua
CHANGED
|
@@ -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
|
|
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
|
-
::
|
|
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.
|
|
3
|
+
"version": "1.0.475",
|
|
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.
|
|
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",
|