godot.registration.Registration.kt Maven / Gradle / Ivy
Show all versions of godot-library-release Show documentation
package godot.registration
import godot.core.KtClass
import godot.core.KtConstructor
import godot.core.KtEnumListProperty
import godot.core.KtEnumProperty
import godot.core.KtFunction
import godot.core.KtFunction0
import godot.core.KtFunction1
import godot.core.KtFunction10
import godot.core.KtFunction11
import godot.core.KtFunction12
import godot.core.KtFunction13
import godot.core.KtFunction14
import godot.core.KtFunction15
import godot.core.KtFunction16
import godot.core.KtFunction2
import godot.core.KtFunction3
import godot.core.KtFunction4
import godot.core.KtFunction5
import godot.core.KtFunction6
import godot.core.KtFunction7
import godot.core.KtFunction8
import godot.core.KtFunction9
import godot.core.KtFunctionInfo
import godot.core.KtObject
import godot.core.KtProperty
import godot.core.KtPropertyInfo
import godot.core.KtRpcConfig
import godot.core.KtSignalInfo
import godot.core.PropertyHint
import godot.core.TypeManager
import godot.core.VariantType
import godot.core.toVariantArray
import godot.core.variantArrayOf
import godot.tools.common.constants.Constraints
import godot.util.camelToSnakeCase
import kotlin.reflect.KClass
import kotlin.reflect.KFunction1
import kotlin.reflect.KFunction10
import kotlin.reflect.KFunction11
import kotlin.reflect.KFunction12
import kotlin.reflect.KFunction13
import kotlin.reflect.KFunction14
import kotlin.reflect.KFunction15
import kotlin.reflect.KFunction16
import kotlin.reflect.KFunction17
import kotlin.reflect.KFunction2
import kotlin.reflect.KFunction3
import kotlin.reflect.KFunction4
import kotlin.reflect.KFunction5
import kotlin.reflect.KFunction6
import kotlin.reflect.KFunction7
import kotlin.reflect.KFunction8
import kotlin.reflect.KFunction9
import kotlin.reflect.KMutableProperty1
import kotlin.reflect.KProperty
data class KtFunctionArgument(
val type: VariantType,
val className: String,
val name: String = "" //empty for return type
) {
internal fun toKtPropertyInfo() = KtPropertyInfo(
type,
name,
className,
PropertyHint.NONE,
"", //always empty. Only used for properties
true, //always true. Only used for properties
)
}
class ClassBuilderDsl(
@PublishedApi internal val registeredName: String,
private val relativeSourcePath: String,
private val compilationTimeRelativeRegistrationFilePath: String,
private val superClasses: List,
private val baseGodotClass: String
) {
private val constructors = mutableMapOf>()
private val functions = mutableMapOf>()
private var notificationFunctions = listOf Unit>()
@PublishedApi
internal val properties = mutableMapOf>()
private val signals = mutableMapOf()
fun constructor(constructor: KtConstructor) {
require(!constructors.containsKey(constructor.parameterCount)) {
"A constructor with ${constructor.parameterCount} argument(s) already exists."
}
require(constructor.parameterCount <= Constraints.MAX_CONSTRUCTOR_ARG_COUNT) {
"Cannot register a constructor with ${constructor.parameterCount} arguments, max argument count is ${Constraints.MAX_CONSTRUCTOR_ARG_COUNT}"
}
constructors[constructor.parameterCount] = constructor
}
fun property(
kProperty: KMutableProperty1,
variantType: VariantType,
type: VariantType,
className: String,
hint: PropertyHint = PropertyHint.NONE,
hintString: String = "",
visibleInEditor: Boolean = true,
isRef: Boolean = false
) {
val propertyName = kProperty.name.camelToSnakeCase()
require(!properties.contains(propertyName)) {
"Found two properties with name $propertyName for class $registeredName"
}
properties[propertyName] = KtProperty(
KtPropertyInfo(
type,
propertyName,
className,
hint,
hintString,
visibleInEditor,
),
kProperty,
variantType,
isRef
)
}
inline fun > enumProperty(
kProperty: KMutableProperty1,
visibleInEditor: Boolean,
hintString: String
) {
val propertyName = kProperty.name.camelToSnakeCase()
require(!properties.contains(propertyName)) {
"Found two properties with name $propertyName for class $registeredName"
}
properties[propertyName] = KtEnumProperty(
KtPropertyInfo(
VariantType.LONG,
propertyName,
"Int",
PropertyHint.ENUM,
hintString,
visibleInEditor,
),
kProperty,
{ enum: P? -> enum?.ordinal ?: 1 },
{ i -> enumValues()[i] }
)
}
inline fun , L : Collection> enumListProperty(
kProperty: KMutableProperty1,
visibleInEditor: Boolean,
hintString: String
) {
val propertyName = kProperty.name.camelToSnakeCase()
require(!properties.contains(propertyName)) {
"Found two properties with name $propertyName for class $registeredName"
}
properties[propertyName] = KtEnumListProperty(
KtPropertyInfo(
VariantType.ARRAY,
propertyName,
"Int",
PropertyHint.ENUM,
hintString,
visibleInEditor,
),
kProperty,
{ enumList: Collection? ->
enumList
?.map { it.ordinal }
?.toVariantArray()
?: variantArrayOf()
},
{ enumOrdinalVariantArray ->
@Suppress("UNCHECKED_CAST")
enumOrdinalVariantArray.map { enumValues
()[it] } as L
}
)
}
@JvmName("enumFlagPropertyMutable")
@Suppress("UNCHECKED_CAST")
inline fun > enumFlagProperty(
kProperty: KMutableProperty1>,
visibleInEditor: Boolean,
hintString: String
) = enumFlagProperty(
kProperty as KMutableProperty1>,
visibleInEditor,
hintString
)
inline fun > enumFlagProperty(
kProperty: KMutableProperty1>,
visibleInEditor: Boolean,
hintString: String
) {
val propertyName = kProperty.name.camelToSnakeCase()
require(!properties.contains(propertyName)) {
"Found two properties with name $propertyName for class $registeredName"
}
properties[propertyName] = KtEnumProperty(
KtPropertyInfo(
VariantType.LONG,
propertyName,
"Int",
PropertyHint.FLAGS,
hintString,
visibleInEditor,
),
kProperty,
{ enumSet ->
var intFlag = 0
enumSet?.forEach { enum ->
intFlag += 1 shl enum.ordinal
}
intFlag
},
{ value ->
val intFlag = (value as P).ordinal
val enums = mutableSetOf()
var bit = 1
for (i in 0 until Int.SIZE_BITS) {
if ((intFlag and bit) > 0) {
val element = enumValues
().firstOrNull { it.ordinal == i }
if (element != null) {
enums.add(element)
}
}
bit = bit shl 1
if (bit > intFlag) break
}
enums
}
)
}
/**
* Notification functions of class hierarchy
*
* Order: child to parent
*
* Only present if the notification function is registered and is overriding [KtObject._notification].
*
* **Note:** Manually declared functions with name `_notification` are not supposed to be added to this list even if
* the return type and parameters match!
*/
fun notificationFunctions(
notificationFunctionsOfClassHierarchy: List Unit>
) {
notificationFunctions = notificationFunctionsOfClassHierarchy
}
fun function(
func: KFunction1,
variantType: VariantType,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction0(
KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(),
returnVal = KtPropertyInfo(
_type = returnType.type,
name = "",
className = returnType.className,
_hint = PropertyHint.NONE,
hintString = "",
visibleInEditor = true, // always true. Only used for properties
),
rpcConfig = rpcConfig
),
func,
variantType
)
)
}
fun function(
func: KFunction2,
variantType: VariantType,
p0Type: Pair,
p0: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction1(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type
)
)
}
fun function(
func: KFunction3,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction2(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type
)
)
}
fun function(
func: KFunction4,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction3(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type
)
)
}
fun function(
func: KFunction5,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction4(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type
)
)
}
fun function(
func: KFunction6,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction5(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type
)
)
}
fun function(
func: KFunction7,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction6(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
)
)
}
fun function(
func: KFunction8,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction7(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
)
)
}
fun function(
func: KFunction9,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
p7: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction8(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
p7.toKtPropertyInfo(),
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
p7Type = p7Type,
)
)
}
fun function(
func: KFunction10,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
p8Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
p7: KtFunctionArgument,
p8: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction9(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
p7.toKtPropertyInfo(),
p8.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
p7Type = p7Type,
p8Type = p8Type
)
)
}
fun function(
func: KFunction11,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
p8Type: Pair,
p9Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
p7: KtFunctionArgument,
p8: KtFunctionArgument,
p9: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction10(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
p7.toKtPropertyInfo(),
p8.toKtPropertyInfo(),
p9.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
p7Type = p7Type,
p8Type = p8Type,
p9Type = p9Type
)
)
}
fun function(
func: KFunction12,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
p8Type: Pair,
p9Type: Pair,
p10Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
p7: KtFunctionArgument,
p8: KtFunctionArgument,
p9: KtFunctionArgument,
p10: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction11(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
p7.toKtPropertyInfo(),
p8.toKtPropertyInfo(),
p9.toKtPropertyInfo(),
p10.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
p7Type = p7Type,
p8Type = p8Type,
p9Type = p9Type,
p10Type = p10Type
)
)
}
fun function(
func: KFunction13,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
p8Type: Pair,
p9Type: Pair,
p10Type: Pair,
p11Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
p7: KtFunctionArgument,
p8: KtFunctionArgument,
p9: KtFunctionArgument,
p10: KtFunctionArgument,
p11: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction12(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
p7.toKtPropertyInfo(),
p8.toKtPropertyInfo(),
p9.toKtPropertyInfo(),
p10.toKtPropertyInfo(),
p11.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
p7Type = p7Type,
p8Type = p8Type,
p9Type = p9Type,
p10Type = p10Type,
p11Type = p11Type
)
)
}
fun function(
func: KFunction14,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
p8Type: Pair,
p9Type: Pair,
p10Type: Pair,
p11Type: Pair,
p12Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
p7: KtFunctionArgument,
p8: KtFunctionArgument,
p9: KtFunctionArgument,
p10: KtFunctionArgument,
p11: KtFunctionArgument,
p12: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction13(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
p7.toKtPropertyInfo(),
p8.toKtPropertyInfo(),
p9.toKtPropertyInfo(),
p10.toKtPropertyInfo(),
p11.toKtPropertyInfo(),
p12.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
p7Type = p7Type,
p8Type = p8Type,
p9Type = p9Type,
p10Type = p10Type,
p11Type = p11Type,
p12Type = p12Type
)
)
}
fun function(
func: KFunction15,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
p8Type: Pair,
p9Type: Pair,
p10Type: Pair,
p11Type: Pair,
p12Type: Pair,
p13Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
p7: KtFunctionArgument,
p8: KtFunctionArgument,
p9: KtFunctionArgument,
p10: KtFunctionArgument,
p11: KtFunctionArgument,
p12: KtFunctionArgument,
p13: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction14(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
p7.toKtPropertyInfo(),
p8.toKtPropertyInfo(),
p9.toKtPropertyInfo(),
p10.toKtPropertyInfo(),
p11.toKtPropertyInfo(),
p12.toKtPropertyInfo(),
p13.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
p7Type = p7Type,
p8Type = p8Type,
p9Type = p9Type,
p10Type = p10Type,
p11Type = p11Type,
p12Type = p12Type,
p13Type = p13Type
)
)
}
fun function(
func: KFunction16,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
p8Type: Pair,
p9Type: Pair,
p10Type: Pair,
p11Type: Pair,
p12Type: Pair,
p13Type: Pair,
p14Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
p7: KtFunctionArgument,
p8: KtFunctionArgument,
p9: KtFunctionArgument,
p10: KtFunctionArgument,
p11: KtFunctionArgument,
p12: KtFunctionArgument,
p13: KtFunctionArgument,
p14: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction15(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
p7.toKtPropertyInfo(),
p8.toKtPropertyInfo(),
p9.toKtPropertyInfo(),
p10.toKtPropertyInfo(),
p11.toKtPropertyInfo(),
p12.toKtPropertyInfo(),
p13.toKtPropertyInfo(),
p14.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
p7Type = p7Type,
p8Type = p8Type,
p9Type = p9Type,
p10Type = p10Type,
p11Type = p11Type,
p12Type = p12Type,
p13Type = p13Type,
p14Type = p14Type
)
)
}
fun function(
func: KFunction17,
variantType: VariantType,
p0Type: Pair,
p1Type: Pair,
p2Type: Pair,
p3Type: Pair,
p4Type: Pair,
p5Type: Pair,
p6Type: Pair,
p7Type: Pair,
p8Type: Pair,
p9Type: Pair,
p10Type: Pair,
p11Type: Pair,
p12Type: Pair,
p13Type: Pair,
p14Type: Pair,
p15Type: Pair,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument,
p5: KtFunctionArgument,
p6: KtFunctionArgument,
p7: KtFunctionArgument,
p8: KtFunctionArgument,
p9: KtFunctionArgument,
p10: KtFunctionArgument,
p11: KtFunctionArgument,
p12: KtFunctionArgument,
p13: KtFunctionArgument,
p14: KtFunctionArgument,
p15: KtFunctionArgument,
returnType: KtFunctionArgument,
rpcConfig: KtRpcConfig
) {
appendFunction(
KtFunction16(
functionInfo = KtFunctionInfo(
name = func.name.camelToSnakeCase(),
_arguments = listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo(),
p5.toKtPropertyInfo(),
p6.toKtPropertyInfo(),
p7.toKtPropertyInfo(),
p8.toKtPropertyInfo(),
p9.toKtPropertyInfo(),
p10.toKtPropertyInfo(),
p11.toKtPropertyInfo(),
p12.toKtPropertyInfo(),
p13.toKtPropertyInfo(),
p14.toKtPropertyInfo(),
p15.toKtPropertyInfo()
),
returnVal = returnType.toKtPropertyInfo(),
rpcConfig = rpcConfig
),
function = func,
variantType = variantType,
p0Type = p0Type,
p1Type = p1Type,
p2Type = p2Type,
p3Type = p3Type,
p4Type = p4Type,
p5Type = p5Type,
p6Type = p6Type,
p7Type = p7Type,
p8Type = p8Type,
p9Type = p9Type,
p10Type = p10Type,
p11Type = p11Type,
p12Type = p12Type,
p13Type = p13Type,
p14Type = p14Type,
p15Type = p15Type
)
)
}
fun signal(kProperty: KProperty) {
appendSignal(
KtSignalInfo(kProperty.name.camelToSnakeCase(), listOf())
)
}
fun signal(
kProperty: KProperty,
p0: KtFunctionArgument
) {
appendSignal(
KtSignalInfo(
kProperty.name.camelToSnakeCase(),
listOf(
p0.toKtPropertyInfo()
)
)
)
}
fun signal(
kProperty: KProperty,
p0: KtFunctionArgument,
p1: KtFunctionArgument
) {
appendSignal(
KtSignalInfo(
kProperty.name.camelToSnakeCase(),
listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo()
)
)
)
}
fun signal(
kProperty: KProperty,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument
) {
appendSignal(
KtSignalInfo(
kProperty.name.camelToSnakeCase(),
listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo()
)
)
)
}
fun signal(
kProperty: KProperty,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument
) {
appendSignal(
KtSignalInfo(
kProperty.name.camelToSnakeCase(),
listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo()
)
)
)
}
fun signal(
kProperty: KProperty,
p0: KtFunctionArgument,
p1: KtFunctionArgument,
p2: KtFunctionArgument,
p3: KtFunctionArgument,
p4: KtFunctionArgument
) {
appendSignal(
KtSignalInfo(
kProperty.name.camelToSnakeCase(),
listOf(
p0.toKtPropertyInfo(),
p1.toKtPropertyInfo(),
p2.toKtPropertyInfo(),
p3.toKtPropertyInfo(),
p4.toKtPropertyInfo()
)
)
)
}
private fun appendFunction(function: KtFunction) {
require(!functions.containsKey(function.functionInfo.name)) {
"A method with ${function.functionInfo.name} already exists."
}
functions[function.functionInfo.name] = function
}
@PublishedApi
internal fun appendSignal(signalInfo: KtSignalInfo) {
require(!signals.containsKey(signalInfo.name)) {
"A signal with ${signalInfo.name} already exists."
}
signals[signalInfo.name] = signalInfo
}
internal fun build(): KtClass {
check(constructors.isNotEmpty()) { "Please provide at least one constructor." }
// Constraints.MAX_CONSTRUCTOR_ARG_COUNT + 1 because we have no arg constructor.
val constructorArray = arrayOfNulls>(Constraints.MAX_CONSTRUCTOR_ARG_COUNT + 1)
constructors.forEach {
constructorArray[it.key] = it.value
}
return KtClass(
registeredName = registeredName,
relativeSourcePath = relativeSourcePath,
compilationTimeRelativeRegistrationFilePath = compilationTimeRelativeRegistrationFilePath,
_registeredSupertypes = superClasses,
_constructors = constructorArray.toList(),
_properties = properties,
_functions = functions,
_notificationFunctions = notificationFunctions,
_signalInfos = signals,
baseGodotClass = baseGodotClass
)
}
}
class ClassRegistry(
private val projectName: String,
private val isDependency: Boolean,
) {
private val _classes = mutableListOf>()
val classes: List> = _classes
fun registerClass(
superClass: List,
kClass: KClass,
isTool: Boolean = false,
baseGodotClass: String,
registeredName: String,
relativeSourcePath: String,
compilationTimeRelativeRegistrationFilePath: String,
cb: ClassBuilderDsl.() -> Unit
) {
val builder = ClassBuilderDsl(registeredName, relativeSourcePath, compilationTimeRelativeRegistrationFilePath, superClass, baseGodotClass)
builder.cb()
TypeManager.registerUserType(registeredName, kClass)
registerClass(builder.build())
}
private fun registerClass(cls: KtClass) {
_classes.add(cls)
}
}
interface ClassRegistrar {
fun register(registry: ClassRegistry)
}