Skip to content

Commit

Permalink
Remove redundant RPCMode enum and change RPCMode enum generation …
Browse files Browse the repository at this point in the history
…to drop `RPC_MODE_` prefix (#222)
  • Loading branch information
chippmann committed Aug 10, 2020
1 parent 674ef46 commit c756676
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 30 deletions.
3 changes: 2 additions & 1 deletion buildSrc/src/main/kotlin/godot/codegen/Enum.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class Enum @JsonCreator constructor(
)
enumBuilder.addProperty("id", Long::class)
values.forEach { (key, value) ->
val valueName = if (name == "RPCMode") key.removePrefix("RPC_MODE_") else key
enumBuilder.addEnumConstant(
key, TypeSpec.anonymousClassBuilder()
valueName, TypeSpec.anonymousClassBuilder()
.addSuperclassConstructorParameter("%L", value)
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object FunctionRegistrationGenerator {
.getAnnotationValue(
REGISTER_FUNCTION_ANNOTATION,
REGISTER_FUNCTION_ANNOTATION_RPC_MODE_ARGUMENT,
Pair(ClassId(FqName("godot.registration"), Name.identifier("RPCMode")), Name.identifier("DISABLED"))
Pair(ClassId(FqName("godot.MultiplayerAPI"), Name.identifier("RPCMode")), Name.identifier("DISABLED"))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ object PropertyRegistrationGenerator {
.getAnnotationValue(
REGISTER_PROPERTY_ANNOTATION,
REGISTER_PROPERTY_ANNOTATION_RPC_MODE_ARGUMENT,
Pair(ClassId(FqName("godot.registration"), Name.identifier("RPCMode")), Name.identifier("DISABLED"))
Pair(ClassId(FqName("godot.MultiplayerAPI"), Name.identifier("RPCMode")), Name.identifier("DISABLED"))
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ object RpcModeAnnotationMapper {
*/
fun mapRpcModeAnnotationToClassName(rpcModeAnnotationAsString: String): ClassName {
return when (rpcModeAnnotationAsString) {
"godot.registration.RPCMode.DISABLED" -> ClassName("godot.registration.RPCMode", "DISABLED")
"godot.registration.RPCMode.REMOTE" -> ClassName("godot.registration.RPCMode", "REMOTE")
"godot.registration.RPCMode.MASTER" -> ClassName("godot.registration.RPCMode", "MASTER")
"godot.registration.RPCMode.PUPPET" -> ClassName("godot.registration.RPCMode", "PUPPET")
"godot.registration.RPCMode.REMOTE_SYNC" -> ClassName("godot.registration.RPCMode", "REMOTE_SYNC")
"godot.registration.RPCMode.MASTER_SYNC" -> ClassName("godot.registration.RPCMode", "MASTER_SYNC")
"godot.registration.RPCMode.PUPPET_SYNC" -> ClassName("godot.registration.RPCMode", "PUPPET_SYNC")
"godot.MultiplayerAPI.RPCMode.DISABLED" -> ClassName("godot.MultiplayerAPI.RPCMode", "DISABLED")
"godot.MultiplayerAPI.RPCMode.REMOTE" -> ClassName("godot.MultiplayerAPI.RPCMode", "REMOTE")
"godot.MultiplayerAPI.RPCMode.MASTER" -> ClassName("godot.MultiplayerAPI.RPCMode", "MASTER")
"godot.MultiplayerAPI.RPCMode.PUPPET" -> ClassName("godot.MultiplayerAPI.RPCMode", "PUPPET")
"godot.MultiplayerAPI.RPCMode.REMOTESYNC" -> ClassName("godot.MultiplayerAPI.RPCMode", "REMOTESYNC")
"godot.MultiplayerAPI.RPCMode.MASTERSYNC" -> ClassName("godot.MultiplayerAPI.RPCMode", "MASTERSYNC")
"godot.MultiplayerAPI.RPCMode.PUPPETSYNC" -> ClassName("godot.MultiplayerAPI.RPCMode", "PUPPETSYNC")
"godot.MultiplayerAPI.RPCMode.SLAVE" -> ClassName("godot.MultiplayerAPI.RPCMode", "SLAVE")
"godot.MultiplayerAPI.RPCMode.SYNC" -> ClassName("godot.MultiplayerAPI.RPCMode", "SYNC")
else -> throw IllegalArgumentException("Unknown annotation or registration $rpcModeAnnotationAsString")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package godot.core

import godot.MultiplayerAPI.RPCMode
import godot.Object
import godot.gdnative.*
import godot.internal.type.nullSafe
import godot.registration.RPCMode
import kotlinx.cinterop.*

@PublishedApi
Expand Down Expand Up @@ -78,9 +78,11 @@ internal class ClassHandle<T : Object>(
RPCMode.REMOTE -> GODOT_METHOD_RPC_MODE_REMOTE
RPCMode.MASTER -> GODOT_METHOD_RPC_MODE_MASTER
RPCMode.PUPPET -> GODOT_METHOD_RPC_MODE_PUPPET
RPCMode.REMOTE_SYNC -> GODOT_METHOD_RPC_MODE_REMOTESYNC
RPCMode.MASTER_SYNC -> GODOT_METHOD_RPC_MODE_MASTERSYNC
RPCMode.PUPPET_SYNC -> GODOT_METHOD_RPC_MODE_PUPPETSYNC
RPCMode.REMOTESYNC -> GODOT_METHOD_RPC_MODE_REMOTESYNC
RPCMode.MASTERSYNC -> GODOT_METHOD_RPC_MODE_MASTERSYNC
RPCMode.PUPPETSYNC -> GODOT_METHOD_RPC_MODE_PUPPETSYNC
RPCMode.SLAVE -> throw IllegalArgumentException("RPCMode.SLAVE is deprecated in godot! Use RPCMode.PUPPET instead")
RPCMode.SYNC -> throw IllegalArgumentException("RPCMode.SYNC is deprecated in godot! Use one of the other sync enums instead")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

package godot.core

import godot.MultiplayerAPI.RPCMode
import godot.Object
import godot.gdnative.godot_property_hint
import godot.internal.type.toNaturalT
import godot.registration.RPCMode
import kotlinx.cinterop.StableRef
import kotlin.reflect.KMutableProperty1

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package godot.annotation

import godot.registration.RPCMode
import godot.MultiplayerAPI.RPCMode

/*
If a change is made to a annotation name or the package path has changed,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package example

import godot.Curve
import godot.MultiplayerAPI.RPCMode
import godot.Node
import godot.Texture
import godot.annotation.*
import godot.core.*
import godot.registration.RPCMode
import godot.registration.Range

const val FLAG_1 = 1
Expand Down Expand Up @@ -55,7 +55,7 @@ class TestingClass : Node() {

}

@RegisterFunction(RPCMode.PUPPET_SYNC)
@RegisterFunction(RPCMode.PUPPETSYNC)
fun foo() = 1

@RegisterProperty
Expand Down

0 comments on commit c756676

Please sign in to comment.