isaacscript-common 1.0.473 → 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
|
-
* @
|
|
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
|
|
@@ -25,10 +37,23 @@ export declare function deployJSONRoom(jsonRoom: JSONRoom, seed?: number): int;
|
|
|
25
37
|
* properly account for each room weight using the algorithm from:
|
|
26
38
|
* https://stackoverflow.com/questions/1761626/weighted-random-numbers
|
|
27
39
|
*
|
|
28
|
-
* @
|
|
29
|
-
*
|
|
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.
|
|
30
55
|
*/
|
|
31
|
-
export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seed?: number): int;
|
|
56
|
+
export declare function deployRandomJSONRoom(jsonRooms: JSONRoom[], seed?: number, verbose?: boolean): int;
|
|
32
57
|
/**
|
|
33
58
|
* Helper function to remove all naturally spawning entities and grid entities from a room. Notably,
|
|
34
59
|
* this will not remove players (1), tears (2), familiars (3), lasers (7), knives (8),
|
|
@@ -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")
|
|
@@ -91,10 +93,10 @@ function removeSpecificNPCs(self)
|
|
|
91
93
|
) do
|
|
92
94
|
do
|
|
93
95
|
if NPC_TYPES_TO_NOT_REMOVE:has(npc.Type) then
|
|
94
|
-
goto
|
|
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 a 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 a 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
|
|
@@ -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
|
|
@@ -2,4 +2,11 @@
|
|
|
2
2
|
import { JSONRoom } from "../types/JSONRoom";
|
|
3
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
|