浏览代码

more implementation

Nicolas Cannasse 9 年之前
父节点
当前提交
d385ad02f4
共有 2 个文件被更改,包括 24 次插入1 次删除
  1. 10 1
      hxd/BitmapData.hx
  2. 14 0
      hxd/Save.hx

+ 10 - 1
hxd/BitmapData.hx

@@ -252,9 +252,18 @@ class BitmapData {
 		var b = new flash.display.BitmapData(w, h);
 		b.copyPixels(bmp, new flash.geom.Rectangle(x, y, w, h), new flash.geom.Point(0, 0));
 		return fromNative(b);
-		#else
+		#elseif (js || lime)
 		notImplemented();
 		return null;
+		#else
+		if( x < 0 || y < 0 || w < 0 || h < 0 || x + w > width || y + h > height ) throw "Outside bounds";
+		var b = new BitmapInnerData();
+		b.width = w;
+		b.height = h;
+		b.pixels = new haxe.ds.Vector(w * h);
+		for( dy in 0...h )
+			haxe.ds.Vector.blit(data.pixels, x + (y + dy) * width * 4, b.pixels, dy * w * 4, w * 4);
+		return fromNative(b);
 		#end
 	}
 

+ 14 - 0
hxd/Save.hx

@@ -15,6 +15,12 @@ class Save {
 	}
 	#end
 
+	#if sys
+	static function savePath( name : String ) {
+		return name + ".sav";
+	}
+	#end
+
 	public static function load<T>( ?defValue : T, ?name = "save" ) : T {
 		#if flash
 		try {
@@ -24,6 +30,8 @@ class Save {
 		} catch( e : Dynamic ) {
 			return defValue;
 		}
+		#elseif sys
+		return try haxe.Unserializer.run(sys.io.File.getContent(savePath(name))) catch( e : Dynamic ) defValue;
 		#else
 		return defValue;
 		#end
@@ -38,6 +46,12 @@ class Save {
 		getObj(name).setProperty("data", data);
 		if( !quick ) try saveObj.flush() catch( e : Dynamic ) throw "Can't write save (disk full ?)";
 		return true;
+		#elseif sys
+		var data = haxe.Serializer.run(val);
+		var file = savePath(name);
+		try if( sys.io.File.getContent(file) == data ) return false catch( e : Dynamic ) {};
+		sys.io.File.saveContent(file, data);
+		return true;
 		#else
 		return false;
 		#end