[editor] support level pack edit
This commit is contained in:
@@ -80,6 +80,10 @@ abstract PackId(Array<Dynamic>) {
|
||||
return new PackId(value[0], value[1]);
|
||||
}
|
||||
|
||||
@:from static public function fromString(value:String):PackId {
|
||||
return fromArray(value.split("_"));
|
||||
}
|
||||
|
||||
@:to public inline function toString():String {
|
||||
return '${type}_${name}';
|
||||
}
|
||||
|
||||
@@ -5,4 +5,5 @@ import ru.m.tankz.Type;
|
||||
|
||||
interface ILevelBundle {
|
||||
public function get(id:PackId):LevelPack;
|
||||
public function list():Array<PackId>;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package ru.m.tankz.util;
|
||||
|
||||
import haxe.zip.Tools;
|
||||
import haxe.io.BytesOutput;
|
||||
import haxe.zip.Writer;
|
||||
import flash.utils.ByteArray;
|
||||
import haxe.io.Bytes;
|
||||
import haxe.io.BytesInput;
|
||||
import haxe.zip.Entry;
|
||||
@@ -87,8 +91,32 @@ class LevelUtil {
|
||||
return level;
|
||||
}
|
||||
|
||||
private static function compress(level:LevelConfig):Entry {
|
||||
var content = LevelUtil.dumps(null, level);
|
||||
var bytes = Bytes.ofString(content);
|
||||
var crc = haxe.crypto.Crc32.make(bytes);
|
||||
var result:Entry = {
|
||||
fileName: '${formatLevel(level.id)}.txt',
|
||||
fileSize: bytes.length,
|
||||
fileTime : Date.now(),
|
||||
compressed : false,
|
||||
dataSize : bytes.length,
|
||||
data : bytes,
|
||||
crc32 : crc,
|
||||
};
|
||||
Tools.compress(result, 9);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static function unpack(bytes:Bytes):Array<LevelConfig> {
|
||||
var files = Reader.readZip(new BytesInput(bytes));
|
||||
return Lambda.array(files.map(extract));
|
||||
}
|
||||
|
||||
public static function pack(data:Array<LevelConfig>):Bytes {
|
||||
var output = new BytesOutput();
|
||||
var writer = new Writer(output);
|
||||
writer.write(Lambda.list(data.map(compress)));
|
||||
return output.getBytes();
|
||||
}
|
||||
}
|
||||
|
||||
BIN
src/common/resources/level/classic_modern.zip
Normal file
BIN
src/common/resources/level/classic_modern.zip
Normal file
Binary file not shown.
BIN
src/common/resources/level/classic_standard.zip
Normal file
BIN
src/common/resources/level/classic_standard.zip
Normal file
Binary file not shown.
BIN
src/common/resources/level/death_standard.zip
Normal file
BIN
src/common/resources/level/death_standard.zip
Normal file
Binary file not shown.
BIN
src/common/resources/level/dota_standard.zip
Normal file
BIN
src/common/resources/level/dota_standard.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user