2025-11-25 10:23:37 +00:00
|
|
|
package com.gamedog.vididin.core.login.login
|
|
|
|
|
|
|
|
|
|
import com.ama.core.architecture.util.DateUtil
|
|
|
|
|
import com.ama.core.architecture.util.DeviceUtil
|
|
|
|
|
import com.ama.core.architecture.util.SpUtil
|
2025-11-27 06:43:33 +00:00
|
|
|
import com.ama.core.architecture.util.eventbus.NotifyMan
|
|
|
|
|
import com.gamedog.vididin.VididinEvents
|
2025-11-25 10:23:37 +00:00
|
|
|
import com.gamedog.vididin.beans.Account
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
object AccountManager {
|
|
|
|
|
|
|
|
|
|
private val mAccount: Account? by lazy {
|
|
|
|
|
var account = SpUtil.instance().getObject<Account>(SpUtil.KEY_ACCOUNT)
|
|
|
|
|
if (account == null) {
|
|
|
|
|
val deviceUUId = DeviceUtil.generateDeviceId()
|
|
|
|
|
account = Account(accountId = "user_$deviceUUId", deviceUUId=deviceUUId, createdAt = DateUtil.getCurTimeMs())
|
|
|
|
|
account.let {
|
|
|
|
|
SpUtil.instance().putObject(SpUtil.KEY_ACCOUNT, account)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
account
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 06:49:15 +00:00
|
|
|
private fun saveAccountInfo() {
|
|
|
|
|
SpUtil.instance().putObject(SpUtil.KEY_ACCOUNT, mAccount)
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-25 10:23:37 +00:00
|
|
|
fun getAccount() : Account? {
|
|
|
|
|
return mAccount
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 06:43:33 +00:00
|
|
|
fun getGold(): Long {
|
|
|
|
|
return mAccount?.goldCount ?: 0L
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun getCash(): Float {
|
|
|
|
|
return mAccount?.cashCount ?: 0F
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun addGold(newGold: Int) {
|
|
|
|
|
mAccount?.goldCount += newGold
|
2025-11-27 06:49:15 +00:00
|
|
|
saveAccountInfo()
|
2025-11-27 06:43:33 +00:00
|
|
|
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Gold_Changed, null)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun addCash(newCash: Float) {
|
|
|
|
|
mAccount?.cashCount += newCash
|
2025-11-27 06:49:15 +00:00
|
|
|
saveAccountInfo()
|
2025-11-27 06:43:33 +00:00
|
|
|
NotifyMan.instance().sendEvent(VididinEvents.Event_Account_Cash_Changed, null)
|
|
|
|
|
}
|
2025-11-25 10:23:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|