forked from team-sg/hero-mark-2
score submission :)
This commit is contained in:
parent
f7581231e8
commit
5610401840
4 changed files with 335 additions and 5 deletions
98
menus/submit_score.gd
Normal file
98
menus/submit_score.gd
Normal file
|
@ -0,0 +1,98 @@
|
|||
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")
|
||||
_set_tag()
|
||||
$"%YesScore".grab_focus()
|
||||
Fade.fade_in(0.4)
|
||||
|
||||
|
||||
func _on_YesScore_pressed() -> void:
|
||||
_scoreboard_id = LevelData.levels[Game.current_level].scores_id
|
||||
_score_value = Game.final_score
|
||||
print(_score_value)
|
||||
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)
|
||||
print(_score_value)
|
||||
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(0.4)
|
||||
yield(Fade, "fade_finished")
|
||||
SceneManager.change_scene(LevelSelect.instance())
|
||||
|
||||
|
||||
func _set_tag() -> 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 Game.has_collection_bonus():
|
||||
_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
|
Loading…
Add table
Add a link
Reference in a new issue