warscript 0.0.1-dev.cdcfbc9 → 0.0.1-dev.d09c685
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/attributes.d.ts +1 -0
- package/attributes.lua +9 -0
- package/core/types/player.d.ts +14 -0
- package/core/types/player.lua +20 -0
- package/engine/behaviour/ability/remove-buffs.d.ts +9 -0
- package/engine/behaviour/ability/remove-buffs.lua +21 -0
- package/engine/internal/unit/ability.lua +3 -3
- package/engine/internal/unit/main-selected.lua +12 -27
- package/engine/internal/unit-missile-launch.lua +39 -24
- package/engine/internal/unit.d.ts +2 -0
- package/engine/internal/unit.lua +20 -10
- package/engine/synchronization.d.ts +11 -0
- package/engine/synchronization.lua +77 -0
- package/net/socket.lua +1 -1
- package/package.json +1 -1
- package/utility/linked-set.d.ts +1 -0
- package/utility/linked-set.lua +19 -1
package/attributes.d.ts
CHANGED
|
@@ -13,5 +13,6 @@ export declare namespace Attribute {
|
|
|
13
13
|
export declare class AttributesHolder {
|
|
14
14
|
readonly get: (<T>(attribute: Attribute<T>) => T | undefined) & LuaExtension<"TableGetMethod">;
|
|
15
15
|
readonly set: (<T>(attribute: Attribute<T>, value: T | undefined) => void) & LuaExtension<"TableSetMethod">;
|
|
16
|
+
getOrPut<T>(attribute: Attribute<T>, defaultValue: () => T): T;
|
|
16
17
|
}
|
|
17
18
|
export {};
|
package/attributes.lua
CHANGED
|
@@ -20,4 +20,13 @@ local AttributesHolder = ____exports.AttributesHolder
|
|
|
20
20
|
AttributesHolder.name = "AttributesHolder"
|
|
21
21
|
function AttributesHolder.prototype.____constructor(self)
|
|
22
22
|
end
|
|
23
|
+
function AttributesHolder.prototype.getOrPut(self, attribute, defaultValue)
|
|
24
|
+
local value = self[attribute]
|
|
25
|
+
if value ~= nil then
|
|
26
|
+
return value
|
|
27
|
+
end
|
|
28
|
+
value = defaultValue()
|
|
29
|
+
self[attribute] = value
|
|
30
|
+
return value
|
|
31
|
+
end
|
|
23
32
|
return ____exports
|
package/core/types/player.d.ts
CHANGED
|
@@ -7,6 +7,18 @@ import { UpgradeId } from "../../engine/object-data/entry/upgrade";
|
|
|
7
7
|
interface Unit {
|
|
8
8
|
handle: junit;
|
|
9
9
|
}
|
|
10
|
+
export declare const enum PlayerAllianceType {
|
|
11
|
+
PASSIVE = 0,
|
|
12
|
+
RESCUABLE = 1,
|
|
13
|
+
HELP_REQUEST = 2,
|
|
14
|
+
HELP_RESPONSE = 3,
|
|
15
|
+
SHARED_XP = 4,
|
|
16
|
+
SHARED_SPELLS = 5,
|
|
17
|
+
SHARED_VISION = 6,
|
|
18
|
+
SHARED_VISION_FORCED = 7,
|
|
19
|
+
SHARED_CONTROL = 8,
|
|
20
|
+
SHARED_ADVANCED_CONTROL = 9
|
|
21
|
+
}
|
|
10
22
|
export declare class Player extends Handle<jplayer> {
|
|
11
23
|
static readonly all: Player[];
|
|
12
24
|
static readonly local: Player;
|
|
@@ -42,6 +54,8 @@ export declare class Player extends Handle<jplayer> {
|
|
|
42
54
|
forceUICancel(): void;
|
|
43
55
|
isAllyOf(other: Player): boolean;
|
|
44
56
|
isEnemyOf(other: Player): boolean;
|
|
57
|
+
setAlliance(other: Player, type: PlayerAllianceType, value: boolean): void;
|
|
58
|
+
getAlliance(other: Player, type: PlayerAllianceType): boolean;
|
|
45
59
|
setAbilityAvailable(abilityId: number, available: boolean): void;
|
|
46
60
|
getMaximumUpgradeLevel(upgradeId: UpgradeId): number;
|
|
47
61
|
setMaximumUpgradeLevel(upgradeId: UpgradeId, maximumLevel: number): void;
|
package/core/types/player.lua
CHANGED
|
@@ -23,14 +23,28 @@ local ____math = require("math")
|
|
|
23
23
|
local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
|
|
24
24
|
local ____player_2Dlocal_2Dhandle = require("engine.internal.misc.player-local-handle")
|
|
25
25
|
local PLAYER_LOCAL_HANDLE = ____player_2Dlocal_2Dhandle.PLAYER_LOCAL_HANDLE
|
|
26
|
+
local getPlayerAlliance = GetPlayerAlliance
|
|
26
27
|
local getPlayerColor = GetPlayerColor
|
|
27
28
|
local getPlayerName = GetPlayerName
|
|
28
29
|
local getPlayerTechCount = GetPlayerTechCount
|
|
29
30
|
local getPlayerTechMaxAllowed = GetPlayerTechMaxAllowed
|
|
31
|
+
local setPlayerAlliance = SetPlayerAlliance
|
|
30
32
|
local setPlayerTechMaxAllowed = SetPlayerTechMaxAllowed
|
|
31
33
|
local setPlayerTechResearched = SetPlayerTechResearched
|
|
32
34
|
local setPlayerAbilityAvailable = SetPlayerAbilityAvailable
|
|
33
35
|
local playerNative = _G.Player
|
|
36
|
+
local nativeByPlayerAllianceType = {
|
|
37
|
+
[0] = ALLIANCE_PASSIVE,
|
|
38
|
+
[1] = ALLIANCE_RESCUABLE,
|
|
39
|
+
[2] = ALLIANCE_HELP_REQUEST,
|
|
40
|
+
[3] = ALLIANCE_HELP_RESPONSE,
|
|
41
|
+
[4] = ALLIANCE_SHARED_XP,
|
|
42
|
+
[5] = ALLIANCE_SHARED_SPELLS,
|
|
43
|
+
[6] = ALLIANCE_SHARED_VISION,
|
|
44
|
+
[7] = ALLIANCE_SHARED_VISION_FORCED,
|
|
45
|
+
[8] = ALLIANCE_SHARED_CONTROL,
|
|
46
|
+
[9] = ALLIANCE_SHARED_ADVANCED_CONTROL
|
|
47
|
+
}
|
|
34
48
|
____exports.Player = __TS__Class()
|
|
35
49
|
local Player = ____exports.Player
|
|
36
50
|
Player.name = "Player"
|
|
@@ -85,6 +99,12 @@ end
|
|
|
85
99
|
function Player.prototype.isEnemyOf(self, other)
|
|
86
100
|
return IsPlayerEnemy(self.handle, other.handle)
|
|
87
101
|
end
|
|
102
|
+
function Player.prototype.setAlliance(self, other, ____type, value)
|
|
103
|
+
setPlayerAlliance(self.handle, other.handle, nativeByPlayerAllianceType[____type], value)
|
|
104
|
+
end
|
|
105
|
+
function Player.prototype.getAlliance(self, other, ____type)
|
|
106
|
+
return getPlayerAlliance(self.handle, other.handle, nativeByPlayerAllianceType[____type])
|
|
107
|
+
end
|
|
88
108
|
function Player.prototype.setAbilityAvailable(self, abilityId, available)
|
|
89
109
|
setPlayerAbilityAvailable(self.handle, abilityId, available)
|
|
90
110
|
end
|
|
@@ -14,3 +14,12 @@ export declare class RemoveBuffsSelfAbilityBehavior extends AbilityBehavior {
|
|
|
14
14
|
constructor(ability: Ability, polarity?: AbilityDependentValue<BuffPolarity> | undefined, resistanceType?: AbilityDependentValue<BuffResistanceType> | undefined, includeExpirationTimers?: AbilityDependentValue<boolean> | undefined, includeAuras?: AbilityDependentValue<boolean> | undefined, autoDispel?: AbilityDependentValue<boolean> | undefined);
|
|
15
15
|
onImpact(caster: Unit): void;
|
|
16
16
|
}
|
|
17
|
+
export declare class RemoveBuffsTargetAbilityBehavior extends AbilityBehavior {
|
|
18
|
+
private readonly polarity?;
|
|
19
|
+
private readonly resistanceType?;
|
|
20
|
+
private readonly includeExpirationTimers?;
|
|
21
|
+
private readonly includeAuras?;
|
|
22
|
+
private readonly autoDispel?;
|
|
23
|
+
constructor(ability: Ability, polarity?: AbilityDependentValue<BuffPolarity> | undefined, resistanceType?: AbilityDependentValue<BuffResistanceType> | undefined, includeExpirationTimers?: AbilityDependentValue<boolean> | undefined, includeAuras?: AbilityDependentValue<boolean> | undefined, autoDispel?: AbilityDependentValue<boolean> | undefined);
|
|
24
|
+
onUnitTargetImpact(_: Unit, target: Unit): void;
|
|
25
|
+
}
|
|
@@ -25,4 +25,25 @@ function RemoveBuffsSelfAbilityBehavior.prototype.onImpact(self, caster)
|
|
|
25
25
|
self:resolveCurrentAbilityDependentValue(self.autoDispel)
|
|
26
26
|
)
|
|
27
27
|
end
|
|
28
|
+
____exports.RemoveBuffsTargetAbilityBehavior = __TS__Class()
|
|
29
|
+
local RemoveBuffsTargetAbilityBehavior = ____exports.RemoveBuffsTargetAbilityBehavior
|
|
30
|
+
RemoveBuffsTargetAbilityBehavior.name = "RemoveBuffsTargetAbilityBehavior"
|
|
31
|
+
__TS__ClassExtends(RemoveBuffsTargetAbilityBehavior, AbilityBehavior)
|
|
32
|
+
function RemoveBuffsTargetAbilityBehavior.prototype.____constructor(self, ability, polarity, resistanceType, includeExpirationTimers, includeAuras, autoDispel)
|
|
33
|
+
AbilityBehavior.prototype.____constructor(self, ability)
|
|
34
|
+
self.polarity = polarity
|
|
35
|
+
self.resistanceType = resistanceType
|
|
36
|
+
self.includeExpirationTimers = includeExpirationTimers
|
|
37
|
+
self.includeAuras = includeAuras
|
|
38
|
+
self.autoDispel = autoDispel
|
|
39
|
+
end
|
|
40
|
+
function RemoveBuffsTargetAbilityBehavior.prototype.onUnitTargetImpact(self, _, target)
|
|
41
|
+
target:removeBuffs(
|
|
42
|
+
self:resolveCurrentAbilityDependentValue(self.polarity),
|
|
43
|
+
self:resolveCurrentAbilityDependentValue(self.resistanceType),
|
|
44
|
+
self:resolveCurrentAbilityDependentValue(self.includeExpirationTimers),
|
|
45
|
+
self:resolveCurrentAbilityDependentValue(self.includeAuras),
|
|
46
|
+
self:resolveCurrentAbilityDependentValue(self.autoDispel)
|
|
47
|
+
)
|
|
48
|
+
end
|
|
28
49
|
return ____exports
|
|
@@ -398,7 +398,7 @@ local function invokeImpactEvent(unit, ability, ...)
|
|
|
398
398
|
eventInvoke(internalAbilityImpactEvent, unit, ability, ...)
|
|
399
399
|
end
|
|
400
400
|
internalAbilityChannelingStartEvent:addListener(
|
|
401
|
-
|
|
401
|
+
999999,
|
|
402
402
|
function(unit, ability, ...)
|
|
403
403
|
ability[impactCallbackIdAttribute] = Timer:run(invokeImpactEvent, unit, ability, ...)
|
|
404
404
|
end
|
|
@@ -409,8 +409,8 @@ local function consumeImpactCallback(_, ability)
|
|
|
409
409
|
consumeZeroTimerCallback(impactCallbackId)
|
|
410
410
|
end
|
|
411
411
|
end
|
|
412
|
-
internalAbilityChannelingFinishEvent:addListener(
|
|
413
|
-
internalAbilityStopEvent:addListener(
|
|
412
|
+
internalAbilityChannelingFinishEvent:addListener(999999, consumeImpactCallback)
|
|
413
|
+
internalAbilityStopEvent:addListener(999999, consumeImpactCallback)
|
|
414
414
|
rawset(
|
|
415
415
|
Unit,
|
|
416
416
|
"abilityImpactEvent",
|
|
@@ -1,46 +1,31 @@
|
|
|
1
1
|
local ____lualib = require("lualib_bundle")
|
|
2
2
|
local __TS__New = ____lualib.__TS__New
|
|
3
3
|
local ____exports = {}
|
|
4
|
-
local ____player = require("core.types.player")
|
|
5
|
-
local Player = ____player.Player
|
|
6
|
-
local ____math = require("math")
|
|
7
|
-
local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
|
|
8
|
-
local MINIMUM_INTEGER = ____math.MINIMUM_INTEGER
|
|
9
4
|
local ____local_2Dclient = require("engine.local-client")
|
|
10
5
|
local LocalClient = ____local_2Dclient.LocalClient
|
|
11
6
|
local ____unit = require("engine.internal.unit")
|
|
12
7
|
local Unit = ____unit.Unit
|
|
13
8
|
local ____event = require("event")
|
|
14
9
|
local Event = ____event.Event
|
|
10
|
+
local ____synchronization = require("engine.synchronization")
|
|
11
|
+
local ObjectBus = ____synchronization.ObjectBus
|
|
15
12
|
local mainSelectedUnitChangeEvent = __TS__New(Event)
|
|
16
13
|
rawset(Unit, "mainSelectedUnitChangeEvent", mainSelectedUnitChangeEvent)
|
|
17
14
|
local mainSelectedUnitByPlayer = {}
|
|
18
|
-
local
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"",
|
|
23
|
-
0
|
|
15
|
+
local unitBus = __TS__New(
|
|
16
|
+
ObjectBus,
|
|
17
|
+
function(unit) return unit.syncId end,
|
|
18
|
+
function(syncId) return Unit:getBySyncId(syncId) end
|
|
24
19
|
)
|
|
25
|
-
BlzFrameSetMinMaxValue(syncSlider, MINIMUM_INTEGER, MAXIMUM_INTEGER)
|
|
26
20
|
LocalClient.mainSelectedUnitChangeEvent:addListener(function()
|
|
27
|
-
|
|
28
|
-
local syncId = ____opt_0 and ____opt_0.syncId
|
|
29
|
-
BlzFrameSetValue(syncSlider, syncId or 0)
|
|
21
|
+
unitBus:send(LocalClient.mainSelectedUnit)
|
|
30
22
|
end)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function()
|
|
36
|
-
local player = Player:of(GetTriggerPlayer())
|
|
37
|
-
local mainSelectedUnit = Unit:getBySyncId(BlzGetTriggerFrameValue())
|
|
38
|
-
if mainSelectedUnit ~= mainSelectedUnitByPlayer[player] then
|
|
39
|
-
mainSelectedUnitByPlayer[player] = mainSelectedUnit
|
|
40
|
-
Event.invoke(mainSelectedUnitChangeEvent, player)
|
|
41
|
-
end
|
|
23
|
+
unitBus.event:addListener(function(player, unit)
|
|
24
|
+
if unit ~= mainSelectedUnitByPlayer[player] then
|
|
25
|
+
mainSelectedUnitByPlayer[player] = unit
|
|
26
|
+
Event.invoke(mainSelectedUnitChangeEvent, player)
|
|
42
27
|
end
|
|
43
|
-
)
|
|
28
|
+
end)
|
|
44
29
|
rawset(
|
|
45
30
|
Unit,
|
|
46
31
|
"getMainSelectedOf",
|
|
@@ -9,11 +9,16 @@ local ____timer = require("core.types.timer")
|
|
|
9
9
|
local Timer = ____timer.Timer
|
|
10
10
|
local ____lua_2Dsets = require("utility.lua-sets")
|
|
11
11
|
local luaSetOf = ____lua_2Dsets.luaSetOf
|
|
12
|
-
local
|
|
13
|
-
local
|
|
12
|
+
local ____attributes = require("attributes")
|
|
13
|
+
local attribute = ____attributes.attribute
|
|
14
|
+
local ____linked_2Dset = require("utility.linked-set")
|
|
15
|
+
local LinkedSet = ____linked_2Dset.LinkedSet
|
|
14
16
|
local autoAttackFinishEvent = __TS__New(Event)
|
|
15
17
|
rawset(Unit, "autoAttackFinishEvent", autoAttackFinishEvent)
|
|
16
|
-
local
|
|
18
|
+
local units = __TS__New(LinkedSet)
|
|
19
|
+
local targetAttribute = attribute()
|
|
20
|
+
local impactDelayAttribute = attribute()
|
|
21
|
+
local passedTimeAttribute = attribute()
|
|
17
22
|
local instantOrderIds = luaSetOf(
|
|
18
23
|
orderId("avatar"),
|
|
19
24
|
orderId("berserk"),
|
|
@@ -30,35 +35,45 @@ local instantOrderIds = luaSetOf(
|
|
|
30
35
|
orderId("unimmolation")
|
|
31
36
|
)
|
|
32
37
|
local function reset(source, orderId)
|
|
33
|
-
if not (instantOrderIds[orderId] ~= nil) then
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
eventTimerByUnit[source] = nil
|
|
38
|
-
end
|
|
38
|
+
if not (instantOrderIds[orderId] ~= nil) and units:remove(source) then
|
|
39
|
+
source[targetAttribute] = nil
|
|
40
|
+
source[impactDelayAttribute] = nil
|
|
41
|
+
source[passedTimeAttribute] = nil
|
|
39
42
|
end
|
|
40
43
|
end
|
|
41
44
|
Unit.onImmediateOrder:addListener(reset)
|
|
42
45
|
Unit.onPointOrder:addListener(reset)
|
|
43
46
|
Unit.onTargetOrder:addListener(reset)
|
|
44
|
-
local
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
local timerPeriod = 1 / 64
|
|
48
|
+
local function invokeEvent(unit)
|
|
49
|
+
units:remove(unit)
|
|
50
|
+
local target = unit[targetAttribute]
|
|
51
|
+
unit[targetAttribute] = nil
|
|
52
|
+
unit[impactDelayAttribute] = nil
|
|
53
|
+
unit[passedTimeAttribute] = nil
|
|
54
|
+
Event.invoke(autoAttackFinishEvent, unit, target)
|
|
55
|
+
end
|
|
56
|
+
local function checkUnit(unit)
|
|
57
|
+
local passedTime = unit[passedTimeAttribute] + timerPeriod
|
|
58
|
+
if passedTime >= unit[impactDelayAttribute] then
|
|
59
|
+
invokeEvent(unit)
|
|
60
|
+
else
|
|
61
|
+
unit[passedTimeAttribute] = passedTime
|
|
62
|
+
end
|
|
47
63
|
end
|
|
64
|
+
Timer.onPeriod[timerPeriod]:addListener(function()
|
|
65
|
+
units:forEach(checkUnit)
|
|
66
|
+
end)
|
|
48
67
|
Unit.autoAttackStartEvent:addListener(
|
|
49
|
-
|
|
68
|
+
999999,
|
|
50
69
|
function(source, target)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
source,
|
|
59
|
-
target
|
|
60
|
-
)
|
|
61
|
-
eventTimerByUnit[source] = timer
|
|
70
|
+
if source[targetAttribute] ~= nil then
|
|
71
|
+
invokeEvent(source)
|
|
72
|
+
end
|
|
73
|
+
source[targetAttribute] = target
|
|
74
|
+
source[impactDelayAttribute] = (source:chooseWeapon(target) or source.firstWeapon).impactDelay
|
|
75
|
+
source[passedTimeAttribute] = -timerPeriod
|
|
76
|
+
units:add(source)
|
|
62
77
|
end
|
|
63
78
|
)
|
|
64
79
|
return ____exports
|
|
@@ -80,6 +80,8 @@ export declare class UnitWeapon {
|
|
|
80
80
|
readonly unit: Unit;
|
|
81
81
|
readonly index: 0 | 1;
|
|
82
82
|
constructor(unit: Unit, index: 0 | 1);
|
|
83
|
+
get isEnabled(): boolean;
|
|
84
|
+
set isEnabled(isEnabled: boolean);
|
|
83
85
|
get cooldown(): number;
|
|
84
86
|
set cooldown(cooldown: number);
|
|
85
87
|
get damage(): [minimumDamage: number, maximumDamage: number];
|
package/engine/internal/unit.lua
CHANGED
|
@@ -410,6 +410,19 @@ function UnitWeapon.prototype.____constructor(self, unit, index)
|
|
|
410
410
|
self.unit = unit
|
|
411
411
|
self.index = index
|
|
412
412
|
end
|
|
413
|
+
__TS__SetDescriptor(
|
|
414
|
+
UnitWeapon.prototype,
|
|
415
|
+
"isEnabled",
|
|
416
|
+
{
|
|
417
|
+
get = function(self)
|
|
418
|
+
return BlzGetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index)
|
|
419
|
+
end,
|
|
420
|
+
set = function(self, isEnabled)
|
|
421
|
+
BlzSetUnitWeaponBooleanField(self.unit.handle, UNIT_WEAPON_BF_ATTACKS_ENABLED, self.index, isEnabled)
|
|
422
|
+
end
|
|
423
|
+
},
|
|
424
|
+
true
|
|
425
|
+
)
|
|
413
426
|
__TS__SetDescriptor(
|
|
414
427
|
UnitWeapon.prototype,
|
|
415
428
|
"cooldown",
|
|
@@ -836,11 +849,13 @@ function Unit.prototype.queueAnimation(self, animation)
|
|
|
836
849
|
QueueUnitAnimation(self.handle, animation)
|
|
837
850
|
end
|
|
838
851
|
function Unit.prototype.chooseWeapon(self, target)
|
|
839
|
-
|
|
840
|
-
|
|
852
|
+
local firstWeapon = self.firstWeapon
|
|
853
|
+
if firstWeapon.isEnabled and target:isAllowedTarget(self, firstWeapon.allowedTargetCombatClassifications) then
|
|
854
|
+
return firstWeapon
|
|
841
855
|
end
|
|
842
|
-
|
|
843
|
-
|
|
856
|
+
local secondWeapon = self.secondWeapon
|
|
857
|
+
if secondWeapon.isEnabled and target:isAllowedTarget(target, secondWeapon.allowedTargetCombatClassifications) then
|
|
858
|
+
return secondWeapon
|
|
844
859
|
end
|
|
845
860
|
return nil
|
|
846
861
|
end
|
|
@@ -2468,12 +2483,7 @@ Unit.onDamaging = (function()
|
|
|
2468
2483
|
preventRetaliation = damagingEventPreventRetaliation
|
|
2469
2484
|
}
|
|
2470
2485
|
if data.isAttack and source then
|
|
2471
|
-
|
|
2472
|
-
if weapon == -1 then
|
|
2473
|
-
local targetsAllowed = BlzGetUnitWeaponIntegerField(source.handle, UNIT_WEAPON_IF_ATTACK_TARGETS_ALLOWED, 0)
|
|
2474
|
-
weapon = 0
|
|
2475
|
-
end
|
|
2476
|
-
data.weapon = assert(source.weapons[weapon + 1])
|
|
2486
|
+
data.weapon = source:chooseWeapon(target)
|
|
2477
2487
|
end
|
|
2478
2488
|
if not data.isAttack or not source or not source._attackHandlers then
|
|
2479
2489
|
invoke(
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** @noSelfInFile */
|
|
2
|
+
import { Player } from "../core/types/player";
|
|
3
|
+
import { Event } from "../event";
|
|
4
|
+
export declare const synchronizer: <T, K extends number>(getSyncId: (object: T) => K, getObject: (syncId: K) => T | undefined) => ((player: Player, object: T | undefined) => Promise<T | undefined>);
|
|
5
|
+
export declare class ObjectBus<T, K extends number> {
|
|
6
|
+
private readonly getSyncId;
|
|
7
|
+
readonly event: Event<[Player, T | undefined]>;
|
|
8
|
+
private readonly syncSlider;
|
|
9
|
+
constructor(getSyncId: (object: T) => K, getObject: (syncId: K) => T | undefined);
|
|
10
|
+
send(object: T | undefined): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
local ____lualib = require("lualib_bundle")
|
|
2
|
+
local __TS__New = ____lualib.__TS__New
|
|
3
|
+
local __TS__Promise = ____lualib.__TS__Promise
|
|
4
|
+
local __TS__Class = ____lualib.__TS__Class
|
|
5
|
+
local ____exports = {}
|
|
6
|
+
local ____player = require("core.types.player")
|
|
7
|
+
local Player = ____player.Player
|
|
8
|
+
local ____math = require("math")
|
|
9
|
+
local MAXIMUM_INTEGER = ____math.MAXIMUM_INTEGER
|
|
10
|
+
local MINIMUM_INTEGER = ____math.MINIMUM_INTEGER
|
|
11
|
+
local ____linked_2Dset = require("utility.linked-set")
|
|
12
|
+
local LinkedSet = ____linked_2Dset.LinkedSet
|
|
13
|
+
local ____event = require("event")
|
|
14
|
+
local Event = ____event.Event
|
|
15
|
+
local eventInvoke = Event.invoke
|
|
16
|
+
local createFrameByType = BlzCreateFrameByType
|
|
17
|
+
local createTrigger = CreateTrigger
|
|
18
|
+
local getOriginFrame = BlzGetOriginFrame
|
|
19
|
+
local getTriggerFrameValue = BlzGetTriggerFrameValue
|
|
20
|
+
local getTriggerPlayer = GetTriggerPlayer
|
|
21
|
+
local frameSetMinMaxValue = BlzFrameSetMinMaxValue
|
|
22
|
+
local frameSetValue = BlzFrameSetValue
|
|
23
|
+
local triggerAddAction = TriggerAddAction
|
|
24
|
+
local triggerRegisterFrameEvent = BlzTriggerRegisterFrameEvent
|
|
25
|
+
____exports.synchronizer = function(getSyncId, getObject)
|
|
26
|
+
local queue = __TS__New(LinkedSet)
|
|
27
|
+
local socket = __TS__New(____exports.ObjectBus, getSyncId, getObject)
|
|
28
|
+
socket.event:addListener(function(_, object)
|
|
29
|
+
local ____opt_0 = queue:pop()
|
|
30
|
+
if ____opt_0 ~= nil then
|
|
31
|
+
____opt_0(object)
|
|
32
|
+
end
|
|
33
|
+
end)
|
|
34
|
+
local function executor(____, resolve)
|
|
35
|
+
queue:add(resolve)
|
|
36
|
+
end
|
|
37
|
+
return function(player, object)
|
|
38
|
+
if player.isLocal then
|
|
39
|
+
socket:send(object)
|
|
40
|
+
end
|
|
41
|
+
return __TS__New(__TS__Promise, executor)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
____exports.ObjectBus = __TS__Class()
|
|
45
|
+
local ObjectBus = ____exports.ObjectBus
|
|
46
|
+
ObjectBus.name = "ObjectBus"
|
|
47
|
+
function ObjectBus.prototype.____constructor(self, getSyncId, getObject)
|
|
48
|
+
self.getSyncId = getSyncId
|
|
49
|
+
local syncSlider = createFrameByType(
|
|
50
|
+
"SLIDER",
|
|
51
|
+
"Synchronizer",
|
|
52
|
+
getOriginFrame(ORIGIN_FRAME_WORLD_FRAME, 0),
|
|
53
|
+
"",
|
|
54
|
+
0
|
|
55
|
+
)
|
|
56
|
+
frameSetMinMaxValue(syncSlider, MINIMUM_INTEGER, MAXIMUM_INTEGER)
|
|
57
|
+
self.syncSlider = syncSlider
|
|
58
|
+
local event = __TS__New(Event)
|
|
59
|
+
local trigger = createTrigger()
|
|
60
|
+
triggerRegisterFrameEvent(trigger, syncSlider, FRAMEEVENT_SLIDER_VALUE_CHANGED)
|
|
61
|
+
triggerAddAction(
|
|
62
|
+
trigger,
|
|
63
|
+
function()
|
|
64
|
+
eventInvoke(
|
|
65
|
+
event,
|
|
66
|
+
Player:of(getTriggerPlayer()),
|
|
67
|
+
getObject(getTriggerFrameValue())
|
|
68
|
+
)
|
|
69
|
+
end
|
|
70
|
+
)
|
|
71
|
+
self.event = event
|
|
72
|
+
end
|
|
73
|
+
function ObjectBus.prototype.send(self, object)
|
|
74
|
+
local syncId = object ~= nil and self.getSyncId(object) or 0
|
|
75
|
+
frameSetValue(self.syncSlider, syncId)
|
|
76
|
+
end
|
|
77
|
+
return ____exports
|
package/net/socket.lua
CHANGED
|
@@ -28,13 +28,13 @@ function Socket.prototype.____constructor(self)
|
|
|
28
28
|
onReceive[self[0]]:addListener(function(sender, data)
|
|
29
29
|
local chunks = chunksByPlayer[sender]
|
|
30
30
|
if chunks ~= nil then
|
|
31
|
+
chunksByPlayer[sender] = nil
|
|
31
32
|
chunks[#chunks + 1] = data
|
|
32
33
|
Event.invoke(
|
|
33
34
|
self.onMessage,
|
|
34
35
|
sender,
|
|
35
36
|
tableConcat(chunks)
|
|
36
37
|
)
|
|
37
|
-
chunksByPlayer[sender] = nil
|
|
38
38
|
else
|
|
39
39
|
Event.invoke(self.onMessage, sender, data)
|
|
40
40
|
end
|
package/package.json
CHANGED
package/utility/linked-set.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ export declare class LinkedSet<T extends AnyNotNil> implements ReadonlyLinkedSet
|
|
|
36
36
|
copyOf(): LinkedSet<T>;
|
|
37
37
|
first(): T | undefined;
|
|
38
38
|
last(): T | undefined;
|
|
39
|
+
pop(): T | undefined;
|
|
39
40
|
next(key: T): T | undefined;
|
|
40
41
|
previous(key: T): T | undefined;
|
|
41
42
|
add(key: T): boolean;
|
package/utility/linked-set.lua
CHANGED
|
@@ -42,6 +42,23 @@ end
|
|
|
42
42
|
function LinkedSet.prototype.last(self)
|
|
43
43
|
return self.l
|
|
44
44
|
end
|
|
45
|
+
function LinkedSet.prototype.pop(self)
|
|
46
|
+
local f = self.f
|
|
47
|
+
if f == nil then
|
|
48
|
+
return nil
|
|
49
|
+
end
|
|
50
|
+
local n = self.n
|
|
51
|
+
local next = n[f]
|
|
52
|
+
n[f] = nil
|
|
53
|
+
self.f = next
|
|
54
|
+
if next ~= nil then
|
|
55
|
+
self.p[next] = nil
|
|
56
|
+
else
|
|
57
|
+
self.l = nil
|
|
58
|
+
end
|
|
59
|
+
self.s = self.s - 1
|
|
60
|
+
return f
|
|
61
|
+
end
|
|
45
62
|
function LinkedSet.prototype.next(self, key)
|
|
46
63
|
return self.n[key]
|
|
47
64
|
end
|
|
@@ -107,8 +124,9 @@ function LinkedSet.prototype.forEach(self, action, ...)
|
|
|
107
124
|
local n = self.n
|
|
108
125
|
local c = self.f
|
|
109
126
|
while c ~= nil do
|
|
127
|
+
local next = n[c]
|
|
110
128
|
action(c, ...)
|
|
111
|
-
c =
|
|
129
|
+
c = next
|
|
112
130
|
end
|
|
113
131
|
end
|
|
114
132
|
function LinkedSet.prototype.toArray(self)
|