diff --git a/Sources/arm/Project.hx b/Sources/arm/Project.hx index a88eff08..ce7cc160 100644 --- a/Sources/arm/Project.hx +++ b/Sources/arm/Project.hx @@ -32,6 +32,7 @@ import arm.io.ImportBlend; import arm.io.ImportMesh; import arm.io.ImportTexture; import arm.io.ExportArm; +import arm.io.ExportGpl; import arm.node.NodesBrush; import arm.Viewport; import arm.ProjectFormat; @@ -574,10 +575,11 @@ class Project { } public static function exportSwatches() { - UIFiles.show("arm", true, false, function(path: String) { + UIFiles.show("arm,gpl", true, false, function(path: String) { var f = UIFiles.filename; if (f == "") f = tr("untitled"); - ExportArm.runSwatches(path + Path.sep + f); + if (f.endsWith(".gpl")) ExportGpl.run(path + Path.sep + f, f.substring(0,f.lastIndexOf(".")), Project.raw.swatches); + else ExportArm.runSwatches(path + Path.sep + f); }); } diff --git a/Sources/arm/io/ExportGpl.hx b/Sources/arm/io/ExportGpl.hx new file mode 100644 index 00000000..fd46cb97 --- /dev/null +++ b/Sources/arm/io/ExportGpl.hx @@ -0,0 +1,22 @@ +package arm.io; + +import haxe.io.BytesOutput; +import arm.ProjectFormat; + +class ExportGpl { + + public static function run(path: String, name: String, swatches: Array) { + var o = new BytesOutput(); + o.bigEndian = false; + o.writeString("GIMP Palette\n"); + o.writeString("Name: " + name + "\n"); + o.writeString("# armorpaint.org\n"); + o.writeString("#\n"); + + for (swatch in swatches) { + o.writeString(Std.string(swatch.base.Rb) + " " + Std.string(swatch.base.Gb) + " " + Std.string(swatch.base.Bb) + "\n"); + } + + Krom.fileSaveBytes(path, o.getBytes().getData(), o.getBytes().length); + } +}