diff --git a/assets/sounds/intro.mp4 b/assets/sounds/intro.mp4 new file mode 100644 index 0000000..3836ba5 Binary files /dev/null and b/assets/sounds/intro.mp4 differ diff --git a/assets/sounds/intro.ogv b/assets/sounds/intro.ogv new file mode 100644 index 0000000..a318536 Binary files /dev/null and b/assets/sounds/intro.ogv differ diff --git a/assets/sounds/intro.ogv.uid b/assets/sounds/intro.ogv.uid new file mode 100644 index 0000000..73754f6 --- /dev/null +++ b/assets/sounds/intro.ogv.uid @@ -0,0 +1 @@ +uid://dlnyxbrvfejbi diff --git a/project.godot b/project.godot index 88ff5ea..434ae0a 100644 --- a/project.godot +++ b/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Randoloot" -run/main_scene="res://scenes/ui/main_menu.tscn" +run/main_scene="res://scenes/ui/intro.tscn" config/features=PackedStringArray("4.7", "Forward Plus") config/icon="res://icon.svg" diff --git a/scenes/ui/intro.tscn b/scenes/ui/intro.tscn new file mode 100644 index 0000000..859de19 --- /dev/null +++ b/scenes/ui/intro.tscn @@ -0,0 +1,52 @@ +[gd_scene load_steps=3 format=3] + +[ext_resource type="Script" path="res://scripts/ui/intro.gd" id="1"] +[ext_resource type="VideoStream" path="res://assets/sounds/intro.ogv" id="2"] + +[node name="Intro" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1") + +[node name="Background" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color(0, 0, 0, 1) + +[node name="VideoAspect" type="AspectRatioContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +ratio = 1.7777778 +stretch_mode = 2 + +[node name="Video" type="VideoStreamPlayer" parent="VideoAspect"] +layout_mode = 2 +mouse_filter = 2 +stream = ExtResource("2") +expand = true + +[node name="SkipHint" type="Label" parent="."] +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -42.0 +offset_bottom = -12.0 +mouse_filter = 2 +theme_override_colors/font_color = Color(1, 1, 1, 0.8) +theme_override_colors/font_outline_color = Color(0, 0, 0, 1) +theme_override_constants/outline_size = 4 +theme_override_font_sizes/font_size = 16 +text = "SPACJA — pomiń intro" +horizontal_alignment = 1 diff --git a/scripts/ui/intro.gd b/scripts/ui/intro.gd new file mode 100644 index 0000000..67565d3 --- /dev/null +++ b/scripts/ui/intro.gd @@ -0,0 +1,26 @@ +extends Control + +const MENU := "res://scenes/ui/main_menu.tscn" +@onready var video: VideoStreamPlayer = $VideoAspect/Video +var _finished := false + +func _ready() -> void: + video.finished.connect(_finish_intro) + video.play() + +func _input(event: InputEvent) -> void: + if event is InputEventKey and event.pressed and not event.echo and (event.physical_keycode == KEY_SPACE or event.keycode == KEY_SPACE): + get_viewport().set_input_as_handled() + _finish_intro() + +func _finish_intro() -> void: + if _finished: + return + _finished = true + video.stop() + _open_menu.call_deferred() + +func _open_menu() -> void: + var error := get_tree().change_scene_to_file(MENU) + if error != OK: + push_error("Nie udało się otworzyć menu: %s" % error_string(error)) diff --git a/scripts/ui/intro.gd.uid b/scripts/ui/intro.gd.uid new file mode 100644 index 0000000..7aac664 --- /dev/null +++ b/scripts/ui/intro.gd.uid @@ -0,0 +1 @@ +uid://bsnbx40kgxhct diff --git a/tests/ships/intro_test.gd b/tests/ships/intro_test.gd new file mode 100644 index 0000000..f3e8357 --- /dev/null +++ b/tests/ships/intro_test.gd @@ -0,0 +1,28 @@ +extends Node + +func _ready() -> void: + for skip in [true, false]: + var intro := preload("res://scenes/ui/intro.tscn").instantiate() as Control + get_tree().root.add_child.call_deferred(intro) + await get_tree().process_frame + get_tree().current_scene = intro + await get_tree().create_timer(0.3).timeout + var video := intro.get_node("VideoAspect/Video") as VideoStreamPlayer + assert(video.is_playing()) + assert(video.stream is VideoStreamTheora) + assert(video.get_video_texture().get_width() == 1920) + if skip: + var event := InputEventKey.new() + event.physical_keycode = KEY_SPACE + event.pressed = true + Input.parse_input_event(event) + else: + video.finished.emit() + for frame in 5: + await get_tree().process_frame + assert(get_tree().current_scene.scene_file_path == "res://scenes/ui/main_menu.tscn") + assert(get_tree().current_scene.get_node("ShipSelectionPanel").visible == false) + get_tree().current_scene.queue_free() + await get_tree().process_frame + print("INTRO_TEST: PASS Theora playback and decoded frame, Space skip, finished signal -> menu") + get_tree().quit() diff --git a/tests/ships/intro_test.gd.uid b/tests/ships/intro_test.gd.uid new file mode 100644 index 0000000..00ea32e --- /dev/null +++ b/tests/ships/intro_test.gd.uid @@ -0,0 +1 @@ +uid://c0u13w0bfs5ry diff --git a/tests/ships/intro_test.tscn b/tests/ships/intro_test.tscn new file mode 100644 index 0000000..a63a06f --- /dev/null +++ b/tests/ships/intro_test.tscn @@ -0,0 +1,4 @@ +[gd_scene load_steps=2 format=3] +[ext_resource type="Script" path="res://tests/ships/intro_test.gd" id="1"] +[node name="IntroTest" type="Node"] +script = ExtResource("1")