warscript 0.0.1-dev.09d09c4 → 0.0.1-dev.0aa6f08

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.
@@ -137,8 +137,21 @@ export declare class Frame extends Handle<jframehandle> {
137
137
  static get onMouseUp(): Event<[Player, jmousebuttontype, number, number]>;
138
138
  private static onMouseDownEvent?;
139
139
  static get onMouseDown(): Event<[Player, jmousebuttontype, number, number]>;
140
- static get onMouseMove(): Event<[player: Player, x: number, y: number]>;
141
- static get onMouseMoveLocal(): Event<[x: number, y: number]>;
140
+ /**
141
+ * Synchronized native mouse movement of every player. Each movement of every player's
142
+ * cursor is sent over the network, so with several players moving their mice this floods
143
+ * the network and raises the latency for everyone. Prefer {@link mouseMoveLocalEvent} and
144
+ * synchronize the needed coordinates explicitly, only when they matter (e.g. on a click).
145
+ */
146
+ static get mouseMoveEvent(): Event<[player: Player, x: number, y: number]>;
147
+ /**
148
+ * Fires on the local client when the world point under the cursor changes, whether the
149
+ * cursor or the camera moved. Polls the local cursor position every 1/64 second and sends
150
+ * nothing over the network. The point is the camera ray's intersection with the terrain,
151
+ * so it ignores units and doodads under the cursor. It is also computed while the cursor
152
+ * is over the UI; check {@link isMouseOnWorld} where that matters.
153
+ */
154
+ static get mouseMoveLocalEvent(): Event<[x: number, y: number]>;
142
155
  static createSimple<T extends Frame>(this: FrameSubclass<T>, name: string, parent?: Frame, createContext?: number): T;
143
156
  static create<T extends Frame>(this: FrameSubclass<T>, name: string, parent: Frame, priority?: number, createContext?: number): T;
144
157
  static createByType<T extends Frame>(this: FrameSubclass<T>, typeName: "BACKDROP" | "BUTTON" | "CHATDISPLAY" | "CHECKBOX" | "CONTROL" | "DIALOG" | "EDITBOX" | "FRAME" | "GLUEBUTTON" | "GLUECHECKBOX" | "GLUETEXTBUTTON" | "HIGHLIGHT" | "LISTBOX" | "MENU" | "POPUPMENU" | "SCROLLBAR" | "SLIDER" | "TEXT" | "TEXTAREA" | "TEXTBUTTON", name: string, parent: Frame, inherits?: string, createContext?: number): T;
@@ -21,9 +21,6 @@ local FRAME_MIN_Y = ____frame_2Dcoordinates.FRAME_MIN_Y
21
21
  local getFrameMinXMaxX = ____frame_2Dcoordinates.getFrameMinXMaxX
22
22
  local ____playerCamera = require("core.types.playerCamera")
23
23
  local frameCoordinatesToWorld = ____playerCamera.frameCoordinatesToWorld
24
- local worldCoordinatesToFrame = ____playerCamera.worldCoordinatesToFrame
25
- local ____get_2Dterrain_2Dz = require("engine.internal.misc.get-terrain-z")
26
- local getTerrainZ = ____get_2Dterrain_2Dz.getTerrainZ
27
24
  local ____lua_2Dsets = require("utility.lua-sets")
28
25
  local mutableLuaSet = ____lua_2Dsets.mutableLuaSet
29
26
  local ____socket = require("net.socket")
@@ -39,8 +36,13 @@ local frameIsVisible = BlzFrameIsVisible
39
36
  local frameSetEnable = BlzFrameSetEnable
40
37
  local frameSetScale = BlzFrameSetScale
41
38
  local getHandleId = GetHandleId
39
+ local getLocalClientHeight = BlzGetLocalClientHeight
40
+ local getMouseScreenPosX = BlzGetMouseScreenPosX
41
+ local getMouseScreenPosY = BlzGetMouseScreenPosY
42
42
  local getOriginFrame = BlzGetOriginFrame
43
43
  local location = Location
44
+ local pixelToFrameX = BlzPixelToFrameX
45
+ local pixelToFrameY = BlzPixelToFrameY
44
46
  local ____rawget = _G.rawget
45
47
  local rawset = _G.rawset
46
48
  local invoke = Event.invoke
@@ -988,7 +990,7 @@ __TS__ObjectDefineProperty(
988
990
  )
989
991
  __TS__ObjectDefineProperty(
990
992
  Frame,
991
- "onMouseMove",
993
+ "mouseMoveEvent",
992
994
  {get = function(self)
993
995
  local event = __TS__New(
994
996
  TriggerEvent,
@@ -1002,48 +1004,32 @@ __TS__ObjectDefineProperty(
1002
1004
  ) end,
1003
1005
  function() return Player:of(GetTriggerPlayer()), BlzGetTriggerPlayerMouseX(), BlzGetTriggerPlayerMouseY() end
1004
1006
  )
1005
- rawset(____exports.Frame, "onMouseMove", event)
1007
+ rawset(____exports.Frame, "mouseMoveEvent", event)
1006
1008
  return event
1007
1009
  end}
1008
1010
  )
1009
1011
  __TS__ObjectDefineProperty(
1010
1012
  Frame,
1011
- "onMouseMoveLocal",
1013
+ "mouseMoveLocalEvent",
1012
1014
  {get = function(self)
1013
- local invoke = Event.invoke
1014
1015
  local event = __TS__New(Event)
1015
- local syncX = 0
1016
- local syncY = 0
1017
- local syncFrameX = 0
1018
- local syncFrameY = 0
1019
- local lastX = syncX
1020
- local lastY = syncY
1021
- self.onMouseMove:addListener(function(player, x, y)
1022
- if player.isLocal then
1023
- syncX = x
1024
- syncY = y
1025
- syncFrameX, syncFrameY = worldCoordinatesToFrame(
1026
- x,
1027
- y,
1028
- getTerrainZ(x, y)
1029
- )
1030
- lastX = x
1031
- lastY = y
1032
- invoke(event, x, y)
1033
- end
1034
- end)
1016
+ local lastX = 0
1017
+ local lastY = 0
1035
1018
  Timer.onPeriod[1 / 64]:addListener(function()
1036
- if syncX == 0 and syncY == 0 then
1019
+ if getLocalClientHeight() == 0 then
1037
1020
  return
1038
1021
  end
1039
- local x, y, ____, isDefinite = frameCoordinatesToWorld(syncFrameX, syncFrameY)
1022
+ local x, y, ____, isDefinite = frameCoordinatesToWorld(
1023
+ pixelToFrameX(getMouseScreenPosX()),
1024
+ pixelToFrameY(getMouseScreenPosY())
1025
+ )
1040
1026
  if isDefinite and (x ~= lastX or y ~= lastY) then
1041
1027
  lastX = x
1042
1028
  lastY = y
1043
1029
  invoke(event, x, y)
1044
1030
  end
1045
1031
  end)
1046
- rawset(____exports.Frame, "onMouseMoveLocal", event)
1032
+ rawset(____exports.Frame, "mouseMoveLocalEvent", event)
1047
1033
  return event
1048
1034
  end}
1049
1035
  )
@@ -1,11 +1,14 @@
1
1
  /** @noSelfInFile */
2
2
  import { AttributesHolder } from "../../attributes";
3
3
  export declare class TileCell extends AttributesHolder implements Readonly<Vec2> {
4
- private readonly id;
4
+ /** Identifies the cell the same way on every client; see {@link TileCell.getById}. */
5
+ readonly id: number;
5
6
  readonly x: number;
6
7
  readonly y: number;
7
8
  readonly z: undefined;
8
- protected constructor(id: number, x: number, y: number, z: undefined);
9
+ protected constructor(
10
+ /** Identifies the cell the same way on every client; see {@link TileCell.getById}. */
11
+ id: number, x: number, y: number, z: undefined);
9
12
  get up(): TileCell;
10
13
  get down(): TileCell;
11
14
  get left(): TileCell;
@@ -20,4 +23,6 @@ export declare class TileCell extends AttributesHolder implements Readonly<Vec2>
20
23
  static getInRect(minX: number, minY: number, maxX: number, maxY: number): TileCell[];
21
24
  static getInRange(x: number, y: number, range: number): TileCell[];
22
25
  static of(this: void, x: number, y: number): TileCell;
26
+ /** The cell with the given {@link id}, e.g. one received over the network. */
27
+ static getById(this: void, id: number): TileCell;
23
28
  }
@@ -118,6 +118,17 @@ function TileCell.of(x, y)
118
118
  nil
119
119
  )
