1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-24 08:44:18 +00:00

Refactor BaseScene

This commit is contained in:
Steffo 2023-01-09 12:25:20 +01:00
parent 358871ad33
commit 4e4ce8b14c
Signed by: steffo
GPG key ID: 6965406171929D01
5 changed files with 59 additions and 33 deletions

View file

@ -1,26 +0,0 @@
extends Node
var current_scn: Node = null
func change_scene(path: String):
var res: Resource = load(path)
var scn: Node = res.instantiate()
add_child(scn)
if current_scn:
current_scn.queue_free()
current_scn = scn
func start_game():
print("Starting game...")
change_scene("res://island/Island.tscn")
func goto_menu():
print("Going to the menu...")
change_scene("res://menu/Menu.tscn")
current_scn.connect("play_pressed", start_game)
func _ready():
goto_menu()

View file

@ -1,6 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://vtsmwim5ayl8"]
[ext_resource type="Script" path="res://base/Base.gd" id="1_fhviw"]
[node name="Base" type="Node"]
script = ExtResource("1_fhviw")

46
base/BaseScene.gd Normal file
View file

@ -0,0 +1,46 @@
extends Node
class_name BaseScene
## The scene manager is about to change the scene to the Island.
signal moving_to_island()
## The scene manager has changed the scene to the Island.
signal moved_to_island()
## The scene manager is about the change the scene back to the main menu.
signal moving_to_menu()
## The scene manager has changed the scene back to the main menu.
signal moved_to_menu()
## The currently loaded scene.
var current_scene: Node = null:
get:
return current_scene
set(new_scene):
if current_scene:
current_scene.queue_free()
current_scene = new_scene
add_child(current_scene)
## Change the current scene to the Island.
func move_to_island():
print("Starting game...")
emit_signal("moving_to_island")
current_scene = load("res://island/Island.tscn").instantiate()
emit_signal("moved_to_island")
## Change the current scene to the main menu.
func move_to_menu():
print("Going to the menu...")
emit_signal("moving_to_menu")
current_scene = load("res://menu/Menu.tscn").instantiate()
current_scene.connect("play_pressed", move_to_island)
emit_signal("moved_to_menu")
func _ready():
# By default, standby in the menu
move_to_menu()

6
base/BaseScene.tscn Normal file
View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://cj86x6gplsbrb"]
[ext_resource type="Script" path="res://base/BaseScene.gd" id="1_n2o7j"]
[node name="BaseScene" type="Node"]
script = ExtResource("1_n2o7j")

View file

@ -9,6 +9,11 @@
config_version=5
_global_script_classes=[{
"base": "Node",
"class": &"BaseScene",
"language": &"GDScript",
"path": "res://base/BaseScene.gd"
}, {
"base": "Node3D",
"class": &"BaseWeapon",
"language": &"GDScript",
@ -40,6 +45,7 @@ _global_script_classes=[{
"path": "res://player/PlayerInputData.gd"
}]
_global_script_class_icons={
"BaseScene": "",
"BaseWeapon": "",
"CanSplash": "",
"CropTile": "",
@ -51,7 +57,7 @@ _global_script_class_icons={
[application]
config/name="LD52"
run/main_scene="res://base/Base.tscn"
run/main_scene="res://base/BaseScene.tscn"
config/features=PackedStringArray("4.0", "GL Compatibility")
boot_splash/bg_color=Color(0.231373, 0.490196, 0.309804, 1)
config/icon="res://assets/icon.svg"