Skip to content

Commit

Permalink
Add null unit checks for SFX and Effects
Browse files Browse the repository at this point in the history
Remove unused code from Scales
  • Loading branch information
Kvel2D committed Oct 3, 2024
1 parent 5ba8a39 commit af24582
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/singletons/effect.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func create_simple(effect_path: String, effect_pos: Vector2) -> int:
# follow the unit if it moves.
# NOTE: Effect.createSimpleAtUnit() in JASS
func create_simple_at_unit(effect_path: String, unit: Unit, body_part: Unit.BodyPart = Unit.BodyPart.CHEST, z_offset: float = 0.0) -> int:
if unit == null:
push_error("null unit passed to Effect.create_simple_at_unit()")

return create_animated(effect_path, Vector3.ZERO, 0.0)

var effect_pos: Vector3 = unit.get_body_part_position(body_part)
effect_pos.z += z_offset

Expand All @@ -57,6 +62,11 @@ func create_simple_at_unit(effect_path: String, unit: Unit, body_part: Unit.Body
# if it moves. The effect will also go away if the unit dies.
# NOTE: Effect.createSimpleOnUnit() in JASS
func create_simple_at_unit_attached(effect_path: String, unit: Unit, body_part: Unit.BodyPart = Unit.BodyPart.CHEST, z_offset: float = 0.0) -> int:
if unit == null:
push_error("null unit passed to Effect.create_simple_at_unit_attached()")

return create_animated(effect_path, Vector3.ZERO, 0.0)

var effects_container: Node = get_tree().get_root().get_node_or_null("GameScene/World/EffectsContainer")

if effects_container == null:
Expand Down
5 changes: 5 additions & 0 deletions src/singletons/sfx.gd
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func sfx_at_pos(sfx_path: String, sfx_position: Vector2, volume_db: float = 0.0,
# SFXAtUnit() from JASS creates a "simple effect" (SFX),
# where "effect" is visual, not sound.
func sfx_at_unit(sfx_path: String, unit: Unit, volume_db: float = 0.0, pitch_scale: float = 1.0):
if unit == null:
push_error("null unit passed to SFX.sfx_at_unit()")

return

var sfx_position: Vector2 = unit.get_visual_position()
sfx_at_pos(sfx_path, sfx_position, volume_db, pitch_scale)

Expand Down
7 changes: 0 additions & 7 deletions src/towers/tower_behaviors/scales.gd
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,6 @@ func on_tower_details() -> MultiboardValues:
return multiboard


# func example_pt_on_hit(p: Projectile, target: Unit):
# if target == null:
# return

# tower.do_spell_damage(target, 123, tower.calc_spell_crit_no_bonus())


# NOTE: "overchargeA()" in original script
func mock_eye_glare_st_on_damage(event: Event, _dummy: SpellDummy):
var target: Unit = event.get_target()
Expand Down

0 comments on commit af24582

Please sign in to comment.