Reorder netplay class
Put all the boring settings at the bottom to reduce scrolling!
This commit is contained in:
1 parent
b72f3c1afc
commit
af2fda5649
1 file changed
+51
-47
+51
-47
@@ -27,9 +27,60 @@ object Netplay {
|
|||||||
private val _connectionErrors = Channel<String>(Channel.BUFFERED)
|
private val _connectionErrors = Channel<String>(Channel.BUFFERED)
|
||||||
val connectionErrors = _connectionErrors.receiveAsFlow()
|
val connectionErrors = _connectionErrors.receiveAsFlow()
|
||||||
|
|
||||||
|
suspend fun join(): Boolean = withContext(Dispatchers.IO) {
|
||||||
|
netPlayClientPointer = Join()
|
||||||
|
val isConnected = netPlayClientPointer != 0L && isClientConnected()
|
||||||
|
|
||||||
|
if (!isActive) {
|
||||||
|
releaseNetplayClient()
|
||||||
|
return@withContext false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isConnected) {
|
||||||
|
return@withContext true
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseNetplayClient()
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun quit() = withContext(Dispatchers.IO) {
|
||||||
|
releaseNetplayClient()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun releaseNetplayClient() {
|
||||||
|
if (netPlayClientPointer != 0L) {
|
||||||
|
ReleaseNetplayClient()
|
||||||
|
netPlayClientPointer = 0
|
||||||
|
}
|
||||||
|
_launchGame.flush()
|
||||||
|
_connectionErrors.flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
private external fun Join(): Long
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
external fun isClientConnected(): Boolean
|
external fun isClientConnected(): Boolean
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
private external fun ReleaseNetplayClient()
|
||||||
|
|
||||||
|
// NetPlayUI callbacks
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun onBootGame(gameFilePath: String, bootSessionDataPointer: Long) {
|
||||||
|
this.bootSessionDataPointer = bootSessionDataPointer
|
||||||
|
_launchGame.trySend(gameFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun onConnectionError(message: String) {
|
||||||
|
_connectionErrors.trySend(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
external fun getNickname(): String
|
external fun getNickname(): String
|
||||||
|
|
||||||
@@ -116,53 +167,6 @@ object Netplay {
|
|||||||
indexName: String,
|
indexName: String,
|
||||||
indexPassword: String,
|
indexPassword: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
suspend fun join(): Boolean = withContext(Dispatchers.IO) {
|
|
||||||
netPlayClientPointer = Join()
|
|
||||||
val isConnected = netPlayClientPointer != 0L && isClientConnected()
|
|
||||||
|
|
||||||
if (!isActive) {
|
|
||||||
releaseNetplayClient()
|
|
||||||
return@withContext false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isConnected) {
|
|
||||||
return@withContext true
|
|
||||||
}
|
|
||||||
|
|
||||||
releaseNetplayClient()
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun quit() = withContext(Dispatchers.IO) {
|
|
||||||
releaseNetplayClient()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun releaseNetplayClient() {
|
|
||||||
if (netPlayClientPointer != 0L) {
|
|
||||||
ReleaseNetplayClient()
|
|
||||||
netPlayClientPointer = 0
|
|
||||||
}
|
|
||||||
_launchGame.flush()
|
|
||||||
_connectionErrors.flush()
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
private external fun Join(): Long
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
private external fun ReleaseNetplayClient()
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun onBootGame(gameFilePath: String, bootSessionDataPointer: Long) {
|
|
||||||
this.bootSessionDataPointer = bootSessionDataPointer
|
|
||||||
_launchGame.trySend(gameFilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
fun onConnectionError(message: String) {
|
|
||||||
_connectionErrors.trySend(message)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Channel<String>.flush() {
|
private fun Channel<String>.flush() {
|
||||||
|
|||||||
Reference in new issue
Block a user