Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Merge pull request #335 from jebedaia360/save_load_fix
Browse files Browse the repository at this point in the history
Fix save/load bug
  • Loading branch information
Jeremi360 authored Apr 9, 2020
2 parents 6309d09 + 555cfe3 commit 08557e5
Show file tree
Hide file tree
Showing 18 changed files with 1,271 additions and 18,931 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ saves/
.directory
.vscode/
.*.kra
reference.json
2 changes: 2 additions & 0 deletions addons/Rakugo/lib/load_file.gd
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ func invoke(save_folder: String, save_name: String, variables: Dictionary):
true
)

yield(r, "started")

for node in r.get_tree().get_nodes_in_group("save"):
if node.has_method("on_load"):
node.on_load(r.game_version)
Expand Down
3 changes: 2 additions & 1 deletion addons/Rakugo/nodes/character.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func _ready() -> void:
func _on_start() -> void:
var dict := get_dict()
character = Rakugo.character(_id, dict)
var dbg = Rakugo.debug_dict(dict, character.parameters_names, "Set Character " + _id + " with ")
var dbg = Rakugo.debug_dict(dict,
character.parameters_names, "Set Character with id: " + _id)


func _set_character_id(value: String) -> void:
Expand Down
24 changes: 11 additions & 13 deletions addons/Rakugo/nodes/rakugo_anim_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ var node_link: NodeLink
func _ready() -> void:
_set_saveable(_saveable)

if _node_id.empty():
_node_id = name

if Engine.editor_hint:
if node_id.empty():
node_id = name
return

Rakugo.connect("play_anim", self, "_on_play")
Rakugo.connect("stop_anim", self, "_on_stop")

if node_id.empty():
node_id = name

node_link = Rakugo.get_node_link(node_id)
node_link = Rakugo.get_node_link(_node_id)

if not node_link:
node_link = Rakugo.node_link(node_id, get_path())
node_link = Rakugo.node_link(_node_id, get_path())


func _set_node_id(value: String):
Expand Down Expand Up @@ -61,14 +59,14 @@ func _get_saveable() -> bool:


func _on_play(id: String, anim_name: String) -> void:
if id != node_id:
if id != _node_id:
return

play(anim_name)


func _on_stop(id: String, reset: bool) -> void:
if id != node_id:
if id != _node_id:
return

if not is_playing():
Expand All @@ -83,7 +81,7 @@ func _on_stop(id: String, reset: bool) -> void:

func on_save():
if not node_link:
push_error("error with saving: %s" %node_id)
push_error("error with saving: %s" %_node_id)
return

node_link.value["anim_name"] = current_animation
Expand All @@ -92,18 +90,18 @@ func on_save():

func on_load(game_version: String) -> void:
if not node_link:
push_error("error with loading: %s" %node_id)
push_error("error with loading: %s" %_node_id)
return

if "is_playing" in node_link.value:
if node_link.value["is_playing"]:
if "anim_name" in node_link.value:
var anim_name = node_link.value["anim_name"]
_on_play(node_id, anim_name)
_on_play(_node_id, anim_name)


func _exit_tree() -> void:
if Engine.editor_hint:
return

Rakugo.variables.erase(node_id)
Rakugo.variables.erase(_node_id)
39 changes: 18 additions & 21 deletions addons/Rakugo/nodes/rakugo_audio_player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class_name RakugoAudioPlayer, "res://addons/Rakugo/icons/rakugo_audio_player.svg

export var node_id : String = name setget _set_node_id, _get_node_id
export var saveable := true setget _set_saveable, _get_saveable

var node_link: NodeLink
var last_pos := 0.0
var _node_id := ""
Expand All @@ -12,23 +13,19 @@ var _saveable := true
func _ready() -> void:
_set_saveable(_saveable)

if Engine.editor_hint:

if node_id.empty():
node_id = name
if _node_id.empty():
_node_id = name

return
if Engine.editor_hint:
return

Rakugo.connect("play_audio", self, "_on_play")
Rakugo.connect("stop_audio", self, "_on_stop")

if node_id.empty():
node_id = name
node_link = Rakugo.get_node_link(_node_id)

node_link = Rakugo.get_node_link(node_id)

if not node_link:
node_link = Rakugo.node_link(node_id, get_path())
if not node_link:
node_link = Rakugo.node_link(_node_id, get_path())


func _set_node_id(value: String):
Expand Down Expand Up @@ -63,15 +60,15 @@ func _get_saveable() -> bool:


func _on_play(id: String, from_pos := 0.0) -> void:
if id != node_id:
if id != _node_id:
return

last_pos = from_pos
play(from_pos)


func _on_stop(id: String) -> void:
if id != node_id:
if id != _node_id:
return

if not is_playing():
Expand All @@ -82,10 +79,10 @@ func _on_stop(id: String) -> void:

