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

Some server functionality so as to communicate with other software. #577

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions material_maker/inform_label.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extends Label


# Declare member variables here. Examples:
# var a = 2
# var b = "text"


# Called when the node enters the scene tree for the first time.
func _ready():
get_parent().connect("informing", self, "_on_informing")

func _on_informing(new_text : String) -> void:
text = new_text
5 changes: 2 additions & 3 deletions material_maker/main_window.gd
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ func create_new_graph_edit_if_needed() -> MMGraphEdit:
graph_edit = new_graph_panel()
return graph_edit

func do_load_material(filename : String, update_hierarchy : bool = true) -> bool:
func do_load_material(filename : String, update_hierarchy : bool = true, try_to_rescue : bool = true) -> bool:
var graph_edit : MMGraphEdit = create_new_graph_edit_if_needed()
graph_edit.load_file(filename)
graph_edit.load_file(filename, try_to_rescue)
if update_hierarchy:
hierarchy.update_from_graph_edit(get_current_graph_edit())
return true
Expand Down Expand Up @@ -918,7 +918,6 @@ func _on_PaintEnvironment_id_pressed(id) -> void:
if paint != null:
paint.set_environment(id)


func environment_editor() -> void:
add_child(load("res://material_maker/windows/environment_editor/environment_editor.tscn").instance())

Expand Down
45 changes: 43 additions & 2 deletions material_maker/main_window.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=25 format=2]
[gd_scene load_steps=28 format=2]

[ext_resource path="res://material_maker/main_window.gd" type="Script" id=1]
[ext_resource path="res://material_maker/main_window_layout.gd" type="Script" id=2]
Expand All @@ -15,6 +15,9 @@
[ext_resource path="res://material_maker/tools/environment_manager/environment_manager.tscn" type="PackedScene" id=13]
[ext_resource path="res://material_maker/tools/library_manager/library_manager.gd" type="Script" id=14]
[ext_resource path="res://material_maker/icons/paste_none.tres" type="Texture" id=15]
[ext_resource path="res://material_maker/inform_label.gd" type="Script" id=16]
[ext_resource path="res://mml_linker/server.gd" type="Script" id=17]
[ext_resource path="res://mml_linker/PortLineEdit.gd" type="Script" id=18]

[sub_resource type="Shader" id=1]
resource_local_to_scene = true
Expand Down Expand Up @@ -167,7 +170,7 @@ margin_right = 1268.0
margin_bottom = 25.0

[node name="Menu" type="HBoxContainer" parent="VBoxContainer/TopBar"]
margin_right = 1177.0
margin_right = 993.0
margin_bottom = 25.0
size_flags_horizontal = 3

Expand All @@ -178,6 +181,41 @@ text = "File"
items = [ "New material", null, 0, false, false, 0, 0, null, "", false, "Load material", null, 0, false, false, 1, 268435535, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Save material", null, 0, false, false, 4, 268435539, null, "", false, "Save material as...", null, 0, false, false, 5, 301989971, null, "", false, "Save all materials...", null, 0, false, false, 6, 0, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Export material", null, 0, false, false, 8, 268435525, null, "", false, "", null, 0, false, false, -1, 0, null, "", true, "Close material", null, 0, false, false, 10, 0, null, "", false, "Quit", null, 0, false, false, 11, 268435537, null, "", false ]
switch_on_hover = true

[node name="Server" type="HBoxContainer" parent="VBoxContainer/TopBar"]
margin_left = 997.0
margin_right = 1177.0
margin_bottom = 25.0
script = ExtResource( 17 )

[node name="ServerStartCheckBox" type="CheckBox" parent="VBoxContainer/TopBar/Server"]
margin_right = 71.0
margin_bottom = 25.0
text = "Server"

[node name="PortLabel" type="Label" parent="VBoxContainer/TopBar/Server"]
margin_left = 75.0
margin_right = 116.0
margin_bottom = 25.0
text = "Port:"
align = 2

[node name="PortLineEdit" type="LineEdit" parent="VBoxContainer/TopBar/Server"]
margin_left = 120.0
margin_right = 180.0
margin_bottom = 25.0
text = "6001"
placeholder_text = "Port"
script = ExtResource( 18 )

[node name="InformLabel" type="Label" parent="VBoxContainer/TopBar/Server"]
visible = false
margin_left = 184.0
margin_right = 560.0
margin_bottom = 25.0
text = "The quick brown fox jumps over the lazy dog"
clip_text = true
script = ExtResource( 16 )

