From f06042e7283020255540d109a3a3a63c51f8b2c5 Mon Sep 17 00:00:00 2001 From: Jazztache Date: Mon, 20 May 2024 12:10:30 +1000 Subject: [PATCH] Refactored and Documented init.gd and boot.tscn I went through and refactored some of the init.gd code to be cleaner, as well as use proper variable references. I did the same with the scene itself, renaming things to be clearer. The only major code changes was the extra loop, and some dummy comments I decided to remove. main.gd also got a bit of documentation as well. --- boot.tscn | 23 ++++++++--------- init.gd | 76 +++++++++++++++++++++++++++++++++---------------------- main.gd | 15 ++++++----- main.tscn | 5 ++-- 4 files changed, 69 insertions(+), 50 deletions(-) diff --git a/boot.tscn b/boot.tscn index c51594f..e1fe47f 100644 --- a/boot.tscn +++ b/boot.tscn @@ -20,7 +20,7 @@ grow_vertical = 2 theme = ExtResource("1_1k54t") script = ExtResource("2_vhxfp") -[node name="TextureRect" type="TextureRect" parent="."] +[node name="WhiteLogo" type="TextureRect" parent="."] modulate = Color(1, 1, 1, 0.137255) layout_mode = 0 offset_left = 124.0 @@ -31,7 +31,7 @@ pivot_offset = Vector2(250, 250) texture = ExtResource("3_gsxu1") expand_mode = 1 -[node name="TextureRect2" type="TextureRect" parent="."] +[node name="OrangeLogo" type="TextureRect" parent="."] modulate = Color(1, 0.447059, 0, 0.137255) layout_mode = 0 offset_left = -521.0 @@ -42,7 +42,7 @@ pivot_offset = Vector2(250, 250) texture = ExtResource("3_gsxu1") expand_mode = 1 -[node name="TextureRect5" type="TextureRect" parent="."] +[node name="RedLogo" type="TextureRect" parent="."] modulate = Color(1, 0.0313726, 0, 0.137255) layout_mode = 0 offset_left = -1466.0 @@ -53,7 +53,7 @@ pivot_offset = Vector2(250, 250) texture = ExtResource("3_gsxu1") expand_mode = 1 -[node name="TextureRect6" type="TextureRect" parent="."] +[node name="YellowLogo" type="TextureRect" parent="."] modulate = Color(1, 0.92549, 0, 0.137255) layout_mode = 0 offset_left = 3232.0 @@ -64,7 +64,7 @@ pivot_offset = Vector2(250, 250) texture = ExtResource("3_gsxu1") expand_mode = 1 -[node name="TextureRect3" type="TextureRect" parent="."] +[node name="GreenLogo" type="TextureRect" parent="."] modulate = Color(0.196078, 1, 0, 0.137255) layout_mode = 0 offset_left = 771.0 @@ -75,7 +75,7 @@ pivot_offset = Vector2(250, 250) texture = ExtResource("3_gsxu1") expand_mode = 1 -[node name="TextureRect4" type="TextureRect" parent="."] +[node name="BlueLogo" type="TextureRect" parent="."] modulate = Color(0, 0.0627451, 1, 0.137255) layout_mode = 0 offset_left = 1282.0 @@ -86,7 +86,7 @@ pivot_offset = Vector2(250, 250) texture = ExtResource("3_gsxu1") expand_mode = 1 -[node name="Label" type="Label" parent="."] +[node name="Initialising" type="Label" parent="."] layout_mode = 0 offset_left = 232.0 offset_top = 143.0 @@ -96,7 +96,7 @@ theme_override_fonts/font = ExtResource("4_6hwq1") theme_override_font_sizes/font_size = 40 text = "Adastral Initialising..." -[node name="Label2" type="Label" parent="."] +[node name="DebugText" type="Label" parent="."] visible = false layout_mode = 0 offset_left = 560.0 @@ -110,20 +110,19 @@ Up to date. Sanity Checks: OK. Launching." -[node name="Node2D" type="Node2D" parent="."] +[node name="MainLogoParent" type="Node2D" parent="."] visible = false position = Vector2(119, 100) metadata/_edit_group_ = true -[node name="TextureRect4" type="TextureRect" parent="Node2D"] +[node name="MainLogo" type="TextureRect" parent="MainLogoParent"] offset_right = 200.0 offset_bottom = 200.0 pivot_offset = Vector2(100, 100) texture = ExtResource("3_gsxu1") expand_mode = 1 -[node name="Label3" type="Label" parent="."] -visible = false +[node name="TitleText" type="Label" parent="."] layout_mode = 0 offset_left = 340.0 offset_top = 142.0 diff --git a/init.gd b/init.gd index 229bf38..c5184f0 100644 --- a/init.gd +++ b/init.gd @@ -1,66 +1,82 @@ extends Control -#var oops = preload("res://oops.tscn") +class_name Init -var spin_tween: Tween +## Initialises Adastral, plays a loading animation + +# Animation Variables + +var spin_tween: Tween ## The tween used for spinning in the boot animation var s: binding -# Called when the node enters the scene tree for the first time. + +# Nodes + +@onready var white_logo: TextureRect = $WhiteLogo ## White logo, used for the animation +@onready var orange_logo: TextureRect = $OrangeLogo ## Orange logo for the animation +@onready var red_logo: TextureRect = $RedLogo ## Red logo for the animation +@onready var yellow_logo: TextureRect = $YellowLogo ## Yellow logo for the animation +@onready var green_logo: TextureRect = $GreenLogo ## Green logo for the animation +@onready var blue_logo: TextureRect = $BlueLogo ## Blue logo for the animation +@onready var main_logo_parent: Node2D = $MainLogoParent ## The parent of the main logo. Used as the target to tween to in the boot animation +@onready var main_logo: TextureRect = $MainLogoParent/MainLogo ## The main logo +@onready var title_text: Label = $TitleText ## The text that reads 'Adastral' for when the boot animation completes +@onready var initialising: Label = $Initialising ## Initisalisation text that is displayed before the full boot animation + + +# Functions + +## Called when the node enters the scene tree for the first time. func _ready(): s = binding.new() s.connect("palace_started",launch) s.init_palace() -# Called every frame. 'delta' is the elapsed time since the previous frame. +## Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): pass - -func do_stuff(): +## Initialise the script, checking that Sutton has launched. +func initialise(): var main = load("res://main.tscn").instantiate() add_child(main) move_child($Control,0) $Control/Main.s = s $Control/Main.ready_after_sutton() $Control.position = Vector2(0,349) - do_the_shiny_thing() - - - - + boot_animation() +## Launch Adastral, checking the sourcemod path func launch(): if(s.find_sourcemod_path() == ""): get_tree().change_scene_to_file("res://oops.tscn") s.init_games() - call_deferred("do_stuff") + call_deferred("initialise") -func do_the_shiny_thing(): - $Label.hide() - #$Label3.show() +## Play the bootup animation +func boot_animation(): + # Hide initialisation text + initialising.hide() + # Set up initial tween conditions spin_tween = create_tween().set_loops().set_parallel() var tween = create_tween().set_parallel() var t = 1.5 var trans = Tween.TRANS_EXPO var ease = Tween.EASE_OUT - spin_tween.tween_property($Label3,"rotation_degrees",360,t).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT) - tween.tween_property($Label3,"visible_characters",8,t).set_trans(Tween.TRANS_SINE).set_ease(ease) - for x in [$TextureRect,$TextureRect2,$TextureRect3,$TextureRect4,$TextureRect5,$TextureRect6]: - tween.tween_property(x,"position",$Node2D.position,t).set_trans(trans).set_ease(ease) + spin_tween.tween_property(title_text,"rotation_degrees",360,t).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT) + tween.tween_property(title_text,"visible_characters",8,t).set_trans(Tween.TRANS_SINE).set_ease(ease) + # Iterate through all texture rects in order + for x in [white_logo,orange_logo,red_logo,yellow_logo,green_logo,blue_logo]: + tween.tween_property(x,"position",main_logo_parent.position,t).set_trans(trans).set_ease(ease) tween.tween_property(x,"size",Vector2(200,200),t).set_trans(trans).set_ease(ease) tween.tween_property(x,"pivot_offset",Vector2(100,100),t).set_trans(trans).set_ease(ease) spin_tween.tween_property(x,"rotation_degrees",360.0+180,t).set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_OUT) tween.tween_property(x,"modulate",Color.WHITE,t).set_trans(trans).set_ease(Tween.EASE_IN) await get_tree().create_timer(t+0.2).timeout - $TextureRect2.hide() - $TextureRect3.hide() - $TextureRect4.hide() - $TextureRect5.hide() - $TextureRect6.hide() - $Label3.reparent($Control/Main) + # Hide the texture rects, except for the white logo + for y in [orange_logo,red_logo,yellow_logo,green_logo,blue_logo,main_logo]: + y.hide() + # Reparent label and finish animation + title_text.reparent($Control/Main) tween = create_tween().set_parallel() tween.tween_property($Control,"position",Vector2(0,0),0.5).set_trans(Tween.TRANS_ELASTIC).set_ease(Tween.EASE_OUT) await get_tree().create_timer(0.5).timeout - $TextureRect.reparent($Control/Main,false) - - - - + white_logo.reparent($Control/Main,false) # Reparent the white instance of the logo so that main.gd can manage it. diff --git a/main.gd b/main.gd index 1fa2556..9aea2c6 100644 --- a/main.gd +++ b/main.gd @@ -150,13 +150,13 @@ func set_buttons(game_name): func apply_theme(theme_name): + # Set up variables for palletes and tweens pallete = theme_json[theme_name] var base_theme = load("res://themes/base.tres") ## we shouldn't be doing this if not pallete.has("secondary"): pallete["secondary"] = pallete["main"] var tween = get_tree().create_tween().set_parallel(true) if pallete["id"] == "adastral": - #$TextureRect2.show() $LatestVersion.hide() $InstalledVersion.hide() $Install.hide() @@ -164,21 +164,24 @@ func apply_theme(theme_name): $Panel2/Background.hide() $AboutInfo/BigLabel.visible_characters = -1 $AboutInfo.show() - if get_node_or_null("TextureRect"): - $TextureRect.show() + # Show or hide the main logo depending on if we are on the home screen. NOTE: The reason we get 'WhiteLogo' is because the node is reparented in init.gd. + if get_node_or_null("WhiteLogo"): + $WhiteLogo.show() $BottomPanel.hide() else: - if get_node_or_null("TextureRect"): - $TextureRect.hide() + if get_node_or_null("WhiteLogo"): + $WhiteLogo.hide() + # Show game version and buttons $AboutInfo.hide() $BottomPanel.show() # these all need to be tweens $Install.show() $Verify.show() $LatestVersion.show() $InstalledVersion.show() - $TextureRect2.hide() + $TextureRect2.hide() # Hide the logo $Panel2/Background.show() #$Panel2.show() + # Set text and textures $LatestVersion.text = "[left]Latest Version: [b]%s[/b]" % s.get_latest_version(theme_name) set_buttons(theme_name) var newbgtexture = load_image(pallete["bg"]) diff --git a/main.tscn b/main.tscn index aebb3db..d94a5d1 100644 --- a/main.tscn +++ b/main.tscn @@ -4,7 +4,7 @@ [ext_resource type="FontVariation" uid="uid://th0tjv2xcuen" path="res://fonts/main_font.tres" id="3_qwbhy"] [ext_resource type="Shader" path="res://tween.gdshader" id="4_5diq2"] [ext_resource type="Texture2D" uid="uid://diee7uq3voana" path="res://assets/adastral-256.svg" id="4_5x6qi"] -[ext_resource type="Texture2D" uid="uid://ccbrk3xcvf5gv" path="res://icon.svg" id="4_epacs"] +[ext_resource type="Texture2D" uid="uid://b02hkhy8f8318" path="res://icon.svg" id="4_epacs"] [ext_resource type="Script" path="res://main.gd" id="6"] [ext_resource type="Shader" path="res://rounded.gdshader" id="9_ife38"] [ext_resource type="Texture2D" uid="uid://b21fcl1p2qpc8" path="res://assets/settings.png" id="10"] @@ -179,7 +179,8 @@ theme_override_colors/font_color = Color(1, 1, 1, 1) theme_override_fonts/font = SubResource("FontVariation_sxnxf") theme_override_font_sizes/font_size = 100 text = "Adastral" -visible_ratio = -0.125 +visible_characters = 0 +visible_ratio = 0.0 [node name="Label" type="Label" parent="Main/AboutInfo"] layout_mode = 0