Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement labeled and discrete parameters #235

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions demo/addons/fmod/tool/property_editors/FmodEventEditorProperty.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,53 @@ func _update_parameters():

var property_matching = existing_parameter_ids.map(func(id): return false)

for param in event_description.get_parameters():
for param: FmodParameterDescription in event_description.get_parameters():
var parameter_name = param.get_name()
var parameter_id_param = "%s/%s/id" % [EVENT_PARAMETER_PREFIX_FOR_PROPERTIES, parameter_name]
var parameter_value_param = "%s/%s/value" % [EVENT_PARAMETER_PREFIX_FOR_PROPERTIES, parameter_name]
var parameter_min_value_param = "%s/%s/min_value" % [EVENT_PARAMETER_PREFIX_FOR_PROPERTIES, parameter_name]
var parameter_max_value_param = "%s/%s/max_value" % [EVENT_PARAMETER_PREFIX_FOR_PROPERTIES, parameter_name]
var parameter_default_value_param = "%s/%s/default_value" % [EVENT_PARAMETER_PREFIX_FOR_PROPERTIES, parameter_name]
var parameter_variant_type = "%s/%s/variant_type" % [EVENT_PARAMETER_PREFIX_FOR_PROPERTIES, parameter_name]
var parameter_labels = "%s/%s/labels" % [EVENT_PARAMETER_PREFIX_FOR_PROPERTIES, parameter_name]

var existing_property_name_index = existing_property_ids.find(parameter_id_param)
var are_properties_already_in_node = existing_property_name_index != -1

var parameter_id = param.get_id()

var variant_type: Variant.Type = TYPE_FLOAT
var default_value = param.get_default_value()
var minimum_value = param.get_minimum()
var maximum_value = param.get_maximum()
if param.is_labeled():
variant_type = TYPE_STRING
default_value = event_description.get_parameter_label_by_id(parameter_id, default_value)
minimum_value = event_description.get_parameter_label_by_id(parameter_id, minimum_value)
maximum_value = event_description.get_parameter_label_by_id(parameter_id, maximum_value)
elif param.is_discrete():
variant_type = TYPE_INT
default_value = int(default_value)
minimum_value = int(minimum_value)
maximum_value = int(maximum_value)

if are_properties_already_in_node:
property_matching[existing_property_name_index] = existing_parameter_ids[existing_property_name_index] == parameter_id

if not are_properties_already_in_node or get_edited_object()[parameter_id_param] == null:
get_edited_object()[parameter_id_param] = parameter_id
if not are_properties_already_in_node or get_edited_object()[parameter_value_param] == null:
get_edited_object()[parameter_value_param] = param.get_default_value()
get_edited_object()[parameter_value_param] = default_value
if not are_properties_already_in_node or get_edited_object()[parameter_min_value_param] == null:
get_edited_object()[parameter_min_value_param] = param.get_minimum()
get_edited_object()[parameter_min_value_param] = minimum_value
if not are_properties_already_in_node or get_edited_object()[parameter_max_value_param] == null:
get_edited_object()[parameter_max_value_param] = param.get_maximum()
get_edited_object()[parameter_max_value_param] = maximum_value
if not are_properties_already_in_node or get_edited_object()[parameter_default_value_param] == null:
get_edited_object()[parameter_default_value_param] = param.get_default_value()
get_edited_object()[parameter_default_value_param] = default_value
if not are_properties_already_in_node or get_edited_object()[parameter_variant_type] == null:
get_edited_object()[parameter_variant_type] = variant_type
if param.is_labeled() and (not are_properties_already_in_node or get_edited_object()[parameter_labels] == null):
get_edited_object()[parameter_labels] = event_description.get_parameter_labels_by_id(parameter_id)

for i in property_matching.size():
if not property_matching[i]:
Expand Down
1 change: 1 addition & 0 deletions demo/addons/fmod/tool/ui/EventParametersDisplay.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func set_fmod_event(event: FmodEventDescription) -> bool: # returns false if the
show()
for parameter : FmodParameterDescription in event_parameters:
var parameter_display: ParameterDisplay = parameter_display_scene.instantiate()
parameter_display.set_event_description(event)
parameter_display.set_parameter(parameter)
if %ParameterDisplaysContainer.get_child_count() > 0:
%ParameterDisplaysContainer.add_child(HSeparator.new())
Expand Down
18 changes: 17 additions & 1 deletion demo/addons/fmod/tool/ui/ParameterDisplay.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
@tool class_name ParameterDisplay extends MarginContainer

var event_description: FmodEventDescription
var parameter: FmodParameterDescription

func set_event_description(p_event_description: FmodEventDescription):
event_description = p_event_description

func set_parameter(p_parameter: FmodParameterDescription):
show()
parameter = p_parameter
Expand All @@ -24,7 +28,19 @@ func _ready():

