mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Added GPL importer, new palette classes for clarification
This commit is contained in:
parent
73f550f723
commit
770c633db2
23
Main.tscn
23
Main.tscn
|
@ -52,7 +52,7 @@
|
|||
[ext_resource path="res://Assets/Graphics/Layers/merge_down.png" type="Texture" id=50]
|
||||
[ext_resource path="res://Assets/Graphics/Layers/merge_down_hover.png" type="Texture" id=51]
|
||||
[ext_resource path="res://Assets/Graphics/Layers/merge_down_disabled.png" type="Texture" id=52]
|
||||
[ext_resource path="res://Scripts/PaletteContainer.gd" type="Script" id=53]
|
||||
[ext_resource path="res://Scripts/Palette/PaletteContainer.gd" type="Script" id=53]
|
||||
[ext_resource path="res://Prefabs/BrushButton.tscn" type="PackedScene" id=54]
|
||||
[ext_resource path="res://Assets/Graphics/Canvas_split.png" type="Texture" id=55]
|
||||
[ext_resource path="res://Assets/Graphics/Canvas_unsplit.png" type="Texture" id=56]
|
||||
|
@ -226,7 +226,6 @@ text = "[64×64]"
|
|||
align = 2
|
||||
|
||||
[node name="UI" type="HBoxContainer" parent="MenuAndUI"]
|
||||
editor/display_folded = true
|
||||
margin_top = 28.0
|
||||
margin_right = 1152.0
|
||||
margin_bottom = 648.0
|
||||
|
@ -1139,7 +1138,6 @@ margin_right = 689.0
|
|||
margin_bottom = 138.0
|
||||
|
||||
[node name="LayerPanel" type="Panel" parent="MenuAndUI/UI"]
|
||||
editor/display_folded = true
|
||||
margin_left = 928.0
|
||||
margin_right = 1152.0
|
||||
margin_bottom = 620.0
|
||||
|
@ -1485,8 +1483,8 @@ resizable = true
|
|||
mode = 0
|
||||
access = 2
|
||||
filters = PoolStringArray( "*.pxo ; Pixelorama Project" )
|
||||
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
||||
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
||||
current_dir = "D:/GitHub/Pixelorama"
|
||||
current_path = "D:/GitHub/Pixelorama/"
|
||||
|
||||
[node name="SaveSprite" type="FileDialog" parent="."]
|
||||
anchor_left = 0.5
|
||||
|
@ -1501,8 +1499,8 @@ window_title = "Save Sprite as .pxo"
|
|||
resizable = true
|
||||
access = 2
|
||||
filters = PoolStringArray( "*.pxo ; Pixelorama Project" )
|
||||
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
||||
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
||||
current_dir = "D:/GitHub/Pixelorama"
|
||||
current_path = "D:/GitHub/Pixelorama/"
|
||||
|
||||
[node name="ImportSprites" type="FileDialog" parent="."]
|
||||
margin_right = 515.0
|
||||
|
@ -1512,8 +1510,8 @@ resizable = true
|
|||
mode = 1
|
||||
access = 2
|
||||
filters = PoolStringArray( "*.bmp ; BMP Image", "*.hdr ; Radiance HDR Image", "*.jpg,*.jpeg ; JPEG Image", "*.png ; PNG Image", "*.svg ; SVG Image", "*.tga ; TGA Image", "*.webp ; WebP Image" )
|
||||
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
||||
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
||||
current_dir = "D:/GitHub/Pixelorama"
|
||||
current_path = "D:/GitHub/Pixelorama/"
|
||||
|
||||
[node name="ExportSprites" type="FileDialog" parent="."]
|
||||
anchor_left = 0.5
|
||||
|
@ -1528,8 +1526,8 @@ window_title = "Export Sprite"
|
|||
resizable = true
|
||||
access = 2
|
||||
filters = PoolStringArray( "*.png ; PNG Image" )
|
||||
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
||||
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
||||
current_dir = "D:/GitHub/Pixelorama"
|
||||
current_path = "D:/GitHub/Pixelorama/"
|
||||
|
||||
[node name="ScaleImage" type="ConfirmationDialog" parent="."]
|
||||
editor/display_folded = true
|
||||
|
@ -1684,8 +1682,7 @@ visible = false
|
|||
[node name="NewPaletteDialog" parent="." instance=ExtResource( 60 )]
|
||||
|
||||
[node name="PaletteImportFileDialog" parent="." instance=ExtResource( 61 )]
|
||||
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
||||
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
||||
filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library" )
|
||||
|
||||
[node name="AnimationTimer" type="Timer" parent="."]
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://Scripts/EditPalettePopup.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Scripts/Palette/EditPalettePopup.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Assets/Graphics/Palette/new_swatch_button.png" type="Texture" id=2]
|
||||
[ext_resource path="res://Assets/Graphics/Palette/new_swatch_button_hover.png" type="Texture" id=3]
|
||||
[ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button.png" type="Texture" id=4]
|
||||
[ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button_hover.png" type="Texture" id=5]
|
||||
|
||||
|
||||
[node name="EditPalettePopup" type="WindowDialog"]
|
||||
visible = true
|
||||
margin_right = 600.0
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_pressedr.tres" type="StyleBox" id=2]
|
||||
[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_focus.tres" type="StyleBox" id=3]
|
||||
[ext_resource path="res://Themes & Styles/StyleBoxes/palette_stylebox_normal.tres" type="StyleBox" id=4]
|
||||
[ext_resource path="res://Scripts/PaletteButton.gd" type="Script" id=5]
|
||||
[ext_resource path="res://Scripts/Palette/PaletteButton.gd" type="Script" id=5]
|
||||
[ext_resource path="res://Assets/Graphics/Palette/palette_button_fill.png" type="Texture" id=6]
|
||||
|
||||
|
||||
[sub_resource type="ImageTexture" id=1]
|
||||
|
||||
[node name="PaletteButton" type="Button"]
|
||||
|
|
53
Scripts/Import.gd
Normal file
53
Scripts/Import.gd
Normal file
|
@ -0,0 +1,53 @@
|
|||
extends Node
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
func import_gpl(path : String) -> Palette:
|
||||
var result : Palette = null
|
||||
var file = File.new()
|
||||
if file.file_exists(path):
|
||||
file.open(path, File.READ)
|
||||
var text = file.get_as_text()
|
||||
var lines = text.split('\n')
|
||||
var line_number := 0
|
||||
var comments := ""
|
||||
for line in lines:
|
||||
# Check if valid Gimp Palette Library file
|
||||
if line_number == 0:
|
||||
if line != "GIMP Palette":
|
||||
break
|
||||
else:
|
||||
result = Palette.new()
|
||||
var name_start = path.find_last('/') + 1
|
||||
var name_end = path.find_last('.')
|
||||
if name_end > name_start:
|
||||
result.name = path.substr(name_start, name_end - name_start)
|
||||
|
||||
# Comments
|
||||
if line.begins_with('#'):
|
||||
comments += line.trim_prefix('#') + '\n'
|
||||
pass
|
||||
elif line_number > 0 && line.length() >= 12:
|
||||
var red : float = line.substr(0, 4).to_float() / 255.0
|
||||
var green : float = line.substr(4, 4).to_float() / 255.0
|
||||
var blue : float = line.substr(8, 4).to_float() / 255.0
|
||||
var name : String = line.substr(12, line.length() - 12)
|
||||
var color = Color(red, green, blue)
|
||||
result.add_color(color, name)
|
||||
line_number += 1
|
||||
|
||||
if result:
|
||||
result.comments = comments
|
||||
file.close()
|
||||
|
||||
return result
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
|
@ -8,8 +8,7 @@ var palette_button = preload("res://Prefabs/PaletteButton.tscn");
|
|||
|
||||
var current_palette : String
|
||||
var current_swatch := -1
|
||||
var working_palette : Dictionary
|
||||
|
||||
var working_palette : Palette
|
||||
|
||||
func open(palette : String) -> void:
|
||||
current_palette = palette
|
||||
|
@ -26,7 +25,7 @@ func _display_palette() -> void:
|
|||
var index := 0
|
||||
|
||||
for color_data in working_palette.colors:
|
||||
var color = Color(color_data.data)
|
||||
var color = color_data.color
|
||||
var new_button = palette_button.instance()
|
||||
|
||||
new_button.color = color
|
||||
|
@ -48,14 +47,12 @@ func _clear_swatches() -> void:
|
|||
|
||||
func on_swatch_select(index : int) -> void:
|
||||
current_swatch = index
|
||||
color_name_edit.text = working_palette.colors[index].name
|
||||
color_picker.color = working_palette.colors[index].data
|
||||
color_name_edit.text = working_palette.get_color_name(index)
|
||||
color_picker.color = working_palette.get_color(index)
|
||||
pass
|
||||
|
||||
func on_move_swatch(from : int, to : int) -> void:
|
||||
var color_to_move = working_palette.colors[from]
|
||||
working_palette.colors.remove(from)
|
||||
working_palette.colors.insert(to, color_to_move)
|
||||
working_palette.move_color(from, to)
|
||||
|
||||
palette_grid.move_child(palette_grid.get_child(from), to)
|
||||
|
||||
|
@ -68,15 +65,14 @@ func on_move_swatch(from : int, to : int) -> void:
|
|||
|
||||
func _on_AddSwatchButton_pressed() -> void:
|
||||
var color = Color.white
|
||||
var color_data = {}
|
||||
color_data.data = color.to_html(true)
|
||||
color_data.name = "no name"
|
||||
working_palette.colors.push_back(color_data)
|
||||
var new_index : int = working_palette.colors.size()
|
||||
working_palette.add_color(color)
|
||||
|
||||
var new_button = palette_button.instance()
|
||||
|
||||
new_button.color = color
|
||||
new_button.get_child(0).modulate = color
|
||||
new_button.hint_tooltip = color_data.data.to_upper() + " " + color_data.name
|
||||
new_button.hint_tooltip = "#" + working_palette.get_color_data(new_index).to_upper() + " " + working_palette.get_color_name(new_index)
|
||||
new_button.draggable = true
|
||||
var index : int = palette_grid.get_child_count()
|
||||
new_button.index = index
|
||||
|
@ -87,7 +83,7 @@ func _on_AddSwatchButton_pressed() -> void:
|
|||
pass # Replace with function body.
|
||||
|
||||
func _on_RemoveSwatchButton_pressed() -> void:
|
||||
working_palette.colors.remove(current_swatch)
|
||||
working_palette.remove_color(current_swatch)
|
||||
palette_grid.remove_child(palette_grid.get_child(current_swatch))
|
||||
pass # Replace with function body.
|
||||
|
||||
|
@ -104,17 +100,17 @@ func _on_EditPaletteCancelButton_pressed() -> void:
|
|||
|
||||
func _on_EditPaletteColorNameLineEdit_text_changed(new_text) -> void:
|
||||
if current_swatch >= 0 && current_swatch < working_palette.colors.size():
|
||||
working_palette.colors[current_swatch].name = new_text
|
||||
working_palette.set_color_name(current_swatch, new_text)
|
||||
_refresh_hint_tooltip(current_swatch)
|
||||
pass
|
||||
|
||||
func _on_EditPaletteColorPicker_color_changed(color) -> void:
|
||||
if current_swatch >= 0 && current_swatch < working_palette.colors.size():
|
||||
palette_grid.get_child(current_swatch).get_child(0).modulate = color
|
||||
working_palette.colors[current_swatch].data = color.to_html(true)
|
||||
working_palette.set_color(current_swatch, color)
|
||||
_refresh_hint_tooltip(current_swatch)
|
||||
pass
|
||||
|
||||
func _refresh_hint_tooltip(index : int):
|
||||
palette_grid.get_child(current_swatch).hint_tooltip = working_palette.colors[current_swatch].data.to_upper() + " " + working_palette.colors[current_swatch].name
|
||||
palette_grid.get_child(current_swatch).hint_tooltip = "#" + working_palette.get_color_data(current_swatch).to_upper() + " " + working_palette.get_color_name(current_swatch)
|
||||
pass
|
132
Scripts/Palette/Palette.gd
Normal file
132
Scripts/Palette/Palette.gd
Normal file
|
@ -0,0 +1,132 @@
|
|||
extends Reference
|
||||
|
||||
class_name Palette
|
||||
func get_class(): return "Palette"
|
||||
func is_class(name): return name == "Palette" or .is_class(name)
|
||||
|
||||
var name : String = "Custom_Palette"
|
||||
var colors : Array = []
|
||||
var comments : String = ""
|
||||
var editable : bool = true
|
||||
|
||||
func insert_color(index : int, new_color : Color, name : String = "no name") -> void:
|
||||
if index < colors.size():
|
||||
var c := PaletteColor.new(new_color, name)
|
||||
colors.insert(index, c)
|
||||
|
||||
func add_color(new_color : Color, name : String = "no name") -> void:
|
||||
var c := PaletteColor.new(new_color, name)
|
||||
|
||||
colors.push_back(c)
|
||||
|
||||
func remove_color(index : int) -> void:
|
||||
if index < colors.size():
|
||||
colors.remove(index)
|
||||
|
||||
func move_color(from : int, to : int) -> void:
|
||||
if from < colors.size() && to < colors.size():
|
||||
var c : PaletteColor = colors[from]
|
||||
remove_color(from)
|
||||
insert_color(to, c.color, c.name)
|
||||
|
||||
func get_color(index : int) -> Color:
|
||||
var result := Color.black
|
||||
|
||||
if index < colors.size():
|
||||
result = colors[index].color
|
||||
|
||||
return result
|
||||
|
||||
func set_color(index : int, new_color : Color) -> void:
|
||||
if index < colors.size():
|
||||
colors[index].color = new_color
|
||||
|
||||
func get_color_data(index : int) -> String:
|
||||
var result := ""
|
||||
|
||||
if index < colors.size():
|
||||
result = colors[index].data
|
||||
|
||||
return result
|
||||
|
||||
func set_color_data(index : int, new_color : String) -> void:
|
||||
if index < colors.size():
|
||||
colors[index].data = new_color
|
||||
|
||||
func get_color_name(index : int) -> String:
|
||||
var result = ""
|
||||
|
||||
if index < colors.size():
|
||||
result = colors[index].name
|
||||
|
||||
return result
|
||||
|
||||
func set_color_name(index : int, new_name : String) -> void:
|
||||
if index < colors.size():
|
||||
colors[index].name = new_name
|
||||
|
||||
func save_to_file(path : String) -> void:
|
||||
var file = File.new()
|
||||
file.open(path, File.WRITE)
|
||||
file.store_string(_serialize())
|
||||
file.close()
|
||||
|
||||
func duplicate() -> Palette:
|
||||
var copy : Palette = get_script().new()
|
||||
copy.name = name
|
||||
copy.comments = comments
|
||||
copy.editable = editable
|
||||
for color in colors:
|
||||
copy.colors.push_back(color.duplicate())
|
||||
return copy
|
||||
|
||||
func _serialize() -> String:
|
||||
var result = ""
|
||||
var serialize_data : Dictionary = {
|
||||
"name" : name,
|
||||
"colors" : [],
|
||||
"comments" : comments,
|
||||
"editable" : editable
|
||||
}
|
||||
for color in colors:
|
||||
serialize_data.colors.push_back(color.toDict())
|
||||
|
||||
result = JSON.print(serialize_data)
|
||||
|
||||
return result;
|
||||
|
||||
func deserialize(input_string : String) -> Palette:
|
||||
var result = get_script().new()
|
||||
|
||||
var result_json = JSON.parse(input_string)
|
||||
#
|
||||
if result_json.error != OK: # If parse has errors
|
||||
print("Error: ", result_json.error)
|
||||
print("Error Line: ", result_json.error_line)
|
||||
print("Error String: ", result_json.error_string)
|
||||
result = null
|
||||
else: # If parse OK
|
||||
var data = result_json.result
|
||||
if data.has("name"): #If data is 'valid' palette file
|
||||
result = get_script().new()
|
||||
result.name = data.name
|
||||
result.comments = data.comments
|
||||
result.editable = data.editable
|
||||
for color_data in data.colors:
|
||||
result.add_color(color_data.data, color_data.name)
|
||||
|
||||
return result
|
||||
|
||||
func load_from_file(path : String) -> Palette:
|
||||
var result : Palette = null
|
||||
var file = File.new()
|
||||
|
||||
if file.file_exists(path):
|
||||
file.open(path, File.READ)
|
||||
|
||||
var text : String = file.get_as_text()
|
||||
result = deserialize(text)
|
||||
|
||||
file.close()
|
||||
|
||||
return result
|
42
Scripts/Palette/PaletteColor.gd
Normal file
42
Scripts/Palette/PaletteColor.gd
Normal file
|
@ -0,0 +1,42 @@
|
|||
extends Reference
|
||||
|
||||
class_name PaletteColor
|
||||
func get_class(): return "PaletteColor"
|
||||
func is_class(name): return name == "PaletteColor" or .is_class(name)
|
||||
|
||||
var color : Color = Color.black setget _set_color
|
||||
var data : String = "" setget _set_data
|
||||
var name : String = "no name"
|
||||
|
||||
func _init(new_color : Color = Color.black, new_name : String = "no name"):
|
||||
self.color = new_color
|
||||
self.name = new_name
|
||||
|
||||
func _set_color(new_value : Color) -> void:
|
||||
color = new_value
|
||||
data = color.to_html(true)
|
||||
|
||||
func _set_data(new_value : String) -> void:
|
||||
data = new_value
|
||||
color = Color(data)
|
||||
|
||||
func toDict() -> Dictionary:
|
||||
var result = {
|
||||
"data" : data,
|
||||
"name" : name
|
||||
}
|
||||
return result
|
||||
|
||||
func fromDict(input_dict : Dictionary) -> PaletteColor:
|
||||
var result = get_script().new()
|
||||
|
||||
result.data = input_dict.data
|
||||
result.name = input_dict.name
|
||||
|
||||
return result
|
||||
|
||||
func duplicate() -> PaletteColor:
|
||||
var copy : PaletteColor = get_script().new()
|
||||
copy.data = data
|
||||
copy.name = name
|
||||
return copy
|
|
@ -3,7 +3,7 @@ extends GridContainer
|
|||
const palette_button = preload("res://Prefabs/PaletteButton.tscn");
|
||||
|
||||
var current_palette = "Default"
|
||||
var from_palette : = {}
|
||||
var from_palette : Palette
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
@ -22,12 +22,11 @@ func on_palette_select(palette_name : String) -> void:
|
|||
_clear_swatches()
|
||||
if Global.palettes.has(palette_name): #Palette exists in memory
|
||||
current_palette = palette_name
|
||||
var palette : Dictionary = Global.palettes[palette_name]
|
||||
var palette : Palette = Global.palettes[palette_name]
|
||||
|
||||
Global.remove_palette_button.disabled = true # Cannot remove by default
|
||||
if palette.has("editable"):
|
||||
if palette.editable:
|
||||
Global.remove_palette_button.disabled = false # Can remove if custom palette
|
||||
if palette.editable:
|
||||
Global.remove_palette_button.disabled = false # Can remove if custom palette
|
||||
|
||||
_display_palette(palette)
|
||||
else: #Use default on fail
|
||||
|
@ -37,7 +36,7 @@ func on_palette_select(palette_name : String) -> void:
|
|||
func on_new_empty_palette() -> void:
|
||||
Global.new_palette_dialog.window_title = "Create a new empty palette?"
|
||||
Global.new_palette_name_line_edit.text = "Custom_Palette"
|
||||
from_palette = {}
|
||||
from_palette = null
|
||||
Global.new_palette_dialog.popup_centered()
|
||||
pass
|
||||
|
||||
|
@ -47,42 +46,35 @@ func on_import_palette() -> void:
|
|||
|
||||
func on_palette_import_file_selected(path) -> void:
|
||||
var file := File.new()
|
||||
|
||||
file.open(path, File.READ)
|
||||
var text = file.get_as_text()
|
||||
var result_json = JSON.parse(text)
|
||||
var result = {}
|
||||
var palette_name = null # Default error condition
|
||||
|
||||
if result_json.error != OK: # If parse has errors
|
||||
print("Error: ", result_json.error)
|
||||
print("Error Line: ", result_json.error_line)
|
||||
print("Error String: ", result_json.error_string)
|
||||
else: # If parse OK
|
||||
var data = result_json.result
|
||||
if data.has("name"): #If data is 'valid' palette file
|
||||
palette_name = data.name
|
||||
if not Global.palettes.has(palette_name):
|
||||
Global.palettes[palette_name] = data
|
||||
Global.palette_option_button.add_item(palette_name)
|
||||
var index := Global.palette_option_button.get_item_count() - 1
|
||||
Global.palette_option_button.set_item_metadata(index, palette_name)
|
||||
Global.palette_option_button.select(index)
|
||||
on_palette_select(palette_name)
|
||||
save_palette(palette_name, palette_name + ".json")
|
||||
else:
|
||||
Global.error_dialog.set_text("Palette named '" + palette_name + "' already exists");
|
||||
Global.error_dialog.popup_centered()
|
||||
file.close()
|
||||
var palette : Palette = null
|
||||
if path.to_lower().ends_with("json"):
|
||||
palette = Palette.new().load_from_file(path)
|
||||
elif path.to_lower().ends_with("gpl"):
|
||||
palette = Import.import_gpl(path)
|
||||
|
||||
if palette:
|
||||
if not Global.palettes.has(palette.name):
|
||||
Global.palettes[palette.name] = palette
|
||||
Global.palette_option_button.add_item(palette.name)
|
||||
var index := Global.palette_option_button.get_item_count() - 1
|
||||
Global.palette_option_button.set_item_metadata(index, palette.name)
|
||||
Global.palette_option_button.select(index)
|
||||
on_palette_select(palette.name)
|
||||
save_palette(palette.name, palette.name + ".json")
|
||||
else:
|
||||
Global.error_dialog.set_text("Palette named '" + palette.name + "' already exists");
|
||||
Global.error_dialog.popup_centered()
|
||||
else:
|
||||
Global.error_dialog.set_text("Invalid Palette file!")
|
||||
Global.error_dialog.popup_centered()
|
||||
pass
|
||||
|
||||
func on_edit_palette() -> void:
|
||||
var palette : Dictionary = Global.palettes[current_palette]
|
||||
|
||||
var create_new_palette := true # Create new palette by default
|
||||
if palette.has("editable"):
|
||||
if palette.editable:
|
||||
create_new_palette = false # Edit if already a custom palette
|
||||
if palette.editable:
|
||||
create_new_palette = false # Edit if already a custom palette
|
||||
|
||||
if create_new_palette:
|
||||
from_palette = Global.palettes[current_palette]
|
||||
|
@ -90,7 +82,7 @@ func on_edit_palette() -> void:
|
|||
Global.new_palette_name_line_edit.text = "Custom_" + current_palette
|
||||
Global.new_palette_dialog.popup_centered()
|
||||
else:
|
||||
from_palette = {}
|
||||
from_palette = null
|
||||
Global.edit_palette_popup.open(current_palette)
|
||||
|
||||
func on_new_palette_confirmed() -> void:
|
||||
|
@ -100,8 +92,8 @@ func on_new_palette_confirmed() -> void:
|
|||
Global.error_dialog.set_text(result);
|
||||
Global.error_dialog.popup_centered()
|
||||
|
||||
func create_new_palette(name : String, from_palette : Dictionary = {}) -> String: # Returns empty string, else error string
|
||||
var new_palette : Dictionary = {}
|
||||
func create_new_palette(name : String, from_palette : Palette) -> String: # Returns empty string, else error string
|
||||
var new_palette : Palette = Palette.new()
|
||||
|
||||
# Check if new name is valid
|
||||
if name.empty():
|
||||
|
@ -112,14 +104,10 @@ func create_new_palette(name : String, from_palette : Dictionary = {}) -> String
|
|||
new_palette.name = name
|
||||
|
||||
# Check if source palette has data
|
||||
if from_palette.has("name"):
|
||||
if from_palette:
|
||||
new_palette = from_palette.duplicate()
|
||||
new_palette.name = name
|
||||
new_palette.editable = true
|
||||
else:
|
||||
new_palette.colors = []
|
||||
new_palette.comments = ""
|
||||
new_palette.editable = true
|
||||
|
||||
# Add palette to Global and options
|
||||
Global.palettes[name] = new_palette
|
||||
|
@ -133,22 +121,22 @@ func create_new_palette(name : String, from_palette : Dictionary = {}) -> String
|
|||
on_palette_select(name)
|
||||
return ""
|
||||
|
||||
func _display_palette(palette : Dictionary) -> void:
|
||||
func _display_palette(palette : Palette) -> void:
|
||||
var index := 0
|
||||
|
||||
for color_data in palette.colors:
|
||||
var color = Color(color_data.data)
|
||||
var color = color_data.color
|
||||
var new_button = palette_button.instance()
|
||||
|
||||
new_button.get_child(0).modulate = color
|
||||
new_button.hint_tooltip = color_data.data.to_upper() + " " + color_data.name
|
||||
new_button.hint_tooltip = "#" + color_data.data.to_upper() + " " + color_data.name
|
||||
new_button.connect("pressed", self, "on_color_select", [index])
|
||||
|
||||
add_child(new_button)
|
||||
index += 1
|
||||
|
||||
func on_color_select(index : int) -> void:
|
||||
var color = Color(Global.palettes[current_palette].colors[index].data)
|
||||
var color : Color = Global.palettes[current_palette].get_color(index)
|
||||
|
||||
if Input.is_action_just_released("left_mouse"):
|
||||
Global.left_color_picker.color = color
|
||||
|
@ -173,23 +161,25 @@ func _load_palettes() -> void:
|
|||
var palette_files : Array = get_palette_files("user://palettes")
|
||||
|
||||
for file_name in palette_files:
|
||||
var result : String = load_palette("user://palettes/" + file_name)
|
||||
if result:
|
||||
Global.palette_option_button.add_item(result)
|
||||
var palette : Palette = Palette.new().load_from_file("user://palettes/" + file_name)
|
||||
if palette:
|
||||
Global.palettes[palette.name] = palette
|
||||
Global.palette_option_button.add_item(palette.name)
|
||||
var index := Global.palette_option_button.get_item_count() - 1
|
||||
Global.palette_option_button.set_item_metadata(index, result)
|
||||
if result == "Default":
|
||||
Global.palette_option_button.set_item_metadata(index, palette.name)
|
||||
if palette.name == "Default":
|
||||
Global.palette_option_button.select(index)
|
||||
|
||||
dir.open("user://palettes/custom")
|
||||
var custom_palette_files : Array = get_palette_files("user://palettes/custom")
|
||||
|
||||
for file_name in custom_palette_files:
|
||||
var result : String = load_palette("user://palettes/custom/" + file_name)
|
||||
if result:
|
||||
Global.palette_option_button.add_item(result)
|
||||
var palette : Palette = Palette.new().load_from_file("user://palettes/custom/" + file_name)
|
||||
if palette:
|
||||
Global.palettes[palette.name] = palette
|
||||
Global.palette_option_button.add_item(palette.name)
|
||||
var index := Global.palette_option_button.get_item_count() - 1
|
||||
Global.palette_option_button.set_item_metadata(index, result)
|
||||
Global.palette_option_button.set_item_metadata(index, palette.name)
|
||||
|
||||
func get_palette_files(path : String) -> Array:
|
||||
var dir := Directory.new()
|
||||
|
@ -209,41 +199,15 @@ func get_palette_files(path : String) -> Array:
|
|||
|
||||
return results
|
||||
|
||||
func load_palette(path : String) -> String:
|
||||
# Open file for reading
|
||||
var file := File.new()
|
||||
file.open(path, File.READ)
|
||||
|
||||
var text = file.get_as_text()
|
||||
var result_json = JSON.parse(text)
|
||||
var result = {}
|
||||
|
||||
var palette_name = null # Default error condition
|
||||
|
||||
if result_json.error != OK: # If parse has errors
|
||||
print("Error: ", result_json.error)
|
||||
print("Error Line: ", result_json.error_line)
|
||||
print("Error String: ", result_json.error_string)
|
||||
else: # If parse OK
|
||||
var data = result_json.result
|
||||
if data.has("name"): #If data is 'valid' palette file
|
||||
palette_name = data.name
|
||||
Global.palettes[data.name] = data
|
||||
|
||||
file.close()
|
||||
|
||||
return palette_name
|
||||
|
||||
func remove_current_palette() -> void:
|
||||
if Global.palettes[current_palette].has("editable"):
|
||||
if Global.palettes[current_palette].editable:
|
||||
_delete_palette_file(current_palette + ".json")
|
||||
Global.palettes.erase(current_palette)
|
||||
var selected_index := Global.palette_option_button.selected
|
||||
Global.palette_option_button.remove_item(selected_index)
|
||||
if(selected_index - 1 >= 0):
|
||||
Global.palette_option_button.select(selected_index - 1)
|
||||
on_palette_select(Global.palette_option_button.get_item_metadata(selected_index - 1))
|
||||
if Global.palettes[current_palette].editable:
|
||||
_delete_palette_file(current_palette + ".json")
|
||||
Global.palettes.erase(current_palette)
|
||||
var selected_index := Global.palette_option_button.selected
|
||||
Global.palette_option_button.remove_item(selected_index)
|
||||
if(selected_index - 1 >= 0):
|
||||
Global.palette_option_button.select(selected_index - 1)
|
||||
on_palette_select(Global.palette_option_button.get_item_metadata(selected_index - 1))
|
||||
pass
|
||||
|
||||
func _delete_palette_file(file_name : String) -> void:
|
||||
|
@ -251,11 +215,6 @@ func _delete_palette_file(file_name : String) -> void:
|
|||
dir.remove("user://palettes/custom/" + file_name)
|
||||
|
||||
func save_palette(palette_name : String, filename : String) -> void:
|
||||
var palette_data = Global.palettes[palette_name]
|
||||
# Open file for writing
|
||||
var file := File.new()
|
||||
file.open("user://palettes/custom/" + filename, File.WRITE)
|
||||
|
||||
# Write palette data to file
|
||||
file.store_string(JSON.print(palette_data))
|
||||
file.close()
|
||||
var palette = Global.palettes[palette_name]
|
||||
|
||||
palette.save_to_file("user://palettes/custom/" + filename)
|
|
@ -23,26 +23,39 @@ _global_script_classes=[ {
|
|||
"class": "LayerContainer",
|
||||
"language": "GDScript",
|
||||
"path": "res://Scripts/LayerContainer.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "Palette",
|
||||
"language": "GDScript",
|
||||
"path": "res://Scripts/Palette/Palette.gd"
|
||||
}, {
|
||||
"base": "Reference",
|
||||
"class": "PaletteColor",
|
||||
"language": "GDScript",
|
||||
"path": "res://Scripts/Palette/PaletteColor.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"Canvas": "",
|
||||
"Guide": "",
|
||||
"LayerContainer": ""
|
||||
"LayerContainer": "",
|
||||
"Palette": "",
|
||||
"PaletteColor": ""
|
||||
}
|
||||
|
||||
[application]
|
||||
|
||||
config/name="Pixelorama"
|
||||
config/description="A free & open-source 2D sprite editor"
|
||||
run/main_scene="res://Main.tscn"
|
||||
boot_splash/image="res://splash.png"
|
||||
boot_splash/bg_color=Color( 0.145098, 0.145098, 0.164706, 1 )
|
||||
config/icon="res://icon.png"
|
||||
config/description="A free & open-source 2D sprite editor"
|
||||
config/Version="v0.5"
|
||||
|
||||
[autoload]
|
||||
|
||||
Global="*res://Scripts/Global.gd"
|
||||
Import="*res://Scripts/Import.gd"
|
||||
|
||||
[debug]
|
||||
|
||||
|
|
Loading…
Reference in a new issue