feat: updated and improved DataGrabber methods

Signed-off-by: moonleay <contact@moonleay.net>
This commit is contained in:
moonleay 2024-01-19 22:40:08 +01:00
parent 97d4143cda
commit 39917e4b5a
Signed by: moonleay
GPG key ID: 82667543CCD715FB

View file

@ -1,6 +1,6 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
* Copyright (C) 2024 moonleay
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,11 +20,12 @@ package net.moonleay.lilJudd.data.api.splatoon3ink
import net.moonleay.lilJudd.data.api.splatoon3ink.schedules.BankaraNode
import net.moonleay.lilJudd.data.api.splatoon3ink.schedules.RegularNode
import net.moonleay.lilJudd.data.api.splatoon3ink.schedules.SalmonRunNode
import net.moonleay.lilJudd.data.api.splatoon3ink.schedules.XNode
import net.moonleay.lilJudd.util.TimeUtil
object Splatoon3ApiDataGrabber {
private fun getRegularMode(timestamp: Long): RegularNode {
fun getRegularMode(timestamp: Long): RegularNode {
Splatoon3Api.schedules!!.data.regularSchedules.nodes.map { modeData ->
val startTime = TimeUtil.deformatJSONTime(modeData.startTime, "UTC")
val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC")
@ -35,7 +36,7 @@ object Splatoon3ApiDataGrabber {
throw Exception("No current mode found")
}
private fun getOpenMode(timestamp: Long): BankaraNode {
fun getOpenMode(timestamp: Long): BankaraNode {
Splatoon3Api.schedules!!.data.bankaraSchedules.nodes.map { modeData ->
val startTime = TimeUtil.deformatJSONTime(modeData.startTime, "UTC")
val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC")
@ -49,7 +50,7 @@ object Splatoon3ApiDataGrabber {
throw Exception("No current mode found")
}
private fun getXMode(timestamp: Long): XNode {
fun getXMode(timestamp: Long): XNode {
Splatoon3Api.schedules!!.data.xSchedules.nodes.map { modeData ->
val startTime = TimeUtil.deformatJSONTime(modeData.startTime, "UTC")
val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC")
@ -60,7 +61,7 @@ object Splatoon3ApiDataGrabber {
throw Exception("No current mode found")
}
private fun getSeriesMode(timestamp: Long): BankaraNode {
fun getSeriesMode(timestamp: Long): BankaraNode {
Splatoon3Api.schedules!!.data.bankaraSchedules.nodes.map { modeData ->
val startTime = TimeUtil.deformatJSONTime(modeData.startTime, "UTC")
val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC")
@ -74,6 +75,16 @@ object Splatoon3ApiDataGrabber {
throw Exception("No current mode found")
}
fun getSalmonRun(timestamp: Long): SalmonRunNode {
Splatoon3Api.schedules!!.data.coopGroupingSchedule.regularSchedules.nodes.map { modeData ->
val startTime = TimeUtil.deformatJSONTime(modeData.startTime, "UTC")
val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC")
if (timestamp in startTime..endTime) {
return modeData
}
}
throw Exception("No current mode found")
}
fun getRotationTime(timestamp: Long): String {
val modeData = getRegularMode(timestamp)
val endTime = TimeUtil.deformatJSONTime(modeData.endTime, "UTC")