Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
19 changes: 15 additions & 4 deletions src/main/kotlin/dev/nextftc/bindings/BindingManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
11 changes: 10 additions & 1 deletion src/main/kotlin/dev/nextftc/bindings/Button.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,16 @@ class Button(private val valueSupplier: Supplier<Boolean>) : Supplier<Boolean> {
fun add(layer: Layer, runnable: Runnable) {
callbacks.add(layer to runnable)
}

fun clear() = callbacks.clear()
}

private sealed interface Layer {
object Global : Layer
class Named(val name: String?) : Layer
}

private var value: Boolean = valueSupplier.get()
private var value: Boolean = false
private var previousValue = value

/**
Expand Down Expand Up @@ -212,4 +214,11 @@ class Button(private val valueSupplier: Supplier<Boolean>) : Supplier<Boolean> {
* 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()
}
}
5 changes: 3 additions & 2 deletions src/main/kotlin/dev/nextftc/bindings/Variable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -32,12 +33,12 @@ import java.util.function.Supplier
* @see Range for creating a double variable with number-specific utilities.
*/
open class Variable<T>(private val valueSupplier: Supplier<T>) : Supplier<T> {
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
Expand Down