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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5 #12

Merged
merged 1 commit into from
Sep 15, 2024
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
34 changes: 19 additions & 15 deletions addons/rakugo_game_template/Autoloads/SceneLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var _loaded_resource : Resource

var _scene_loading_complete : bool = false
var _background_loading : bool
var _wait_after_load : bool = true
var _force_wait_after_load : bool = true

func _check_scene_path() -> bool:
if _scene_path == null or _scene_path == "":
Expand Down Expand Up @@ -38,12 +38,13 @@ func get_resource():
_loaded_resource = current_loaded_resource
return _loaded_resource

func change_scene_to_resource() -> void:
func change_scene_to_resource(open_transition:bool = true) -> void:
var current_tree = get_tree()
current_tree.paused = true

Transitions.transition(Transitions.transition_type.Diamond)
await Transitions.animation_player.animation_finished
if open_transition:
Transitions.transition(Transitions.transition_type.Diamond)
await Transitions.animation_player.animation_finished

var err = current_tree.change_scene_to_packed(get_resource())
if err:
Expand All @@ -55,10 +56,13 @@ func change_scene_to_resource() -> void:

current_tree.paused = false

func change_scene_to_loading_screen() -> void:
func change_scene_to_loading_screen(open_transition:bool = true) -> void:
get_tree().paused = true
Transitions.transition(Transitions.transition_type.Diamond)
await Transitions.animation_player.animation_finished

if open_transition:
Transitions.transition(Transitions.transition_type.Diamond)
await Transitions.animation_player.animation_finished

var err = get_tree().call_deferred("change_scene_to_packed", _loading_screen)
if err:
push_error("failed to change scenes to loading screen: %d" % err)
Expand Down Expand Up @@ -103,23 +107,23 @@ func load_scene_in_background(scene_path : String):
ResourceLoader.load_threaded_request(_scene_path)
set_process(true)

func change_scene(scene_path : String, wait_after_load : bool = true) -> void:
func change_scene(scene_path : String, force_wait_after_load : bool = true, open_transition:bool = true) -> void:
if scene_path == null or scene_path.is_empty():
push_error("no path given to load")
return
_scene_path = scene_path
_scene_loading_complete = false
_wait_after_load = wait_after_load
_force_wait_after_load = force_wait_after_load
if ResourceLoader.has_cached(scene_path):
_scene_loading_complete = true
call_deferred("emit_signal", "scene_loaded")
if _wait_after_load:
change_scene_to_loading_screen()
if _force_wait_after_load:
change_scene_to_loading_screen(open_transition)
return
change_scene_to_resource()
change_scene_to_resource(open_transition)
return
ResourceLoader.load_threaded_request(_scene_path)
change_scene_to_loading_screen()
change_scene_to_loading_screen(open_transition)

func _ready():
set_process(false)
Expand All @@ -137,11 +141,11 @@ func _process(_delta):
if _background_loading:
set_process(false)
return
elif not _wait_after_load:
elif not _force_wait_after_load:
change_scene_to_resource()
set_process(false)
return
elif _wait_after_load and Input.is_anything_pressed():
elif _force_wait_after_load and Input.is_anything_pressed():
change_scene_to_resource()
set_process(false)
return
2 changes: 1 addition & 1 deletion scenes/Bootstrap/bootstrap.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ extends Node
#you can use this scene to show your splashscreen

func _ready():
SceneLoader.change_scene(RGT_Globals.main_menu_setting)
SceneLoader.change_scene(RGT_Globals.main_menu_setting, true, false)
2 changes: 1 addition & 1 deletion scenes/LoadingScreen/LoadingScreen.gd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func _process(_delta):
if new_progress > progress_bar.value:
progress_bar.value = new_progress
ResourceLoader.THREAD_LOAD_LOADED:
if SceneLoader._wait_after_load:
if SceneLoader._force_wait_after_load:
progress_bar.value = progress_bar.max_value
status_label.text = LOADING_COMPLETE_TEXT
continue_label.text = CONTINUE_LABEL_TEXT
Expand Down