hero-mark-2/menus/submit_score.gd

98 lines
2.4 KiB
GDScript

extends Node
const NewgroundsLogin := preload("res://menus/newgrounds_login.tscn")
const LevelSelect := preload("res://menus/level_select_scholar.tscn")
var _scoreboard_id: int = -1
var _scoreboard_tag: String = ""
var _score_value: int = -1
onready var tab_container: TabContainer = $"%TabContainer"
func _ready() -> void:
yield(get_tree(), "idle_frame")
$"%YesScore".grab_focus()
Fade.fade_in(Options.transition_speed_secs)
func _on_YesScore_pressed() -> void:
_scoreboard_id = LevelData.levels[Game.current_level].scores_id
_score_value = Game.final_score
_set_tag(false)
tab_container.current_tab = 2
if yield(_submit(), "completed"):
tab_container.current_tab = 3
else:
tab_container.current_tab = 4
yield(get_tree().create_timer(1.0), "timeout")
tab_container.current_tab = 1
$"%YesTime".grab_focus()
func _on_NoScore_pressed() -> void:
tab_container.current_tab = 1
$"%YesTime".grab_focus()
func _on_YesTime_pressed() -> void:
_scoreboard_id = LevelData.levels[Game.current_level].times_id
_score_value = int(Game.time * 1000.0)
_set_tag(true)
tab_container.current_tab = 2
if yield(_submit(), "completed"):
tab_container.current_tab = 3
else:
tab_container.current_tab = 4
yield(get_tree().create_timer(1.0), "timeout")
_next_screen()
func _on_NoTime_pressed() -> void:
_next_screen()
func _next_screen() -> void:
Game.clear_collectibles()
Fade.fade_out(Options.transition_speed_secs)
yield(Fade, "fade_finished")
SceneManager.change_scene(LevelSelect.instance())
func _set_tag(include_completion: bool = false) -> void:
match Game.difficulty:
Game.Difficulty.SWEET:
_scoreboard_tag = "sweet"
Game.Difficulty.SALTY:
_scoreboard_tag = "salty"
Game.Difficulty.SPICY:
_scoreboard_tag = "spicy"
Game.Difficulty.PUNGENT:
_scoreboard_tag = "pungent"
if include_completion:
if Game.keys >= 50 and Game.shards >= 5:
_scoreboard_tag += "-100%"
else:
_scoreboard_tag += "-any%"
# returns true if the score was successfully submitted
func _submit() -> bool:
if Ngio.session.user == null:
var login_screen = NewgroundsLogin.instance()
add_child(login_screen)
yield(login_screen, "tree_exited")
if Ngio.session.user == null:
return false
var response = yield(Ngio.request_execute("ScoreBoard.postScore", {
id = _scoreboard_id,
tag = _scoreboard_tag,
value = _score_value,
}), "completed")
if Ngio.has_result(response):
if response.result.data.success:
return true
return false