One_Eleven_Android/scripts/CustomControls/Lightning.gd
2024-11-10 03:34:28 +03:00

74 lines
1.6 KiB
GDScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends Node2D
var state;
var playerReference:AudioStreamPlayer;
var scenePath;
var imagesLoaded;
func _ready():
pass;
func Init(number:int, audioPlayer:AudioStreamPlayer):
state = number;
playerReference = audioPlayer;
imagesLoaded = false;
var _temp = SceneLoader.connect("on_scene_loaded", self, "ImagesLoaded");
scenePath = str("res://resources/customControls/Lightning/Lightning", number, ".tscn");
if not ResourceLoader.exists(scenePath):
OS.alert("МОЛНИИ НЕТ!!!");
SceneLoader.load_scene(scenePath)
func SetPosition(pos:Vector2, _scale:Vector2):
yield (get_tree().create_timer(0.1), "timeout");
position = pos;
scale = _scale;
func ImagesLoaded(obj):
if obj.path != scenePath:
return ;
add_child(obj.instance);
obj.instance.connect("animation_finished", self, "_on_Animation_animation_finished");
imagesLoaded = true;
SceneLoader.disconnect("on_scene_loaded", self, "ImagesLoaded");
func StartAnimation():
if not has_node("Animation"):
return ;
var sprite:AnimatedSprite = $Animation;
if sprite.is_playing():
return ;
sprite.visible = true;
sprite.frame = 0;
sprite.play("default");
func _process(_delta):
if not imagesLoaded:
return ;
if playerReference == null:
return
var time = playerReference.get_playback_position();
match playerReference.stream.resource_path:
"res://resources/audio/sfx/Rain Loop.ogg":
if time >= 2.4 and time <= 2.5:
StartAnimation();
"res://resources/audio/sfx/Mayak_night.ogg":
if time >= 3.1 and time <= 3.2:
StartAnimation();
_:
pass;
func _on_Animation_animation_finished():
if has_node("Animation"):
$Animation.visible = false;