%NameLabel.text = parameter.get_name()
%IdLabel.text = str(parameter.get_id())
%RangeLabel.text = "[%s, %s]" % [minimum_value, maximum_value]
if parameter.is_labeled():
%RangeTitle.text = "Values"
var values_text = "["
var is_first: bool = true
for label: String in event_description.get_parameter_labels_by_id(parameter.get_id()):
if not is_first:
values_text += ", "
values_text += label
is_first = false
values_text += "]"
%RangeLabel.text = values_text
else:
%RangeLabel.text = "[%s, %s]" % [minimum_value, maximum_value]
%DefaultValueLabel.text = str(default_value)
%NameCopyButton.pressed.connect(_on_copy_name_button)
%IdCopyButton.pressed.connect(_on_copy_id_button)
Expand Down
2 changes: 2 additions & 0 deletions demo/addons/fmod/tool/ui/ParameterDisplay.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[ext_resource type="Script" path="res://addons/fmod/tool/ui/ParameterDisplay.gd" id="1_fxyw8"]

[node name="ParameterDisplay" type="MarginContainer"]
visible = false
offset_right = 168.0
offset_bottom = 160.0
size_flags_horizontal = 3
Expand Down Expand Up @@ -33,6 +34,7 @@ size_flags_vertical = 10
text = "ID: "

[node name="RangeTitle" type="Label" parent="VBoxContainer/VBoxContainer/TitleContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 10
text = "Range: "
Expand Down
10 changes: 9 additions & 1 deletion demo/high_level_2D/FmodNodesTest.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="Script" path="res://high_level_2D/sin_move.gd" id="1_2lkrj"]
[ext_resource type="Script" path="res://high_level_2D/Emitter.gd" id="2_5cntr"]
[ext_resource type="Texture2D" uid="uid://c872sqsokojxe" path="res://icon.png" id="2_llv2n"]
[ext_resource type="Texture2D" uid="uid://dichdnwxg2opa" path="res://icon.png" id="2_llv2n"]
[ext_resource type="Script" path="res://high_level_2D/Kinematic.gd" id="3_dlbku"]
[ext_resource type="Script" path="res://high_level_2D/ChangeColor.gd" id="5_5p5kb"]
[ext_resource type="Script" path="res://low_level_2D/EnterAndLeave.gd" id="5_jxvuy"]
Expand Down Expand Up @@ -40,11 +40,13 @@ event_parameter/RPM/value = 600.0
event_parameter/RPM/min_value = 0.0
event_parameter/RPM/max_value = 10000.0
event_parameter/RPM/default_value = 0.0
event_parameter/RPM/variant_type = 3
event_parameter/Load/id = -1795603775021193717
event_parameter/Load/value = -1.0
event_parameter/Load/min_value = -1.0
event_parameter/Load/max_value = 1.0
event_parameter/Load/default_value = -1.0
event_parameter/Load/variant_type = 3
self_modulate = Color(0.988235, 0, 0, 1)
position = Vector2(-3.05176e-05, 0)
script = ExtResource("2_5cntr")
Expand Down Expand Up @@ -121,6 +123,12 @@ script = ExtResource("5_5p5kb")
event_name = "event:/Music/Level 02"
event_guid = "{c7f946fd-d695-499b-a820-752799c4921d}"
autoplay = true
event_parameter/Area/id = 2292969625611591407
event_parameter/Area/value = 0.0
event_parameter/Area/min_value = 0.0
event_parameter/Area/max_value = 80.0
event_parameter/Area/default_value = 0.0
event_parameter/Area/variant_type = 3

[node name="CollisionShape2D" type="CollisionShape2D" parent="FmodBankLoader/SoundArea2"]
position = Vector2(52.8021, 45.8286)
Expand Down
6 changes: 3 additions & 3 deletions demo/high_level_3D/FPSCounter.gd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extends Label

func _ready():
set_process(true)
set_process(true)
func _process(_delta: float):
self.text = 'FPS: %s' % Engine.get_frames_per_second()
self.text = 'FPS: %s' % Engine.get_frames_per_second()
5 changes: 5 additions & 0 deletions demo/high_level_3D/World.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ event_parameter/RPM/value = 1000.0
event_parameter/RPM/min_value = 0.0
event_parameter/RPM/max_value = 10000.0
event_parameter/RPM/default_value = 0.0
event_parameter/RPM/variant_type = 3
event_parameter/Load/id = -1795603775021193717
event_parameter/Load/value = -1.0
event_parameter/Load/min_value = -1.0
event_parameter/Load/max_value = 1.0
event_parameter/Load/default_value = -1.0
event_parameter/Load/variant_type = 3
script = ExtResource("4_vlj6k")

