8000 Added Vector3 Support · DoomTas3r/changes-block-coding@5afe404 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5afe404

Browse files
committed
Added Vector3 Support
Vector3 was previously only supported as a getter block, now it also is supported as a setter along with new math blocks and a new vector3 variable block. I made the following changes - adding vector3 to the parameter_input scene - adding vector3 to types.gd - adding vector3 to blocks_catalog.gd and blocks_ast.gd - created new math blocks: vector3_x, vector3_y, vector3_z and vector3_multiply - created new vector3 variable block Fixes endlessm#330
1 parent a9c7193 commit 5afe404

File tree

10 files changed

+308
-3
lines changed

10 files changed

+308
-3
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://bff7cwmpisihj"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_52jwf"]
4+
5+
[resource]
6+
script = ExtResource("1_52jwf")
7+
name = &"vector3_multiply"
8+
target_node_class = ""
9+
description = "Multiplies a Vector3 with a number. Use this, for example, to get a point some distance away along an angle."
10+
category = "Math"
11+
type = 3
12+
variant_type = 9
13+
display_template = "multiply {vector: VECTOR3} by {number: FLOAT}"
14+
code_template = "{vector} * {number}"
15+
defaults = {
16+
"number": 1.0,
17+
"vector": Vector3(1, 1, 1)
18+
}
19+
signal_name = ""
20+
scope = ""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cehtd3jqu5es2"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_p3bft"]
4+
5+
[resource]
6+
script = ExtResource("1_p3bft")
7+
name = &"vector3_x"
8+
target_node_class = ""
9+
description = "Gives the x of a [i]Vector3[/i]"
10+
category = "Math"
11+
type = 3
12+
variant_type = 3
13+
display_template = "x of {vector3: VECTOR3}"
14+
code_template = "{vector3}.x"
15+
defaults = {
16+
"vector3": Vector3(0, 0, 0)
17+
}
18+
signal_name = ""
19+
scope = ""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cehtd3jqu5es2"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_p3bft"]
4+
5+
[resource]
6+
script = ExtResource("1_p3bft")
7+
name = &"vector3_y"
8+
target_node_class = ""
9+
description = "Gives the y of a [i]Vector3[/i]"
10+
category = "Math"
11+
type = 3
12+
variant_type = 3
13+
display_template = "y of {vector3: VECTOR3}"
14+
code_template = "{vector3}.y"
15+
defaults = {
16+
"vector3": Vector3(0, 0, 0)
17+
}
18+
signal_name = ""
19+
scope = ""
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://cehtd3jqu5es2"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_p3bft"]
4+
5+
[resource]
6+
script = ExtResource("1_p3bft")
7+
name = &"vector3_z"
8+
target_node_class = ""
9+
description = "Gives the z of a [i]Vector3[/i]"
10+
category = "Math"
11+
type = 3
12+
variant_type = 3
13+
display_template = "z of {vector3: VECTOR3}"
14+
code_template = "{vector3}.z"
15+
defaults = {
16+
"vector3": Vector3(0, 0, 0)
17+
}
18+
signal_name = ""
19+
scope = ""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[gd_resource type="Resource" load_steps=2 format=3 uid="uid://ddj24k1fp0s82"]
2+
3+
[ext_resource type="Script" path="res://addons/block_code/code_generation/block_definition.gd" id="1_ilw3v"]
4+
5+
[resource]
6+
script = ExtResource("1_ilw3v")
7+
name = &"vector3"
8+
target_node_class = ""
9+
description = ""
10+
category = "Math"
11+
type = 3
12+
variant_type = 9
13+
display_template = "vector3 x: {x: FLOAT} y: {y: FLOAT}: z: {z: FLOAT}"
14+
code_template = "Vector3({x}, {y}, {z})"
15+
defaults = {
16+
"x": 0.0,
17+
"y": 0.0,
18+
"z": 0.0
19+
}
20+
signal_name = "& 10000 quot;
21+
scope = ""

addons/block_code/code_generation/block_ast.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ static func raw_input_to_code_string(input) -> String:
131131
return "'%s'" % input.c_escape()
132132
TYPE_VECTOR2:
133133
return "Vector2%s" % str(input)
134+
TYPE_VECTOR3:
135+
return "Vector3%s" % str(input)
134136
TYPE_COLOR:
135137
return "Color%s" % str(input)
136138
_:

