소스 검색

implemented calculator logic and added preview node

Jonathan Higgins 6 달 전
부모
커밋
e815ae6d78
5개의 변경된 파일91개의 추가작업 그리고 12개의 파일을 삭제
  1. 4 0
      scenes/Nodes/audioplayer.gd
  2. 17 5
      scenes/Nodes/calculator.gd
  3. 54 6
      scenes/Nodes/nodes.tscn
  4. 11 0
      scenes/main/process_help.json
  5. 5 1
      scenes/main/scripts/run_thread.gd

+ 4 - 0
scenes/Nodes/audioplayer.gd

@@ -78,6 +78,10 @@ func _on_file_selected(path: String):
 	set_meta("inputfile", path)
 	reset_playback()
 	
+	#output signal that the input has loaded and it is safe to continue with running thread
+	#Used for preview nodes in run_thread to avoid deleting the input file before it is done loading
+	
+	
 func reset_playback():
 	$LoopRegion.size.x = 0
 	$Playhead.position.x = 0

+ 17 - 5
scenes/Nodes/calculator.gd

@@ -1,7 +1,8 @@
 extends GraphNode
 
-var calulated = false
+var calculated = false
 var expression = ""
+var lastresult = 0.0
 signal open_help
 
 func _ready() -> void:
@@ -39,17 +40,28 @@ func _open_help():
 	open_help.emit(self.get_meta("command"), self.title)
 	
 func calculate(button: Button):
-	print("button pressed")
 	var label = button.text
 	var value = button.get_meta("calc")
-	print(label)
-	print(value)
+	
+	if calculated == true:
+		$Screen.text = ""
+		expression = ""
+		calculated = false
+		if value in ["+", "-", "*", "/"]:
+			$Screen.text += str(lastresult)
+			expression += str(lastresult)
+			
 	
 	if value == "clear":
 		$Screen.text = ""
 	elif value == "del":
 		$Screen.text = $Screen.text.substr(0, $Screen.text.length() - 1)
 	elif value == "=":
-		pass
+		var expr = Expression.new()
+		expr.parse(expression)
+		lastresult = expr.execute()
+		$Screen.text += "\n= " + str(lastresult)
+		calculated = true
 	else:
 		$Screen.text += label
+		expression += value

+ 54 - 6
scenes/Nodes/nodes.tscn

@@ -55,6 +55,43 @@ layout_mode = 2
 metadata/loadenable = true
 metadata/inputfunction = "audioplayer"
 
+[node name="preview" type="GraphNode" parent="."]
+layout_mode = 0
+offset_left = 26.0
+offset_top = 283.0
+offset_right = 454.0
+offset_bottom = 513.0
+tooltip_text = "Stores your input file to be processed. Supports mono and stereo .wav files."
+title = "Preview"
+slot/0/left_enabled = true
+slot/0/left_type = 0
+slot/0/left_color = Color(1, 1, 1, 1)
+slot/0/left_icon = null
+slot/0/right_enabled = false
+slot/0/right_type = 0
+slot/0/right_color = Color(1, 1, 1, 0.564706)
+slot/0/right_icon = null
+slot/0/draw_stylebox = true
+slot/1/left_enabled = false
+slot/1/left_type = 0
+slot/1/left_color = Color(1, 1, 1, 1)
+slot/1/left_icon = null
+slot/1/right_enabled = false
+slot/1/right_type = 0
+slot/1/right_color = Color(1, 1, 1, 1)
+slot/1/right_icon = null
+slot/1/draw_stylebox = true
+script = ExtResource("3_uv17x")
+metadata/command = "preview"
+metadata/input = false
+
+[node name="Control" type="Control" parent="preview"]
+layout_mode = 2
+
+[node name="AudioPlayer" parent="preview" groups=["inputnode"] instance=ExtResource("2_b6nw4")]
+layout_mode = 2
+metadata/inputfunction = "audioplayer"
+
 [node name="outputfile" type="GraphNode" parent="."]
 layout_mode = 0
 offset_left = 523.0
@@ -601,18 +638,29 @@ slot/5/right_type = 0
 slot/5/right_color = Color(1, 1, 1, 1)
 slot/5/right_icon = null
 slot/5/draw_stylebox = true
+slot/6/left_enabled = false
+slot/6/left_type = 0
+slot/6/left_color = Color(1, 1, 1, 1)
+slot/6/left_icon = null
+slot/6/right_enabled = false
+slot/6/right_type = 0
+slot/6/right_color = Color(1, 1, 1, 1)
+slot/6/right_icon = null
+slot/6/draw_stylebox = true
 script = ExtResource("8_5syjs")
 metadata/command = "calculator"
 metadata/utility = true
 metadata/input = false
 
-[node name="Screen" type="RichTextLabel" parent="calculator"]
+[node name="Screen" type="CodeEdit" parent="calculator"]
 custom_minimum_size = Vector2(0, 100)
 layout_mode = 2
-theme_override_font_sizes/normal_font_size = 24
-bbcode_enabled = true
-scroll_following = true
-horizontal_alignment = 2
+theme_override_font_sizes/font_size = 25
+editable = false
+
+[node name="MarginContainer7" type="MarginContainer" parent="calculator"]
+layout_mode = 2
+theme_override_constants/margin_bottom = 4
 
 [node name="HBoxContainer" type="HBoxContainer" parent="calculator"]
 custom_minimum_size = Vector2(0, 50)
@@ -695,7 +743,7 @@ metadata/calc = "6"
 [node name="Button4" type="Button" parent="calculator/HBoxContainer2"]
 layout_mode = 2
 size_flags_horizontal = 3
-text = "x"
+text = "×"
 metadata/calc = "*"
 
 [node name="HBoxContainer3" type="HBoxContainer" parent="calculator"]

+ 11 - 0
scenes/main/process_help.json

@@ -5394,5 +5394,16 @@
 	"stereo": false,
 	"subcategory": "utility",
 	"title": "Notes"
+  },
+  "preview": {
+	"category": "utility",
+	"description": "Connect this node to a point in your thread to preview the output file at that point. Note many of these in a thread may cause lag with long input files.\n",
+	"inputtype": "",
+	"outputtype": "",
+	"parameters": {},
+	"short_description": "Connect inside thread to preview output at that point",
+	"stereo": false,
+	"subcategory": "utility",
+	"title": "Preview"
   }
 }

+ 5 - 1
scenes/main/scripts/run_thread.gd

@@ -377,7 +377,11 @@ func run_thread_with_branches():
 					# Mark file for cleanup if needed
 					if control_script.delete_intermediate_outputs:
 						intermediate_files.append(output_file)
-
+				elif node.get_meta("command") == "preview":
+					var preview_audioplayer = node.get_child(1)
+					preview_audioplayer._on_file_selected(current_infile)
+					if current_infile in intermediate_files:
+						intermediate_files.erase(current_infile)
 				else:
 					#Detect if input file is mono or stereo
 					var input_stereo = await is_stereo(current_infile)