mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-09-14 22:36:01 -05:00
Add Netplay settings JNI layer and wire up NetplaySetupViewModel
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
// Copyright 2003 Dolphin Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.netplay
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.netplay.model.ConnectionType
|
||||
|
||||
object Netplay {
|
||||
@JvmStatic
|
||||
external fun getNickname(): String
|
||||
|
||||
fun getConnectionType(): ConnectionType = ConnectionType.all
|
||||
.find { it.configValue == getTraversalChoice() } ?: throw IllegalStateException()
|
||||
|
||||
@JvmStatic
|
||||
external fun getTraversalChoice(): String
|
||||
|
||||
@JvmStatic
|
||||
external fun getAddress(): String
|
||||
|
||||
@JvmStatic
|
||||
external fun getHostCode(): String
|
||||
|
||||
@JvmStatic
|
||||
external fun getConnectPort(): Int
|
||||
|
||||
@JvmStatic
|
||||
external fun getHostPort(): Int
|
||||
|
||||
@JvmStatic
|
||||
external fun getUseUpnp(): Boolean
|
||||
|
||||
@JvmStatic
|
||||
external fun getEnableChunkedUploadLimit(): Boolean
|
||||
|
||||
@JvmStatic
|
||||
external fun getChunkedUploadLimit(): Int
|
||||
|
||||
@JvmStatic
|
||||
external fun getUseIndex(): Boolean
|
||||
|
||||
@JvmStatic
|
||||
external fun getIndexRegion(): String
|
||||
|
||||
@JvmStatic
|
||||
external fun getIndexName(): String
|
||||
|
||||
@JvmStatic
|
||||
external fun getIndexPassword(): String
|
||||
|
||||
fun saveSetup(
|
||||
nickname: String,
|
||||
connectionType: ConnectionType,
|
||||
address: String,
|
||||
hostCode: String,
|
||||
connectPort: Int,
|
||||
) {
|
||||
SaveSetup(
|
||||
nickname = nickname,
|
||||
traversalChoice = connectionType.configValue,
|
||||
address = address,
|
||||
hostCode = hostCode,
|
||||
connectPort = connectPort,
|
||||
hostPort = 2626,
|
||||
useUpnp = false,
|
||||
useListenPort = false,
|
||||
listenPort = 2626,
|
||||
enableChunkedUploadLimit = false,
|
||||
chunkedUploadLimit = 3000,
|
||||
useIndex = false,
|
||||
indexRegion = "",
|
||||
indexName = "",
|
||||
indexPassword = "",
|
||||
)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
external fun SaveSetup(
|
||||
nickname: String,
|
||||
traversalChoice: String,
|
||||
address: String,
|
||||
hostCode: String,
|
||||
connectPort: Int,
|
||||
hostPort: Int,
|
||||
useUpnp: Boolean,
|
||||
useListenPort: Boolean,
|
||||
listenPort: Int,
|
||||
enableChunkedUploadLimit: Boolean,
|
||||
chunkedUploadLimit: Int,
|
||||
useIndex: Boolean,
|
||||
indexRegion: String,
|
||||
indexName: String,
|
||||
indexPassword: String,
|
||||
)
|
||||
|
||||
}
|
||||
@@ -5,13 +5,16 @@ import org.dolphinemu.dolphinemu.R
|
||||
|
||||
sealed class ConnectionType(
|
||||
@StringRes val labelId: Int,
|
||||
val configValue: String,
|
||||
) {
|
||||
object DirectConnection : ConnectionType(
|
||||
labelId = R.string.netplay_connection_type_direct_connection,
|
||||
configValue = "direct",
|
||||
)
|
||||
|
||||
object TraversalServer : ConnectionType(
|
||||
labelId = R.string.netplay_connection_type_traversal_server,
|
||||
configValue = "traversal",
|
||||
)
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -5,24 +5,25 @@ package org.dolphinemu.dolphinemu.features.netplay.model
|
||||
import androidx.lifecycle.ViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import org.dolphinemu.dolphinemu.features.netplay.Netplay
|
||||
|
||||
class NetplaySetupViewModel : ViewModel() {
|
||||
private val _connectionRole = MutableStateFlow<ConnectionRole>(ConnectionRole.Connect)
|
||||
val connectionRole = _connectionRole.asStateFlow()
|
||||
|
||||
private val _nickname = MutableStateFlow("")
|
||||
private val _nickname = MutableStateFlow(Netplay.getNickname())
|
||||
val nickname = _nickname.asStateFlow()
|
||||
|
||||
private val _connectionType = MutableStateFlow<ConnectionType>(ConnectionType.DirectConnection)
|
||||
private val _connectionType = MutableStateFlow(Netplay.getConnectionType())
|
||||
val connectionType = _connectionType.asStateFlow()
|
||||
|
||||
private val _ipAddress = MutableStateFlow("")
|
||||
private val _ipAddress = MutableStateFlow(Netplay.getAddress())
|
||||
val ipAddress = _ipAddress.asStateFlow()
|
||||
|
||||
private val _hostCode = MutableStateFlow("")
|
||||
private val _hostCode = MutableStateFlow(Netplay.getHostCode())
|
||||
val hostCode = _hostCode.asStateFlow()
|
||||
|
||||
private val _connectPort = MutableStateFlow(0.toString())
|
||||
private val _connectPort = MutableStateFlow(Netplay.getConnectPort().toString())
|
||||
val connectPort = _connectPort.asStateFlow()
|
||||
|
||||
fun setConnectionRole(connectionRole: ConnectionRole) {
|
||||
@@ -54,5 +55,12 @@ class NetplaySetupViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun connect() {
|
||||
Netplay.saveSetup(
|
||||
nickname = nickname.value,
|
||||
connectionType = connectionType.value,
|
||||
address = ipAddress.value,
|
||||
hostCode = hostCode.value,
|
||||
connectPort = connectPort.value.toInt(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user