addons/block_code/code_generation/blocks_catalog.gd

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const _FALLBACK_SET_FOR_TYPE = {
1212
TYPE_INT: 0,
1313
TYPE_FLOAT: 0.0,
1414
TYPE_VECTOR2: Vector2(0, 0),
15+
TYPE_VECTOR3: Vector3(0, 0, 0),
1516
TYPE_COLOR: Color.DARK_ORANGE,
1617
}
1718

@@ -20,6 +21,7 @@ const _FALLBACK_CHANGE_FOR_TYPE = {
2021
TYPE_INT: 1,
2122
TYPE_FLOAT: 1.0,
2223
TYPE_VECTOR2: Vector2(1, 1),
24+
TYPE_VECTOR3: Vector3(1, 1, 1),
2325
TYPE_COLOR: Color.DARK_ORANGE,
2426
}
2527

@@ -45,6 +47,27 @@ const _SETTINGS_FOR_CLASS_PROPERTY = {
4547
"default_change": Vector2(0.1, 0.1),
4648
},
4749
},
50+
"Node3D":
51+
{
52+
"position":
53+
{
54+
"category": "Transform | Position",
55+
"default_set": Vector3(0, 0, 0),
56+
"default_change": Vector3(0.1, 0.1, 0.1),
57+
},
58+
"rotation":
59+
{
60+
"category": "Transform | Rotation",
61+
"default_set": Vector3(0, 0, 0),
62+
"default_change": Vector3(0.1, 0.1, 0.1),
63+
},
64+
"scale":
65+
{
66+
"category": "Transform | Scale",
67+
"default_set": Vector3(1, 1, 1),
68+
"default_change": Vector3(0.1, 0.1, 0.1),
69+
}
70+
},
4871
"CanvasItem":
4972
{
5073
"modulate":
@@ -280,13 +303,13 @@ static func get_variable_getter_block_definition(variable: VariableDefinition) -
280303

281304

282305
static func get_variable_setter_block_definition(variable: VariableDefinition) -> BlockDefinition:
283-
var type_string: String = Types.VARIANT_TYPE_TO_STRING[variable.var_type]
306+
var _type_string: String = Types.VARIANT_TYPE_TO_STRING[variable.var_type]
284307
var block_def := BlockDefinition.new()
285308

286309
block_def.name = "set_var_%s" % variable.var_name
287310
block_def.category = "Variables"
288311
block_def.type = Types.BlockType.STATEMENT
289-
block_def.display_template = "Set %s to {value: %s}" % [variable.var_name, type_string]
312+
block_def.display_template = "Set %s to {value: %s}" % [variable.var_name, _type_string]
290313
block_def.code_template = "%s = {value}" % variable.var_name
291314

292315
return block_def

addons/block_code/types/types.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const VARIANT_TYPE_TO_STRING: Dictionary = {
1414
TYPE_FLOAT: "FLOAT",
1515
TYPE_BOOL: "BOOL",
1616
TYPE_VECTOR2: "VECTOR2",
17+
TYPE_VECTOR3: "VECTOR3",
1718
TYPE_COLOR: "COLOR",
1819
TYPE_NODE_PATH: "NODE_PATH",
1920
TYPE_OBJECT: "OBJECT",
@@ -27,6 +28,7 @@ const STRING_TO_VARIANT_TYPE: Dictionary = {
2728
"FLOAT": TYPE_FLOAT,
2829
"BOOL": TYPE_BOOL,
2930
"VECTOR2": TYPE_VECTOR2,
31+
"VECTOR3": TYPE_VECTOR3,
3032
"COLOR": TYPE_COLOR,
3133
"NODE_PATH": TYPE_NODE_PATH,
3234
"OBJECT": TYPE_OBJECT,
@@ -42,6 +44,8 @@ const cast_relationships = [
4244
[TYPE_COLOR, TYPE_STRING, "str(%s)"],
4345
[TYPE_VECTOR2, TYPE_STRING, "str(%s)"],
4446
[TYPE_VECTOR2, TYPE_BOOL, "%s"],
47+
[TYPE_VECTOR3, TYPE_STRING, "str(%s)"],
48+
[TYPE_VECTOR3, TYPE_BOOL, "%s"],
4549
]
4650

4751
# Directed graph, edges are CastGraphEdge

addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ var _drag_start: Vector2 = Vector2.INF
3737
@onready var _vector2_input := %Vector2Input
3838
@onready var _x_line_edit := %XLineEdit
3939
@onready var _y_line_edit := %YLineEdit
40+
# Vector3
41+
@onready var _vector3_input := %Vector3Input
42+
@onready var _v3_x_line_edit := %V3XLineEdit
43+
@onready var _v3_y_line_edit := %V3YLineEdit
44+
@onready var _v3_z_line_edit := %V3ZLineEdit
4045
# Bool
4146
@onready var _bool_input := %BoolInput
4247
@onready var _bool_input_option := %BoolInputOption
@@ -46,6 +51,9 @@ var _drag_start: Vector2 = Vector2.INF
4651
_line_edit: "",
4752
_x_line_edit: "",
4853
_y_line_edit: "",
54+
_v3_x_line_edit: "",
55+
_v3_y_line_edit: "",
56+
_v3_z_line_edit: "",
4957
}
5058

5159

@@ -73,6 +81,10 @@ func set_raw_input(raw_input: Variant):
7381
# Rounding because floats are doubles by default but Vector2s have single components
7482
_x_line_edit.text = ("%.4f" % raw_input.x).rstrip("0").rstrip(".") if raw_input != null else ""
7583
_y_line_edit.text = ("%.4f" % raw_input.y).rstrip("0").rstrip(".") if raw_input != null else ""
84+
TYPE_VECTOR3:
85+
_v3_x_line_edit.text = ("%.4f" % raw_input.x).rstrip("0").rstrip(".") if raw_input != null else ""
86+
_v3_y_line_edit.text = ("%.4f" % raw_input.y).rstrip("0").rstrip(".") if raw_input != null else ""
87+
_v3_z_line_edit.text = ("%.4f" % raw_input.z).rstrip("0").rstrip(".") if raw_input != null else ""
7688
TYPE_BOOL:
7789
_bool_input_option.select(1 if raw_input else 0)
7890
TYPE_NIL:
@@ -83,6 +95,9 @@ func set_raw_input(raw_input: Variant):
8395
_last_submitted_text[_line_edit] = _line_edit.text
8496
_last_submitted_text[_x_line_edit] = _x_line_edit.text
8597
_last_submitted_text[_y_line_edit] = _y_line_edit.text
98+
_last_submitted_text[_v3_x_line_edit] = _v3_x_line_edit.text
99+
_last_submitted_text[_v3_y_line_edit] = _v3_y_line_edit.text
100+
_last_submitted_text[_v3_z_line_edit] = _v3_z_line_edit.text
86101

87102

88103
## Gets the value, which could be one of a variety of types depending on
@@ -102,6 +117,8 @@ func get_raw_input() -> Variant:
102117
return _color_input.color
103118
TYPE_VECTOR2:
104119
return Vector2(float(_x_line_edit.text), float(_y_line_edit.text))
120+
TYPE_VECTOR3:
121+
return Vector3(float(_v3_x_line_edit.text), float(_v3_y_line_edit.text), float(_v3_z_line_edit.text))
105122
TYPE_BOOL:
106123
return bool(_bool_input_option.selected)
107124
TYPE_INT:
@@ -203,6 +220,30 @@ func _on_y_line_edit_focus_exited():
203220
_validate_and_submit_edit_text(_y_line_edit, TYPE_FLOAT)
204221

205222

223+
func _on_v3_x_line_edit_text_submitted(_new_text):
224+
_validate_and_submit_edit_text(_v3_x_line_edit, TYPE_FLOAT)
225+
226+
227+
func _on_v3_x_line_edit_focus_exited():
228+
_validate_and_submit_edit_text(_v3_x_line_edit, TYPE_FLOAT)
229+
230+
231+
func _on_v3_y_line_edit_text_submitted(_new_text):
232+
_validate_and_submit_edit_text(_v3_y_line_edit, TYPE_FLOAT)
233+
234+
235+
func _on_v3_y_line_edit_focus_exited():
236+
_validate_and_submit_edit_text(_v3_y_line_edit, TYPE_FLOAT)
237+
238+
239+
func _on_v3_z_line_edit_text_submitted(_new_text):
240+
_validate_and_submit_edit_text(_v3_z_line_edit, TYPE_FLOAT)
241+
242+
243+
func _on_v3_z_line_edit_focus_exited():
244+
_validate_and_submit_edit_text(_v3_z_line_edit, TYPE_FLOAT)
245+
246+
206247
func _update_visible_input():
207248
if snap_point.has_snapped_block():
208249
_switch_input(null)
@@ -214,6 +255,8 @@ func _update_visible_input():
214255
_switch_input(_color_input)
215256
TYPE_VECTOR2:
216257
_switch_input(_vector2_input)
258+
TYPE_VECTOR3:
259+
_switch_input(_vector3_input)
217260
TYPE_BOOL:
218261
_switch_input(_bool_input)
219262
_:

0 commit comments

Comments
 (0)
0