120
120
  end
121
+ function TileCell.getById(id)
122
+ local yId = (id + 16384) // 32768
123
+ local xId = id - yId * 32768
124
+ return tileCellById[id] or __TS__New(
125
+ ____exports.TileCell,
126
+ id,
127
+ xId * 128,
128
+ yId * 128,
129
+ nil
130
+ )
131
+ end
121
132
  __TS__SetDescriptor(
122
133
  TileCell.prototype,
123
134
  "up",
@@ -1,6 +1,10 @@
1
1
  /** @noSelfInFile */
2
2
  import { DiseaseCloudAbilityType } from "./disease-cloud";
3
+ import { CombatClassifications } from "../../auxiliary/combat-classification";
4
+ import { ObjectDataEntryLevelFieldValueSupplier } from "../../entry";
3
5
  export declare class BlankPassiveAbilityType extends DiseaseCloudAbilityType {
4
6
  static readonly IS_SYNTHETIC = true;
5
7
  constructor(object: WarObject);
8
+ get allowedTargetCombatClassifications(): CombatClassifications[];
9
+ set allowedTargetCombatClassifications(allowedTargetCombatClassifications: ObjectDataEntryLevelFieldValueSupplier<CombatClassifications>);
6
10
  }
@@ -1,11 +1,18 @@
1
1
  local ____lualib = require("lualib_bundle")
2
2
  local __TS__Class = ____lualib.__TS__Class
3
3
  local __TS__ClassExtends = ____lualib.__TS__ClassExtends
4
+ local __TS__SetDescriptor = ____lualib.__TS__SetDescriptor
4
5
  local ____exports = {}
5
6
  local ____disease_2Dcloud = require("engine.object-data.entry.ability-type.disease-cloud")
6
7
  local DiseaseCloudAbilityType = ____disease_2Dcloud.DiseaseCloudAbilityType
7
8
  local ____combat_2Dclassification = require("engine.object-data.auxiliary.combat-classification")
8
9
  local combatClassificationsOf = ____combat_2Dclassification.combatClassificationsOf
10
+ local combatClassificationsToStringArray = ____combat_2Dclassification.combatClassificationsToStringArray
11
+ local ____ability = require("engine.standard.fields.ability")
12
+ local ALLOWED_TARGETS_ABILITY_COMBAT_CLASSIFICATIONS_LEVEL_FIELD = ____ability.ALLOWED_TARGETS_ABILITY_COMBAT_CLASSIFICATIONS_LEVEL_FIELD
13
+ local function noneCombatClassificationStrings()
14
+ return combatClassificationsToStringArray(combatClassificationsOf(1))
15
+ end
9
16
  ____exports.BlankPassiveAbilityType = __TS__Class()
10
17
  local BlankPassiveAbilityType = ____exports.BlankPassiveAbilityType
11
18
  BlankPassiveAbilityType.name = "BlankPassiveAbilityType"
@@ -15,14 +22,27 @@ function BlankPassiveAbilityType.prototype.____constructor(self, object)
15
22
  self.levelCount = 1
16
23
  self.iconPath = ""
17
24
  self.targetEffectPresets = {}
18
- self.diseaseDuration = 0
19
- self.damagePerSecond = 0
20
- self.plagueWardDuration = 0
21
- self.plagueWardUnitTypeId = 0
22
- self.allowedTargetCombatClassifications = combatClassificationsOf(1)
23
- self.areaOfEffect = 0
24
- self.buffTypeIds = {}
25
+ self.diseaseDuration = function() return 0 end
26
+ self.damagePerSecond = function() return 0 end
27
+ self.plagueWardDuration = function() return 0 end
28
+ self.plagueWardUnitTypeId = function() return 0 end
29
+ self:setStringsLevelField("atar", noneCombatClassificationStrings)
30
+ self.areaOfEffect = function() return 0 end
31
+ self.buffTypeIds = function() return {} end
25
32
  self.techTreeDependencies = {}
26
33
  end
27
34
  BlankPassiveAbilityType.IS_SYNTHETIC = true
35
+ __TS__SetDescriptor(
36
+ BlankPassiveAbilityType.prototype,
37
+ "allowedTargetCombatClassifications",
38
+ {
39
+ get = function(self)
40
+ return ALLOWED_TARGETS_ABILITY_COMBAT_CLASSIFICATIONS_LEVEL_FIELD:getValue(self)
41
+ end,
42
+ set = function(self, allowedTargetCombatClassifications)
43
+ ALLOWED_TARGETS_ABILITY_COMBAT_CLASSIFICATIONS_LEVEL_FIELD:setValue(self, allowedTargetCombatClassifications)
44
+ end
45
+ },
46
+ true
47
+ )
28
48
  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.09d09c4",
4
+ "version": "0.0.1-dev.0aa6f08",
5
5
  "description": "A typescript library for Warcraft III using Warpack.",
6
6
  "keywords": [
7
7
  "warcraft",
@@ -1,6 +1,11 @@
1
1
  /** @noSelfInFile */
2
- import { TupleOf } from "./types";
2
+ import { NonEmptyArray, ReadonlyNonEmptyArray, TupleOf } from "./types";
3
3
  export declare const emptyArray: <T>() => readonly T[];
4
+ /** Checks for any element with `next` instead of computing the length. */
5
+ export declare const isNonEmptyArray: {
6
+ <T>(array: T[]): array is NonEmptyArray<T>;
7
+ <T>(array: readonly T[]): array is ReadonlyNonEmptyArray<T>;
8
+ };
4
9
  export declare const joinToString: <T>(array: readonly T[], separator: string, transform?: (element: T) => string) => string;
5
10
  export declare const arrayOfNotNull: <T>(...elements: readonly (T | undefined | null)[]) => T[];
6
11
  export declare const array: <T, N extends number>(length: N, initialize: (index: number) => T) => TupleOf<T, N>;
@@ -7,6 +7,7 @@ local ____functions = require("utility.functions")
7
7
  local identity = ____functions.identity
8
8
  local mathMax = math.max
9
9
  local mathMin = math.min
10
+ local next = _G.next
10
11
  local select = _G.select
11
12
  local tableConcat = table.concat
12
13
  local tableSort = table.sort
@@ -14,6 +15,10 @@ local EMPTY_ARRAY = {}
14
15
  ____exports.emptyArray = function()
15
16
  return EMPTY_ARRAY
16
17
  end
18
+ --- Checks for any element with `next` instead of computing the length.
19
+ ____exports.isNonEmptyArray = function(array)
20
+ return (next(array)) ~= nil
21
+ end
17
22
  ____exports.joinToString = function(array, separator, transform)
18
23
  if transform == nil then
19
24
  transform = tostring