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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session saving #78

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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