diff --git a/.idea/misc.xml b/.idea/misc.xml
index 9879958..bb57085 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,10 +1,9 @@
-
-
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7..4c6280e 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,5 +1,11 @@
+
+
+
+
+
+
diff --git a/gradle.properties b/gradle.properties
index 2babfe4..5cb6b92 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,5 +1,5 @@
kotlin.code.style=official
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
-version=1.0.0
+version=1.0.1
automaticMavenCentralSync=true
diff --git a/src/main/kotlin/dev/nextftc/bindings/BindingManager.kt b/src/main/kotlin/dev/nextftc/bindings/BindingManager.kt
index d0e2f91..67bc410 100644
--- a/src/main/kotlin/dev/nextftc/bindings/BindingManager.kt
+++ b/src/main/kotlin/dev/nextftc/bindings/BindingManager.kt
@@ -69,14 +69,25 @@ object BindingManager {
}
/**
- * Resets the manager to its initial state.
+ * Removes all callback bindings. **DOES NOT** stop updating the state of buttons and variables.
*
- * Removes all variables and buttons and sets the current layer to null.
+ * Removes all bindings and sets the current layer to null.
*/
@JvmStatic
fun reset() {
- variables.clear()
- buttons.clear()
+ buttons.forEach { it.clear() }
layer = null
}
+
+ /**
+ * Calls [reset] along with removing all buttons and variables from being updated.
+ *
+ * Complete reset to the initial state.
+ */
+ @JvmStatic
+ fun fullReset() {
+ buttons.clear()
+ variables.clear()
+ reset()
+ }
}
diff --git a/src/main/kotlin/dev/nextftc/bindings/Button.kt b/src/main/kotlin/dev/nextftc/bindings/Button.kt
index 2f69d0c..7a42570 100644
--- a/src/main/kotlin/dev/nextftc/bindings/Button.kt
+++ b/src/main/kotlin/dev/nextftc/bindings/Button.kt
@@ -61,6 +61,8 @@ class Button(private val valueSupplier: Supplier) : Supplier {
fun add(layer: Layer, runnable: Runnable) {
callbacks.add(layer to runnable)
}
+
+ fun clear() = callbacks.clear()
}
private sealed interface Layer {
@@ -68,7 +70,7 @@ class Button(private val valueSupplier: Supplier) : Supplier {
class Named(val name: String?) : Layer
}
- private var value: Boolean = valueSupplier.get()
+ private var value: Boolean = false
private var previousValue = value
/**
@@ -212,4 +214,11 @@ class Button(private val valueSupplier: Supplier) : Supplier {
* Returns a new button whose state is the logical not of the state of this button.
*/
operator fun not() = button { !get() }
+
+ internal fun clear() {
+ risingEdgeCallback.clear()
+ fallingEdgeCallback.clear()
+ trueCallback.clear()
+ falseCallback.clear()
+ }
}
\ No newline at end of file
diff --git a/src/main/kotlin/dev/nextftc/bindings/Variable.kt b/src/main/kotlin/dev/nextftc/bindings/Variable.kt
index d34d9d8..9d6b179 100644
--- a/src/main/kotlin/dev/nextftc/bindings/Variable.kt
+++ b/src/main/kotlin/dev/nextftc/bindings/Variable.kt
@@ -20,6 +20,7 @@ package dev.nextftc.bindings
import java.util.function.Predicate
import java.util.function.Supplier
+import kotlin.error
/**
* A variable that can be updated, mapped, and used as a button.
@@ -32,12 +33,12 @@ import java.util.function.Supplier
* @see Range for creating a double variable with number-specific utilities.
*/
open class Variable(private val valueSupplier: Supplier) : Supplier {
- private var value: T = valueSupplier.get()
+ private var value: T? = null
/**
* Gets the cached value of the variable. The cached value is updated when [update] is called.
*/
- override fun get(): T = value
+ override fun get(): T = value ?: error("Variable not updated; call update() first")
/**
* Creates a new [Variable] that maps the value of this variable using the given [mapper] and registers it with