isaacscript-common 1.2.46 → 1.2.47

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.
@@ -6,7 +6,7 @@ local hasSubscriptions, postPEffectUpdate, postPlayerInit, postPlayerUpdate, pos
6
6
  local ____exports = require("features.saveDataManager.exports")
7
7
  local saveDataManager = ____exports.saveDataManager
8
8
  local ____array = require("functions.array")
9
- local arrayEmpty = ____array.arrayEmpty
9
+ local emptyArray = ____array.emptyArray
10
10
  local ____player = require("functions.player")
11
11
  local getPlayerFromIndex = ____player.getPlayerFromIndex
12
12
  local getPlayerIndex = ____player.getPlayerIndex
@@ -89,7 +89,7 @@ function dequeue(self, playerIndexes, fireFunction)
89
89
  end
90
90
  ::__continue23::
91
91
  end
92
- arrayEmpty(nil, playerIndexes)
92
+ emptyArray(nil, playerIndexes)
93
93
  end
94
94
  v = {run = {
95
95
  postGameStartedFiredOnThisRun = false,
@@ -2,13 +2,14 @@
2
2
  local ____lualib = require("lualib_bundle")
3
3
  local Set = ____lualib.Set
4
4
  local __TS__New = ____lualib.__TS__New
5
+ local __TS__ArrayPush = ____lualib.__TS__ArrayPush
5
6
  local Map = ____lualib.Map
6
7
  local ____exports = {}
7
- local hasSubscriptions, postPEffectUpdateReordered, UNUSED_TRANSFORMATIONS, v
8
+ local hasSubscriptions, postPEffectUpdateReordered, playerTransformationChanged, updateForgottenOrSoulTransformation, TRANSFORMATIONS, v
8
9
  local ____exports = require("features.saveDataManager.exports")
9
10
  local saveDataManager = ____exports.saveDataManager
10
11
  local ____array = require("functions.array")
11
- local arrayInit = ____array.arrayInit
12
+ local copyArray = ____array.copyArray
12
13
  local ____player = require("functions.player")
13
14
  local getPlayerIndex = ____player.getPlayerIndex
14
15
  local ____ModCallbacksCustom = require("types.ModCallbacksCustom")
@@ -23,32 +24,59 @@ function postPEffectUpdateReordered(self, player)
23
24
  if not hasSubscriptions(nil) then
24
25
  return
25
26
  end
26
- local index = getPlayerIndex(nil, player)
27
- local transformations = v.run.transformations:get(index)
27
+ local playerIndex = getPlayerIndex(nil, player)
28
+ local transformations = v.run.transformations:get(playerIndex)
28
29
  if transformations == nil then
29
- transformations = arrayInit(nil, false, PlayerForm.NUM_PLAYER_FORMS - 1)
30
- v.run.transformations:set(index, transformations)
30
+ transformations = __TS__New(Map)
31
+ v.run.transformations:set(playerIndex, transformations)
31
32
  end
32
- do
33
- local playerForm = 0
34
- while playerForm < PlayerForm.NUM_PLAYER_FORMS do
35
- do
36
- if UNUSED_TRANSFORMATIONS:has(playerForm) then
37
- goto __continue7
38
- end
39
- local hasForm = player:HasPlayerForm(playerForm)
40
- local storedForm = transformations[playerForm + 1]
41
- if hasForm ~= storedForm then
42
- transformations[playerForm + 1] = hasForm
43
- postTransformationFire(nil, player, playerForm, hasForm)
44
- end
33
+ for ____, playerForm in ipairs(TRANSFORMATIONS) do
34
+ local hasForm = player:HasPlayerForm(playerForm)
35
+ local storedForm = transformations:get(playerForm)
36
+ if storedForm == nil then
37
+ local defaultValue = false
38
+ storedForm = defaultValue
39
+ transformations:set(playerForm, defaultValue)
40
+ end
41
+ if hasForm ~= storedForm then
42
+ transformations:set(playerForm, hasForm)
43
+ playerTransformationChanged(nil, player, playerForm, hasForm)
44
+ end
45
+ end
46
+ end
47
+ function playerTransformationChanged(self, player, playerForm, hasForm)
48
+ postTransformationFire(nil, player, playerForm, hasForm)
49
+ updateForgottenOrSoulTransformation(nil, player, playerForm, hasForm)
50
+ end
51
+ function updateForgottenOrSoulTransformation(self, player, playerForm, hasForm)
52
+ local subPlayer = player:GetSubPlayer()
53
+ if subPlayer == nil then
54
+ return
55
+ end
56
+ local subPlayerIndex = getPlayerIndex(nil, subPlayer)
57
+ local transformations = v.run.transformations:get(subPlayerIndex)
58
+ if transformations == nil then
59
+ transformations = __TS__New(Map)
60
+ v.run.transformations:set(subPlayerIndex, transformations)
61
+ end
62
+ transformations:set(playerForm, hasForm)
63
+ end
64
+ local UNUSED_TRANSFORMATIONS = __TS__New(Set, {PlayerForm.PLAYERFORM_FLIGHT})
65
+ local tempTransformations = {}
66
+ do
67
+ local playerForm = 0
68
+ while playerForm < PlayerForm.NUM_PLAYER_FORMS do
69
+ do
70
+ if UNUSED_TRANSFORMATIONS:has(playerForm) then
71
+ goto __continue2
45
72
  end
46
- ::__continue7::
47
- playerForm = playerForm + 1
73
+ __TS__ArrayPush(tempTransformations, playerForm)
48
74
  end
75
+ ::__continue2::
76
+ playerForm = playerForm + 1
49
77
  end
50
78
  end
51
- UNUSED_TRANSFORMATIONS = __TS__New(Set, {PlayerForm.PLAYERFORM_FLIGHT})
79
+ TRANSFORMATIONS = copyArray(nil, tempTransformations)
52
80
  v = {run = {transformations = __TS__New(Map)}}
53
81
  function ____exports.postTransformationCallbackInit(self, mod)
54
82
  saveDataManager(nil, "postTransformation", v, hasSubscriptions)
@@ -1,20 +1,19 @@
1
1
  /// <reference types="isaac-typescript-definitions" />
2
2
  /// <reference types="typescript-to-lua/language-extensions" />
3
3
  /**
4
- * Helper function to combine arrays. Returns a new array that is the composition of all of the
5
- * specified arrays. This function is variadic, meaning that you can specify N arguments to combine
6
- * N arrays. Note that this will only perform a shallow copy of the array elements.
4
+ * Helper function to combine two or more arrays. Returns a new array that is the composition of all
5
+ * of the specified arrays. This function is variadic, meaning that you can specify N arguments to
6
+ * combine N arrays. Note that this will only perform a shallow copy of the array elements.
7
7
  */
8
- export declare function arrayCombine<T>(...arrays: Array<T[] | readonly T[]>): T[];
8
+ export declare function combineArray<T>(...arrays: Array<T[] | readonly T[]>): T[];
9
9
  /** Helper function to perform a shallow copy. */
10
- export declare function arrayCopy<T>(array: T[] | readonly T[]): T[];
11
- export declare function arrayEmpty<T>(array: T[]): void;
10
+ export declare function copyArray<T>(array: T[] | readonly T[]): T[];
11
+ export declare function emptyArray<T>(array: T[]): void;
12
12
  /**
13
13
  * Helper function for determining if two arrays contain the exact same elements. Note that this
14
14
  * only performs a shallow comparison.
15
15
  */
16
16
  export declare function arrayEquals<T>(array1: T[] | readonly T[], array2: T[] | readonly T[]): boolean;
17
- export declare function arrayInArray<T>(arrayToMatch: T[] | readonly T[], parentArray: Array<T[] | readonly T[]>): boolean;
18
17
  /**
19
18
  * Initializes an array with all elements containing the specified default value.
20
19
  *
@@ -23,20 +22,21 @@ export declare function arrayInArray<T>(arrayToMatch: T[] | readonly T[], parent
23
22
  * const playerTransformations = initArray(false, PlayerForm.NUM_PLAYER_FORMS - 1);
24
23
  * ```
25
24
  */
26
- export declare function arrayInit<T>(defaultValue: T, size: int): T[];
25
+ export declare function initArray<T>(defaultValue: T, size: int): T[];
26
+ export declare function isArrayInArray<T>(arrayToMatch: T[] | readonly T[], parentArray: Array<T[] | readonly T[]>): boolean;
27
27
  /**
28
28
  * Shallow copies and shuffles the array using the Fisher-Yates algorithm. Returns the copied array.
29
29
  *
30
30
  * From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
31
31
  */
32
- export declare function arrayShuffle<T>(originalArray: T[] | readonly T[], seed?: number): T[];
32
+ export declare function shuffleArray<T>(originalArray: T[] | readonly T[], seed?: number): T[];
33
33
  /**
34
34
  * Shuffles the provided array in-place using the Fisher-Yates algorithm.
35
35
  *
36
36
  * From: https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
37
37
  */
38
- export declare function arrayShuffleInPlace<T>(array: T[], seed?: number): void;
39
- export declare function arraySum(array: number[] | readonly number[]): number;
38
+ export declare function shuffleArrayInPlace<T>(array: T[], seed?: number): void;
39
+ export declare function sumArray(array: number[] | readonly number[]): number;
40
40
  export declare function arrayToString<T>(array: T[]): string;
41
41
  /**
42
42
  * Shallow copies and removes the specified element(s) from the array. Returns the copied array. If
@@ -11,7 +11,7 @@ local ____exports = {}
11
11
  local ____random = require("functions.random")
12
12
  local getRandomInt = ____random.getRandomInt
13
13
  local nextSeed = ____random.nextSeed
14
- function ____exports.arrayShuffleInPlace(self, array, seed)
14
+ function ____exports.shuffleArrayInPlace(self, array, seed)
15
15
  if seed == nil then
16
16
  seed = Random()
17
17
  end
@@ -36,7 +36,7 @@ function ____exports.getRandomArrayIndex(self, array, seed)
36
36
  local randomIndex = getRandomInt(nil, 0, #array - 1, seed)
37
37
  return randomIndex
38
38
  end
39
- function ____exports.arrayCombine(self, ...)
39
+ function ____exports.combineArray(self, ...)
40
40
  local arrays = {...}
41
41
  local elements = {}
42
42
  for ____, array in ipairs(arrays) do
@@ -46,10 +46,10 @@ function ____exports.arrayCombine(self, ...)
46
46
  end
47
47
  return elements
48
48
  end
49
- function ____exports.arrayCopy(self, array)
49
+ function ____exports.copyArray(self, array)
50
50
  return {table.unpack(array)}
51
51
  end
52
- function ____exports.arrayEmpty(self, array)
52
+ function ____exports.emptyArray(self, array)
53
53
  __TS__ArraySplice(array, 0, #array)
54
54
  end
55
55
  function ____exports.arrayEquals(self, array1, array2)
@@ -64,13 +64,7 @@ function ____exports.arrayEquals(self, array1, array2)
64
64
  end
65
65
  )
66
66
  end
67
- function ____exports.arrayInArray(self, arrayToMatch, parentArray)
68
- return __TS__ArraySome(
69
- parentArray,
70
- function(____, element) return ____exports.arrayEquals(nil, element, arrayToMatch) end
71
- )
72
- end
73
- function ____exports.arrayInit(self, defaultValue, size)
67
+ function ____exports.initArray(self, defaultValue, size)
74
68
  local array = {}
75
69
  do
76
70
  local i = 0
@@ -81,15 +75,21 @@ function ____exports.arrayInit(self, defaultValue, size)
81
75
  end
82
76
  return array
83
77
  end
84
- function ____exports.arrayShuffle(self, originalArray, seed)
78
+ function ____exports.isArrayInArray(self, arrayToMatch, parentArray)
79
+ return __TS__ArraySome(
80
+ parentArray,
81
+ function(____, element) return ____exports.arrayEquals(nil, element, arrayToMatch) end
82
+ )
83
+ end
84
+ function ____exports.shuffleArray(self, originalArray, seed)
85
85
  if seed == nil then
86
86
  seed = Random()
87
87
  end
88
- local array = ____exports.arrayCopy(nil, originalArray)
89
- ____exports.arrayShuffleInPlace(nil, array, seed)
88
+ local array = ____exports.copyArray(nil, originalArray)
89
+ ____exports.shuffleArrayInPlace(nil, array, seed)
90
90
  return array
91
91
  end
92
- function ____exports.arraySum(self, array)
92
+ function ____exports.sumArray(self, array)
93
93
  return __TS__ArrayReduce(
94
94
  array,
95
95
  function(____, accumulator, element) return accumulator + element end,
@@ -109,7 +109,7 @@ function ____exports.arrayToString(self, array)
109
109
  end
110
110
  function ____exports.arrayRemove(self, originalArray, ...)
111
111
  local elements = {...}
112
- local array = ____exports.arrayCopy(nil, originalArray)
112
+ local array = ____exports.copyArray(nil, originalArray)
113
113
  for ____, element in ipairs(elements) do
114
114
  local index = __TS__ArrayIndexOf(array, element)
115
115
  if index > -1 then
@@ -5,7 +5,7 @@ local __TS__ArrayMap = ____lualib.__TS__ArrayMap
5
5
  local ____exports = {}
6
6
  local getTotalWeightOfJSONRooms, getJSONRoomWithChosenWeight
7
7
  local ____array = require("functions.array")
8
- local arraySum = ____array.arraySum
8
+ local sumArray = ____array.sumArray
9
9
  local ____log = require("functions.log")
10
10
  local log = ____log.log
11
11
  local ____random = require("functions.random")
@@ -22,7 +22,7 @@ function getTotalWeightOfJSONRooms(self, jsonRooms)
22
22
  return roomWeight
23
23
  end
24
24
  )
25
- return arraySum(nil, weights)
25
+ return sumArray(nil, weights)
26
26
  end
27
27
  function getJSONRoomWithChosenWeight(self, jsonRooms, chosenWeight)
28
28
  for ____, jsonRoom in ipairs(jsonRooms) do
@@ -21,7 +21,7 @@ local MAX_VANILLA_CHARACTER = ____constants.MAX_VANILLA_CHARACTER
21
21
  local ____HealthType = require("types.HealthType")
22
22
  local HealthType = ____HealthType.HealthType
23
23
  local ____array = require("functions.array")
24
- local arraySum = ____array.arraySum
24
+ local sumArray = ____array.sumArray
25
25
  local ____bitwise = require("functions.bitwise")
26
26
  local getKBitOfN = ____bitwise.getKBitOfN
27
27
  local getNumBitsOfN = ____bitwise.getNumBitsOfN
@@ -433,7 +433,7 @@ function ____exports.getTotalPlayerCollectibles(self, collectibleType)
433
433
  players,
434
434
  function(____, player) return player:GetCollectibleNum(collectibleType) end
435
435
  )
436
- return arraySum(nil, numCollectiblesArray)
436
+ return sumArray(nil, numCollectiblesArray)
437
437
  end
438
438
  function ____exports.hasLostCurse(self, player)
439
439
  local effects = player:GetEffects()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isaacscript-common",
3
- "version": "1.2.46",
3
+ "version": "1.2.47",
4
4
  "description": "Helper functions for IsaacScript mods",
5
5
  "keywords": [
6
6
  "isaac",