mirror of
				https://github.com/tonytins/CozyPixelStudio.git
				synced 2025-11-03 23:44:42 -05:00 
			
		
		
		
	Set up xdg thing, now for the loader modification nyaa ^.^
This commit is contained in:
		
							parent
							
								
									89c125a4a9
								
							
						
					
					
						commit
						1593c5c12b
					
				
					 3 changed files with 77 additions and 2 deletions
				
			
		| 
						 | 
					@ -7,6 +7,7 @@ enum Brush_Types {PIXEL, CIRCLE, FILLED_CIRCLE, FILE, RANDOM_FILE, CUSTOM}
 | 
				
			||||||
var root_directory := "."
 | 
					var root_directory := "."
 | 
				
			||||||
var window_title := "" setget title_changed # Why doesn't Godot have get_window_title()?
 | 
					var window_title := "" setget title_changed # Why doesn't Godot have get_window_title()?
 | 
				
			||||||
var config_cache := ConfigFile.new()
 | 
					var config_cache := ConfigFile.new()
 | 
				
			||||||
 | 
					var directory_module := preload("res://Scripts/XDGDataPaths.gd")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# warning-ignore:unused_class_variable
 | 
					# warning-ignore:unused_class_variable
 | 
				
			||||||
var loaded_locales : Array
 | 
					var loaded_locales : Array
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ extends GridContainer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const palette_button = preload("res://Prefabs/PaletteButton.tscn")
 | 
					const palette_button = preload("res://Prefabs/PaletteButton.tscn")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var palettes_path := "Palettes"
 | 
					var palettes_path := "Palettes"
 | 
				
			||||||
var current_palette = "Default"
 | 
					var current_palette = "Default"
 | 
				
			||||||
var from_palette : Palette
 | 
					var from_palette : Palette
 | 
				
			||||||
