itb-community / ITB-ModLoader

A lua-based mod loader for the game Into the Breach
48 stars 18 forks source link

Add functions to check userdata type #209

Closed Lemonymous closed 1 year ago

Lemonymous commented 1 year ago

Adds functions to several userdata objects, to make it possible to check what kind of userdata object they are. The intended use is to always call the global GetUserdataType function, instead of calling the various userdata objects' GetUserdataType functions; since a userdata object is not guaranteed to have a GetUserdataType function defined.

This PR will allow #205 to distinguish between SpaceDamage and SkillEffect objects in order to dispatch the appropriate events.

This might not be an exhaustive list of userdata types, so feel free to add to the list.

userdata

This page describes helper functions for userdata objects that have been added as part of modding API.

 

 

GetUserdataType

Argument name Type Description
userdata userdata The userdata object we want to query

returns a string of the userdata type of the specified userdata, or "Unknown", if the userdata does not have a GetUserdataType function.

 

modApi.isUserdataClass

Argument name Type Description
userdata userdata The userdata object we want to query

returns true if the userdata object is a class, otherwise, false.

 

modApi.isUserdataInstance

Argument name Type Description
userdata userdata The userdata object we want to query

returns true if the userdata object is an instance of a class, otherwise, false.

 

Game:GetUserdataType

returns "Game"

 

Board:GetUserdataType

returns "Board"

 

Pawn:GetUserdataType

returns "Pawn"

 

PAWN_FACTORY:GetUserdataType

returns "PAWN_FACTORY"

 

Point:GetUserdataType

returns "Point" if it is a class instance, or "PointClass" if it is the Point class itself.

 

SkillEffect:GetUserdataType

returns "SkillEffect" if it is a class instance, or "SkillEffectClass" if it is the SkillEffect class itself.

 

SpaceDamage:GetUserdataType

returns "SpaceDamage" if it is a class instance, or "SpaceDamageClass" if it is the SpaceDamage class itself.

 

tos-x commented 1 year ago

Copy/paste error, very last entry in the documentation should be: or "SpaceDamageClass" if it is the SpaceDamage class itself.

Lemonymous commented 1 year ago

Well spotted! Thank you!