From c14550a4d3792d0feac0f093631c3af111550454 Mon Sep 17 00:00:00 2001 From: RobinCode Date: Mon, 17 Jun 2024 17:03:50 +0800 Subject: [PATCH 1/5] Update lua api --- build/lua/overrides.ts | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/build/lua/overrides.ts b/build/lua/overrides.ts index 27a49d6..e5aecd8 100644 --- a/build/lua/overrides.ts +++ b/build/lua/overrides.ts @@ -88,6 +88,90 @@ export const overrides: Record = { }, }, }, + + 'CBaseEntity.IsPlayerController': { + return: 'this is CDOTAPlayerController', + }, + 'CBaseEntity.IsPlayerPawn': { + return: 'this is CBasePlayerPawn', + }, + CreateItem: { + args: { + purchaser: 'CDOTA_BaseNPC_Hero | undefined', + }, + }, + EntIndexToHScript: { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindAllByName': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T[]', + }, + 'CEntities.FindAllByNameWithin': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T[]', + }, + 'CEntities.FindAllByTarget': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T[]', + }, + 'CEntities.FindAllByClassname': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T[]', + }, + 'CEntities.FindAllByClassnameWithin': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T[]', + }, + 'CEntities.FindAllByModel': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T[]', + }, + 'CEntities.FindAllInSphere': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T[]', + }, + 'CEntities.FindByClassname': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindByClassnameNearest': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindByClassnameWithin': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindByModel': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindByModelWithin': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindByName': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindByNameNearest': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindByNameWithin': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindByTarget': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, + 'CEntities.FindInSphere': { + generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], + return: 'T | undefined', + }, }; for (const name of ['QueueConcept', 'QueueTeamConcept', 'QueueTeamConceptNoSpectators']) { From 68684cfdb21b52869718df0471b542409d96bcf5 Mon Sep 17 00:00:00 2001 From: RobinCode Date: Mon, 17 Jun 2024 17:17:29 +0800 Subject: [PATCH 2/5] Update api.generated.d.ts --- .../dota-lua-types/types/api.generated.d.ts | 70 ++++++++++++------- 1 file changed, 46 insertions(+), 24 deletions(-) diff --git a/packages/dota-lua-types/types/api.generated.d.ts b/packages/dota-lua-types/types/api.generated.d.ts index 918c406..7288b08 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. * @@ -9681,7 +9703,7 @@ declare function CreateIllusions( declare function CreateItem( itemName: string, owner: CDOTAPlayerController | undefined, - purchaser: CDOTAPlayerController | undefined, + purchaser: CDOTA_BaseNPC_Hero | undefined, ): CDOTA_Item | undefined; /** @@ -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. From ba7b305b7b623e12290613ff035e50e45e05f7b5 Mon Sep 17 00:00:00 2001 From: RobinCode Date: Mon, 17 Jun 2024 17:34:46 +0800 Subject: [PATCH 3/5] Change CEntities using for statement --- build/lua/overrides.ts | 95 +++++++++++++----------------------------- 1 file changed, 30 insertions(+), 65 deletions(-) diff --git a/build/lua/overrides.ts b/build/lua/overrides.ts index e5aecd8..d266282 100644 --- a/build/lua/overrides.ts +++ b/build/lua/overrides.ts @@ -104,75 +104,40 @@ export const overrides: Record = { generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], return: 'T | undefined', }, - 'CEntities.FindAllByName': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T[]', - }, - 'CEntities.FindAllByNameWithin': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T[]', - }, - 'CEntities.FindAllByTarget': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T[]', - }, - 'CEntities.FindAllByClassname': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T[]', - }, - 'CEntities.FindAllByClassnameWithin': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T[]', - }, - 'CEntities.FindAllByModel': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T[]', - }, - 'CEntities.FindAllInSphere': { +}; + +for (const name of [ + 'FindAllByName', + 'FindAllByNameWithin', + 'FindAllByTarget', + 'FindAllByClassname', + 'FindAllByClassnameWithin', + 'FindAllByModel', + 'FindAllInSphere', +]) { + overrides[`CEntities.${name}`] = { generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], return: 'T[]', - }, - 'CEntities.FindByClassname': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T | undefined', - }, - 'CEntities.FindByClassnameNearest': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T | undefined', - }, - 'CEntities.FindByClassnameWithin': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T | undefined', - }, - 'CEntities.FindByModel': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T | undefined', - }, - 'CEntities.FindByModelWithin': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T | undefined', - }, - 'CEntities.FindByName': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T | undefined', - }, - 'CEntities.FindByNameNearest': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T | undefined', - }, - 'CEntities.FindByNameWithin': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T | undefined', - }, - 'CEntities.FindByTarget': { - generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], - return: 'T | undefined', - }, - 'CEntities.FindInSphere': { + }; +} + +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}`] = { From 85c8b1cdc3b162cfd6ebcdc0e2b0353d6358099f Mon Sep 17 00:00:00 2001 From: RobinCode Date: Mon, 17 Jun 2024 17:38:56 +0800 Subject: [PATCH 4/5] IsPlayerController move to typePredicates --- build/lua/overrides.ts | 6 ------ build/lua/utils.ts | 2 ++ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/build/lua/overrides.ts b/build/lua/overrides.ts index d266282..ddcd777 100644 --- a/build/lua/overrides.ts +++ b/build/lua/overrides.ts @@ -89,12 +89,6 @@ export const overrides: Record = { }, }, - 'CBaseEntity.IsPlayerController': { - return: 'this is CDOTAPlayerController', - }, - 'CBaseEntity.IsPlayerPawn': { - return: 'this is CBasePlayerPawn', - }, CreateItem: { args: { purchaser: 'CDOTA_BaseNPC_Hero | undefined', 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', }; From 3434beae51df3095a36c47400e18cc7eea8dd16f Mon Sep 17 00:00:00 2001 From: RobinCode Date: Mon, 17 Jun 2024 17:42:40 +0800 Subject: [PATCH 5/5] Remove override CreateItem --- build/lua/overrides.ts | 5 ----- packages/dota-lua-types/types/api.generated.d.ts | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/build/lua/overrides.ts b/build/lua/overrides.ts index ddcd777..5e88edf 100644 --- a/build/lua/overrides.ts +++ b/build/lua/overrides.ts @@ -89,11 +89,6 @@ export const overrides: Record = { }, }, - CreateItem: { - args: { - purchaser: 'CDOTA_BaseNPC_Hero | undefined', - }, - }, EntIndexToHScript: { generics: [{ name: 'T', extend: 'CBaseEntity = CBaseEntity' }], return: 'T | undefined', diff --git a/packages/dota-lua-types/types/api.generated.d.ts b/packages/dota-lua-types/types/api.generated.d.ts index 7288b08..66a2efc 100644 --- a/packages/dota-lua-types/types/api.generated.d.ts +++ b/packages/dota-lua-types/types/api.generated.d.ts @@ -9703,7 +9703,7 @@ declare function CreateIllusions( declare function CreateItem( itemName: string, owner: CDOTAPlayerController | undefined, - purchaser: CDOTA_BaseNPC_Hero | undefined, + purchaser: CDOTAPlayerController | undefined, ): CDOTA_Item | undefined; /**