From 39917e4b5a633277055a138b7913c13ac548dacf Mon Sep 17 00:00:00 2001 From: moonleay Date: Fri, 19 Jan 2024 22:40:08 +0100 Subject: [PATCH] feat: updated and improved DataGrabber methods Signed-off-by: moonleay --- .../splatoon3ink/Splatoon3ApiDataGrabber.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/net/moonleay/lilJudd/data/api/splatoon3ink/Splatoon3ApiDataGrabber.kt b/src/main/kotlin/net/moonleay/lilJudd/data/api/splatoon3ink/Splatoon3ApiDataGrabber.kt index 298e943..f24a46f 100644 --- a/src/main/kotlin/net/moonleay/lilJudd/data/api/splatoon3ink/Splatoon3ApiDataGrabber.kt +++ b/src/main/kotlin/net/moonleay/lilJudd/data/api/splatoon3ink/Splatoon3ApiDataGrabber.kt @@ -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")