Compare commits
2 commits
main
...
config_han
Author | SHA1 | Date | |
---|---|---|---|
74fc19c64d | |||
67426165b7 |
4 changed files with 124 additions and 27 deletions
|
@ -2,23 +2,131 @@ package club.clubk.ktag.konfigurator
|
||||||
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
|
const val EDIT_DELAY_TIME: Long = 3L
|
||||||
|
|
||||||
|
sealed class DeviceState {
|
||||||
|
data object Configurable : DeviceState()
|
||||||
|
data object Ready : DeviceState()
|
||||||
|
data object Playing : DeviceState()
|
||||||
|
data object WrapUp : DeviceState()
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class DeviceConfigureState {
|
||||||
|
data object Discovered: DeviceConfigureState()
|
||||||
|
data object Configuring: DeviceConfigureState()
|
||||||
|
data object Success: DeviceConfigureState()
|
||||||
|
data object Failure: DeviceConfigureState()
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class DeviceParameter {
|
||||||
|
PLAYER_ID, TEAM, SECONDARY_COLOR, MAX_HEALTH, SPECIAL_WEAPONS
|
||||||
|
}
|
||||||
|
|
||||||
data class Device(val uuid: UUID = UUID.randomUUID(),
|
data class Device(val uuid: UUID = UUID.randomUUID(),
|
||||||
var name: String = "Unknown Device",
|
var name: String = "Unknown Device",
|
||||||
var address: String = "FF:FF:FF:FF:FF:FF",
|
var address: String = "00:00:00:00:00:00",
|
||||||
var deviceType : Int? = null,
|
var deviceType: UInt? = null,
|
||||||
var team : Int? = null,
|
var deviceState: DeviceState? = null,
|
||||||
var playerID : Int? = null,
|
// All configurable variables
|
||||||
var deviceState: DeviceState? = null
|
private var _playerID: UInt? = null,
|
||||||
|
private var _team: UInt? = null,
|
||||||
|
private var _secondaryColor: UInt? = null,
|
||||||
|
private var _maxHealth: UInt? = null,
|
||||||
|
private var _specialWeapons: UInt? = null
|
||||||
) {
|
) {
|
||||||
|
var deviceConfigureState: DeviceConfigureState = DeviceConfigureState.Discovered
|
||||||
|
private set
|
||||||
|
|
||||||
|
var dirtyPlayerID: Boolean = false
|
||||||
|
private set
|
||||||
|
var dirtyTeam: Boolean = false
|
||||||
|
private set
|
||||||
|
var dirtySecondaryColor: Boolean = false
|
||||||
|
private set
|
||||||
|
var dirtyMaxHealth: Boolean = false
|
||||||
|
private set
|
||||||
|
var dirtySpecialWeapons: Boolean = false
|
||||||
|
private set
|
||||||
|
|
||||||
|
var lastEditTime: Long = 0L
|
||||||
|
private set
|
||||||
|
|
||||||
|
val playerID: UInt? get() = _playerID
|
||||||
|
val team: UInt? get() = _team
|
||||||
|
val secondaryColor: UInt? get() = _secondaryColor
|
||||||
|
val maxHealth: UInt? get() = _maxHealth
|
||||||
|
val specialWeapons: UInt? get() = _specialWeapons
|
||||||
|
|
||||||
fun deviceTypeName(): String {
|
fun deviceTypeName(): String {
|
||||||
return when(deviceType) {
|
return when(deviceType) {
|
||||||
0 -> "Little Boy BLuE"
|
0u -> "Little Boy BLuE"
|
||||||
1 -> "2020TPC"
|
1u -> "2020TPC"
|
||||||
2 -> "Mobile App"
|
2u -> "Mobile App"
|
||||||
3 -> "32ESPecial"
|
3u -> "32ESPecial"
|
||||||
else -> "Unknown Device Type"
|
else -> "Unknown Device Type"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
fun deviceTypeDrawable() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isDirty(): Boolean {
|
||||||
|
return dirtyPlayerID || dirtyTeam || dirtySecondaryColor
|
||||||
|
|| dirtyMaxHealth || dirtySpecialWeapons
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isPastEditTime(): Boolean {
|
||||||
|
return System.nanoTime() - lastEditTime!! >= EDIT_DELAY_TIME
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setParameter(parameter: DeviceParameter, value: Any) {
|
||||||
|
lastEditTime = System.nanoTime()
|
||||||
|
when (parameter) {
|
||||||
|
DeviceParameter.PLAYER_ID -> {
|
||||||
|
_playerID = value as UInt
|
||||||
|
dirtyPlayerID = true
|
||||||
|
}
|
||||||
|
DeviceParameter.TEAM -> {
|
||||||
|
_team = value as UInt
|
||||||
|
dirtyTeam = true
|
||||||
|
}
|
||||||
|
DeviceParameter.SECONDARY_COLOR -> {
|
||||||
|
_secondaryColor = value as UInt
|
||||||
|
dirtySecondaryColor = true
|
||||||
|
}
|
||||||
|
DeviceParameter.MAX_HEALTH -> {
|
||||||
|
_maxHealth = value as UInt
|
||||||
|
dirtyMaxHealth = true
|
||||||
|
}
|
||||||
|
DeviceParameter.SPECIAL_WEAPONS -> {
|
||||||
|
_specialWeapons = value as UInt
|
||||||
|
dirtySpecialWeapons = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun checkForDirt() {
|
||||||
|
if (isDirty() && isPastEditTime()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getDirtyParameters(): List<DeviceParameter> {
|
||||||
|
val changed = mutableListOf<DeviceParameter>()
|
||||||
|
if (dirtyPlayerID) changed.add(DeviceParameter.PLAYER_ID)
|
||||||
|
if (dirtyTeam) changed.add(DeviceParameter.TEAM)
|
||||||
|
if (dirtySecondaryColor) changed.add(DeviceParameter.SECONDARY_COLOR)
|
||||||
|
if (dirtyMaxHealth) changed.add(DeviceParameter.MAX_HEALTH)
|
||||||
|
if (dirtySpecialWeapons) changed.add(DeviceParameter.SPECIAL_WEAPONS)
|
||||||
|
return changed
|
||||||
|
}
|
||||||
|
|
||||||
|
fun clearDirt() {
|
||||||
|
dirtyPlayerID = false
|
||||||
|
dirtyTeam = false
|
||||||
|
dirtySecondaryColor = false
|
||||||
|
dirtyMaxHealth = false
|
||||||
|
dirtySpecialWeapons = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
package club.clubk.ktag.konfigurator
|
|
||||||
|
|
||||||
sealed class DeviceState {
|
|
||||||
object Configurable : DeviceState()
|
|
||||||
object Ready : DeviceState()
|
|
||||||
object Playing : DeviceState()
|
|
||||||
object WrapUp : DeviceState()
|
|
||||||
}
|
|
|
@ -5,5 +5,5 @@ data class GameConfig(var name: String = "Default",
|
||||||
var pregameLength: Int = 60000,
|
var pregameLength: Int = 60000,
|
||||||
var numRounds: Int = 2,
|
var numRounds: Int = 2,
|
||||||
var maxHealth: Int = 10,
|
var maxHealth: Int = 10,
|
||||||
var numBombs: Int = 1 // Special Weapons Received on Game Reentry
|
var specialWeapons: Int = 1 // Special Weapons Received on Game Reentry
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package club.clubk.ktag.konfigurator
|
package club.clubk.ktag.konfigurator
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.bluetooth.BluetoothManager
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
@ -23,7 +21,6 @@ import androidx.core.content.ContextCompat
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
|
@ -253,7 +250,7 @@ fun GameConfigEditor(oldGameConfig: GameConfig,
|
||||||
var pregameLength by rememberSaveable(oldGameConfig.pregameLength) { mutableStateOf(oldGameConfig.pregameLength.toString()) }
|
var pregameLength by rememberSaveable(oldGameConfig.pregameLength) { mutableStateOf(oldGameConfig.pregameLength.toString()) }
|
||||||
var numRounds by rememberSaveable(oldGameConfig.numRounds) { mutableStateOf(oldGameConfig.numRounds.toString()) }
|
var numRounds by rememberSaveable(oldGameConfig.numRounds) { mutableStateOf(oldGameConfig.numRounds.toString()) }
|
||||||
var maxHealth by rememberSaveable(oldGameConfig.maxHealth) { mutableStateOf(oldGameConfig.maxHealth.toString()) }
|
var maxHealth by rememberSaveable(oldGameConfig.maxHealth) { mutableStateOf(oldGameConfig.maxHealth.toString()) }
|
||||||
var numBombs by rememberSaveable(oldGameConfig.numBombs) { mutableStateOf(oldGameConfig.numBombs.toString()) }
|
var numBombs by rememberSaveable(oldGameConfig.specialWeapons) { mutableStateOf(oldGameConfig.specialWeapons.toString()) }
|
||||||
|
|
||||||
// For tracking validation errors
|
// For tracking validation errors
|
||||||
var gameLengthError by rememberSaveable { mutableStateOf(false) }
|
var gameLengthError by rememberSaveable { mutableStateOf(false) }
|
||||||
|
@ -283,7 +280,7 @@ fun GameConfigEditor(oldGameConfig: GameConfig,
|
||||||
pregameLength = pregameLength.toIntOrNull() ?: oldGameConfig.pregameLength,
|
pregameLength = pregameLength.toIntOrNull() ?: oldGameConfig.pregameLength,
|
||||||
numRounds = numRounds.toIntOrNull() ?: oldGameConfig.numRounds,
|
numRounds = numRounds.toIntOrNull() ?: oldGameConfig.numRounds,
|
||||||
maxHealth = maxHealth.toIntOrNull() ?: oldGameConfig.maxHealth,
|
maxHealth = maxHealth.toIntOrNull() ?: oldGameConfig.maxHealth,
|
||||||
numBombs = numBombs.toIntOrNull() ?: oldGameConfig.numBombs
|
specialWeapons = numBombs.toIntOrNull() ?: oldGameConfig.specialWeapons
|
||||||
)
|
)
|
||||||
onSave(newGameConfig)
|
onSave(newGameConfig)
|
||||||
}
|
}
|
||||||
|
@ -479,9 +476,9 @@ fun SideBySideButtons(
|
||||||
@Composable
|
@Composable
|
||||||
fun DeviceCard(stateMachine: StateMachineViewModel, device: Device) {
|
fun DeviceCard(stateMachine: StateMachineViewModel, device: Device) {
|
||||||
val backgroundColor = when (device.team) {
|
val backgroundColor = when (device.team) {
|
||||||
0 -> Color.Magenta
|
0u -> Color.Magenta
|
||||||
1 -> Color.Red
|
1u -> Color.Red
|
||||||
2 -> Color.Blue
|
2u -> Color.Blue
|
||||||
else -> MaterialTheme.colorScheme.surface // Default color
|
else -> MaterialTheme.colorScheme.surface // Default color
|
||||||
}
|
}
|
||||||
Card(modifier = Modifier
|
Card(modifier = Modifier
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue