@@ -16,6 +16,7 @@ import com.almasb.fxgl.app.services.SystemBundleService
16
16
import com.almasb.fxgl.audio.AudioPlayer
17
17
import com.almasb.fxgl.audio.Music
18
18
import com.almasb.fxgl.core.EngineService
19
+ import com.almasb.fxgl.core.collection.PropertyChangeListener
19
20
import com.almasb.fxgl.core.concurrent.Async
20
21
import com.almasb.fxgl.core.concurrent.Executor
21
22
import com.almasb.fxgl.core.math.FXGLMath
@@ -326,6 +327,67 @@ class FXGL private constructor() { companion object {
326
327
327
328
@JvmStatic fun inc (varName : String , value : Double ) = getWorldProperties().increment(varName, value)
328
329
330
+ @JvmStatic fun onIntChangeTo (varName : String , value : Int , action : Runnable ): PropertyChangeListener <Int > {
331
+ return onIntChange(varName) {
332
+ if (it == value)
333
+ action.run ()
334
+ }
335
+ }
336
+
337
+ @JvmStatic fun onIntChange (varName : String , action : Consumer <Int >): PropertyChangeListener <Int > {
338
+ val listener = PropertyChangeListener <Int > { _, newValue -> action.accept(newValue) }
339
+
340
+ getWorldProperties().addListener(varName, listener)
341
+
342
+ return listener
343
+ }
344
+
345
+ @JvmStatic fun onDoubleChange (varName : String , action : Consumer <Double >): PropertyChangeListener <Double > {
346
+ val listener = PropertyChangeListener <Double > { _, newValue -> action.accept(newValue) }
347
+
348
+ getWorldProperties().addListener(varName, listener)
349
+
350
+ return listener
351
+ }
352
+
353
+ @JvmStatic fun onBooleanChangeTo (varName : String , value : Boolean , action : Runnable ): PropertyChangeListener <Boolean > {
354
+ return onBooleanChange(varName) {
355
+ if (it == value)
356
+ action.run ()
357
+ }
358
+ }
359
+
360
+ @JvmStatic fun onBooleanChange (varName : String , action : Consumer <Boolean >): PropertyChangeListener <Boolean > {
361
+ val listener = PropertyChangeListener <Boolean > { _, newValue -> action.accept(newValue) }
362
+
363
+ getWorldProperties().addListener(varName, listener)
364
+
365
+ return listener
366
+ }
367
+
368
+ @JvmStatic fun onStringChangeTo (varName : String , value : String , action : Runnable ): PropertyChangeListener <String > {
369
+ return onStringChange(varName) {
370
+ if (it == value)
371
+ action.run ()
372
+ }
373
+ }
374
+
375
+ @JvmStatic fun onStringChange (varName : String , action : Consumer <String >): PropertyChangeListener <String > {
376
+ val listener = PropertyChangeListener <String > { _, newValue -> action.accept(newValue) }
377
+
378
+ getWorldProperties().addListener(varName, listener)
379
+
380
+ return listener
381
+ }
382
+
383
+ @JvmStatic fun <T > onObjectChange (varName : String , action : Consumer <T >): PropertyChangeListener <T > {
384
+ val listener = PropertyChangeListener <T > { _, newValue -> action.accept(newValue) }
385
+
386
+ getWorldProperties().addListener(varName, listener)
387
+
388
+ return listener
389
+ }
390
+
329
391
/* ASSET LOADING */
330
392
331
393
@JvmStatic fun image (assetName : String ): Image = getAssetLoader().loadImage(assetName)
0 commit comments