Make loading work

This commit is contained in:
Hamcha 2019-06-01 23:52:16 +02:00
parent 0139ebbd30
commit 10a1f37794
Signed by: hamcha
GPG key ID: A40413D21021EAEE
10 changed files with 158 additions and 11 deletions

View file

@ -10,6 +10,7 @@ signal card_dropped_anim()
signal card_menu()
signal card_moved(origin, direction, t)
signal card_clicked()
signal loaded()
var clicked := false
var exhausted := false
@ -99,6 +100,7 @@ func _card_fetched(result: int, response_code: int, headers: PoolStringArray, bo
texture.create_from_image(img)
mat.albedo_texture = texture
cardImage.set_surface_material(0, mat)
emit_signal("loaded")
func tween_move_to(targetPos: Vector3, duration: float = 0.1):
$Tween.interpolate_property(self, "translation",

50
Scenes/Global/Loader.gd Normal file
View file

@ -0,0 +1,50 @@
extends Node
var loadingScreen = preload("res://Scenes/Loading.tscn")
var loader: ResourceInteractiveLoader = null
var current_scene = null
var load_next: String = ""
onready var root = get_tree().get_root()
onready var loading = $LoadingScreen
func _ready():
set_process(false)
func load_scene(path: String):
current_scene = root.get_child(root.get_child_count() -1)
loading.fade_in()
load_next = path
var delay := 0.1
var cur_delay := 0.0
func set_new_scene(scene):
current_scene.queue_free()
var instance = scene.instance()
instance.connect("loaded", self, "_fade_out")
root.add_child(instance)
root.move_child(instance, 0)
func _process(delta):
if loader == null:
# no need to process anymore
set_process(false)
return
cur_delay += delta
if cur_delay > delay:
cur_delay = 0
var err = loader.poll()
if err == ERR_FILE_EOF: # Finished loading.
var resource = loader.get_resource()
loader = null
set_new_scene(resource)
func _fade_in():
loader = ResourceLoader.load_interactive(load_next)
set_process(true)
func _fade_out():
loading.fade_out()

10
Scenes/Global/Loader.tscn Normal file
View file

@ -0,0 +1,10 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://Scenes/Global/Loader.gd" type="Script" id=1]
[ext_resource path="res://Scenes/Loading.tscn" type="PackedScene" id=2]
[node name="Node" type="Node"]
script = ExtResource( 1 )
[node name="LoadingScreen" parent="." instance=ExtResource( 2 )]
[connection signal="faded_in" from="LoadingScreen" to="." method="_fade_in"]

View file

@ -33,6 +33,30 @@ tracks/1/keys = {
"method": "scatter_in"
} ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("TextureRect:visible")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 0.5 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ false, true ]
}
tracks/3/type = "value"
tracks/3/path = NodePath(".:mouse_filter")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0, 0.2 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ 2, 0 ]
}
[sub_resource type="Animation" id=2]
resource_name = "fade_out"
@ -63,10 +87,35 @@ tracks/1/keys = {
"method": "scatter_out"
} ]
}
tracks/2/type = "value"
tracks/2/path = NodePath("TextureRect:visible")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"times": PoolRealArray( 0, 0.8 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ true, false ]
}
tracks/3/type = "value"
tracks/3/path = NodePath(".:mouse_filter")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0, 0.8 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ 0, 2 ]
}
[node name="LoadingScreen" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
script = ExtResource( 1 )
[node name="Cards" type="Node2D" parent="."]
@ -75,12 +124,15 @@ scale = Vector2( 0.5, 0.5 )
script = ExtResource( 2 )
[node name="TextureRect" type="TextureRect" parent="."]
modulate = Color( 1, 1, 1, 0.784314 )
visible = false
modulate = Color( 1, 1, 1, 0 )
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
texture = ExtResource( 3 )
expand = true
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/fade_in = SubResource( 1 )
anims/fade_out = SubResource( 2 )
[connection signal="animation_finished" from="AnimationPlayer" to="." method="_on_animation_finished"]

View file

@ -1,13 +1,18 @@
extends Control
var passed := 0.0
var once := true
signal faded_in()
signal faded_out()
func _ready():
func fade_in():
$AnimationPlayer.play("fade_in")
func _process(delta):
passed += delta
if passed > 5.0 and once:
$AnimationPlayer.play("fade_out")
once = false
func fade_out():
$AnimationPlayer.play("fade_out")
func _on_animation_finished(anim_name):
match anim_name:
"fade_in":
emit_signal("faded_in")
"fade_out":
$Cards.cleanup()
emit_signal("faded_out")

View file

@ -77,4 +77,8 @@ func scatter_in():
func scatter_out():
for card in get_children():
card.tweenTo(Vector2((card.position.x / 2)-3000, (card.position.y)-1800), PI)
card.tweenTo(Vector2((card.position.x / 2)-3000, (card.position.y)-1800), PI)
func cleanup():
for card in get_children():
card.queue_free()

View file

@ -2,6 +2,8 @@ extends Spatial
class_name Board
signal loaded()
onready var CardTemplate := preload("res://Scenes/Components/Card.tscn")
onready var camera := $Camera
@ -18,6 +20,7 @@ var currentZone: Stack = null
var mouseOrigin: Vector2
var lastCameraTransform: Transform
var cardsToLoad: int = 0
onready var zones: Dictionary = {
"player1.deck": $Cards/P1Deck,
@ -39,6 +42,7 @@ func _ready():
"pr10","pr11","pr12","pr13","pr14","pr15","pr16","pr12","pr13","pr14",
"pr10","pr11","pr12","pr13","pr14","pr15","pr16","pr12","pr13","pr14"
]
cardsToLoad = len(deck)
# Fill deck with cards
for card in deck:
add_card(card, 0, "player1.deck")
@ -191,6 +195,11 @@ func _card_menu_action(id: int, card: Card):
card.animation.queue("flip")
card.flipped = true
func _card_loaded():
cardsToLoad -= 1
if cardsToLoad <= 0:
emit_signal("loaded")
func reparent(object: Node, from: Node, to: Node):
from.remove_child(object)
to.add_child(object)
@ -215,6 +224,7 @@ func add_card(cardID: String, playerID: int, zone: String):
card.connect("card_moved", self, "_card_moved", [card])
card.connect("card_menu", ui, "show_card_menu", [card, self, "_card_menu_action"])
card.connect("card_clicked", self, "_card_clicked", [card])
card.connect("loaded", self, "_card_loaded")
if card.inHand:
# TODO support for >2 players
if playerID == 0:

5
Scenes/SplashScreen.gd Normal file
View file

@ -0,0 +1,5 @@
extends Control
func _ready():
#TODO Splash screen
Loader.load_scene("res://Scenes/Board.tscn")

8
Scenes/SplashScreen.tscn Normal file
View file

@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Scenes/SplashScreen.gd" type="Script" id=1]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )

View file

@ -45,13 +45,14 @@ _global_script_class_icons={
[application]
config/name="MLP CARD GAME"
run/main_scene="res://Scenes/Board.tscn"
run/main_scene="res://Scenes/SplashScreen.tscn"
config/icon="res://icon.png"
[autoload]
Remote="*res://Scenes/Global/Remote.tscn"
Mods="*res://Scenes/Global/Mods.tscn"
Loader="*res://Scenes/Global/Loader.tscn"
[display]