isaacscript-common 1.2.4 → 1.2.8
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/constants.d.ts +6 -2
- package/dist/constants.lua +6 -2
- package/dist/features/disableInputs.lua +4 -4
- package/dist/features/saveDataManager/exports.d.ts +17 -4
- package/dist/features/saveDataManager/exports.lua +8 -0
- package/dist/features/saveDataManager/main.lua +6 -0
- package/dist/functions/array.d.ts +9 -0
- package/dist/functions/array.lua +11 -0
- package/dist/functions/input.lua +29 -46
- package/dist/functions/math.d.ts +2 -0
- package/dist/functions/math.lua +11 -0
- package/package.json +2 -2
package/dist/constants.d.ts
CHANGED
|
@@ -102,10 +102,14 @@ export declare const MAX_PLAYER_TRINKET_SLOTS = 2;
|
|
|
102
102
|
export declare const MAX_ROOM_INDEX = 168;
|
|
103
103
|
export declare const MAX_VANILLA_CHARACTER = PlayerType.PLAYER_THESOUL_B;
|
|
104
104
|
export declare const MAX_VANILLA_COLLECTIBLE_TYPE = CollectibleType.COLLECTIBLE_MOMS_RING;
|
|
105
|
-
export declare const
|
|
105
|
+
export declare const SECOND_IN_MILLISECONDS = 1000;
|
|
106
|
+
export declare const MINUTE_IN_MILLISECONDS: number;
|
|
107
|
+
export declare const MOVEMENT_ACTIONS: ButtonAction[];
|
|
108
|
+
export declare const MOVEMENT_ACTIONS_SET: Set<ButtonAction>;
|
|
106
109
|
export declare const ONE_BY_ONE_ROOM_GRID_SIZE = 135;
|
|
107
110
|
export declare const SINGLE_USE_ACTIVE_COLLECTIBLE_TYPES: Set<CollectibleType>;
|
|
108
|
-
export declare const SHOOTING_ACTIONS:
|
|
111
|
+
export declare const SHOOTING_ACTIONS: ButtonAction[];
|
|
112
|
+
export declare const SHOOTING_ACTIONS_SET: Set<ButtonAction>;
|
|
109
113
|
export declare const STORY_BOSSES: Set<EntityType>;
|
|
110
114
|
/**
|
|
111
115
|
* This is the number of draw coordinates that each heart spans on the UI in the upper left hand
|
package/dist/constants.lua
CHANGED
|
@@ -88,7 +88,10 @@ ____exports.MAX_PLAYER_TRINKET_SLOTS = 2
|
|
|
88
88
|
____exports.MAX_ROOM_INDEX = 168
|
|
89
89
|
____exports.MAX_VANILLA_CHARACTER = PlayerType.PLAYER_THESOUL_B
|
|
90
90
|
____exports.MAX_VANILLA_COLLECTIBLE_TYPE = CollectibleType.COLLECTIBLE_MOMS_RING
|
|
91
|
-
____exports.
|
|
91
|
+
____exports.SECOND_IN_MILLISECONDS = 1000
|
|
92
|
+
____exports.MINUTE_IN_MILLISECONDS = 60 * ____exports.SECOND_IN_MILLISECONDS
|
|
93
|
+
____exports.MOVEMENT_ACTIONS = {ButtonAction.ACTION_LEFT, ButtonAction.ACTION_RIGHT, ButtonAction.ACTION_UP, ButtonAction.ACTION_DOWN}
|
|
94
|
+
____exports.MOVEMENT_ACTIONS_SET = __TS__New(Set, ____exports.MOVEMENT_ACTIONS)
|
|
92
95
|
____exports.ONE_BY_ONE_ROOM_GRID_SIZE = 135
|
|
93
96
|
____exports.SINGLE_USE_ACTIVE_COLLECTIBLE_TYPES = __TS__New(Set, {
|
|
94
97
|
CollectibleType.COLLECTIBLE_FORGET_ME_NOW,
|
|
@@ -100,7 +103,8 @@ ____exports.SINGLE_USE_ACTIVE_COLLECTIBLE_TYPES = __TS__New(Set, {
|
|
|
100
103
|
CollectibleType.COLLECTIBLE_DEATH_CERTIFICATE,
|
|
101
104
|
CollectibleType.COLLECTIBLE_R_KEY
|
|
102
105
|
})
|
|
103
|
-
____exports.SHOOTING_ACTIONS =
|
|
106
|
+
____exports.SHOOTING_ACTIONS = {ButtonAction.ACTION_SHOOTLEFT, ButtonAction.ACTION_SHOOTRIGHT, ButtonAction.ACTION_SHOOTUP, ButtonAction.ACTION_SHOOTDOWN}
|
|
107
|
+
____exports.SHOOTING_ACTIONS_SET = __TS__New(Set, ____exports.SHOOTING_ACTIONS)
|
|
104
108
|
____exports.STORY_BOSSES = __TS__New(Set, {
|
|
105
109
|
EntityType.ENTITY_MOM,
|
|
106
110
|
EntityType.ENTITY_MOMS_HEART,
|
|
@@ -4,8 +4,8 @@ local Set = ____lualib.Set
|
|
|
4
4
|
local ____exports = {}
|
|
5
5
|
local isActionPressed, isActionTriggered, getActionValue, getReturnValue, v
|
|
6
6
|
local ____constants = require("constants")
|
|
7
|
-
local
|
|
8
|
-
local
|
|
7
|
+
local MOVEMENT_ACTIONS_SET = ____constants.MOVEMENT_ACTIONS_SET
|
|
8
|
+
local SHOOTING_ACTIONS_SET = ____constants.SHOOTING_ACTIONS_SET
|
|
9
9
|
local ____errors = require("errors")
|
|
10
10
|
local getUpgradeErrorMsg = ____errors.getUpgradeErrorMsg
|
|
11
11
|
local ____exports = require("features.saveDataManager.exports")
|
|
@@ -85,9 +85,9 @@ function ____exports.disableAllInputsExceptFor(self, whitelist)
|
|
|
85
85
|
v.run.blacklist = nil
|
|
86
86
|
end
|
|
87
87
|
function ____exports.disableMovementInputs(self)
|
|
88
|
-
____exports.enableAllInputsExceptFor(nil,
|
|
88
|
+
____exports.enableAllInputsExceptFor(nil, MOVEMENT_ACTIONS_SET)
|
|
89
89
|
end
|
|
90
90
|
function ____exports.disableShootingInputs(self)
|
|
91
|
-
____exports.enableAllInputsExceptFor(nil,
|
|
91
|
+
____exports.enableAllInputsExceptFor(nil, SHOOTING_ACTIONS_SET)
|
|
92
92
|
end
|
|
93
93
|
return ____exports
|
|
@@ -50,12 +50,17 @@ import { SaveData } from "../../types/SaveData";
|
|
|
50
50
|
* }
|
|
51
51
|
* ```
|
|
52
52
|
*
|
|
53
|
-
* - Save data is loaded from disk in the MC_POST_PLAYER_INIT callback
|
|
54
|
-
*
|
|
53
|
+
* - Save data is loaded from disk in the MC_POST_PLAYER_INIT callback (i.e. the first callback that
|
|
54
|
+
* can possibly run).
|
|
55
55
|
* - Save data is recorded to disk in the MC_PRE_GAME_EXIT callback.
|
|
56
56
|
*
|
|
57
57
|
* Note that before using the save data manager, you must call the [[`upgradeMod`]] function.
|
|
58
58
|
*
|
|
59
|
+
* If you want the save data manager to load data before the MC_POST_PLAYER_INIT callback (i.e. in
|
|
60
|
+
* the main menu), then you should explicitly call the [[`saveDataManagerLoad`]] function. (The save
|
|
61
|
+
* data manager cannot do this on its own because it cannot know when your mod features are finished
|
|
62
|
+
* initializing.)
|
|
63
|
+
*
|
|
59
64
|
* Finally, some features may have variables that need to be automatically reset per run/level, but
|
|
60
65
|
* not saved to disk on game exit. (For example, if they contain functions or other non-serializable
|
|
61
66
|
* data.) For these cases, set a special key of "dontSave" alongside "run", "level", and so forth.
|
|
@@ -65,8 +70,8 @@ import { SaveData } from "../../types/SaveData";
|
|
|
65
70
|
* @param saveData An object that corresponds to the `SaveData` interface. The object is
|
|
66
71
|
* conventionally called "v" for brevity (which is short for "local variables").
|
|
67
72
|
* @param conditionalFunc An optional function to run upon saving this key to disk. If the function
|
|
68
|
-
*
|
|
69
|
-
* "save#.dat" file with unnecessary keys.
|
|
73
|
+
* returns false, the key will not be written to disk. This allows mod features to avoid cluttering
|
|
74
|
+
* the "save#.dat" file with unnecessary keys.
|
|
70
75
|
*/
|
|
71
76
|
export declare function saveDataManager(key: string, saveData: SaveData, conditionalFunc?: () => boolean): void;
|
|
72
77
|
/**
|
|
@@ -75,6 +80,14 @@ export declare function saveDataManager(key: string, saveData: SaveData, conditi
|
|
|
75
80
|
* of its variables to disk immediately.
|
|
76
81
|
*/
|
|
77
82
|
export declare function saveDataManagerSave(): void;
|
|
83
|
+
/**
|
|
84
|
+
* The save data manager will automatically load variables from disk at the appropriate times (i.e.
|
|
85
|
+
* when a new run is started). Use this function to explicitly force the save data manager to load
|
|
86
|
+
* all of its variables from disk immediately.
|
|
87
|
+
*
|
|
88
|
+
* Note that doing this will overwrite current data, which can potentially result in lost state.
|
|
89
|
+
*/
|
|
90
|
+
export declare function saveDataManagerLoad(): void;
|
|
78
91
|
/**
|
|
79
92
|
* Sets the global variable of "g" equal to all of the save data variables for this mod.
|
|
80
93
|
* Sets the global variable of "gd" equal to all of the save data default variables for this mod.
|
|
@@ -10,6 +10,7 @@ local deepCopy = ____deepCopy.deepCopy
|
|
|
10
10
|
local SerializationType = ____deepCopy.SerializationType
|
|
11
11
|
local ____main = require("features.saveDataManager.main")
|
|
12
12
|
local FEATURE_NAME = ____main.FEATURE_NAME
|
|
13
|
+
local forceSaveDataManagerLoad = ____main.forceSaveDataManagerLoad
|
|
13
14
|
local forceSaveDataManagerSave = ____main.forceSaveDataManagerSave
|
|
14
15
|
local isSaveDataManagerInitialized = ____main.isSaveDataManagerInitialized
|
|
15
16
|
local ____maps = require("features.saveDataManager.maps")
|
|
@@ -48,6 +49,13 @@ function ____exports.saveDataManagerSave(self)
|
|
|
48
49
|
end
|
|
49
50
|
forceSaveDataManagerSave(nil)
|
|
50
51
|
end
|
|
52
|
+
function ____exports.saveDataManagerLoad(self)
|
|
53
|
+
if not isSaveDataManagerInitialized(nil) then
|
|
54
|
+
local msg = getUpgradeErrorMsg(nil, FEATURE_NAME)
|
|
55
|
+
error(msg)
|
|
56
|
+
end
|
|
57
|
+
forceSaveDataManagerLoad(nil)
|
|
58
|
+
end
|
|
51
59
|
function ____exports.saveDataManagerSetGlobal(self)
|
|
52
60
|
g = saveDataMap
|
|
53
61
|
gd = saveDataDefaultsMap
|
|
@@ -109,4 +109,10 @@ function ____exports.forceSaveDataManagerSave(self)
|
|
|
109
109
|
end
|
|
110
110
|
saveToDisk(nil, mod, saveDataMap, saveDataConditionalFuncMap)
|
|
111
111
|
end
|
|
112
|
+
function ____exports.forceSaveDataManagerLoad(self)
|
|
113
|
+
if mod == nil then
|
|
114
|
+
return
|
|
115
|
+
end
|
|
116
|
+
loadFromDisk(nil, mod, saveDataMap)
|
|
117
|
+
end
|
|
112
118
|
return ____exports
|
|
@@ -61,6 +61,15 @@ export declare function arrayRemoveInPlace<T>(array: T[], ...elements: T[]): boo
|
|
|
61
61
|
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
62
62
|
*/
|
|
63
63
|
export declare function getRandomArrayElement<T>(array: T[], seed?: number, exceptions?: T[]): T;
|
|
64
|
+
/**
|
|
65
|
+
* Helper function to get a random element from the provided array. Once the random element is
|
|
66
|
+
* decided, it is then removed from the array (in-place).
|
|
67
|
+
*
|
|
68
|
+
* @param array The array to get an element from.
|
|
69
|
+
* @param seed Optional. The seed used to select the random element. `Random()` by default.
|
|
70
|
+
* @param exceptions Optional. An array of elements to skip over if selected.
|
|
71
|
+
*/
|
|
72
|
+
export declare function getRandomArrayElementAndRemove<T>(array: T[], seed?: number, exceptions?: T[]): T;
|
|
64
73
|
export declare function getRandomArrayIndex<T>(array: T[], seed?: number): int;
|
|
65
74
|
/**
|
|
66
75
|
* Since Lua uses tables for every non-primitive data structure, it is non-trivial to determine if a
|
package/dist/functions/array.lua
CHANGED
|
@@ -145,6 +145,17 @@ function ____exports.getRandomArrayElement(self, array, seed, exceptions)
|
|
|
145
145
|
local randomIndex = ____exports.getRandomArrayIndex(nil, arrayWithoutExceptions, seed)
|
|
146
146
|
return arrayWithoutExceptions[randomIndex + 1]
|
|
147
147
|
end
|
|
148
|
+
function ____exports.getRandomArrayElementAndRemove(self, array, seed, exceptions)
|
|
149
|
+
if seed == nil then
|
|
150
|
+
seed = Random()
|
|
151
|
+
end
|
|
152
|
+
if exceptions == nil then
|
|
153
|
+
exceptions = {}
|
|
154
|
+
end
|
|
155
|
+
local randomArrayElement = ____exports.getRandomArrayElement(nil, array, seed, exceptions)
|
|
156
|
+
____exports.arrayRemoveInPlace(nil, array, randomArrayElement)
|
|
157
|
+
return randomArrayElement
|
|
158
|
+
end
|
|
148
159
|
function ____exports.isArray(self, ____table)
|
|
149
160
|
local metatable = getmetatable(____table)
|
|
150
161
|
if metatable ~= nil then
|
package/dist/functions/input.lua
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
|
|
2
2
|
local ____lualib = require("lualib_bundle")
|
|
3
|
-
local Set = ____lualib.Set
|
|
4
3
|
local __TS__StringReplace = ____lualib.__TS__StringReplace
|
|
5
4
|
local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
|
|
6
|
-
local
|
|
5
|
+
local __TS__ArraySome = ____lualib.__TS__ArraySome
|
|
7
6
|
local __TS__StringSlice = ____lualib.__TS__StringSlice
|
|
8
7
|
local ____exports = {}
|
|
9
8
|
local ____constants = require("constants")
|
|
10
9
|
local MAX_NUM_INPUTS = ____constants.MAX_NUM_INPUTS
|
|
11
10
|
local MOVEMENT_ACTIONS = ____constants.MOVEMENT_ACTIONS
|
|
12
11
|
local SHOOTING_ACTIONS = ____constants.SHOOTING_ACTIONS
|
|
12
|
+
local ____math = require("functions.math")
|
|
13
|
+
local range = ____math.range
|
|
13
14
|
local ControllerLiteral = ControllerLiteral or ({})
|
|
14
15
|
ControllerLiteral.DPAD_LEFT = 0
|
|
15
16
|
ControllerLiteral[ControllerLiteral.DPAD_LEFT] = "DPAD_LEFT"
|
|
@@ -72,63 +73,45 @@ function ____exports.controllerToString(self, controller)
|
|
|
72
73
|
return "unknown"
|
|
73
74
|
end
|
|
74
75
|
function ____exports.isActionPressedOnAnyInput(self, buttonAction)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
end
|
|
81
|
-
i = i + 1
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
return false
|
|
76
|
+
local validInputs = range(nil, 0, MAX_NUM_INPUTS - 1)
|
|
77
|
+
return __TS__ArraySome(
|
|
78
|
+
validInputs,
|
|
79
|
+
function(____, input) return Input.IsActionPressed(buttonAction, input) end
|
|
80
|
+
)
|
|
85
81
|
end
|
|
86
82
|
function ____exports.isActionTriggeredOnAnyInput(self, buttonAction)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
end
|
|
93
|
-
i = i + 1
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
return false
|
|
83
|
+
local validInputs = range(nil, 0, MAX_NUM_INPUTS - 1)
|
|
84
|
+
return __TS__ArraySome(
|
|
85
|
+
validInputs,
|
|
86
|
+
function(____, input) return Input.IsActionTriggered(buttonAction, input) end
|
|
87
|
+
)
|
|
97
88
|
end
|
|
98
89
|
function ____exports.isKeyboardPressed(self, key)
|
|
99
90
|
return Input.IsButtonPressed(key, 0)
|
|
100
91
|
end
|
|
101
92
|
function ____exports.isMoveActionPressedOnAnyInput(self)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
end
|
|
107
|
-
return false
|
|
93
|
+
return __TS__ArraySome(
|
|
94
|
+
MOVEMENT_ACTIONS,
|
|
95
|
+
function(____, moveAction) return ____exports.isActionPressedOnAnyInput(nil, moveAction) end
|
|
96
|
+
)
|
|
108
97
|
end
|
|
109
98
|
function ____exports.isMoveActionTriggeredOnAnyInput(self)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
end
|
|
115
|
-
return false
|
|
99
|
+
return __TS__ArraySome(
|
|
100
|
+
MOVEMENT_ACTIONS,
|
|
101
|
+
function(____, moveAction) return ____exports.isActionTriggeredOnAnyInput(nil, moveAction) end
|
|
102
|
+
)
|
|
116
103
|
end
|
|
117
104
|
function ____exports.isShootActionPressedOnAnyInput(self)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
end
|
|
123
|
-
return false
|
|
105
|
+
return __TS__ArraySome(
|
|
106
|
+
SHOOTING_ACTIONS,
|
|
107
|
+
function(____, shootAction) return ____exports.isActionPressedOnAnyInput(nil, shootAction) end
|
|
108
|
+
)
|
|
124
109
|
end
|
|
125
110
|
function ____exports.isShootActionTriggeredOnAnyInput(self)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
end
|
|
131
|
-
return false
|
|
111
|
+
return __TS__ArraySome(
|
|
112
|
+
SHOOTING_ACTIONS,
|
|
113
|
+
function(____, shootAction) return ____exports.isActionTriggeredOnAnyInput(nil, shootAction) end
|
|
114
|
+
)
|
|
132
115
|
end
|
|
133
116
|
function ____exports.keyboardToString(self, keyboard)
|
|
134
117
|
for ____, ____value in ipairs(__TS__ObjectEntries(Keyboard)) do
|
package/dist/functions/math.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export declare function isEven(num: int): boolean;
|
|
|
17
17
|
export declare function isOdd(num: int): boolean;
|
|
18
18
|
export declare function lerp(a: number, b: number, pos: float): number;
|
|
19
19
|
export declare function lerpAngleDegrees(aStart: number, aEnd: number, percent: float): number;
|
|
20
|
+
/** Helper function to return an array with the elements from start to end, inclusive. */
|
|
21
|
+
export declare function range(start: int, end: int): int[];
|
|
20
22
|
/**
|
|
21
23
|
* If rounding fails, this function returns 0.
|
|
22
24
|
* From: http://lua-users.org/wiki/SimpleRound
|
package/dist/functions/math.lua
CHANGED
|
@@ -87,6 +87,17 @@ end
|
|
|
87
87
|
function ____exports.lerpAngleDegrees(self, aStart, aEnd, percent)
|
|
88
88
|
return aStart + ____exports.getAngleDifference(nil, aStart, aEnd) * percent
|
|
89
89
|
end
|
|
90
|
+
function ____exports.range(self, start, ____end)
|
|
91
|
+
local array = {}
|
|
92
|
+
do
|
|
93
|
+
local i = start
|
|
94
|
+
while i <= ____end do
|
|
95
|
+
__TS__ArrayPush(array, i)
|
|
96
|
+
i = i + 1
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
return array
|
|
100
|
+
end
|
|
90
101
|
function ____exports.round(self, num, numDecimalPlaces)
|
|
91
102
|
if numDecimalPlaces == nil then
|
|
92
103
|
numDecimalPlaces = 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "isaacscript-common",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8",
|
|
4
4
|
"description": "Helper functions for IsaacScript mods",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"isaac",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@zamiell/typescript-to-lua": "^1.4.0",
|
|
29
|
-
"isaac-typescript-definitions": "^1.0.
|
|
29
|
+
"isaac-typescript-definitions": "^1.0.336",
|
|
30
30
|
"isaacscript-lint": "^1.0.79",
|
|
31
31
|
"isaacscript-tsconfig": "^1.1.8",
|
|
32
32
|
"typedoc": "^0.22.11",
|