Skip to content

Commit 155e19f

Browse files
add and remove custom types that are present
1 parent f33f709 commit 155e19f

File tree

2 files changed

+53
-25
lines changed

2 files changed

+53
-25
lines changed

addons/health_hitbox_hurtbox/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="Health, HitBoxes, HurtBoxes, and HitScans"
44
description="2D and 3D Components to manage health, damage, and healing"
55
author="ClutteredCode"
6-
version="3.2.0"
6+
version="3.2.1"
77
script="plugin.gd"
Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,71 @@
11
@tool
22
extends EditorPlugin
33

4+
const addon_path = "res://addons/health_hitbox_hurtbox/%s"
5+
6+
var hit_box_2d_added: bool
7+
var hit_scan_2d_added: bool
8+
var hurt_box_2d_added: bool
9+
10+
var hit_box_3d_added: bool
11+
var hit_scan_3d_added: bool
12+
var hurt_box_3d_added: bool
13+
414
func _enter_tree() -> void:
515
add_custom_type("Health", "Node",
616
preload("health/health.gd"),
717
preload("health/health.svg"))
818

919
# Load 2D components
10-
add_custom_type("HitBox2D", "Area2D",
11-
preload("2d/hit_box_2d/hit_box_2d.gd"),
12-
preload("2d/hit_box_2d/hit_box_2d.svg"))
13-
add_custom_type("HitScan2D", "RayCast2D",
14-
preload("2d/hit_scan_2d/hit_scan_2d.gd"),
15-
preload("2d/hit_scan_2d/hit_scan_2d.svg"))
16-
add_custom_type("HurtBox2D", "Area2D",
17-
preload("2d/hurt_box_2d/hurt_box_2d.gd"),
18-
preload("2d/hurt_box_2d/hurt_box_2d.svg"))
20+
if FileAccess.file_exists(addon_path % "2d/hit_box_2d/hit_box_2d.gd"):
21+
hit_box_2d_added = true
22+
add_custom_type("HitBox2D", "Area2D",
23+
preload("2d/hit_box_2d/hit_box_2d.gd"),
24+
preload("2d/hit_box_2d/hit_box_2d.svg"))
25+
if FileAccess.file_exists(addon_path % "2d/hit_scan_2d/hit_scan_2d.gd"):
26+
hit_scan_2d_added = true
27+
add_custom_type("HitScan2D", "RayCast2D",
28+
preload("2d/hit_scan_2d/hit_scan_2d.gd"),
29+
preload("2d/hit_scan_2d/hit_scan_2d.svg"))
30+
if FileAccess.file_exists(addon_path % "2d/hurt_box_2d/hurt_box_2d.gd"):
31+
hurt_box_2d_added = true
32+
add_custom_type("HurtBox2D", "Area2D",
33+
preload("2d/hurt_box_2d/hurt_box_2d.gd"),
34+
preload("2d/hurt_box_2d/hurt_box_2d.svg"))
1935

2036
# Load 3D components
21-
add_custom_type("HitBox3D", "Area3D",
22-
preload("3d/hit_box_3d/hit_box_3d.gd"),
23-
preload("3d/hit_box_3d/hit_box_3d.svg"))
24-
add_custom_type("HitScan3D", "RayCast3D",
25-
preload("3d/hit_scan_3d/hit_scan_3d.gd"),
26-
preload("3d/hit_scan_3d/hit_scan_3d.svg"))
27-
add_custom_type("HurtBox3D", "Area3D",
28-
preload("3d/hurt_box_3d/hurt_box_3d.gd"),
29-
preload("3d/hurt_box_3d/hurt_box_3d.svg"))
37+
if FileAccess.file_exists(addon_path % "3d/hit_box_3d/hit_box_3d.gd"):
38+
hit_box_3d_added = true
39+
add_custom_type("HitBox3D", "Area3D",
40+
preload("3d/hit_box_3d/hit_box_3d.gd"),
41+
preload("3d/hit_box_3d/hit_box_3d.svg"))
42+
if FileAccess.file_exists(addon_path % "3d/hit_scan_3d/hit_scan_3d.gd"):
43+
hit_scan_3d_added = true
44+
add_custom_type("HitScan3D", "RayCast3D",
45+
preload("3d/hit_scan_3d/hit_scan_3d.gd"),
46+
preload("3d/hit_scan_3d/hit_scan_3d.svg"))
47+
if FileAccess.file_exists(addon_path % "3d/hurt_box_3d/hurt_box_3d.gd"):
48+
hurt_box_3d_added = true
49+
add_custom_type("HurtBox3D", "Area3D",
50+
preload("3d/hurt_box_3d/hurt_box_3d.gd"),
51+
preload("3d/hurt_box_3d/hurt_box_3d.svg"))
3052

3153

3254
func _exit_tree() -> void:
3355
remove_custom_type("Health")
3456

3557
# Remove 2D components
36-
remove_custom_type("HitBox2D")
37-
remove_custom_type("HitScan2D")
38-
remove_custom_type("HurtBox2D")
58+
if hit_box_2d_added:
59+
remove_custom_type("HitBox2D")
60+
if hit_scan_2d_added:
61+
remove_custom_type("HitScan2D")
62+
if hurt_box_2d_added:
63+
remove_custom_type("HurtBox2D")
3964

4065
# Remove 3D components
41-
remove_custom_type("HitBox3D")
42-
remove_custom_type("HitScan3D")
43-
remove_custom_type("HurtBox3D")
66+
if hit_box_3d_added:
67+
remove_custom_type("HitBox3D")
68+
if hit_scan_3d_added:
69+
remove_custom_type("HitScan3D")
70+
if hurt_box_3d_added:
71+
remove_custom_type("HurtBox3D")

0 commit comments

Comments
 (0)