-
-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add SerializableType to PropertyMap, closes #1250
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ package com.almasb.fxgl.core.collection | |
import javafx.beans.property.* | ||
import javafx.beans.value.ChangeListener | ||
import javafx.beans.value.ObservableValue | ||
import com.almasb.fxgl.core.serialization.SerializableType | ||
import com.almasb.fxgl.core.serialization.Bundle | ||
import java.util.* | ||
|
||
|
||
|
@@ -23,10 +25,11 @@ import java.util.* | |
* SimpleObjectProperty. | ||
* | ||
* Null values are not allowed. | ||
* Object Properties are not supported for Serialization. | ||
* | ||
* @author Almas Baimagambetov ([email protected]) | ||
*/ | ||
class PropertyMap { | ||
class PropertyMap : SerializableType { | ||
|
||
companion object { | ||
@JvmStatic fun fromStringMap(map: Map<String, String>): PropertyMap { | ||
|
@@ -309,6 +312,20 @@ class PropertyMap { | |
} | ||
} | ||
|
||
override fun write(bundle: Bundle) { | ||
// Convert to string map | ||
this.toStringMap().forEach { (key, value) -> | ||
// write to bundle | ||
bundle.put(key, value) | ||
} | ||
} | ||
|
||
override fun read(bundle: Bundle) { | ||
bundle.data.forEach { (key, value) -> | ||
this.setValue(key, toValue(value.toString())) | ||
} | ||
} | ||
|
||
override fun toString(): String { | ||
return properties.toMap().toString() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters