Skip to content

Commit a08b0d1

Browse files
committed
Update definitions
1 parent 4a9b5af commit a08b0d1

File tree

7 files changed

+96
-32
lines changed

7 files changed

+96
-32
lines changed

definitions/feature/hudmodule.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ declare class HudModule extends Module {
22
constructor(name: string, displayName: string, description: string, key: KeyCode, resizable: boolean);
33

44
getRect(): Rect;
5-
setRect(newRect: Rect): void;
5+
setRect(newRect: IRect): void;
66
setBounds(width: number, height: number): void;
77
getSize(): number;
88
setSize(): number;

definitions/feature/screen.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ declare class Screen {
5252
* @param rect The rectangle to check bounds
5353
* @param point The point to check (by default, mouse position.)
5454
*/
55-
isHover(rect: Rect, point?: Vector2): boolean;
55+
isHover(rect: IRect, point?: IVector2): boolean;
5656

5757
/**
5858
* If the screen is currently on or off

definitions/gfx/graphics.d.ts

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
declare interface IRect {
2+
left: number;
3+
top: number;
4+
right: number;
5+
bottom: number;
6+
}
7+
8+
declare interface IVector2 {
9+
x: number;
10+
y: number;
11+
}
12+
13+
declare interface IVector3 extends IVector2 {
14+
z: number;
15+
}
16+
117
/**
218
* A class representing a rectangle on the screen.
319
* @member left The x coordinate of the top-left point.
420
* @member top The y coordinate of the top-left point.
521
* @member right The x coordinate of the bottom-right point.
622
* @member bottom The y coordinate of the bottom-right point.
723
*/
8-
declare class Rect {
24+
declare class Rect implements IRect {
925
/**
1026
*
1127
* @param left The x coordinate of the top-left point.
@@ -24,12 +40,13 @@ declare class Rect {
2440
getHeight(): number;
2541
}
2642

27-
declare class Vector2 {
28-
add: (vec: Vector2) => Vector2;
29-
sub: (vec: Vector2) => Vector2;
30-
mul: (vec: Vector2) => Vector2;
31-
div: (vec: Vector2) => Vector2;
32-
distanceTo: (pos: Vector2) => number;
43+
44+
declare class Vector2 implements IVector2 {
45+
add: (vec: IVector2) => Vector2;
46+
sub: (vec: IVector2) => Vector2;
47+
mul: (vec: IVector2) => Vector2;
48+
div: (vec: IVector2) => Vector2;
49+
distanceTo: (pos: IVector2) => number;
3350
/**
3451
* A point on the screen.
3552
* @param x The x coordinate.
@@ -42,15 +59,20 @@ declare class Vector2 {
4259
y: number;
4360
}
4461

45-
declare class Vector3 {
46-
add: (vec: Vector3) => Vector3;
47-
sub: (vec: Vector3) => Vector3;
48-
mul: (vec: Vector3) => Vector3;
49-
div: (vec: Vector3) => Vector3;
50-
distanceTo: (pos: Vector3) => number;
62+
declare class Vector3 implements IVector3 {
63+
add: (vec: IVector3) => Vector3;
64+
sub: (vec: IVector3) => Vector3;
65+
mul: (vec: IVector3) => Vector3;
66+
div: (vec: IVector3) => Vector3;
67+
distanceTo: (pos: IVector3) => number;
5168

5269
constructor(x: number, y: number, z: number);
70+
71+
/**
72+
* Create a `Vector3` object with all fields initialized to `0`
73+
*/
5374
constructor();
75+
5476
x: number;
5577
y: number;
5678
z: number;
@@ -82,7 +104,7 @@ declare class Color {
82104
* @param b Blue (0 to 255)
83105
* @param a Opacity (0 to 255)
84106
*/
85-
static RGB(r: number, g: number, b: number, a: number | undefined): Color;
107+
static RGB(r: number, g: number, b: number, a?: number): Color;
86108

87109
static WHITE: Color;
88110
static BLACK: Color;
@@ -105,22 +127,20 @@ declare const enum VerticalAlignment {
105127

106128
type BackendType
107129
=
108-
/**
109-
* */
110-
"dx";
130+
"dx" | "minecraft";
111131

112132
declare interface Graphics {
113133
/**
114134
*
115135
* @param renderer `"dx"`: uses Direct2D/DirectWrite, `"minecraft":` use the Minecraft renderer
116136
*/
117-
use(renderer: "dx" | "minecraft"): void;
118-
drawRect(rect: Rect, color: Color, thickness: number, radius?: number): void;
119-
fillRect(rect: Rect, color: Color, radius?: number): void;
137+
use(renderer: BackendType): void;
138+
drawRect(rect: IRect, color: Color, thickness: number, radius?: number): void;
139+
fillRect(rect: IRect, color: Color, radius?: number): void;
120140

121141
getTextSize(text: string, textSize: number): Vector2;
122142

123-
setClippingRect(rect: Rect): void;
143+
setClippingRect(rect: IRect): void;
124144
restoreClippingRect(): void;
125145

126146
/**
@@ -130,7 +150,7 @@ declare interface Graphics {
130150
* @param size The size of the text in pixels
131151
* @param color The color of the text
132152
*/
133-
drawText(pos: Vector2, text: string, size: number, color: Color): void;
153+
drawText(pos: IVector2, text: string, size: number, color: Color): void;
134154

135155
/**
136156
* A full verison of drawText, where you can specify the bounds of the text and the alignment
@@ -141,7 +161,7 @@ declare interface Graphics {
141161
* @param alignment The horizontal alignment
142162
* @param verticalAlignment The vertical alignment
143163
*/
144-
drawTextFull(area: Rect, text: string, size: number, color: Color, alignment: TextAlignment, verticalAlignment: VerticalAlignment): void;
164+
drawTextFull(area: IRect, text: string, size: number, color: Color, alignment: TextAlignment, verticalAlignment: VerticalAlignment): void;
145165

146166
/**
147167
* Draws a texture.
@@ -151,7 +171,7 @@ declare interface Graphics {
151171
* @param sizeY The size of the texture in pixels
152172
* @param color The overlay color of the texture (defaults to white)
153173
*/
154-
drawTexture(texture: Texture, pos: Vector2, sizeX: number, sizeY: number, color?: Color): void;
174+
drawTexture(texture: Texture, pos: IVector2, sizeX: number, sizeY: number, color?: Color): void;
155175

156176
/**
157177
* Draw an item instance.
@@ -160,7 +180,7 @@ declare interface Graphics {
160180
* @param sizeModifier The relative size modifier (defualt: 1.0, aka 16 pixels)
161181
* @param opacity The opacity of the item
162182
*/
163-
drawItem(item: ItemStack, pos: Vector2, sizeModifier: number, opacity: number): void;
183+
drawItem(item: ItemStack, pos: IVector2, sizeModifier: number, opacity: number): void;
164184
}
165185

166186
declare const graphics: Graphics;

definitions/gfx/graphics3.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ declare interface Graphics3D {
1717
* @param p1
1818
* @param p2
1919
*/
20-
drawLine(p1: Vector3, p2: Vector3): void;
20+
drawLine(p1: IVector3, p2: IVector3): void;
2121

2222
/**
2323
* Draws a triangle into the world (adds a triangle into the vertex buffer)
2424
* @param p1
2525
* @param p2
2626
* @param p3
2727
*/
28-
drawTriangle(p1: Vector3, p2: Vector3, p3: Vector3): void;
28+
drawTriangle(p1: IVector3, p2: IVector3, p3: IVector3): void;
2929

3030
/**
3131
* Draws a quad into the world (adds a quad into the vertex buffer)
@@ -34,7 +34,7 @@ declare interface Graphics3D {
3434
* @param p3
3535
* @param p4
3636
*/
37-
drawQuad(p1: Vector3, p2: Vector3, p3: Vector3, p4: Vector3): void;
37+
drawQuad(p1: IVector3, p2: IVector3, p3: IVector3, p4: IVector3): void;
3838

3939
/**
4040
* Call this every time you're done rendering. (batched renders the current vertex buffer into the world)

definitions/util/buffer.d.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
declare interface Uint8Array {
2+
/**
3+
* Read a 16-bit, little-endian integer at the specified index.
4+
*/
25
readInt16(idx: number): number;
6+
/**
7+
* Read a 32-bit, little-endian integer at the specified index.
8+
*/
39
readInt32(idx: number): number;
10+
/**
11+
* Read a 64-bit, little-endian integer at the specified index, but truncated as a JavaScript `number` value. The maximum safely usable value that can be returned by this function is `Number.MAX_SAFE_INTEGER`.
12+
*/
413
readInt64AsFloat(idx: number): number;
514

15+
/**
16+
* Read a JavaScript-standard 32 bit floating point number at the specified index.
17+
*/
618
readFloat32(idx: number): number;
19+
/**
20+
* Read a JavaScript-standard 64 bit floating point number at the specified index.
21+
*/
722
readFloat64(idx: number): number;
823

9-
/// Reads a null-terminated string
24+
/**
25+
* Reads a null-terminated byte-per-character string at the specified index.
26+
*/
1027
readString(idx: number): string;
1128
}
1229

30+
/**
31+
* This declaration reperesents the interface used by the Latite API to represent byte arrays.
32+
*/
1333
declare type Buffer = Uint8Array;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
declare const enum WebSocketEncoding {
2+
Binary = 0,
3+
Utf8 = 1
4+
}
5+
6+
interface WebSocketEvents {
7+
/**
8+
* Called on a message being received.
9+
* @param data The data being received. Could be a string or buffer depending on the `WebSocketEncoding`.
10+
*/
11+
"receive": (data: Buffer | string) => void,
12+
/**
13+
* Called on the WebSocket server or client closing the connection.
14+
*/
15+
"close": () => void,
16+
}
17+
18+
declare class WebSocket {
19+
constructor(url: string, encoding: WebSocketEncoding)
20+
21+
send: (data: string | Buffer) => void
22+
close: (code?: number, reason?: string) => void
23+
on: <K extends keyof WebSocketEvents>(eventName: K, handler: WebSocketEvents[K]) => void;
24+
}

definitions/world/entity.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ declare class Entity {
137137
* This function is restricted - it only works if you have operator.
138138
* @param vector The new velocity
139139
*/
140-
setVelocity(vector: Vector3): void;
140+
setVelocity(vector: IVector3): void;
141141
}
142142

143143
declare class Player extends Entity {

0 commit comments

Comments
 (0)