File tree Expand file tree Collapse file tree
main/kotlin/com/almasb/fxgl/dsl/components
test/kotlin/com/almasb/fxgl/dsl/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,13 +47,18 @@ abstract class RechargeableDoubleComponent
4747) : DoubleComponent (initialValue) {
4848
4949 private val maxValueProp = SimpleDoubleProperty (maxValue)
50+ private val valuePercentBinding = valueProperty().divide(maxValueProp).multiply(100 )
5051
5152 fun maxValueProperty () = maxValueProp
53+ fun valuePercentProperty () = valuePercentBinding
5254
5355 var maxValue: Double
5456 get() = maxValueProp.value
5557 set(value) { maxValueProp.value = value }
5658
59+ val valuePercent: Double
60+ get() = valuePercentBinding.value
61+
5762 /* *
5863 * Set component value to 0.
5964 */
Original file line number Diff line number Diff line change @@ -155,4 +155,16 @@ class RechargeableDoubleComponentTest {
155155 assertThat(value, `is `(30.0 ))
156156 assertThat(zero, `is `(false ))
157157 }
158+
159+ @Test
160+ fun `value in percent` () {
161+ hp.value = 10.0
162+ hp.maxValue = 100.0
163+
164+ assertThat(hp.valuePercent, `is `(10.0 ))
165+
166+ hp.maxValue = 50.0
167+
168+ assertThat(hp.valuePercent, `is `(20.0 ))
169+ }
158170}
You can’t perform that action at this time.
0 commit comments