From 8e6bca536a46982d7456697cecc01dff00db753f Mon Sep 17 00:00:00 2001 From: blaze-developer Date: Fri, 9 Jan 2026 17:02:04 -0800 Subject: [PATCH 1/2] Add Java specific enum logging methods --- .../chrono/structure/LogTable.kt | 36 +++++++++++++++++-- .../chrono/structure/LoggableInputs.kt | 1 - 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/chrono/src/main/java/com/blazedeveloper/chrono/structure/LogTable.kt b/chrono/src/main/java/com/blazedeveloper/chrono/structure/LogTable.kt index 1bfd08e..52b89f8 100644 --- a/chrono/src/main/java/com/blazedeveloper/chrono/structure/LogTable.kt +++ b/chrono/src/main/java/com/blazedeveloper/chrono/structure/LogTable.kt @@ -211,12 +211,13 @@ class LogTable @JvmOverloads constructor( fun get(key: String, default: Array) = get(key, default.asLogValue()).value as Array - /** Gets an enum item from the table at the specified [key], + /** + * Gets an enum item from the table at the specified [key], * If the data does not exist or is of the wrong type, * the [default] is returned. */ inline fun > get(key: String, default: E) = - enumValueOf(get(key, default.name)) + get(key, default, E::class.java) /** * Gets an enum array item from the table at the specified [key], @@ -224,7 +225,36 @@ class LogTable @JvmOverloads constructor( * the [default] is returned. */ inline fun > get(key: String, default: Array) = - get(key, default.map { it.name }.toTypedArray()).map { enumValueOf(it) }.toTypedArray() + get(key, default, E::class.java) + + /** + * Gets an enum item from the table at the specified [key], + * If the data does not exist or is of the wrong type, + * the [default] is returned. + * + * This method requires the enum's class, this is due to Java's type + * erasure, and Kotlin users should leave out the class parameter. + */ + fun > get(key: String, default: E, clazz: Class): E = + java.lang.Enum.valueOf(clazz, get(key, default.name)) + + /** + * Gets an enum array item from the table at the specified [key], + * If the data does not exist or is of the wrong type, + * the [default] is returned. + * + * This method requires the enum's class, this is due to Java's type + * erasure, and Kotlin users should leave out the class parameter. + */ + @Suppress("UNCHECKED_CAST") + fun > get(key: String, default: Array, clazz: Class): Array { + val names = get(key, default.map { it.name }.toTypedArray()) + return (java.lang.reflect.Array.newInstance(clazz, names.size) as Array).apply { + names.forEachIndexed { index, name -> + set(index, java.lang.Enum.valueOf(clazz, name)) + } + } + } /** * Gets a color object from the table at the specified [key], diff --git a/chrono/src/main/java/com/blazedeveloper/chrono/structure/LoggableInputs.kt b/chrono/src/main/java/com/blazedeveloper/chrono/structure/LoggableInputs.kt index a66cd85..3c0b404 100644 --- a/chrono/src/main/java/com/blazedeveloper/chrono/structure/LoggableInputs.kt +++ b/chrono/src/main/java/com/blazedeveloper/chrono/structure/LoggableInputs.kt @@ -17,7 +17,6 @@ abstract class AutoLoggableInputs : LoggableInputs { ) { operator fun setValue(thisRef: Any, property: KProperty<*>, newValue: T) { value = newValue } operator fun getValue(thisRef: Any, property: KProperty<*>) = value - operator fun provideDelegate(thisRef: Any, property: KProperty<*>): Field { toLogs.add { it.toLog(key, value) } fromLogs.add { it.fromLog(key, value) } From 72ac17aa1178e9758c0debb491e8e5f583ea35ec Mon Sep 17 00:00:00 2001 From: blaze-developer Date: Fri, 9 Jan 2026 17:12:53 -0800 Subject: [PATCH 2/2] Add docs --- docs/docs/functionality/data-types.md | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/docs/functionality/data-types.md b/docs/docs/functionality/data-types.md index 2c305f0..6c70c7d 100644 --- a/docs/docs/functionality/data-types.md +++ b/docs/docs/functionality/data-types.md @@ -1,6 +1,8 @@ --- title: "Logged Data" --- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; :::info Log data is stored in the same way as AdvantageKit, with string keys and @@ -23,6 +25,33 @@ Chrono supports these simple types and their arrays: Chrono also supports logging and replaying generic enum values and enum arrays. They are represented by string values from the enum's ``name()`` method. +:::note +Enum logging requires Java users to pass the class of your enum to retrieve it from the log table. +This is unnecessary for Kotlin users. Check the example below. + + + + +```kotlin +override fun fromLog(table: LogTable) { + state = table.get("State", state) + stateArray = table.get("StateArray", stateArray) +} +``` + + + +```java +@Override +public void fromLog(LogTable table) { + state = table.get("State", state, State.class); + stateArray = table.get("StateArray", stateArray, State.class); +} +``` + + +::: + ### Normalized Colors Chrono also supports logging and replaying ``NormalizedRGBA`` objects from color sensors. These are represented by float arrays, storing the colors components in order: