Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PAL palette format import #315

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Autoload/Import.gd
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,28 @@ func import_png_palette(path: String, image : Image) -> Palette:
result.name = path.get_basename().get_file()

return result


func import_pal_palette(path : String, text : String) -> Palette:
var result: Palette = null

var lines = text.split('\n')

if lines[0] != 'JASC-PAL' or lines[1] != '0100':
return result
else:
result = Palette.new()
result.name = path.get_basename().get_file()

var num_colors = int(lines[2])

for i in range(3, num_colors + 3):
var color_data = lines[i].split(' ')
var red : float = color_data[0].to_float() / 255.0
var green : float = color_data[1].to_float() / 255.0
var blue : float = color_data[2].to_float() / 255.0

var color = Color(red, green, blue)
result.add_color(color)

return result
7 changes: 7 additions & 0 deletions src/Palette/PaletteContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func on_palette_import_file_selected(path : String) -> void:
var text = file.get_as_text()
file.close()
palette = Import.import_gpl(path, text)
elif path.to_lower().ends_with("pal"):
var file = File.new()
if file.file_exists(path):
file.open(path, File.READ)
var text = file.get_as_text()
file.close()
palette = Import.import_pal_palette(path, text)
elif path.to_lower().ends_with("png") or path.to_lower().ends_with("bmp") or path.to_lower().ends_with("hdr") or path.to_lower().ends_with("jpg") or path.to_lower().ends_with("svg") or path.to_lower().ends_with("tga") or path.to_lower().ends_with("webp"):
var image := Image.new()
var err := image.load(path)
Expand Down
1 change: 1 addition & 0 deletions src/Palette/PalettePanelContainer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ margin_left = 7.0
margin_top = 7.0
margin_right = 507.0
margin_bottom = 307.0
filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library", "*.png; Portable Network Graphics", "*.pal; JASC Palette" )

[node name="EditPalettePopup" parent="." instance=ExtResource( 7 )]
margin_left = 7.0
Expand Down