diff --git a/build/lua/overrides.ts b/build/lua/overrides.ts index 27a49d6..5e88edf 100644 --- a/build/lua/overrides.ts +++ b/build/lua/overrides.ts @@ -88,8 +88,46 @@ export const overrides: Record = { }, }, }, + + EntIndexToHScript: { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, }; +for (const name of [ + 'FindAllByName', + 'FindAllByNameWithin', + 'FindAllByTarget', + 'FindAllByClassname', + 'FindAllByClassnameWithin', + 'FindAllByModel', + 'FindAllInSphere', +]) { + overrides[`CEntities.${name}`] = { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T[]', + }; +} + +for (const name of [ + 'FindByClassname', + 'FindByClassnameNearest', + 'FindByClassnameWithin', + 'FindByModel', + 'FindByModelWithin', + 'FindByName', + 'FindByNameNearest', + 'FindByNameWithin', + 'FindByTarget', + 'FindInSphere', +]) { + overrides[`CEntities.${name}`] = { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }; +} + for (const name of ['QueueConcept', 'QueueTeamConcept', 'QueueTeamConceptNoSpectators']) { overrides[`CDOTA_BaseNPC.${name}`] = { callback: 'optional', diff --git a/build/lua/utils.ts b/build/lua/utils.ts index 424fe38..c4cff8b 100644 --- a/build/lua/utils.ts +++ b/build/lua/utils.ts @@ -89,6 +89,8 @@ const typePredicates: Record = { 'CDOTA_PlayerResource.IsValidPlayerID': 'playerId is PlayerID', 'CDOTA_PlayerResource.IsValidTeamPlayer': 'playerId is PlayerID', 'CDOTA_PlayerResource.IsValidTeamPlayerID': 'playerId is PlayerID', + 'CBaseEntity.IsPlayerController': 'this is CDOTAPlayerController', + 'CBaseEntity.IsPlayerPawn': 'this is CBasePlayerPawn', 'CDOTABaseAbility.IsItem': 'this is CDOTA_Item', 'ProjectileManager.IsValidProjectile': 'value is ProjectileID', }; diff --git a/packages/dota-lua-types/types/api.generated.d.ts b/packages/dota-lua-types/types/api.generated.d.ts index 918c406..66a2efc 100644 --- a/packages/dota-lua-types/types/api.generated.d.ts +++ b/packages/dota-lua-types/types/api.generated.d.ts @@ -327,11 +327,11 @@ declare interface CBaseEntity extends CEntityInstance { /** * Is this entity a player controller? */ - IsPlayerController(): boolean; + IsPlayerController(): this is CDOTAPlayerController; /** * Is this entity a player pawn? */ - IsPlayerPawn(): boolean; + IsPlayerPawn(): this is CBasePlayerPawn; Kill(): void; NextMovePeer(): CBaseEntity; /** @@ -8250,95 +8250,117 @@ declare interface CEntities { * Finds all entities by class name. Returns an array containing all the found * entities. */ - FindAllByClassname(className: string): CBaseEntity[]; + FindAllByClassname(className: string): T[]; /** * Find entities by class name within a radius. */ - FindAllByClassnameWithin(className: string, location: Vector, radius: number): CBaseEntity[]; + FindAllByClassnameWithin( + className: string, + location: Vector, + radius: number, + ): T[]; /** * Find entities by model name. */ - FindAllByModel(modelName: string): CBaseEntity[]; + FindAllByModel(modelName: string): T[]; /** * Find all entities by name. Returns an array containing all the found entities * in it. */ - FindAllByName(name: string): CBaseEntity[]; + FindAllByName(name: string): T[]; /** * Find entities by name within a radius. */ - FindAllByNameWithin(name: string, location: Vector, radius: number): CBaseEntity[]; + FindAllByNameWithin(name: string, location: Vector, radius: number): T[]; /** * Find entities by targetname. */ - FindAllByTarget(target: string): CBaseEntity[]; + FindAllByTarget(target: string): T[]; /** * Find entities within a radius. */ - FindAllInSphere(location: Vector, radius: number): CBaseEntity[]; + FindAllInSphere(location: Vector, radius: number): T[]; /** * Find entities by class name. Pass 'null' to start an iteration, or reference to * a previously found entity to continue a search. */ - FindByClassname(previous: CBaseEntity | undefined, className: string): CBaseEntity | undefined; + FindByClassname( + previous: CBaseEntity | undefined, + className: string, + ): T | undefined; /** * Find entities by class name nearest to a point. */ - FindByClassnameNearest(className: string, location: Vector, radius: number): CBaseEntity | undefined; + FindByClassnameNearest( + className: string, + location: Vector, + radius: number, + ): T | undefined; /** * Find entities by class name within a radius. Pass 'null' to start an iteration, * or reference to a previously found entity to continue a search. */ - FindByClassnameWithin( + FindByClassnameWithin( previous: CBaseEntity | undefined, className: string, location: Vector, radius: number, - ): CBaseEntity | undefined; + ): T | undefined; /** * Find entities by model name. Pass 'null' to start an iteration, or reference to * a previously found entity to continue a search. */ - FindByModel(previous: CBaseEntity | undefined, modelName: string): CBaseEntity | undefined; + FindByModel( + previous: CBaseEntity | undefined, + modelName: string, + ): T | undefined; /** * Find entities by model name within a radius. Pass 'null' to start an iteration, * or reference to a previously found entity to continue a search. */ - FindByModelWithin( + FindByModelWithin( previous: CBaseEntity | undefined, modelName: string, location: Vector, radius: number, - ): CBaseEntity | undefined; + ): T | undefined; /** * Find entities by name. Pass 'null' to start an iteration, or reference to a * previously found entity to continue a search. */ - FindByName(previous: CBaseEntity | undefined, name: string): CBaseEntity | undefined; + FindByName(previous: CBaseEntity | undefined, name: string): T | undefined; /** * Find entities by name nearest to a point. */ - FindByNameNearest(name: string, location: Vector, radius: number): CBaseEntity | undefined; + FindByNameNearest( + name: string, + location: Vector, + radius: number, + ): T | undefined; /** * Find entities by name within a radius. Pass 'null' to start an iteration, or * reference to a previously found entity to continue a search. */ - FindByNameWithin( + FindByNameWithin( previous: CBaseEntity | undefined, name: string, location: Vector, radius: number, - ): CBaseEntity | undefined; + ): T | undefined; /** * Find entities by targetname. Pass 'null' to start an iteration, or reference to * a previously found entity to continue a search. */ - FindByTarget(previous: CBaseEntity | undefined, target: string): CBaseEntity | undefined; + FindByTarget(previous: CBaseEntity | undefined, target: string): T | undefined; /** * Find entities within a radius. Pass 'null' to start an iteration, or reference * to a previously found entity to continue a search. */ - FindInSphere(previous: CBaseEntity | undefined, location: Vector, radius: number): CBaseEntity | undefined; + FindInSphere( + previous: CBaseEntity | undefined, + location: Vector, + radius: number, + ): T | undefined; /** * Begin an iteration over the list of entities. * @@ -10195,7 +10217,7 @@ declare function EmitSoundOnLocationWithCaster(location: Vector, soundName: stri * * @both */ -declare function EntIndexToHScript(entityIndex: EntityIndex): CBaseEntity | undefined; +declare function EntIndexToHScript(entityIndex: EntityIndex): T | undefined; /** * Issue an order from a script table.