Skip to content

Commit

Permalink
Merge pull request #78 from Yagich/remember-last-session
Browse files Browse the repository at this point in the history
Session saving
  • Loading branch information
mbrlabs committed Oct 27, 2021
2 parents dbf8963 + 4560f8a commit a15a06e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lorien/Config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const VERSION_STATUS := "-dev"
const VERSION_STRING := "%d.%d.%d%s" % [VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_STATUS]
const CONFIG_PATH := "user://settings.cfg"
const PALETTES_PATH := "user://palettes.cfg"
const SESSION_PATH := "user://session.cfg"
const MAX_PALETTE_SIZE := 40
const MIN_PALETTE_SIZE := 1
const DEFAULT_CANVAS_COLOR := Color("202124")
Expand Down
10 changes: 10 additions & 0 deletions lorien/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func _ready():

# Create the default project
_create_active_default_project()

# Check if the session file exists
var file = ConfigFile.new()
if file.load(Config.SESSION_PATH) == 0:
for i in range(0, file.get_section_keys("last").size()):
_on_open_project(file.get_value("last", str(i)))

# Open project passed as CLI argument
for arg in OS.get_cmdline_args():
Expand All @@ -87,6 +93,10 @@ func _notification(what):
if ProjectManager.has_unsaved_changes():
_exit_dialog.call_deferred("popup")
else:
var file := ConfigFile.new()
for i in range(0, ProjectManager.get_open_projects().size()):
file.set_value("last", str(i), ProjectManager.get_open_projects()[i].filepath)
file.save(Config.SESSION_PATH)
get_tree().quit()

elif NOTIFICATION_WM_FOCUS_IN == what:
Expand Down
4 changes: 4 additions & 0 deletions lorien/ProjectManager/ProjectManager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,7 @@ func get_project_count() -> int:
# -------------------------------------------------------------------------------------------------
func is_active_project(project: Project) -> bool:
return _active_project == project

# -------------------------------------------------------------------------------------------------
func get_open_projects() -> Array:
return _open_projects

0 comments on commit a15a06e

Please sign in to comment.