summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/input/model/PlayerInput.kt
blob: d35de80c4758870435a054fed74f0024d1becec5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-FileCopyrightText: 2024 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

package org.yuzu.yuzu_emu.features.input.model

import androidx.annotation.Keep

@Keep
data class PlayerInput(
    var connected: Boolean,
    var buttons: Array<String>,
    var analogs: Array<String>,
    var motions: Array<String>,

    var vibrationEnabled: Boolean,
    var vibrationStrength: Int,

    var bodyColorLeft: Long,
    var bodyColorRight: Long,
    var buttonColorLeft: Long,
    var buttonColorRight: Long,
    var profileName: String,

    var useSystemVibrator: Boolean
) {
    // It's recommended to use the generated equals() and hashCode() methods
    // when using arrays in a data class
    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as PlayerInput

        if (connected != other.connected) return false
        if (!buttons.contentEquals(other.buttons)) return false
        if (!analogs.contentEquals(other.analogs)) return false
        if (!motions.contentEquals(other.motions)) return false
        if (vibrationEnabled != other.vibrationEnabled) return false
        if (vibrationStrength != other.vibrationStrength) return false
        if (bodyColorLeft != other.bodyColorLeft) return false
        if (bodyColorRight != other.bodyColorRight) return false
        if (buttonColorLeft != other.buttonColorLeft) return false
        if (buttonColorRight != other.buttonColorRight) return false
        if (profileName != other.profileName) return false
        return useSystemVibrator == other.useSystemVibrator
    }

    override fun hashCode(): Int {
        var result = connected.hashCode()
        result = 31 * result + buttons.contentHashCode()
        result = 31 * result + analogs.contentHashCode()
        result = 31 * result + motions.contentHashCode()
        result = 31 * result + vibrationEnabled.hashCode()
        result = 31 * result + vibrationStrength
        result = 31 * result + bodyColorLeft.hashCode()
        result = 31 * result + bodyColorRight.hashCode()
        result = 31 * result + buttonColorLeft.hashCode()
        result = 31 * result + buttonColorRight.hashCode()
        result = 31 * result + profileName.hashCode()
        result = 31 * result + useSystemVibrator.hashCode()
        return result
    }

    fun hasMapping(): Boolean {
        var hasMapping = false
        buttons.forEach {
            if (it != "[empty]") {
                hasMapping = true
            }
        }
        analogs.forEach {
            if (it != "[empty]") {
                hasMapping = true
            }
        }
        motions.forEach {
            if (it != "[empty]") {
                hasMapping = true
            }
        }
        return hasMapping
    }
}