func on_save():
if not node_link:
if node_id != "":
push_error("error with saveing: %s" %node_id)
if _node_id != "":
push_error("error with saveing: %s" % _node_id)
else:
push_error("error with saveing: %s it propably it don't have id" %name)
push_error("error with saveing: %s it propably it don't have id" % name)
return

node_link.value["is_playing"] = is_playing()
Expand All @@ -94,23 +91,23 @@ func on_save():

func on_load(game_version: String) -> void:
if not node_link:
if node_id != "":
push_error("error with loading: %s" %node_id)
if _node_id != "":
push_error("error with loading: %s" %_node_id)
else:
push_error("error with loading: %s it propably it don't have id" %name)
return

if "is_playing" in node_link:
if node_link.value["is_playing"]:
var last_pos = node_link.value["from_pos"]
_on_play(node_id, last_pos)
_on_play(_node_id, last_pos)

else:
_on_stop(node_id)
_on_stop(_node_id)


func _exit_tree() -> void:
if Engine.editor_hint:
return

Rakugo.variables.erase(node_id)
Rakugo.variables.erase(_node_id)
31 changes: 10 additions & 21 deletions addons/Rakugo/nodes/rakugo_avatar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,25 @@ var avatar_link: Avatar
func _ready():
_set_saveable(_saveable)

if _avatar_id.empty():
_avatar_id = name

if Engine.editor_hint:
if avatar_id.empty():
avatar_id = name
return

Rakugo.connect("show", self, "_on_show")
rnode.connect("on_substate", self, "_on_substate")

if avatar_id.empty():
avatar_id = name

avatar_link = Rakugo.get_avatar_link(avatar_id)
avatar_link = Rakugo.get_avatar_link(_avatar_id)

if not avatar_link:
avatar_link = Rakugo.avatar_link(avatar_id, get_path())
avatar_link = Rakugo.avatar_link(_avatar_id, get_path())

else:
avatar_link.node_path = get_path()

add_to_group("save", true)

var node_link = Rakugo.get_node_link(avatar_id)
var node_link = Rakugo.get_node_link(_avatar_id)

if node_link:
if "state" in node_link.value:
Expand Down Expand Up @@ -81,8 +78,8 @@ func _get_saveable() -> bool:
return _saveable


func _on_show(avatar_id: String, state_value: Array, show_args: Dictionary) -> void:
if self.avatar_id != avatar_id:
func _on_show(id: String, state_value: Array, show_args: Dictionary) -> void:
if _avatar_id != id:
return

_set_state(state_value)
Expand All @@ -103,23 +100,15 @@ func _set_state(value: Array) -> void:

func _get_state() -> Array:
return _state


func _exit_tree() -> void:
if Engine.editor_hint:
return

var id = Avatar.new("").var_prefix + avatar_id
Rakugo.variables.erase(id)



func on_save() -> void:
avatar_link.value["state"] = _state


func on_load(game_version: String) -> void:
_state = avatar_link.value["state"]
_on_show(avatar_id, _state , {})
_on_show(_avatar_id, _state , {})


func _on_substate(substate):
Expand Down
27 changes: 20 additions & 7 deletions addons/Rakugo/nodes/rakugo_base_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ func connect_if_not(sig:String, target:Node, method:String):


func upadate_colors():
if _use_colors_from_theme:
var rt := theme as RakugoTheme
idle_node_color = rt.idle_node_color
focus_node_color = rt.focus_node_color
hover_node_color = rt.hover_node_color
pressed_node_color = rt.pressed_node_color
disable_node_color = rt.disable_node_color
load_theme()
if _use_colors_from_theme:
var rt := theme as RakugoTheme
if rt:
idle_node_color = rt.idle_node_color
focus_node_color = rt.focus_node_color
hover_node_color = rt.hover_node_color
pressed_node_color = rt.pressed_node_color
disable_node_color = rt.disable_node_color


func set_colors_from_theme(value: bool):
Expand Down Expand Up @@ -104,3 +106,14 @@ func set_disabled(value: bool) -> void:
return

_on_idle()


func load_theme():
var path = ProjectSettings.get_setting("application/rakugo/theme")
var cfg_path = ProjectSettings.get_setting("application/config/project_settings_override")
if cfg_path:
var cfg := ConfigFile.new()
cfg.load(cfg_path)
path = cfg.get_value("application", "rakugo/theme")

theme = load(path)
13 changes: 8 additions & 5 deletions addons/Rakugo/nodes/rakugo_base_control.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ func get_use_theme_form_settings() -> bool:


func load_theme():
theme = load(
ProjectSettings.get_setting(
"application/rakugo/theme"
)
)
var path = ProjectSettings.get_setting("application/rakugo/theme")
var cfg_path = ProjectSettings.get_setting("application/config/project_settings_override")
if cfg_path:
var cfg := ConfigFile.new()
cfg.load(cfg_path)
path = cfg.get_value("application", "rakugo/theme")

theme = load(path)
Loading

0 comments on commit 08557e5

Please sign in to comment.