Fix serialization of block arguments.

This commit is contained in:
Sergio Martínez Portela 2020-05-26 10:52:46 +02:00
parent 7f2686166e
commit acb0dbec05
2 changed files with 11 additions and 17 deletions

View File

@ -3,9 +3,10 @@ package com.codigoparallevar.minicards.parts.strings;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import androidx.annotation.NonNull;
import android.util.Log;
import androidx.annotation.NonNull;
import com.codigoparallevar.minicards.PartInstantiator;
import com.codigoparallevar.minicards.ScrolledCanvas;
import com.codigoparallevar.minicards.parts.connectors.AnyRoundInputConnector;
@ -15,10 +16,10 @@ import com.codigoparallevar.minicards.types.Moveable;
import com.codigoparallevar.minicards.types.Part;
import com.codigoparallevar.minicards.types.PartConnection;
import com.codigoparallevar.minicards.types.PartGrid;
import com.codigoparallevar.minicards.types.functional.Tuple2;
import com.codigoparallevar.minicards.types.connectors.input.AnyInputConnector;
import com.codigoparallevar.minicards.types.connectors.input.InputConnector;
import com.codigoparallevar.minicards.types.connectors.output.OutputConnector;
import com.codigoparallevar.minicards.types.functional.Tuple2;
import com.codigoparallevar.minicards.types.wireData.StringSignal;
import com.codigoparallevar.minicards.types.wireData.WireDataType;
import com.codigoparallevar.minicards.utils.Serializations;
@ -250,7 +251,6 @@ public class ConvertToString implements Part {
public void send(InputConnector roundInputConnector, WireDataType signal) {
String encoded = "null";
Object value = signal.get();
if (value != null){
encoded = value.toString();
}

View File

@ -12,7 +12,11 @@ class ProgramakerCustomBlockArgument(
val callback: String?
) {
fun serialize(): JSONObject {
val serialized = hashMapOf<String, JSONObject>()
val serialized = hashMapOf<String, String?>(
"type" to type,
"default_value" to default_value,
"callback" to callback
)
return JSONObject(serialized as Map<*, *>)
}
@ -42,19 +46,9 @@ class ProgramakerCustomBlockArgument(
}
private fun deserialize(arguments: JSONObject): ProgramakerCustomBlockArgument {
var type: String? = null
var default_value: String? = null
var callback: String? = null
if (arguments.has("type")) {
type = arguments.getString("type")
}
if (arguments.has("default_value")) {
default_value = arguments.getString("default_value")
}
if (arguments.has("callback")) {
callback = arguments.getString("callback")
}
val type: String? = arguments.optString("type")
val default_value: String? = arguments.optString("default_value")
val callback: String? = arguments.optString("callback")
return ProgramakerCustomBlockArgument(type, default_value, callback)
}