fixed loading bug
This commit is contained in:
parent
4750befdfb
commit
5708cf5ea2
14 changed files with 421 additions and 98 deletions
43
MainMenu.gd
43
MainMenu.gd
|
@ -1,20 +1,41 @@
|
|||
extends Control
|
||||
|
||||
const MAIN_SCENE_PATH = "res://main.tscn"
|
||||
var tip_level = 1
|
||||
var config = ConfigFile.new()
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
$Layout/Play.disabled = true
|
||||
ResourceLoader.load_threaded_request(MAIN_SCENE_PATH)
|
||||
if config.load("user://settings.cfg") == OK:
|
||||
if config.get_value("hidden", "tip_level") == null:
|
||||
tip_level = 1
|
||||
config.set_value("hidden", "tip_level", tip_level)
|
||||
else:
|
||||
tip_level = config.get_value("hidden", "tip_level")
|
||||
|
||||
if randi_range(0, 20) == 5: # small chance to get more and more insane tips as you keep playing
|
||||
tip_level += 1
|
||||
config.set_value("hidden", "tip_level", tip_level)
|
||||
|
||||
func pick(l):
|
||||
return l[randi_range(0, len(l)-1)]
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
var progress = ResourceLoader.load_threaded_get_status(MAIN_SCENE_PATH)
|
||||
if progress == ResourceLoader.THREAD_LOAD_LOADED:
|
||||
$Layout/Play.disabled = false
|
||||
$Layout/Play.text = "Play"
|
||||
func sort_tips():
|
||||
var tips = FileAccess.open("res://tips.txt", FileAccess.READ).get_as_text().strip_edges().split("\n")
|
||||
var tips_by_level = {1: [], 2: [], 3: []}
|
||||
for tip in tips:
|
||||
var level = int(tip.split(" | ")[0])
|
||||
var text = tip.split(" | ")[1]
|
||||
tips_by_level[level].append(text)
|
||||
return tips_by_level
|
||||
|
||||
func play():
|
||||
var game = ResourceLoader.load_threaded_get(MAIN_SCENE_PATH)
|
||||
get_tree().change_scene_to_packed(game)
|
||||
$"LoadingScreen".show()
|
||||
var tip_options = []
|
||||
for i in range(1, tip_level+1):
|
||||
tip_options += sort_tips()[i]
|
||||
|
||||
var tip = pick(tip_options)
|
||||
$LoadingScreen/Tip.text = "Tip: %s" % tip
|
||||
await get_tree().create_timer(0.2).timeout
|
||||
#var game = ResourceLoader.load_threaded_get(MAIN_SCENE_PATH)
|
||||
get_tree().change_scene_to_file(MAIN_SCENE_PATH)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue