A proposal for resolving the loading problem of json files
[Mograsim.git] / net.mograsim.logic.model / src / net / mograsim / logic / model / serializing / SubmodelComponentSerializer.java
index 9611967..a062eaa 100644 (file)
@@ -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)