Merge pull request #1357 from MathemanFlo/ImportGpl

Import gpl
This commit is contained in:
Lubos Lenco
2022-04-06 17:48:08 +02:00
committed by GitHub
4 changed files with 62 additions and 4 deletions
+5 -3
View File
@@ -28,6 +28,7 @@ import arm.data.MaterialSlot;
import arm.node.MakeMaterial;
import arm.io.ImportAsset;
import arm.io.ImportArm;
import arm.io.ImportGpl;
import arm.io.ImportBlend;
import arm.io.ImportMesh;
import arm.io.ImportTexture;
@@ -498,8 +499,9 @@ class Project {
}
public static function importSwatches(replaceExisting = false) {
UIFiles.show("arm", false, false, function(path: String) {
ImportArm.runSwatches(path, replaceExisting);
UIFiles.show("arm,gpl", false, false, function(path: String) {
if (Path.isGimpColorPalette(path)) ImportGpl.run(path, replaceExisting);
else ImportArm.runSwatches(path, replaceExisting);
});
}
@@ -578,7 +580,7 @@ class Project {
UIFiles.show("arm,gpl", true, false, function(path: String) {
var f = UIFiles.filename;
if (f == "") f = tr("untitled");
if (f.endsWith(".gpl")) ExportGpl.run(path + Path.sep + f, f.substring(0, f.lastIndexOf(".")), Project.raw.swatches);
if (Path.isGimpColorPalette(f)) ExportGpl.run(path + Path.sep + f, f.substring(0, f.lastIndexOf(".")), Project.raw.swatches);
else ExportArm.runSwatches(path + Path.sep + f);
});
}
+3
View File
@@ -57,6 +57,9 @@ class ImportAsset {
else if (Path.isFolder(path)) {
ImportFolder.run(path);
}
else if (Path.isGimpColorPalette(path)) {
ImportGpl.run(path, false);
}
else {
if (Context.enableImportPlugin(path)) {
run(path, dropX, dropY, showBox);
+53
View File
@@ -0,0 +1,53 @@
package arm.io;
import kha.Color;
import haxe.io.BytesInput;
import kha.Blob;
import iron.data.Data;
class ImportGpl {
public static function run(path: String, replaceExisting: Bool) {
Data.getBlob(path, function(b: Blob) {
var swatches = [];
try {
var input = new BytesInput(b.bytes);
// GIMP's color palette importer: https://gitlab.gnome.org/GNOME/gimp/-/blob/gimp-2-10/app/core/gimppalette-load.c#L39
if (!input.readLine().startsWith("GIMP Palette")) {
Console.error(tr("Not a valid GIMP color palette"));
return;
}
var delimiter = ~/\s+/ig;
while (true) {
var line = input.readLine();
if (line.startsWith("Name:")) continue;
else if (line.startsWith("Columns:")) continue;
else if (line.startsWith("#")) continue;
else {
var tokens = delimiter.split(line);
if (tokens.length < 3) continue;
var swatch = Project.makeSwatch(Color.fromBytes(Std.parseInt(tokens[0]), Std.parseInt(tokens[1]), Std.parseInt(tokens[2])));
swatches.push(swatch);
}
}
}
catch (e: haxe.io.Eof) {
// Is thrown if end of file is reached.
}
if (replaceExisting) {
Project.raw.swatches = [];
if (swatches.length == 0) { // No swatches contained
Project.raw.swatches.push(Project.makeSwatch());
}
}
if (swatches.length > 0) {
for (s in swatches) {
Project.raw.swatches.push(s);
}
}
});
}
}
+1 -1
View File
@@ -72,7 +72,7 @@ class UIMenu {
if (menuButton(ui, tr("Import Font..."))) Project.importAsset("ttf,ttc,otf");
if (menuButton(ui, tr("Import Material..."))) Project.importMaterial();
if (menuButton(ui, tr("Import Brush..."))) Project.importBrush();
if (menuButton(ui, tr("Import Swatches..."))) Project.importAsset("arm");
if (menuButton(ui, tr("Import Swatches..."))) Project.importSwatches();
if (menuButton(ui, tr("Import Mesh..."))) Project.importMesh();
if (menuButton(ui, tr("Reimport Mesh"), Config.keymap.file_reimport_mesh)) Project.reimportMesh();
if (menuButton(ui, tr("Reimport Textures"), Config.keymap.file_reimport_textures)) Project.reimportTextures();