| 
						 | 
					@ -154,9 +155,16 @@ func on_color_select(index : int) -> void:
 | 
				
			||||||
		Global.update_right_custom_brush()
 | 
							Global.update_right_custom_brush()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _load_palettes() -> void:
 | 
					func _load_palettes() -> void:
 | 
				
			||||||
 | 
						# These are the paths for looking for palettes.
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						# The user path for palettes.
 | 
				
			||||||
 | 
						# this directory is created if it does not exist.
 | 
				
			||||||
 | 
						var user_palette_directory := Global.directory_module.get_palette_write_path()
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	palettes_path = Global.root_directory.plus_file("Palettes")
 | 
						palettes_path = Global.root_directory.plus_file("Palettes")
 | 
				
			||||||
	var dir := Directory.new()
 | 
						var dir := Directory.new()
 | 
				
			||||||
	dir.open(Global.root_directory)
 | 
						dir.open(Global.root_directory)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	if not dir.dir_exists(palettes_path):
 | 
						if not dir.dir_exists(palettes_path):
 | 
				
			||||||
		dir.make_dir(palettes_path)
 | 
							dir.make_dir(palettes_path)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -194,6 +202,7 @@ func get_palette_files(path : String) -> Array:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func save_palette(palette_name : String, filename : String) -> void:
 | 
					func save_palette(palette_name : String, filename : String) -> void:
 | 
				
			||||||
	var palette = Global.palettes[palette_name]
 | 
						var palette = Global.palettes[palette_name]
 | 
				
			||||||
 | 
						var palettes_write_path:= Global.directory_module.get_palette_write_path()
 | 
				
			||||||
	palette.save_to_file(palettes_path.plus_file(filename))
 | 
						palette.save_to_file(palettes_path.plus_file(filename))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,6 +9,9 @@ const default_xdg_data_dirs := ["/usr/local/share", "/usr/share"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const config_subdir_name := "pixelorama"
 | 
					const config_subdir_name := "pixelorama"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const palettes_data_subdirectory := "Palettes"
 | 
				
			||||||
 | 
					const brushes_data_subdirectory := "Brushes"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Declare member variables here. Examples:
 | 
					# Declare member variables here. Examples:
 | 
				
			||||||
# var a = 2
 | 
					# var a = 2
 | 
				
			||||||
# var b = "text"
 | 
					# var b = "text"
 | 
				
			||||||
| 
						 | 
					@ -17,8 +20,70 @@ const config_subdir_name := "pixelorama"
 | 
				
			||||||
# Called when the node enters the scene tree for the first time.
 | 
					# Called when the node enters the scene tree for the first time.
 | 
				
			||||||
func _ready():
 | 
					func _ready():
 | 
				
			||||||
	if OS.has_feature("X11"):
 | 
						if OS.has_feature("X11"):
 | 
				
			||||||
		xdg_data_home = OS.get_environment("HOME").plus_file(default_xdg_data_home_rel)
 | 
							var home := OS.get_environment("HOME")
 | 
				
			||||||
 | 
							xdg_data_home = home.plus_file(
 | 
				
			||||||
 | 
								default_xdg_data_home_rel
 | 
				
			||||||
 | 
							).plus_file(
 | 
				
			||||||
 | 
								config_subdir_name
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							# Create defaults
 | 
				
			||||||
 | 
							xdg_data_dirs = []
 | 
				
			||||||
 | 
							for default_loc in default_xdg_data_dirs:
 | 
				
			||||||
 | 
								xdg_data_dirs.append(
 | 
				
			||||||
 | 
									default_loc.plus_file(config_subdir_name)
 | 
				
			||||||
 | 
								)
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
							# Now check the XDG environment variables and if
 | 
				
			||||||
 | 
							# present, replace the defaults with them!
 | 
				
			||||||
 | 
							# See: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
 | 
				
			||||||
 | 
							# Checks the xdg data home var
 | 
				
			||||||
 | 
							if OS.has_environment("XDG_DATA_HOME"):
 | 
				
			||||||
 | 
								xdg_data_home = OS.get_environment("XDG_DATA_HOME").plus_file(config_subdir_name)
 | 
				
			||||||
 | 
							# Checks the list of files var, and processes them.
 | 
				
			||||||
 | 
							if OS.has_environment("XDG_DATA_DIRS"):
 | 
				
			||||||
 | 
								var raw_env_var := OS.get_environment("XDG_DATA_DIRS")
 | 
				
			||||||
 | 
								# includes empties.
 | 
				
			||||||
 | 
								var unappended_subdirs := raw_env_var.split(":", true)
 | 
				
			||||||
 | 
								xdg_data_dirs = []
 | 
				
			||||||
 | 
								for unapp_subdir in unappended_subdirs:
 | 
				
			||||||
 | 
									xdg_data_dirs.append(unapp_subdir.plus_file(config_subdir_name))
 | 
				
			||||||
 | 
								
 | 
				
			||||||
 | 
						else:
 | 
				
			||||||
 | 
							xdg_data_home = Global.root_directory
 | 
				
			||||||
 | 
							xdg_data_dirs = []
 | 
				
			||||||
 | 
						 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func append_file_to_all(basepaths: Array, subpath: String) -> Array:
 | 
				
			||||||
 | 
						var res := []
 | 
				
			||||||
 | 
						for _path in basepaths:
 | 
				
			||||||
 | 
							res.append(_path.plus_file(subpath))
 | 
				
			||||||
 | 
						return res
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Get search paths in order of priority
 | 
				
			||||||
 | 
					func get_search_paths_in_order() -> Array:
 | 
				
			||||||
 | 
						return [xdg_data_home] + xdg_data_dirs
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					# Gets the paths, in order of search priority, for palettes.
 | 
				
			||||||
 | 
					func get_palette_search_path_in_order() -> Array:
 | 
				
			||||||
 | 
						var base_paths := get_search_paths_in_order()
 | 
				
			||||||
 | 
						return append_file_to_all(base_paths, palettes_data_subdirectory)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Gets the paths, in order of search priority, for brushes.
 | 
				
			||||||
 | 
					func get_brushes_search_path_in_order() -> Array:
 | 
				
			||||||
 | 
						var base_paths := get_search_paths_in_order()
 | 
				
			||||||
 | 
						return append_file_to_all(base_paths, brushes_data_subdirectory)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Get the path that we are ok to be writing palettes to:
 | 
				
			||||||
 | 
					func get_palette_write_path() -> String:
 | 
				
			||||||
 | 
						return xdg_data_home.plus_file(palettes_data_subdirectory)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					# Get the path that we are ok to be writing brushes to:
 | 
				
			||||||
 | 
					func get_brushes_write_path() -> String:
 | 
				
			||||||
 | 
						return xdg_data_home.plus_file(brushes_data_subdirectory)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue