From 7785103510346e6866389d626d710e445c69e8ac Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Sat, 8 Feb 2020 18:22:17 +0100 Subject: [PATCH] Fix incorrect assumptions in getPersistedOrDefault() in orx-gui --- orx-gui/src/main/kotlin/Gui.kt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/orx-gui/src/main/kotlin/Gui.kt b/orx-gui/src/main/kotlin/Gui.kt index f39a49c1..90abe1c6 100644 --- a/orx-gui/src/main/kotlin/Gui.kt +++ b/orx-gui/src/main/kotlin/Gui.kt @@ -32,7 +32,8 @@ private fun getPersistedOrDefault(compartmentLabel: String, property: if (state == null) { return property.get(obj) } else { - return state.parameterValues[property.name] as? T? + @Suppress("UNCHECKED_CAST") + return (state.parameterValues[property.name] as? T?) ?: return property.get(obj) } } @@ -71,7 +72,7 @@ class GUI : Extension { } styleSheet(has class_ "toolbar") { - this.height = 30.px + this.height = 50.px this.width = 100.percent this.display = Display.FLEX this.flexDirection = FlexDirection.Row @@ -150,7 +151,7 @@ class GUI : Extension { div("sidebar") { id = "sidebar" for ((labeledObject, binding) in trackedObjects) { - val (label, obj) = labeledObject + val (label, _) = labeledObject val header = h3 { label } val collapsible = div("compartment") { @@ -322,18 +323,19 @@ class GUI : Extension { } private fun loadParameters(file: File) { - fun KMutableProperty1?.qset(obj: Any, value:T) { + fun KMutableProperty1?.qset(obj: Any, value: T) { return (this as KMutableProperty1).set(obj, value) } + val json = file.readText() val tt = object : TypeToken>>() {} val labeledValues: Map> = Gson().fromJson(json, tt.type) - labeledValues.forEach { label, ps -> + labeledValues.forEach { (label, ps) -> trackedObjects.keys.find { it.label == label }?.let { lo -> val binding = trackedObjects[lo]!! ps.forEach { (parameterName, parameterValue) -> - binding.parameters.find { it.property?.name == parameterName}?.let { parameter -> + binding.parameters.find { it.property?.name == parameterName }?.let { parameter -> when (parameter.parameterType) { ParameterType.Double -> parameterValue.doubleValue?.let { parameter.property.qset(lo.obj, it) @@ -407,7 +409,7 @@ class GUI : Extension { (parameter.property as KMutableProperty1).set(labeledObject.obj, c) } else -> { - // do nothing + // intentionally do nothing } } }