X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=net.mograsim.logic.model%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fmodel%2Fserializing%2FSubmodelComponentSerializer.java;h=a062eaaaba0268dc0ee7bf3090e795e139770db7;hb=95a225aed8eae0fc080440dba779abfdf867ff3d;hp=96119678ecf55a8daab932d376d1f39fd8d3416e;hpb=bbe38c55aaa999d025f534245f9207a88643f6e5;p=Mograsim.git diff --git a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/SubmodelComponentSerializer.java b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/SubmodelComponentSerializer.java index 96119678..a062eaaa 100644 --- a/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/SubmodelComponentSerializer.java +++ b/net.mograsim.logic.model/src/net/mograsim/logic/model/serializing/SubmodelComponentSerializer.java @@ -1,6 +1,8 @@ package net.mograsim.logic.model.serializing; import java.io.IOException; +import java.util.Arrays; +import java.util.Comparator; import com.google.gson.JsonElement; @@ -24,11 +26,9 @@ import net.mograsim.logic.model.util.Version; */ public final class SubmodelComponentSerializer { - // TODO serialize pin usage - // TODO set pin usages of existing components - public static final Version JSON_VERSION_CURRENT_SERIALIZING = Version.parseSemver("0.1.4"); + public static final Version JSON_VERSION_CURRENT_SERIALIZING = Version.parseSemver("0.1.5"); public static final Version JSON_VERSION_LATEST_SUPPORTED_DESERIALIZING = Version.parseSemver("0.1.5"); - public static final Version JSON_VERSION_EARLIEST_WITH_USAGE_SERIALIZED = Version.parseSemver("0.1.4"); + public static final Version JSON_VERSION_EARLIEST_WITH_USAGE_SERIALIZED = Version.parseSemver("0.1.5"); // convenience methods /** @@ -165,12 +165,13 @@ public final class SubmodelComponentSerializer Version version = params.version; if (version.compareTo(JSON_VERSION_LATEST_SUPPORTED_DESERIALIZING) > 0) throw new IllegalArgumentException("JSON version " + version + " not supported yet"); - boolean hasUsageSerialized = version.compareTo(JSON_VERSION_EARLIEST_WITH_USAGE_SERIALIZED) > 0; + boolean hasUsageSerialized = version.compareTo(JSON_VERSION_EARLIEST_WITH_USAGE_SERIALIZED) >= 0; DeserializedSubmodelComponent comp = new DeserializedSubmodelComponent(model, name, idForSerializingOverride, paramsForSerializingOverride); comp.setSubmodelScale(params.innerScale); comp.setSize(params.width, params.height); for (InterfacePinParams iPinParams : params.interfacePins) + // TRISTATE because we don't have a better choice comp.addSubmodelInterface(new MovablePin(comp, iPinParams.name, iPinParams.logicWidth, hasUsageSerialized ? iPinParams.usage : PinUsage.TRISTATE, iPinParams.location.x, iPinParams.location.y)); ViewModelModifiable submodelModifiable = comp.getSubmodelModifiable(); @@ -212,9 +213,11 @@ public final class SubmodelComponentSerializer iPinParams.location = p.getRelPos(); iPinParams.name = p.name; iPinParams.logicWidth = p.logicWidth; + iPinParams.usage = p.usage; i++; } params.interfacePins = iPins; + Arrays.sort(params.interfacePins, Comparator.comparing(p -> p.name)); Renderer symbolRenderer = comp.getSymbolRenderer(); if (symbolRenderer != null)