altoslib: Switch preserved state format to JSON
[fw/altos] / altoslib / AltosRotation.java
index e9c447ad1e4d69e355a96b25ab630809878a6fdf..4b7ab407514331e6b3bb62ee117a0a78f62d62c7 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.altoslib_11;
 
 
 package org.altusmetrum.altoslib_11;
 
-public class AltosRotation implements AltosHashable {
+public class AltosRotation implements AltosHashable, AltosJsonable {
        private AltosQuaternion         rotation;
 
        public double tilt() {
        private AltosQuaternion         rotation;
 
        public double tilt() {
@@ -55,6 +55,10 @@ public class AltosRotation implements AltosHashable {
                return h;
        }
 
                return h;
        }
 
+       public AltosJson json() {
+               return rotation.json();
+       }
+
        public AltosRotation(AltosHashSet h) {
                rotation = new AltosQuaternion(h.getHash("rotation"));
        }
        public AltosRotation(AltosHashSet h) {
                rotation = new AltosQuaternion(h.getHash("rotation"));
        }
@@ -65,4 +69,15 @@ public class AltosRotation implements AltosHashable {
 
                return new AltosRotation(h);
        }
 
                return new AltosRotation(h);
        }
+
+       public AltosRotation(AltosJson j) {
+               rotation = new AltosQuaternion(j);
+       }
+
+       public static AltosRotation fromJson(AltosJson j, AltosRotation def) {
+               if (j == null)
+                       return def;
+
+               return new AltosRotation(j);
+       }
 }
 }