Skip to content

Commit ba4b5e6

Browse files
authored
Update lua api (#39)
* Update lua api * Update api.generated.d.ts * Change CEntities using for statement * IsPlayerController move to typePredicates * Remove override CreateItem
1 parent 82f9168 commit ba4b5e6

3 files changed

Lines changed: 85 additions & 23 deletions

File tree

build/lua/overrides.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,46 @@ export const overrides: Record<string, ApiOverride> = {
8888
},
8989
},
9090
},
91+
92+
EntIndexToHScript: {
93+
generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }],
94+
return: 'T | undefined',
95+
},
9196
};
9297

98+
for (const name of [
99+
'FindAllByName',
100+
'FindAllByNameWithin',
101+
'FindAllByTarget',
102+
'FindAllByClassname',
103+
'FindAllByClassnameWithin',
104+
'FindAllByModel',
105+
'FindAllInSphere',
106+
]) {
107+
overrides[`CEntities.${name}`] = {
108+
generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }],
109+
return: 'T[]',
110+
};
111+
}
112+
113+
for (const name of [
114+
'FindByClassname',
115+
'FindByClassnameNearest',
116+
'FindByClassnameWithin',
117+
'FindByModel',
118+
'FindByModelWithin',
119+
'FindByName',
120+
'FindByNameNearest',
121+
'FindByNameWithin',
122+
'FindByTarget',
123+
'FindInSphere',
124+
]) {
125+
overrides[`CEntities.${name}`] = {
126+
generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }],
127+
return: 'T | undefined',
128+
};
129+
}
130+
93131
for (const name of ['QueueConcept', 'QueueTeamConcept', 'QueueTeamConceptNoSpectators']) {
94132
overrides[`CDOTA_BaseNPC.${name}`] = {
95133
callback: 'optional',

build/lua/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ const typePredicates: Record<string, string> = {
8989
'CDOTA_PlayerResource.IsValidPlayerID': 'playerId is PlayerID',
9090
'CDOTA_PlayerResource.IsValidTeamPlayer': 'playerId is PlayerID',
9191
'CDOTA_PlayerResource.IsValidTeamPlayerID': 'playerId is PlayerID',
92+
'CBaseEntity.IsPlayerController': 'this is CDOTAPlayerController',
93+
'CBaseEntity.IsPlayerPawn': 'this is CBasePlayerPawn',
9294
'CDOTABaseAbility.IsItem': 'this is CDOTA_Item',
9395
'ProjectileManager.IsValidProjectile': 'value is ProjectileID',
9496
};

packages/dota-lua-types/types/api.generated.d.ts

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ declare interface CBaseEntity extends CEntityInstance {
327327
/**
328328
* Is this entity a player controller?
329329
*/
330-
IsPlayerController(): boolean;
330+
IsPlayerController(): this is CDOTAPlayerController;
331331
/**
332332
* Is this entity a player pawn?
333333
*/
334-
IsPlayerPawn(): boolean;
334+
IsPlayerPawn(): this is CBasePlayerPawn;
335335
Kill(): void;
336336
NextMovePeer(): CBaseEntity;
337337
/**
@@ -8250,95 +8250,117 @@ declare interface CEntities {
82508250
* Finds all entities by class name. Returns an array containing all the found
82518251
* entities.
82528252
*/
8253-
FindAllByClassname(className: string): CBaseEntity[];
8253+
FindAllByClassname<T extends CBaseEntity = CBaseEntity>(className: string): T[];
82548254
/**
82558255
* Find entities by class name within a radius.
82568256
*/
8257-
FindAllByClassnameWithin(className: string, location: Vector, radius: number): CBaseEntity[];
8257+
FindAllByClassnameWithin<T extends CBaseEntity = CBaseEntity>(
8258+
className: string,
8259+
location: Vector,
8260+
radius: number,
8261+
): T[];
82588262
/**
82598263
* Find entities by model name.
82608264
*/
8261-
FindAllByModel(modelName: string): CBaseEntity[];
8265+
FindAllByModel<T extends CBaseEntity = CBaseEntity>(modelName: string): T[];
82628266
/**
82638267
* Find all entities by name. Returns an array containing all the found entities
82648268
* in it.
82658269
*/
8266-
FindAllByName(name: string): CBaseEntity[];
8270+
FindAllByName<T extends CBaseEntity = CBaseEntity>(name: string): T[];
82678271
/**
82688272
* Find entities by name within a radius.
82698273
*/
8270-
FindAllByNameWithin(name: string, location: Vector, radius: number): CBaseEntity[];
8274+
FindAllByNameWithin<T extends CBaseEntity = CBaseEntity>(name: string, location: Vector, radius: number): T[];
82718275
/**
82728276
* Find entities by targetname.
82738277
*/
8274-
FindAllByTarget(target: string): CBaseEntity[];
8278+
FindAllByTarget<T extends CBaseEntity = CBaseEntity>(target: string): T[];
82758279
/**
82768280
* Find entities within a radius.
82778281
*/
8278-
FindAllInSphere(location: Vector, radius: number): CBaseEntity[];
8282+
FindAllInSphere<T extends CBaseEntity = CBaseEntity>(location: Vector, radius: number): T[];
82798283
/**
82808284
* Find entities by class name. Pass 'null' to start an iteration, or reference to
82818285
* a previously found entity to continue a search.
82828286
*/
8283-
FindByClassname(previous: CBaseEntity | undefined, className: string): CBaseEntity | undefined;
8287+
FindByClassname<T extends CBaseEntity = CBaseEntity>(
8288+
previous: CBaseEntity | undefined,
8289+
className: string,
8290+
): T | undefined;
82848291
/**
82858292
* Find entities by class name nearest to a point.
82868293
*/
8287-
FindByClassnameNearest(className: string, location: Vector, radius: number): CBaseEntity | undefined;
8294+
FindByClassnameNearest<T extends CBaseEntity = CBaseEntity>(
8295+
className: string,
8296+
location: Vector,
8297+
radius: number,
8298+
): T | undefined;
82888299
/**
82898300
* Find entities by class name within a radius. Pass 'null' to start an iteration,
82908301
* or reference to a previously found entity to continue a search.
82918302
*/
8292-
FindByClassnameWithin(
8303+
FindByClassnameWithin<T extends CBaseEntity = CBaseEntity>(
82938304
previous: CBaseEntity | undefined,
82948305
className: string,
82958306
location: Vector,
82968307
radius: number,
8297-
): CBaseEntity | undefined;
8308+
): T | undefined;
82988309
/**
82998310
* Find entities by model name. Pass 'null' to start an iteration, or reference to
83008311
* a previously found entity to continue a search.
83018312
*/
8302-
FindByModel(previous: CBaseEntity | undefined, modelName: string): CBaseEntity | undefined;
8313+
FindByModel<T extends CBaseEntity = CBaseEntity>(
8314+
previous: CBaseEntity | undefined,
8315+
modelName: string,
8316+
): T | undefined;
83038317
/**
83048318
* Find entities by model name within a radius. Pass 'null' to start an iteration,
83058319
* or reference to a previously found entity to continue a search.
83068320
*/
8307-
FindByModelWithin(
8321+
FindByModelWithin<T extends CBaseEntity = CBaseEntity>(
83088322
previous: CBaseEntity | undefined,
83098323
modelName: string,
83108324
location: Vector,
83118325
radius: number,
8312-
): CBaseEntity | undefined;
8326+
): T | undefined;
83138327
/**
83148328
* Find entities by name. Pass 'null' to start an iteration, or reference to a
83158329
* previously found entity to continue a search.
83168330
*/
8317-
FindByName(previous: CBaseEntity | undefined, name: string): CBaseEntity | undefined;
8331+
FindByName<T extends CBaseEntity = CBaseEntity>(previous: CBaseEntity | undefined, name: string): T | undefined;
83188332
/**
83198333
* Find entities by name nearest to a point.
83208334
*/
8321-
FindByNameNearest(name: string, location: Vector, radius: number): CBaseEntity | undefined;
8335+
FindByNameNearest<T extends CBaseEntity = CBaseEntity>(
8336+
name: string,
8337+
location: Vector,
8338+
radius: number,
8339+
): T | undefined;
83228340
/**
83238341
* Find entities by name within a radius. Pass 'null' to start an iteration, or
83248342
* reference to a previously found entity to continue a search.
83258343
*/
8326-
FindByNameWithin(
8344+
FindByNameWithin<T extends CBaseEntity = CBaseEntity>(
83278345
previous: CBaseEntity | undefined,
83288346
name: string,
83298347
location: Vector,
83308348
radius: number,
8331-
): CBaseEntity | undefined;
8349+
): T | undefined;
83328350
/**
83338351
* Find entities by targetname. Pass 'null' to start an iteration, or reference to
83348352
* a previously found entity to continue a search.
83358353
*/
8336-
FindByTarget(previous: CBaseEntity | undefined, target: string): CBaseEntity | undefined;
8354+
FindByTarget<T extends CBaseEntity = CBaseEntity>(previous: CBaseEntity | undefined, target: string): T | undefined;
83378355
/**
83388356
* Find entities within a radius. Pass 'null' to start an iteration, or reference
83398357
* to a previously found entity to continue a search.
83408358
*/
8341-
FindInSphere(previous: CBaseEntity | undefined, location: Vector, radius: number): CBaseEntity | undefined;
8359+
FindInSphere<T extends CBaseEntity = CBaseEntity>(
8360+
previous: CBaseEntity | undefined,
8361+
location: Vector,
8362+
radius: number,
8363+
): T | undefined;
83428364
/**
83438365
* Begin an iteration over the list of entities.
83448366
*
@@ -10195,7 +10217,7 @@ declare function EmitSoundOnLocationWithCaster(location: Vector, soundName: stri
1019510217
*
1019610218
* @both
1019710219
*/
10198-
declare function EntIndexToHScript(entityIndex: EntityIndex): CBaseEntity | undefined;
10220+
declare function EntIndexToHScript<T extends CBaseEntity = CBaseEntity>(entityIndex: EntityIndex): T | undefined;
1019910221

1020010222
/**
1020110223
* Issue an order from a script table.

0 commit comments

Comments
 (0)