diff --git a/README.md b/README.md index d333506..bd5ae33 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,29 @@ # abstract-dashboard An abstraction of NetworkTables, Shuffleboard, SmartDashboard, and LiveWindow +### Why use this? +This library has no global state, meaning that you are free to use NetworkTables how you want to. + +Although this library was heavily influenced by NetworkTables, Shuffleboard, etc, this library gives +your program a layer of abstraction that allows you to change how different things work later. + +### Why was this created +While working on [robo-sim](https://github.com/frc1444/robo-sim), I needed to be able to completely +clear the shuffleboard state and restart NetworkTables. Because the Shuffleboard API in WPILib is +lots and lots of static variables, I was unable to clear that global state. + +In an attempt to be able to restart a robot simulation without restarting the JVM, +I over-engineered this beast while (in my opinion) improving on some tightly coupled aspects +of the NetworkTable/Sendable/Shuffleboard library in WPILib. Some people won't like the change that this +library brings, and that's OK. I needed this library to be very loosely coupled to work in my simulation +and it won't fit everyone's needs. + +### How to use this? +See [robot2019-sim](https://github.com/frc1444/robot2019-sim) for an example. + +### Who should use this? +Until this has been used for a full year, it is not recommended for public use. However, if you are +an advanced team and are OK with using libraries outside of WPILib + ### TODO * Nothing right now! diff --git a/core/src/main/java/com/first1444/dashboard/advanced/implementations/chooser/ChooserListener.kt b/core/src/main/java/com/first1444/dashboard/advanced/implementations/chooser/ChooserListener.kt index dc32dd5..982cd57 100644 --- a/core/src/main/java/com/first1444/dashboard/advanced/implementations/chooser/ChooserListener.kt +++ b/core/src/main/java/com/first1444/dashboard/advanced/implementations/chooser/ChooserListener.kt @@ -7,10 +7,8 @@ interface ChooserListener { val IGNORE = ChooserListener {} @JvmSynthetic - operator fun invoke(lambda: (String) -> Unit) = object : ChooserListener { - override fun onKeyChange(key: String) { - lambda(key) - } + inline operator fun invoke(crossinline lambda: (String) -> Unit) = object : ChooserListener { + override fun onKeyChange(key: String) = lambda(key) } } } diff --git a/core/src/main/java/com/first1444/dashboard/enable/EnabledProvider.kt b/core/src/main/java/com/first1444/dashboard/enable/EnabledProvider.kt index a531997..713362e 100644 --- a/core/src/main/java/com/first1444/dashboard/enable/EnabledProvider.kt +++ b/core/src/main/java/com/first1444/dashboard/enable/EnabledProvider.kt @@ -5,7 +5,7 @@ interface EnabledProvider { companion object { @JvmSynthetic - operator fun invoke(lambda: () -> Boolean) = object : EnabledProvider { + inline operator fun invoke(crossinline lambda: () -> Boolean) = object : EnabledProvider { override val isEnabled: Boolean get() = lambda() } diff --git a/core/src/main/java/com/first1444/dashboard/shuffleboard/MetadataEditor.kt b/core/src/main/java/com/first1444/dashboard/shuffleboard/MetadataEditor.kt index dd68bec..df071de 100644 --- a/core/src/main/java/com/first1444/dashboard/shuffleboard/MetadataEditor.kt +++ b/core/src/main/java/com/first1444/dashboard/shuffleboard/MetadataEditor.kt @@ -9,10 +9,9 @@ interface MetadataEditor { @JvmField val NOTHING = MetadataEditor {} - operator fun invoke(lambda: (metadataDashboard: BasicDashboard) -> Unit) = object : MetadataEditor { - override fun editMetadata(metadataDashboard: BasicDashboard) { - lambda(metadataDashboard) - } + @JvmSynthetic + inline operator fun invoke(crossinline lambda: (metadataDashboard: BasicDashboard) -> Unit) = object : MetadataEditor { + override fun editMetadata(metadataDashboard: BasicDashboard) = lambda(metadataDashboard) } } } diff --git a/core/src/main/java/com/first1444/dashboard/value/ValueProperty.kt b/core/src/main/java/com/first1444/dashboard/value/ValueProperty.kt index 3aa8874..4f780f2 100644 --- a/core/src/main/java/com/first1444/dashboard/value/ValueProperty.kt +++ b/core/src/main/java/com/first1444/dashboard/value/ValueProperty.kt @@ -7,9 +7,17 @@ interface ValueProperty { fun setValue(value: BasicValue) val supportsSetting: Boolean + @FunctionalInterface + interface Getter { + fun get(): BasicValue + } + @FunctionalInterface + interface Setter { + fun set(value: BasicValue) + } companion object { - @JvmStatic - fun createGetOnly(getter: () -> BasicValue) = object : ValueProperty { + @JvmSynthetic + inline fun createGetOnly(crossinline getter: () -> BasicValue) = object : ValueProperty { override fun getValue(): BasicValue = getter() override val supportsGetting: Boolean = true @@ -20,7 +28,9 @@ interface ValueProperty { } @JvmStatic - fun createSetOnly(setter: (BasicValue) -> Unit) = object : ValueProperty { + fun createGetOnly(getter: Getter) = createGetOnly(getter::get) + @JvmSynthetic + inline fun createSetOnly(crossinline setter: (BasicValue) -> Unit) = object : ValueProperty { override fun getValue(): BasicValue { throw UnsupportedOperationException() } @@ -32,14 +42,17 @@ interface ValueProperty { override val supportsSetting: Boolean = true } @JvmStatic - fun create(getter: () -> BasicValue, setter: (BasicValue) -> Unit) = object : ValueProperty { + fun createSetOnly(setter: Setter) = createSetOnly(setter::set) + @JvmSynthetic + inline fun create(crossinline getter: () -> BasicValue, crossinline setter: (BasicValue) -> Unit) = object : ValueProperty { override fun getValue(): BasicValue = getter() override val supportsGetting: Boolean = true override fun setValue(value: BasicValue) { setter(value) } override val supportsSetting: Boolean = true - } + @JvmStatic + fun create(getter: Getter, setter: Setter) = create(getter::get, setter::set) } } diff --git a/core/src/main/java/com/first1444/dashboard/value/listener/EntryListener.kt b/core/src/main/java/com/first1444/dashboard/value/listener/EntryListener.kt index f241796..61c497a 100644 --- a/core/src/main/java/com/first1444/dashboard/value/listener/EntryListener.kt +++ b/core/src/main/java/com/first1444/dashboard/value/listener/EntryListener.kt @@ -5,7 +5,7 @@ interface EntryListener { companion object { @JvmSynthetic - operator fun invoke(lambda: (EntryNotification) -> Unit) = object : EntryListener { + inline operator fun invoke(crossinline lambda: (EntryNotification) -> Unit) = object : EntryListener { override fun onNotification(notification: EntryNotification) = lambda(notification) } }