From da5afd485a330af2749590a823b77a6971d68b18 Mon Sep 17 00:00:00 2001
From: Florent Berthaut <florent.berthaut@univ-lille.fr>
Date: Wed, 6 Sep 2023 14:20:58 +0200
Subject: [PATCH] Fixed array in tunnels and midi values

---
 core/IvmiNode.gd                            |  2 +-
 techniques/control/Tunnel/Tunnel.gd         | 14 ++++++++++----
 techniques/control/Tunnel/TunnelPreset.tscn |  6 +++---
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/core/IvmiNode.gd b/core/IvmiNode.gd
index ecb8ea4..a53a245 100644
--- a/core/IvmiNode.gd
+++ b/core/IvmiNode.gd
@@ -136,7 +136,7 @@ func _get_ivmi_type():
 	return _ivmi_type
 
 func _process(delta):	
-	if !Engine.is_editor_hint(): 
+	if is_inside_tree(): 
 		#get cam dist if needed
 		if _properties["distance_to_camera"]._listen:
 			var cam_pos = get_viewport().get_camera_3d().to_global(Vector3(0,0,0))
diff --git a/techniques/control/Tunnel/Tunnel.gd b/techniques/control/Tunnel/Tunnel.gd
index 5c20130..b538e25 100644
--- a/techniques/control/Tunnel/Tunnel.gd
+++ b/techniques/control/Tunnel/Tunnel.gd
@@ -56,11 +56,14 @@ func _update_slices() :
 		s.scale.z = 0.5
 		s.rotation_degrees.x = 0
 		for param in tunnel_preset_array[_preset_index]:
-			var value
+			var value : float
 			if param.data_type == DATA_TYPE.array:
 				value = _find_value_in_array(ratio,param.array)
 			else:
 				value = param.curve.sample(ratio)
+			
+			if value > 1.0 :
+				value/=127
 				
 			match param.name:
 				"tunnel_color_scale" :
@@ -94,6 +97,8 @@ func _physics_process(delta):
 								value = _find_value_in_array(ratio,param.array)
 							else:
 								value = param.curve.sample(ratio)
+							if value > 1.0 :
+								value/=127
 							col.set_property(param.name, [value])
 
 func get_extent():
@@ -101,10 +106,11 @@ func get_extent():
 
 # Find the highest vec.x < x in the array
 func _find_value_in_array(x,array):
+	var val : float = array[array.size()-1].y
 	for vec in array:
-		if x<=vec.x:
-			return vec.y
-	return array[array.size()-1].y
+		if vec.x<=x:
+			val = vec.y
+	return val
 
 func _cycle_preset():
 	_preset_index = (_preset_index+1)%tunnel_preset_array.size()
diff --git a/techniques/control/Tunnel/TunnelPreset.tscn b/techniques/control/Tunnel/TunnelPreset.tscn
index c64e947..89a083a 100644
--- a/techniques/control/Tunnel/TunnelPreset.tscn
+++ b/techniques/control/Tunnel/TunnelPreset.tscn
@@ -1,6 +1,6 @@
-[gd_scene load_steps=2 format=2]
+[gd_scene load_steps=2 format=3 uid="uid://dnssxrdl7c38r"]
 
-[ext_resource path="res://addons/ivmi-builder/techniques/control/Tunnel/TunnelPreset.gd" type="Script" id=1]
+[ext_resource type="Script" path="res://addons/ivmi-builder/techniques/control/Tunnel/TunnelPreset.gd" id="1"]
 
 [node name="TunnelPreset" type="Node3D"]
-script = ExtResource( 1 )
+script = ExtResource("1")
-- 
GitLab