[node name="Ball2" parent="." instance=ExtResource("3_bkia1")]
Expand All @@ -75,11 +77,13 @@ event_parameter/Size/value = 0.5
event_parameter/Size/min_value = 0.0
event_parameter/Size/max_value = 3.0
event_parameter/Size/default_value = 0.0
event_parameter/Size/variant_type = 3
event_parameter/Distance/id = -6363846794978107960
event_parameter/Distance/value = 3.40282e+38
event_parameter/Distance/min_value = 0.0
event_parameter/Distance/max_value = 100.0
event_parameter/Distance/default_value = 3.40282e+38
event_parameter/Distance/variant_type = 3
script = ExtResource("4_mxf3j")

[node name="Ball3" parent="." instance=ExtResource("3_bkia1")]
Expand All @@ -95,6 +99,7 @@ event_parameter/Speed/value = 0.0
event_parameter/Speed/min_value = 0.0
event_parameter/Speed/max_value = 8.0
event_parameter/Speed/default_value = 0.0
event_parameter/Speed/variant_type = 3
script = ExtResource("5_d681a")

[node name="Wall" parent="." instance=ExtResource("4_jv1x4")]
Expand Down
4 changes: 2 additions & 2 deletions demo/high_level_3D/environment/sin_move.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extends RigidBody3D

func _process(delta: float) -> void:
var time = Time.get_ticks_msec()/1000.0
self.position.x = 10 * sin(time)
var time = Time.get_ticks_msec()/1000.0
self.position.x = 10 * sin(time)
12 changes: 6 additions & 6 deletions demo/high_level_3D/environment/soundcollider.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ var moving := false

func _process(_delta: float):

var parent: RigidBody3D = get_parent()
if moving == false and parent.linear_velocity.length() > 1:
moving = true
self.play()
elif parent.linear_velocity.length() < 1:
moving = false
var parent: RigidBody3D = get_parent()
if moving == false and parent.linear_velocity.length() > 1:
moving = true
self.play()
elif parent.linear_velocity.length() < 1:
moving = false
86 changes: 43 additions & 43 deletions demo/high_level_3D/player/Camera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,60 +6,60 @@ extends Camera3D
const CAMERA_TURN_SPEED = 200

func _ready():
## Tell Godot that we want to handle input
set_process_input(true)
## Tell Godot that we want to handle input
set_process_input(true)

func look_updown_rotation(new_rotation = 0):
"""
Returns a new Vector3 which contains only the x direction
We'll use this vector to compute the final 3D rotation later
"""
var toReturn = self.get_rotation() + Vector3(new_rotation, 0, 0)
"""
Returns a new Vector3 which contains only the x direction
We'll use this vector to compute the final 3D rotation later
"""
var toReturn = self.get_rotation() + Vector3(new_rotation, 0, 0)

##
## We don't want the player to be able to bend over backwards
## neither to be able to look under their arse.
## Here we'll clamp the vertical look to 90° up and down
toReturn.x = clamp(toReturn.x, PI / -2, PI / 2)
##
## We don't want the player to be able to bend over backwards
## neither to be able to look under their arse.
## Here we'll clamp the vertical look to 90° up and down
toReturn.x = clamp(toReturn.x, PI / -2, PI / 2)

return toReturn
return toReturn

func look_leftright_rotation(new_rotation = 0):
"""
Returns a new Vector3 which contains only the y direction
We'll use this vector to compute the final 3D rotation later
"""
return Player.get_rotation() + Vector3(0, new_rotation, 0)
"""
Returns a new Vector3 which contains only the y direction
We'll use this vector to compute the final 3D rotation later
"""
return Player.get_rotation() + Vector3(0, new_rotation, 0)

func _input(event):
"""
First person camera controls
"""
##
## We'll only process mouse motion events
if not event is InputEventMouseMotion:
return
"""
First person camera controls
"""
##
## We'll only process mouse motion events
if not event is InputEventMouseMotion:
return

##
## We'll use the parent node "Player" to set our left-right rotation
## This prevents us from adding the x-rotation to the y-rotation
## which would result in a kind of flight-simulator camera
Player.set_rotation(look_leftright_rotation(event.relative.x / -CAMERA_TURN_SPEED))
##
## We'll use the parent node "Player" to set our left-right rotation
## This prevents us from adding the x-rotation to the y-rotation
## which would result in a kind of flight-simulator camera
Player.set_rotation(look_leftright_rotation(event.relative.x / -CAMERA_TURN_SPEED))

##
## Now we can simply set our y-rotation for the camera, and let godot
## handle the transformation of both together
self.set_rotation(look_updown_rotation(event.relative.y / -CAMERA_TURN_SPEED))
##
## Now we can simply set our y-rotation for the camera, and let godot
## handle the transformation of both together
self.set_rotation(look_updown_rotation(event.relative.y / -CAMERA_TURN_SPEED))

func _enter_tree():
"""
Hide the mouse when we start
"""
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
"""
Hide the mouse when we start
"""
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _leave_tree():
"""
Show the mouse when we leave
"""
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
"""
Show the mouse when we leave
"""
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
Loading
Loading