[node name="Share" parent="VBoxContainer/TopBar" instance=ExtResource( 12 )]
margin_left = 1181.0
margin_right = 1268.0
Expand Down Expand Up @@ -453,6 +491,9 @@ __meta__ = {
[node name="AnimationPlayer" type="AnimationPlayer" parent="UndoRedoLabel"]
anims/show = SubResource( 7 )

[connection signal="toggled" from="VBoxContainer/TopBar/Server/ServerStartCheckBox" to="VBoxContainer/TopBar/Server" method="toggle"]
[connection signal="text_entered" from="VBoxContainer/TopBar/Server/PortLineEdit" to="VBoxContainer/TopBar/Server/PortLineEdit" method="_on_PortLineEdit_text_entered"]
[connection signal="valid_port_entered" from="VBoxContainer/TopBar/Server/PortLineEdit" to="VBoxContainer/TopBar/Server" method="set_port"]
[connection signal="dragged" from="VBoxContainer/Layout" to="VBoxContainer/Layout" method="_on_Left_dragged"]
[connection signal="resized" from="VBoxContainer/Layout" to="VBoxContainer/Layout" method="_on_Layout_resized"]
[connection signal="tab_changed" from="VBoxContainer/Layout/Left/Top" to="VBoxContainer/Layout" method="_on_tab_changed"]
Expand Down
4 changes: 2 additions & 2 deletions material_maker/panels/graph_edit/graph_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,12 @@ func find_buffers(g) -> int:
rv += find_buffers(c)
return rv

func load_file(filename) -> bool:
func load_file(filename, try_to_rescue : bool = true) -> bool:
var rescued = false
var new_generator = null
var file = File.new()
var recovery_path = filename+".mmcr"
if filename != null and file.file_exists(recovery_path):
if filename != null and file.file_exists(recovery_path) and try_to_rescue:
var dialog = preload("res://material_maker/windows/accept_dialog/accept_dialog.tscn").instance()
dialog.dialog_text = "Rescue file for "+filename.get_file()+" was found.\nLoad it?"
dialog.get_ok().text = "Rescue"
Expand Down
22 changes: 22 additions & 0 deletions mml_linker/PortLineEdit.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
extends LineEdit


var previous_string : String = "6001"
signal valid_port_entered

func _ready():
pass # Replace with function body.

func _on_PortLineEdit_text_entered(string : String) -> void:
print("a")
if string == previous_string:
print("b")
return
if string.is_valid_integer():
print("c")
var int_value = int(string)
if not 1080 < int_value and int_value < 65536:
print("d")
text = previous_string
return
emit_signal("valid_port_entered", int_value)
74 changes: 74 additions & 0 deletions mml_linker/ProjectContainer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
extends Node
class_name MMLProjectContainer

# Class that finds and contains data from MM projects to be used along MMLServer

var remote_params_gens_dict : Dictionary = {}
var local_params_gens_dict : Dictionary = {}
var project : MMGraphEdit
var remote_gen : MMGenRemote
var material_node : MMGenMaterial
var remote_parameters
var local_parameters

signal warning

func init(project : MMGraphEdit):
self.project = project
material_node = project.get_material_node()
remote_gen = find_remote()
remote_parameters = find_remote_parameters()
local_parameters = find_local_parameters()

func find_remote() -> MMGenRemote:
for child in project.top_generator.get_children():
if child.get_type() == "remote":
print("\n\n\nRemote node found.\n\n\n")
emit_signal("\n\n\nRemote node found.\n\n\n")
return child
emit_signal("warning", "Warning: Remote node not found.")
return null

func find_remote_parameters() -> Array:
remote_params_gens_dict.clear()

var output = []
if remote_gen == null:
emit_signal("warning", "\n\n\nRemote node not found.\n\n\n")
return output
for widget in remote_gen.widgets:
for lw in widget.linked_widgets:
var top_gen = project.top_generator.get_node(lw.node)
var param = top_gen.get_parameter(lw.widget)
output.push_back( { 'node' : lw.node, 'param_name' : lw.widget, 'param_value' : param, 'param_label':widget.label } )
remote_params_gens_dict["{}/{}".format([lw.node, lw.widget], "{}")] = top_gen
return output

func find_local_parameters() -> Array:
var output = []
for child in project.top_generator.get_children():
if child.get_type() == "remote":
continue
for param in child.parameters:
var identifier = "{}/{}".format([child.get_hier_name(), param], "{}")
local_params_gens_dict[identifier] = child
output.push_back( { 'node' : child.get_hier_name(), 'param_name' : param, 'param_label':"", 'param_value' : child.get_parameter(param), 'param_type':child.get_parameter_def(param) } )
print("local_params_gens_dict: ", local_params_gens_dict)
return output

func set_parameter_value(node_name : String, param_name : String, value : String, is_remote : bool):
var dict = remote_params_gens_dict if is_remote else local_params_gens_dict
var identifier = "{}/{}".format([node_name, param_name], "{}")
var gen = dict[identifier]
var type = gen.get_parameter_def(param_name).type
var typed_value = null
if type == "enum" or type == "boolean" or type == "size":
typed_value = int(value)
elif type == "float":
typed_value = float(value)
elif value.is_valid_integer():
typed_value = value
else:
emit_signal("warning", "Warning: Invalid parameter value input.")
return
gen.set_parameter(param_name, typed_value)
1 change: 1 addition & 0 deletions mml_linker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# mml_linker
Loading