warscript 0.0.1-dev.27fa654 → 0.0.1-dev.282b76e

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.
@@ -8,6 +8,7 @@ export type StunImmunityUnitBehaviourParameters = {
8
8
  buffTypeIds?: LuaSet<BuffTypeId>;
9
9
  textTagPreset?: TextTagPreset;
10
10
  textTagText?: string;
11
+ additionalAction?: (this: void, unit: Unit) => void;
11
12
  };
12
13
  export declare class StunImmunityUnitBehavior extends UnitBehavior {
13
14
  readonly parameters: Readonly<StunImmunityUnitBehaviourParameters>;
@@ -17,4 +18,5 @@ export declare class StunImmunityUnitBehavior extends UnitBehavior {
17
18
  onDamageReceived(): void;
18
19
  onTargetingAbilityChannelingStart(): void;
19
20
  onTargetingAbilityImpact(): void;
21
+ protected onEffect(): void;
20
22
  }
@@ -48,8 +48,15 @@ local function process(behavior)
48
48
  for buffTypeId in pairs(behavior.parameters.buffTypeIds or DEFAULT_BUFF_TYPE_IDS) do
49
49
  hasRemovedBuffs = hasRemovedBuffs or behavior.unit:removeBuff(buffTypeId)
50
50
  end
51
- if hasRemovedBuffs and behavior.parameters.textTagText ~= nil then
52
- TextTag:flash(TextTag.MISS, behavior.parameters.textTagText, behavior.unit.x, behavior.unit.y)
51
+ if hasRemovedBuffs then
52
+ behavior.onEffect(behavior)
53
+ if behavior.parameters.textTagText ~= nil then
54
+ TextTag:flash(TextTag.MISS, behavior.parameters.textTagText, behavior.unit.x, behavior.unit.y)
55
+ end
56
+ local ____opt_0 = behavior.parameters.additionalAction
57
+ if ____opt_0 ~= nil then
58
+ ____opt_0(behavior.unit)
59
+ end
53
60
  end
54
61
  end
55
62
  ____exports.StunImmunityUnitBehavior = __TS__Class()
@@ -79,5 +86,7 @@ end
79
86
  function StunImmunityUnitBehavior.prototype.onTargetingAbilityImpact(self)
80
87
  process(self)
81
88
  end
89
+ function StunImmunityUnitBehavior.prototype.onEffect(self)
90
+ end
82
91
  StunImmunityUnitBehavior.defaultParameters = {buffTypeIds = DEFAULT_BUFF_TYPE_IDS, textTagPreset = TextTag.MISS, textTagText = nil}
83
92
  return ____exports
@@ -12,6 +12,7 @@ import type { Widget } from "../../core/types/widget";
12
12
  import { Destructable } from "../../core/types/destructable";
13
13
  import type { Buff } from "../buff";
14
14
  import { UnitBonusType } from "../internal/unit/bonus";
15
+ import { Player } from "../../core/types/player";
15
16
  export type UnitBehaviorConstructor<Args extends any[]> = new (unit: Unit, ...args: Args) => UnitBehavior;
16
17
  export declare abstract class UnitBehavior<PeriodicActionParameters extends any[] = any[]> extends Behavior<Unit, PeriodicActionParameters> {
17
18
  readonly sourceAbilityBehavior?: AbilityBehavior;
@@ -55,4 +56,5 @@ export declare abstract class UnitBehavior<PeriodicActionParameters extends any[
55
56
  onItemChargesChanged(item: Item): void;
56
57
  onKill(target: Unit): void;
57
58
  onDeath(source: Unit | undefined): void;
59
+ onOwnerChange(previousOwner: Player): void;
58
60
  }
@@ -165,6 +165,8 @@ function UnitBehavior.prototype.onKill(self, target)
165
165
  end
166
166
  function UnitBehavior.prototype.onDeath(self, source)
167
167
  end
168
+ function UnitBehavior.prototype.onOwnerChange(self, previousOwner)
169
+ end
168
170
  __TS__SetDescriptor(
169
171
  UnitBehavior.prototype,
170
172
  "unit",
@@ -276,6 +278,9 @@ __TS__SetDescriptor(
276
278
  Unit.itemChargesChangedEvent:addListener(function(unit, item)
277
279
  ____exports.UnitBehavior:forAll(unit, "onItemChargesChanged", item)
278
280
  end)
281
+ Unit.onOwnerChange:addListener(function(unit, previousOwner)
282
+ ____exports.UnitBehavior:forAll(unit, "onOwnerChange", previousOwner)
283
+ end)
279
284
  end)(UnitBehavior)
280
285
  Unit.destroyEvent:addListener(function(unit)
281
286
  ____exports.UnitBehavior:forAll(unit, "destroy")
@@ -28,22 +28,22 @@ export declare class Item extends Handle<jitem> {
28
28
  get extendedTooltip(): string;
29
29
  set iconPath(v: string);
30
30
  get iconPath(): string;
31
- set dropOnDeath(v: boolean);
32
- get dropOnDeath(): boolean;
33
- set droppable(v: boolean);
34
- get droppable(): boolean;
35
- set pawnable(v: boolean);
36
- get pawnable(): boolean;
37
- set perishable(v: boolean);
38
- get perishable(): boolean;
39
- set powerup(v: boolean);
40
- get powerup(): boolean;
31
+ set dropsOnDeath(dropsOnDeath: boolean);
32
+ get dropsOnDeath(): boolean;
33
+ set canBeDropped(canBeDropped: boolean);
34
+ get canBeDropped(): boolean;
35
+ set canBeSold(canBeSold: boolean);
36
+ get canBeSold(): boolean;
37
+ set perishes(perishes: boolean);
38
+ get perishes(): boolean;
39
+ set isPowerUp(isPowerUp: boolean);
40
+ get isPowerUp(): boolean;
41
41
  get isAlive(): boolean;
42
42
  get isDead(): boolean;
43
43
  set isInvulnerable(isInvulnerable: boolean);
44
44
  get isInvulnerable(): boolean;
45
- set usable(v: boolean);
46
- get usable(): boolean;
45
+ set isActivelyUsed(isActivelyUsed: boolean);
46
+ get isActivelyUsed(): boolean;
47
47
  set visible(v: boolean);
48
48
  get visible(): boolean;
49
49
  set level(v: number);
@@ -50,6 +50,13 @@ local unitRemoveItem = UnitRemoveItem
50
50
  local unitUseItem = UnitUseItem
51
51
  local unitUseItemPoint = UnitUseItemPoint
52
52
  local unitUseItemTarget = UnitUseItemTarget
53
+ local setItemDropOnDeath = SetItemDropOnDeath
54
+ local setItemDroppable = SetItemDroppable
55
+ local setItemPawnable = SetItemPawnable
56
+ local isItemPawnable = IsItemPawnable
57
+ local getItemIntegerField = BlzGetItemIntegerField
58
+ local setItemBooleanField = BlzSetItemBooleanField
59
+ local getItemBooleanField = BlzGetItemBooleanField
53
60
  local tableRemove = table.remove
54
61
  _G.SetItemCharges = function(whichItem, charges)
55
62
  setItemCharges(whichItem, charges)
@@ -58,9 +65,6 @@ _G.SetItemCharges = function(whichItem, charges)
58
65
  ____exports.Item:of(whichItem)
59
66
  )
60
67
  end
61
- local getItemIntegerField = BlzGetItemIntegerField
62
- local setItemBooleanField = BlzSetItemBooleanField
63
- local getItemBooleanField = BlzGetItemBooleanField
64
68
  invoke = Event.invoke
65
69
  local enumRect = Rect:create(0, 0, 0, 0).handle
66
70
  ---
@@ -328,65 +332,68 @@ __TS__SetDescriptor(
328
332
  )
329
333
  __TS__SetDescriptor(
330
334
  Item.prototype,
331
- "dropOnDeath",
335
+ "dropsOnDeath",
332
336
  {
333
337
  get = function(self)
334
- return BlzGetItemBooleanField(self.handle, ITEM_BF_DROPPED_WHEN_CARRIER_DIES)
338
+ return getItemBooleanField(self.handle, ITEM_BF_DROPPED_WHEN_CARRIER_DIES)
335
339
  end,
336
- set = function(self, v)
337
- SetItemDropOnDeath(self.handle, v)
340
+ set = function(self, dropsOnDeath)
341
+ setItemDropOnDeath(self.handle, dropsOnDeath)
338
342
  end
339
343
  },
340
344
  true
341
345
  )
342
346
  __TS__SetDescriptor(
343
347
  Item.prototype,
344
- "droppable",
348
+ "canBeDropped",
345
349
  {
346
350
  get = function(self)
347
- return BlzGetItemBooleanField(self.handle, ITEM_BF_CAN_BE_DROPPED)
351
+ return getItemBooleanField(self.handle, ITEM_BF_CAN_BE_DROPPED)
348
352
  end,
349
- set = function(self, v)
350
- SetItemDroppable(self.handle, v)
353
+ set = function(self, canBeDropped)
354
+ setItemDroppable(self.handle, canBeDropped)
351
355
  end
352
356
  },
353
357
  true
354
358
  )
355
359
  __TS__SetDescriptor(
356
360
  Item.prototype,
357
- "pawnable",
361
+ "canBeSold",
358
362
  {
359
363
  get = function(self)
360
- return IsItemPawnable(self.handle)
364
+ return isItemPawnable(self.handle)
361
365
  end,
362
- set = function(self, v)
363
- SetItemPawnable(self.handle, v)
366
+ set = function(self, canBeSold)
367
+ setItemPawnable(self.handle, canBeSold)
364
368
  end
365
369
  },
366
370
  true
367
371
  )
368
372
  __TS__SetDescriptor(
369
373
  Item.prototype,
370
- "perishable",
374
+ "perishes",
371
375
  {
372
376
  get = function(self)
373
377
  return getItemBooleanField(self.handle, ITEM_BF_PERISHABLE)
374
378
  end,
375
- set = function(self, v)
376
- BlzSetItemBooleanField(self.handle, ITEM_BF_PERISHABLE, v)
379
+ set = function(self, perishes)
380
+ local handle = self.handle
381
+ local powerUp = isItemPowerup(handle)
382
+ setItemBooleanField(handle, ITEM_BF_PERISHABLE, perishes)
383
+ setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, powerUp)
377
384
  end
378
385
  },
379
386
  true
380
387
  )
381
388
  __TS__SetDescriptor(
382
389
  Item.prototype,
383
- "powerup",
390
+ "isPowerUp",
384
391
  {
385
392
  get = function(self)
386
393
  return isItemPowerup(self.handle)
387
394
  end,
388
- set = function(self, v)
389
- setItemBooleanField(self.handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, v)
395
+ set = function(self, isPowerUp)
396
+ setItemBooleanField(self.handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, isPowerUp)
390
397
  end
391
398
  },
392
399
  true
@@ -422,16 +429,24 @@ __TS__SetDescriptor(
422
429
  )
423
430
  __TS__SetDescriptor(
424
431
  Item.prototype,
425
- "usable",
432
+ "isActivelyUsed",
426
433
  {
427
434
  get = function(self)
428
435
  return getItemBooleanField(self.handle, ITEM_BF_ACTIVELY_USED)
429
436
  end,
430
- set = function(self, v)
437
+ set = function(self, isActivelyUsed)
431
438
  local handle = self.handle
432
- local powerup = isItemPowerup(handle)
433
- setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, v)
434
- setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, powerup)
439
+ local powerUp = isItemPowerup(handle)
440
+ local perishes = getItemBooleanField(handle, ITEM_BF_PERISHABLE)
441
+ local dropsOnDeath = getItemBooleanField(handle, ITEM_BF_DROPPED_WHEN_CARRIER_DIES)
442
+ local canBeDropped = getItemBooleanField(handle, ITEM_BF_CAN_BE_DROPPED)
443
+ local canBeSold = isItemPawnable(handle)
444
+ setItemBooleanField(handle, ITEM_BF_ACTIVELY_USED, isActivelyUsed)
445
+ setItemPawnable(handle, canBeSold)
446
+ setItemDroppable(handle, canBeDropped)
447
+ setItemDropOnDeath(handle, dropsOnDeath)
448
+ setItemBooleanField(handle, ITEM_BF_PERISHABLE, perishes)
449
+ setItemBooleanField(handle, ITEM_BF_USE_AUTOMATICALLY_WHEN_ACQUIRED, powerUp)
435
450
  end
436
451
  },
437
452
  true
@@ -23,6 +23,8 @@ local ____lazy = require("utility.lazy")
23
23
  local lazyRecord = ____lazy.lazyRecord
24
24
  local ____timer = require("core.types.timer")
25
25
  local Timer = ____timer.Timer
26
+ local ____lua_2Dsets = require("utility.lua-sets")
27
+ local luaSetOf = ____lua_2Dsets.luaSetOf
26
28
  local eventInvoke = Event.invoke
27
29
  local condition = Condition
28
30
  local createTrigger = CreateTrigger
@@ -407,14 +409,13 @@ rawset(
407
409
  extractAbilityTypeId
408
410
  )
409
411
  )
412
+ local internalAbilityChannelingFinishEvent = __TS__New(UnitTriggerEvent, EVENT_PLAYER_UNIT_SPELL_FINISH, collectUnitAbilityEventParameters)
410
413
  rawset(
411
414
  Unit,
412
415
  "abilityChannelingFinishEvent",
413
- createDispatchingEvent(
414
- __TS__New(UnitTriggerEvent, EVENT_PLAYER_UNIT_SPELL_FINISH, collectUnitAbilityEventParameters),
415
- extractAbilityTypeId
416
- )
416
+ createDispatchingEvent(internalAbilityChannelingFinishEvent, extractAbilityTypeId)
417
417
  )
418
+ local internalAbilityStopEvent = __TS__New(UnitTriggerEvent, EVENT_PLAYER_UNIT_SPELL_ENDCAST, collectUnitAbilityEventParameters)
418
419
  rawset(
419
420
  Unit,
420
421
  "abilityStopEvent",
@@ -450,4 +451,11 @@ rawset(
450
451
  end)
451
452
  end)
452
453
  )
454
+ local spellEffectOnlyAbilityTypeIds = luaSetOf(fourCC("AAns"))
455
+ internalAbilityChannelingStartEvent:addListener(function(unit, ability)
456
+ if spellEffectOnlyAbilityTypeIds[ability.parentTypeId] ~= nil then
457
+ eventInvoke(internalAbilityChannelingFinishEvent, unit, ability)
458
+ eventInvoke(internalAbilityStopEvent, unit, ability)
459
+ end
460
+ end)
453
461
  return ____exports
@@ -45,14 +45,20 @@ local function timerCallback(source, target)
45
45
  eventTimerByUnit[source] = nil
46
46
  Event.invoke(autoAttackFinishEvent, source, target)
47
47
  end
48
- Unit.autoAttackStartEvent:addListener(function(source, target)
49
- local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
50
- local timer = Timer:simple(
51
- attackPoint + min(0.001, attackPoint / 2),
52
- timerCallback,
53
- source,
54
- target
55
- )
56
- eventTimerByUnit[source] = timer
57
- end)
48
+ Unit.autoAttackStartEvent:addListener(
49
+ 4,
50
+ function(source, target)
51
+ local attackPoint = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
52
+ local timer = Timer:simple(
53
+ attackPoint + min(
54
+ compiletime(1 / 64),
55
+ attackPoint / 2
56
+ ),
57
+ timerCallback,
58
+ source,
59
+ target
60
+ )
61
+ eventTimerByUnit[source] = timer
62
+ end
63
+ )
58
64
  return ____exports
@@ -38,6 +38,8 @@ local ____sound = require("core.types.sound")
38
38
  local isSoundLabelCustom = ____sound.isSoundLabelCustom
39
39
  local Sound3D = ____sound.Sound3D
40
40
  local SoundSettings = ____sound.SoundSettings
41
+ local ____lua_2Dsets = require("utility.lua-sets")
42
+ local luaSetOf = ____lua_2Dsets.luaSetOf
41
43
  local castAnimationFQNByAbilityTypeId = {}
42
44
  local isButtonVisibleFalseAbilityTypes = {}
43
45
  local casterCastingEffectPresetsByAbilityTypeId = {}
@@ -1004,9 +1006,10 @@ for abilityTypeId, soundPresetId in pairs(postcompile(function() return targetEf
1004
1006
  )
1005
1007
  end
1006
1008
  end
1009
+ local unsupportedEffectSoundAbilityTypeIds = luaSetOf(fourCC("AAns"))
1007
1010
  Unit.abilityChannelingStartEvent:addListener(function(caster, ability)
1008
1011
  local soundPresetId = ability:getField(ABILITY_SF_EFFECT_SOUND)
1009
- if isSoundLabelCustom(soundPresetId) then
1012
+ if isSoundLabelCustom(soundPresetId) or soundPresetId ~= "" and unsupportedEffectSoundAbilityTypeIds[ability.parentTypeId] ~= nil then
1010
1013
  Sound3D:playFromLabel(soundPresetId, SoundSettings.Ability, caster)
1011
1014
  end
1012
1015
  end)
@@ -14,3 +14,7 @@ export declare const randomElement: {
14
14
  <T>(array: ReadonlyNonEmptyArray<T>): T;
15
15
  <T>(array: ReadonlyArray<T>): T | undefined;
16
16
  };
17
+ export declare const random: {
18
+ <T>(element: T, ...elements: T[]): T;
19
+ <T>(...elements: T[]): T | undefined;
20
+ };
package/engine/random.lua CHANGED
@@ -4,6 +4,7 @@ local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
4
4
  local PI = ____math.PI
5
5
  local getRandomInt = GetRandomInt
6
6
  local getRandomReal = GetRandomReal
7
+ local select = _G.select
7
8
  local cos = math.cos
8
9
  local sin = math.sin
9
10
  local sqrt = math.sqrt
@@ -18,4 +19,13 @@ end
18
19
  ____exports.randomElement = function(array)
19
20
  return array[getRandomInt(1, #array)]
20
21
  end
22
+ ____exports.random = function(...)
23
+ return (select(
24
+ getRandomInt(
25
+ 1,
26
+ select("#", ...)
27
+ ),
28
+ ...
29
+ ))
30
+ end
21
31
  return ____exports
@@ -141,7 +141,7 @@ __TS__SetDescriptor(
141
141
  setTextTagText(
142
142
  ensureHandle(self),
143
143
  self[103] or "",
144
- DEFAULT_FONT_SIZE
144
+ fontSize
145
145
  )
146
146
  self[104] = fontSize
147
147
  end
package/objutil/buff.lua CHANGED
@@ -762,7 +762,7 @@ Unit.onDamaging:addListener(function(source, target, event)
762
762
  end
763
763
  end)
764
764
  Unit.itemPickedUpEvent:addListener(function(unit, item)
765
- if item.powerup and item:hasAbility(fourCC("APdi")) then
765
+ if item.isPowerUp and item:hasAbility(fourCC("APdi")) then
766
766
  end
767
767
  end)
768
768
  return ____exports
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "warscript",
4
- "version": "0.0.1-dev.27fa654",
4
+ "version": "0.0.1-dev.282b76e",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
@@ -5,6 +5,7 @@ export declare const joinToString: <T>(array: readonly T[], separator: string, t
5
5
  export declare const arrayOfNotNull: <T>(...elements: readonly (T | undefined | null)[]) => T[];
6
6
  export declare const array: <T, N extends number>(length: N, initialize: (index: number) => T) => TupleOf<T, N>;
7
7
  export declare const toLuaSet: <T extends AnyNotNil>(array: readonly T[]) => LuaSet<T>;
8
+ export declare const contains: <T>(array: readonly T[], element: T) => boolean;
8
9
  export declare const forEach: <T, Args extends any[]>(array: readonly T[], consumerOrKey: ((value: T, ...args: Args) => void) | KeysOfType<T, (this: T, ...args: Args) => void>, ...args: Args) => void;
9
10
  export declare const all: {
10
11
  <T>(array: readonly T[], transform: (value: T) => boolean): boolean;
@@ -49,6 +49,14 @@ ____exports.toLuaSet = function(array)
49
49
  end
50
50
  return result
51
51
  end
52
+ ____exports.contains = function(array, element)
53
+ for i = 1, #array do
54
+ if array[i] == element then
55
+ return true
56
+ end
57
+ end
58
+ return false
59
+ end
52
60
  ____exports.forEach = function(array, consumerOrKey, ...)
53
61
  if type(consumerOrKey) == "function" then
54
62
  for i = 1, #array do
@@ -4,6 +4,15 @@ export declare const emptyLuaMap: <K extends AnyNotNil, V>() => ReadonlyLuaMap<K
4
4
  export declare const mutableLuaMap: <K extends AnyNotNil, V>() => LuaMap<K, V>;
5
5
  export declare const mutableWeakLuaMap: <K extends AnyNotNil, V>() => LuaMap<K, V>;
6
6
  export declare const luaMapOf: <K extends AnyNotNil, V>(...pairs: Flatten<TupleOf<[K, V], 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40>>) => LuaMap<K, V>;
7
- export declare const luaMapInvert: <K extends AnyNotNil, V extends AnyNotNil>(luaMap: LuaMap<K, V>) => LuaMap<V, K>;
8
- export declare const mapValues: <K extends AnyNotNil, V1, V2>(luaMap: LuaMap<K, V1>, transform: (value: V1) => V2) => LuaMap<K, V2>;
7
+ export declare const luaMapInvert: <K extends AnyNotNil, V extends AnyNotNil>(luaMap: ReadonlyLuaMap<K, V | undefined | null>) => LuaMap<V, K>;
8
+ export declare const toLuaMap: <K extends PropertyKey, V>(record: Record<K, V>) => LuaMap<K, V>;
9
+ export declare const flattenKeys: <K extends AnyNotNil, V>(luaMap: ReadonlyLuaMap<readonly K[], V> | ReadonlyLuaMap<K[], V>) => LuaMap<K, V>;
10
+ export declare const mapKeys: {
11
+ <K1 extends AnyNotNil, K2 extends AnyNotNil, V>(luaMap: ReadonlyLuaMap<K1, V>, transform: (value: K1) => K2): LuaMap<K2, V>;
12
+ <K1 extends AnyNotNil, K2 extends keyof K1, V>(luaMap: ReadonlyLuaMap<K1, V>, key: K2): K1[K2] extends AnyNotNil ? LuaMap<K1[K2], V> : never;
13
+ };
14
+ export declare const mapValues: {
15
+ <K extends AnyNotNil, V1, V2>(luaMap: ReadonlyLuaMap<K, V1>, transform: (value: V1) => V2): LuaMap<K, V2>;
16
+ <K extends AnyNotNil, V1, V2 extends keyof V1>(luaMap: ReadonlyLuaMap<K, V1>, key: V2): LuaMap<K, V1[V2]>;
17
+ };
9
18
  export declare const getOrPut: <K extends AnyNotNil, V>(luaMap: LuaMap<K, V>, key: K, defaultValue: () => V) => V;
@@ -27,10 +27,41 @@ ____exports.luaMapInvert = function(luaMap)
27
27
  end
28
28
  return invertLuaMap
29
29
  end
30
+ ____exports.toLuaMap = function(record)
31
+ return record
32
+ end
33
+ ____exports.flattenKeys = function(luaMap)
34
+ local result = {}
35
+ for keys, value in pairs(luaMap) do
36
+ for ____, key in ipairs(keys) do
37
+ result[key] = value
38
+ end
39
+ end
40
+ return result
41
+ end
42
+ ____exports.mapKeys = function(luaMap, transform)
43
+ local result = {}
44
+ if type(transform) == "function" then
45
+ for key, value in pairs(luaMap) do
46
+ result[transform(key)] = value
47
+ end
48
+ else
49
+ for key, value in pairs(luaMap) do
50
+ result[key[transform]] = value
51
+ end
52
+ end
53
+ return result
54
+ end
30
55
  ____exports.mapValues = function(luaMap, transform)
31
56
  local result = {}
32
- for key, value in pairs(luaMap) do
33
- result[key] = transform(value)
57
+ if type(transform) == "function" then
58
+ for key, value in pairs(luaMap) do
59
+ result[key] = transform(value)
60
+ end
61
+ else
62
+ for key, value in pairs(luaMap) do
63
+ result[key] = value[transform]
64
+ end
34
65
  end
35
66
  return result
36
67
  end