Implement save and loading games (#8)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# The escorie main script
|
||||
# The escoria main script
|
||||
extends Node
|
||||
|
||||
# Escoria version number
|
||||
const ESCORIA_VERSION = "0.1.0"
|
||||
|
||||
# Current game state
|
||||
# * DEFAULT: Common game function
|
||||
@@ -56,31 +58,7 @@ var dialog_player
|
||||
var inventory
|
||||
|
||||
# These are settings that the player can affect and save/load later
|
||||
var settings : Dictionary
|
||||
|
||||
# These are default settings
|
||||
var settings_default : Dictionary = {
|
||||
# Text language
|
||||
"text_lang": ProjectSettings.get_setting("escoria/main/text_lang"),
|
||||
# Voice language
|
||||
"voice_lang": ProjectSettings.get_setting("escoria/main/voice_lang"),
|
||||
# Speech enabled
|
||||
"speech_enabled": ProjectSettings.get_setting("escoria/sound/speech_enabled"),
|
||||
# Master volume (max is 1.0)
|
||||
"master_volume": ProjectSettings.get_setting("escoria/sound/master_volume"),
|
||||
# Music volume (max is 1.0)
|
||||
"music_volume": ProjectSettings.get_setting("escoria/sound/music_volume"),
|
||||
# Sound effects volume (max is 1.0)
|
||||
"sfx_volume": ProjectSettings.get_setting("escoria/sound/sfx_volume"),
|
||||
# Voice volume (for speech only, max is 1.0)
|
||||
"voice_volume": ProjectSettings.get_setting("escoria/sound/speech_volume"),
|
||||
# Set fullscreen
|
||||
"fullscreen": false,
|
||||
# Allow dialog skipping
|
||||
"skip_dialog": true,
|
||||
# XXX: What is this? `achievements.gd` looks like iOS-only
|
||||
"rate_shown": false,
|
||||
}
|
||||
var settings: ESCSaveSettings
|
||||
|
||||
|
||||
# The current state of the game
|
||||
@@ -95,8 +73,8 @@ onready var main = $main
|
||||
# The escoria inputs manager
|
||||
onready var inputs_manager = $inputs_manager
|
||||
|
||||
# Savegame management
|
||||
onready var save_data = load("res://addons/escoria-core/game/core-scripts/save_data/save_data.gd").new()
|
||||
# Savegames and settings manager
|
||||
var save_manager: ESCSaveManager
|
||||
|
||||
|
||||
# Initialize various objects
|
||||
@@ -113,14 +91,13 @@ func _init():
|
||||
self.esc_compiler = ESCCompiler.new()
|
||||
self.resource_cache = ESCResourceCache.new()
|
||||
self.resource_cache.start()
|
||||
self.save_manager = ESCSaveManager.new()
|
||||
|
||||
|
||||
# Load settings
|
||||
func _ready():
|
||||
save_data.start()
|
||||
save_data.check_settings()
|
||||
var settings = save_data.load_settings(null)
|
||||
escoria.settings = parse_json(settings)
|
||||
settings = ESCSaveSettings.new()
|
||||
settings = save_manager.load_settings()
|
||||
escoria._on_settings_loaded(escoria.settings)
|
||||
|
||||
|
||||
@@ -148,7 +125,7 @@ func new_game():
|
||||
#
|
||||
# - action: type of the action to run
|
||||
# - params: Parameters for the action
|
||||
func do(action : String, params : Array = []) -> void:
|
||||
func do(action: String, params: Array = []) -> void:
|
||||
if current_state == GAME_STATE.DEFAULT:
|
||||
match action:
|
||||
"walk":
|
||||
@@ -171,7 +148,7 @@ func do(action : String, params : Array = []) -> void:
|
||||
# Walk to Position2D.
|
||||
if params[1] is Vector2:
|
||||
var target_position = params[1]
|
||||
var is_fast : bool = false
|
||||
var is_fast: bool = false
|
||||
if params.size() > 2 and params[2] == true:
|
||||
is_fast = true
|
||||
var walk_context = ESCWalkContext.new(
|
||||
@@ -195,9 +172,9 @@ func do(action : String, params : Array = []) -> void:
|
||||
|
||||
var object = self.object_manager.get_object(params[1])
|
||||
if object:
|
||||
var target_position : Vector2 = \
|
||||
var target_position: Vector2 = \
|
||||
object.node.interact_position
|
||||
var is_fast : bool = false
|
||||
var is_fast: bool = false
|
||||
if params.size() > 2 and params[2] == true:
|
||||
is_fast = true
|
||||
var walk_context = ESCWalkContext.new(
|
||||
@@ -211,7 +188,7 @@ func do(action : String, params : Array = []) -> void:
|
||||
"item_left_click":
|
||||
if params[0] is String:
|
||||
self.logger.info(
|
||||
"escoria.do() : item_left_click on item ",
|
||||
"escoria.do(): item_left_click on item ",
|
||||
[params[0]]
|
||||
)
|
||||
var item = self.object_manager.get_object(params[0])
|
||||
@@ -220,7 +197,7 @@ func do(action : String, params : Array = []) -> void:
|
||||
"item_right_click":
|
||||
if params[0] is String:
|
||||
self.logger.info(
|
||||
"escoria.do() : item_right_click on item ",
|
||||
"escoria.do(): item_right_click on item ",
|
||||
[params[0]]
|
||||
)
|
||||
var item = self.object_manager.get_object(params[0])
|
||||
@@ -230,7 +207,7 @@ func do(action : String, params : Array = []) -> void:
|
||||
var trigger_id = params[0]
|
||||
var object_id = params[1]
|
||||
var trigger_in_verb = params[2]
|
||||
self.logger.info("escoria.do() : trigger_in %s by %s" % [
|
||||
self.logger.info("escoria.do(): trigger_in %s by %s" % [
|
||||
trigger_id,
|
||||
object_id
|
||||
])
|
||||
@@ -244,7 +221,7 @@ func do(action : String, params : Array = []) -> void:
|
||||
var trigger_id = params[0]
|
||||
var object_id = params[1]
|
||||
var trigger_out_verb = params[2]
|
||||
self.logger.info("escoria.do() : trigger_out %s by %s" % [
|
||||
self.logger.info("escoria.do(): trigger_out %s by %s" % [
|
||||
trigger_id,
|
||||
object_id
|
||||
])
|
||||
@@ -299,7 +276,7 @@ func _ev_left_click_on_item(obj, event, default_action = false):
|
||||
# Don't interact after player movement towards object
|
||||
# (because object is inactive for example)
|
||||
var dont_interact = false
|
||||
var destination_position : Vector2 = main.current_scene.player.\
|
||||
var destination_position: Vector2 = main.current_scene.player.\
|
||||
global_position
|
||||
|
||||
# Create walk context
|
||||
@@ -386,16 +363,12 @@ func _ev_left_click_on_item(obj, event, default_action = false):
|
||||
# #### Parameters
|
||||
#
|
||||
# * p_settings: Loaded settings
|
||||
func _on_settings_loaded(p_settings : Dictionary) -> void:
|
||||
escoria.logger.info("******* settings loaded", p_settings)
|
||||
func _on_settings_loaded(p_settings: ESCSaveSettings) -> void:
|
||||
escoria.logger.info("******* settings loaded")
|
||||
if p_settings != null:
|
||||
settings = p_settings
|
||||
else:
|
||||
settings = {}
|
||||
|
||||
for k in settings_default:
|
||||
if !(k in settings):
|
||||
settings[k] = settings_default[k]
|
||||
settings = ESCSaveSettings.new()
|
||||
|
||||
# TODO Apply globally
|
||||
# AudioServer.set_fx_global_volume_scale(settings.sfx_volume)
|
||||
@@ -414,4 +387,3 @@ func _on_settings_loaded(p_settings : Dictionary) -> void:
|
||||
TranslationServer.set_locale(settings.text_lang)
|
||||
# music_volume_changed()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user