Przeglądaj źródła

Fixed bug in Gradient Editor

The gradient editor would silently crash if it's value was null at
creation
Clement Espeute 3 lat temu
rodzic
commit
22e0f85693
2 zmienionych plików z 12 dodań i 5 usunięć
  1. 5 5
      hide/comp/PropsEditor.hx
  2. 7 0
      hrt/impl/TextureType.hx

+ 5 - 5
hide/comp/PropsEditor.hx

@@ -1,4 +1,5 @@
 package hide.comp;
+import hrt.impl.TextureType.Utils;
 import hrt.prefab.Props;
 
 class PropsEditor extends Component {
@@ -331,10 +332,9 @@ class PropsField extends Component {
 			}
 			return;
 		case "texturechoice":
-			var a = getAccess();
 			tchoice = new TextureChoice(null, f);
 			tchoice.value = current;
-			currentSave = haxe.Json.parse(haxe.Json.stringify(current));
+			currentSave = Utils.copyTextureData(current);
 
 			tchoice.onChange = function(shouldUndo : Bool) {
 
@@ -342,14 +342,14 @@ class PropsField extends Component {
 					var setVal = function(val, undo) {
 						var f = resolveField();
 						f.current = val;
-						f.currentSave = haxe.Json.parse(haxe.Json.stringify(val));
+						f.currentSave = Utils.copyTextureData(val);
 						f.tchoice.value = val;
 						setFieldValue(val);
 						f.onChange(undo);
 					}
 
-					var oldVal = haxe.Json.parse(haxe.Json.stringify(currentSave));
-					var newVal = haxe.Json.parse(haxe.Json.stringify(tchoice.value));
+					var oldVal = Utils.copyTextureData(currentSave);
+					var newVal = Utils.copyTextureData(tchoice.value);
 
 					props.undo.change(Custom(function(undo) {
 						if (undo) {

+ 7 - 0
hrt/impl/TextureType.hx

@@ -31,4 +31,11 @@ class Utils {
         }
         return null;
     }
+
+    public static function copyTextureData(val : Any) : Any {
+        if (Type.typeof(val) == TObject)
+            return haxe.Json.parse(haxe.Json.stringify(val));
+
+        return val;
+    }
 }