Prevent crash when launching frog minigame
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
class_name FrogMinigame
|
||||
extends WordsMinigame
|
||||
|
||||
const LILYPAD_TRACK_SCENE: PackedScene = preload("res://sources/minigames/frog/lilypad_track.tscn")
|
||||
const RIVER_SCENE_PATH: String = "res://sources/minigames/frog/river.tscn"
|
||||
const FROG_SCENE_PATH: String = "res://sources/minigames/frog/frog.tscn"
|
||||
const LILYPAD_TRACK_SCENE_PATH: String = "res://sources/minigames/frog/lilypad_track.tscn"
|
||||
|
||||
var difficulty_settings: Array[DifficultySettings] = [
|
||||
DifficultySettings.new(0.75, 100., 200.),
|
||||
@@ -10,14 +12,52 @@ var difficulty_settings: Array[DifficultySettings] = [
|
||||
DifficultySettings.new(0.25, 250., 350.),
|
||||
DifficultySettings.new(0.25, 300., 400.)
|
||||
]
|
||||
var river: River
|
||||
var frog: Frog
|
||||
var lilypad_track_scene: PackedScene
|
||||
|
||||
@onready var start: Control = %Start
|
||||
@onready var end: Control = %End
|
||||
@onready var frog_spawn_point: Control = %FrogSpawnPoint
|
||||
@onready var frog_despawn_point: Control = %FrogDespawnPoint
|
||||
@onready var river: River = $GameRoot/Background/River
|
||||
@onready var lilypad_tracks_container: HBoxContainer = %LilypadTracksContainer
|
||||
@onready var frog: Frog = %Frog
|
||||
|
||||
|
||||
func _setup_minigame() -> void:
|
||||
super()
|
||||
await _instantiate_subscenes()
|
||||
|
||||
|
||||
func _instantiate_subscenes() -> void:
|
||||
var background_node: Control = $GameRoot/Background
|
||||
var game_root_node: Control = $GameRoot
|
||||
|
||||
await get_tree().process_frame
|
||||
if not is_inside_tree():
|
||||
return
|
||||
|
||||
river = (load(RIVER_SCENE_PATH) as PackedScene).instantiate()
|
||||
river.name = "River"
|
||||
background_node.add_child(river)
|
||||
background_node.move_child(river, 0)
|
||||
|
||||
await get_tree().process_frame
|
||||
if not is_inside_tree():
|
||||
return
|
||||
|
||||
frog = (load(FROG_SCENE_PATH) as PackedScene).instantiate()
|
||||
frog.name = "Frog"
|
||||
frog.offset_left = 360.0
|
||||
frog.offset_top = 900.0
|
||||
frog.offset_right = 360.0
|
||||
frog.offset_bottom = 900.0
|
||||
game_root_node.add_child(frog)
|
||||
|
||||
await get_tree().process_frame
|
||||
if not is_inside_tree():
|
||||
return
|
||||
|
||||
lilypad_track_scene = load(LILYPAD_TRACK_SCENE_PATH) as PackedScene
|
||||
|
||||
|
||||
func _setup_word_progression() -> void:
|
||||
@@ -65,7 +105,7 @@ func _create_tracks() -> void:
|
||||
var current_word: Dictionary = _get_current_stimulus()
|
||||
var current_distractors: Array = _get_current_distractors()
|
||||
for index: int in range((current_word.GPs as Array).size()):
|
||||
var track: LilypadTrack = LILYPAD_TRACK_SCENE.instantiate()
|
||||
var track: LilypadTrack = lilypad_track_scene.instantiate()
|
||||
lilypad_tracks_container.add_child(track)
|
||||
track.difficulty_settings = difficulty_settings[difficulty]
|
||||
track.gp = current_word.GPs[index]
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
[ext_resource type="Script" uid="uid://b7q0v031ffg1v" path="res://sources/minigames/frog/frog_minigame.gd" id="2_0xg3r"]
|
||||
[ext_resource type="Texture2D" uid="uid://jvpu77isfi5b" path="res://assets/minigames/frog/graphics/gauge_icon_frog_empty.png" id="2_e38i1"]
|
||||
[ext_resource type="Texture2D" uid="uid://re7qgivb3n5w" path="res://assets/minigames/frog/graphics/gauge_icon_frog_full.png" id="3_vjlmb"]
|
||||
[ext_resource type="PackedScene" uid="uid://sumrd1i3g6f7" path="res://sources/minigames/frog/river.tscn" id="5_3fy8q"]
|
||||
[ext_resource type="Texture2D" uid="uid://bgi4vveige3qv" path="res://assets/minigames/frog/graphics/background.png" id="6_t6p6q"]
|
||||
[ext_resource type="PackedScene" uid="uid://bloyucpsbvpx8" path="res://sources/minigames/frog/frog.tscn" id="13_o6mls"]
|
||||
|
||||
[node name="FrogMinigame" unique_id=37863016 instance=ExtResource("1_ng5er")]
|
||||
script = ExtResource("2_0xg3r")
|
||||
@@ -32,10 +30,7 @@ grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="River" parent="GameRoot/Background" index="0" unique_id=1451318535 instance=ExtResource("5_3fy8q")]
|
||||
layout_mode = 1
|
||||
|
||||
[node name="background" type="TextureRect" parent="GameRoot/Background" index="1" unique_id=1762725401]
|
||||
[node name="background" type="TextureRect" parent="GameRoot/Background" index="0" unique_id=1762725401]
|
||||
layout_mode = 1
|
||||
anchors_preset = 11
|
||||
anchor_left = 1.0
|
||||
@@ -99,11 +94,3 @@ offset_bottom = 250.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
alignment = 1
|
||||
|
||||
[node name="Frog" parent="GameRoot" parent_id_path=PackedInt32Array(1053321881) index="3" unique_id=1044684229 instance=ExtResource("13_o6mls")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 0
|
||||
offset_left = 360.0
|
||||
offset_top = 900.0
|
||||
offset_right = 360.0
|
||||
offset_bottom = 900.0
|
||||
|
||||
@@ -3,7 +3,9 @@ extends Control
|
||||
|
||||
signal lilypad_in_center(lilypad: Lilypad)
|
||||
|
||||
const LILYPAD_SCENE: PackedScene = preload("res://sources/minigames/frog/lilypad.tscn")
|
||||
const LILYPAD_SCENE_PATH: String = "res://sources/minigames/frog/lilypad.tscn"
|
||||
|
||||
static var _lilypad_scene: PackedScene
|
||||
|
||||
var top_to_bottom: bool = false
|
||||
var is_stopped: bool = false
|
||||
@@ -79,7 +81,9 @@ func pick_distractor() -> Dictionary:
|
||||
#region Lilypads
|
||||
|
||||
func _spawn_lilypad() -> void:
|
||||
var lilypad: Lilypad = LILYPAD_SCENE.instantiate()
|
||||
if not _lilypad_scene:
|
||||
_lilypad_scene = load(LILYPAD_SCENE_PATH) as PackedScene
|
||||
var lilypad: Lilypad = _lilypad_scene.instantiate()
|
||||
lilypads.append(lilypad)
|
||||
add_child(lilypad)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user