Skip to content

Commit

Permalink
Fixed fatal bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Dark-Peace authored Apr 14, 2022
1 parent 5bdcee0 commit 4bd8f48
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
52 changes: 23 additions & 29 deletions BuHSpawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ func _ready():
if not Engine.is_editor_hint():
a.add_track(Animation.TYPE_METHOD, 0)
a.track_set_path(0, self.get_path())
a.add_track(Animation.TYPE_METHOD, 1)
a.track_set_path(1, self.get_path())
assigned_animation = "Spawning"


Expand Down Expand Up @@ -167,60 +169,52 @@ func direct_spawn(bullets:Array, target:Node2D, activated:bool=true):
return bullets.duplicate()

func plan_spawn(bullets:Array, spawn_delay:float=0):
var time
if a.length < current_animation_position+spawn_delay:
time = spawn_delay-(a.length-current_animation_position)
else: time = current_animation_position+spawn_delay
var key_data = getKeyTime(spawn_delay)
var time = key_data[0]; var track = key_data[1];

var key = a.track_find_key(0, time, true)
var key = a.track_find_key(track, time, true)
if key > -1:
var args:Array = a.method_track_get_params(0,key)
var args:Array = a.method_track_get_params(track,key)
args[0].append_array(bullets)
a.track_insert_key(0, time, {"method": "_spawn_and_shoot", "args": args})
else: a.track_insert_key(0, time, {"method": "_spawn_and_shoot", "args": [bullets,[]]})
a.track_insert_key(track, time, {"method": "_spawn_and_shoot", "args": args})
else: a.track_insert_key(track, time, {"method": "_spawn_and_shoot", "args": [bullets,[]]})

if current_animation != "Spawning" and a.track_get_key_count(0) > 0: play("Spawning")


func plan_shoot(bullets:Array, shoot_delay:float=0):
var time
if a.length < current_animation_position+shoot_delay:
time = shoot_delay-(a.length-current_animation_position)
else: time = current_animation_position+shoot_delay
var key_data = getKeyTime(shoot_delay)
var time = key_data[0]; var track = key_data[1];

var key = a.track_find_key(0, time, true)
var key = a.track_find_key(track, time, true)
if key > -1:
var args:Array = a.method_track_get_params(0,key)
var args:Array = a.method_track_get_params(track,key)
args[1].append_array(bullets)
a.track_insert_key(0, time, {"method": "_spawn_and_shoot", "args": args})
else: a.track_insert_key(0, time, {"method": "_spawn_and_shoot", "args": [[],bullets]})
a.track_insert_key(track, time, {"method": "_spawn_and_shoot", "args": args})
else: a.track_insert_key(track, time, {"method": "_spawn_and_shoot", "args": [[],bullets]})

if current_animation != "Spawning" and a.track_get_key_count(0) > 0: play("Spawning")

func getKeyTime(delay):
if a.length < current_animation_position+delay:
return [delay-(a.length-current_animation_position), 1]
else: return [current_animation_position+delay, 0]

func _spawn_and_shoot(to_spawn:Array, to_shoot:Array):
_spawn(to_spawn)
_shoot(to_shoot)

func _spawn(bullets:Array):
print(current_animation_position)
for b in bullets: b.activated = true
if current_animation and a.track_get_key_count(0) > 0:
print(a.track_get_key_count(0))
a.track_remove_key_at_position(0, current_animation_position)
print(a.track_get_key_count(0))
if a.track_get_key_count(0) == 0: stop()

func _shoot(bullets:Array):
for b in bullets: b.shoot()
if current_animation and a.track_get_key_count(0) > 0:
# print(current_animation_position)
a.track_remove_key_at_position(0, current_animation_position)
if a.track_get_key_count(0) == 0: stop()




func reset_timeline(none):
a.remove_track(0)
a.add_track(Animation.TYPE_METHOD, 1)
a.track_set_path(1, self.get_path())
play("Spawning")



5 changes: 3 additions & 2 deletions Spawning.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

[sub_resource type="Animation" id=1]
resource_name = "Spawning"
length = 1000.0
loop = true
length = 999999.0
step = 0.01

[node name="SpawnerGlobal" type="AnimationPlayer"]
Expand All @@ -14,3 +13,5 @@ script = ExtResource( 1 )
__meta__ = {
"_editor_description_": ""
}

[connection signal="animation_finished" from="." to="." method="reset_timeline"]

0 comments on commit 4bd8f48

Please sign in to comment.