diff --git a/project.godot b/project.godot index eacf75e..f84c3fa 100644 --- a/project.godot +++ b/project.godot @@ -22,8 +22,10 @@ config/icon="res://icon.svg" [autoload] -Windowman="*res://scripts/autoloads/windowman.gd" +WindowManager="*res://scripts/autoloads/windowman.gd" DialogueManager="*res://addons/dialogue_manager/dialogue_manager.gd" +EventManager="*res://scripts/autoloads/event_manager.gd" +Save="*res://scripts/autoloads/save.gd" [display] diff --git a/scripts/autoloads/event_manager.gd b/scripts/autoloads/event_manager.gd new file mode 100644 index 0000000..61510e1 --- /dev/null +++ b/scripts/autoloads/event_manager.gd @@ -0,0 +1 @@ +extends Node diff --git a/scripts/autoloads/event_manager.gd.uid b/scripts/autoloads/event_manager.gd.uid new file mode 100644 index 0000000..dff73a0 --- /dev/null +++ b/scripts/autoloads/event_manager.gd.uid @@ -0,0 +1 @@ +uid://b08q3lqbuoolb diff --git a/scripts/autoloads/save.gd b/scripts/autoloads/save.gd new file mode 100644 index 0000000..d0fec4e --- /dev/null +++ b/scripts/autoloads/save.gd @@ -0,0 +1,50 @@ +class_name SaveManager +extends Node + +var file: ConfigFile = ConfigFile.new() +var save_path: String = "user://save.binary" + +func get_section_name(res: Resource) -> String: + return res.resource_name if res.resource_name != "" else res.get_class() + +func save(res: Resource) -> bool: + if not is_instance_valid(res): + push_error("cannot save: invalid resource") + return false + + var section_name: String = get_section_name(res) + + if FileAccess.file_exists(save_path) and file.load(save_path) != OK: + printerr("Save file corrupted!") + return false + + file.set_value("meta", "savedate", Time.get_datetime_string_from_system()) + + for property in res.get_property_list(): + if property.usage & PROPERTY_USAGE_STORAGE: + var v_name: String = property.name + file.set_value(section_name, v_name, res.get(v_name)) + + return file.save(save_path) == OK + +func load(res: Resource) -> bool: + if not FileAccess.file_exists(save_path): + return true + if file.load(save_path) != OK: + printerr("Save file corrupted!") + return false + + var section_name: String = get_section_name(res) + var props := [] + for p in res.get_property_list(): + if p.usage & PROPERTY_USAGE_STORAGE: + props.append(p.name) + + for key in file.get_section_keys(section_name): + if key in props: + res.set(key, file.get_value(section_name, key)) + return true + +func delete() -> void: + file.clear() + file.save(save_path) diff --git a/scripts/autoloads/save.gd.uid b/scripts/autoloads/save.gd.uid new file mode 100644 index 0000000..e947ebc --- /dev/null +++ b/scripts/autoloads/save.gd.uid @@ -0,0 +1 @@ +uid://dfgqnmfb710g8 diff --git a/scripts/autoloads/windowman.gd b/scripts/autoloads/windowman.gd index f66499c..a412748 100644 --- a/scripts/autoloads/windowman.gd +++ b/scripts/autoloads/windowman.gd @@ -1,10 +1,15 @@ extends Node -@onready var fullscreen: bool = ProjectSettings.get_setting("display/window/size/mode") == Window.MODE_EXCLUSIVE_FULLSCREEN | Window.MODE_FULLSCREEN +var config: Config = Config.new() + +func _ready() -> void: + Save.load(config) + toggle_fullscreen() func _process(_delta: float) -> void: if Input.is_action_just_pressed("fullscreen"): - fullscreen = !fullscreen + config.fullscreen = !config.fullscreen + Save.save(config) toggle_fullscreen() func _notification(what: int) -> void: @@ -18,7 +23,7 @@ func _unhandled_input(event: InputEvent) -> void: Input.mouse_mode = Input.MOUSE_MODE_HIDDEN func toggle_fullscreen() -> void: - if fullscreen: + if config.fullscreen: if OS.get_name() == "Windows": DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN) else: diff --git a/scripts/player.gd b/scripts/player.gd index 9fce216..9a05664 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -31,19 +31,18 @@ func _ready() -> void: func _physics_process(delta: float) -> void: velocity = Input.get_vector("move_left","move_right","move_up","move_down").normalized() * delta * SPEED * 3 move_and_slide() - position.x = clamp(position.x, position_limit_rect.position.x, position_limit_rect.end.x) - position.y = clamp(position.y, position_limit_rect.position.y, position_limit_rect.end.y) - + position = position.clamp(position_limit_rect.position, position_limit_rect.end) - animated_sprite.flip_h = velocity.x < 0 if velocity.length() != 0: animated_sprite.play() - if velocity.x != 0: + animated_sprite.flip_h = false + if abs(velocity.x) > abs(velocity.y): animated_sprite.animation = "side" + animated_sprite.flip_h = velocity.x < 0 elif velocity.y < 0: animated_sprite.animation = "up" else: animated_sprite.animation = "down" else: animated_sprite.stop() - + diff --git a/scripts/resources/config.gd b/scripts/resources/config.gd new file mode 100644 index 0000000..1616f7b --- /dev/null +++ b/scripts/resources/config.gd @@ -0,0 +1,4 @@ +class_name Config +extends Resource + +@export var fullscreen: bool = ProjectSettings.get_setting("display/window/size/mode") == Window.MODE_EXCLUSIVE_FULLSCREEN | Window.MODE_FULLSCREEN diff --git a/scripts/resources/config.gd.uid b/scripts/resources/config.gd.uid new file mode 100644 index 0000000..babe32c --- /dev/null +++ b/scripts/resources/config.gd.uid @@ -0,0 +1 @@ +uid://b0xr7lumdnvci