Convert demos to Godot 4 using regular expressions in a script

This commit is contained in:
Aaron Franke
2022-03-26 05:00:50 -05:00
parent 410d783126
commit bbe50fc9da
1095 changed files with 13628 additions and 13557 deletions

View File

@@ -1,4 +1,4 @@
tool
@tool
extends Panel
# In this file, the word "silly" is used to make it obvious that the name is arbitrary.
@@ -7,20 +7,20 @@ var editor_interface
func _ready():
# Connect all of the signals we'll need to save and load silly materials
get_node("VBoxContainer/ApplyButton").connect("pressed", self, "apply_pressed")
get_node("VBoxContainer/SaveButton").connect("pressed", self, "save_pressed")
get_node("VBoxContainer/LoadButton").connect("pressed", self, "load_pressed")
get_node("SaveMaterialDialog").connect("file_selected", self, "save_file_selected")
get_node("LoadMaterialDialog").connect("file_selected", self, "load_file_selected")
VisualServer.canvas_item_set_clip(get_canvas_item(), true)
get_node(^"VBoxContainer/ApplyButton").connect(&"pressed", self.apply_pressed)
get_node(^"VBoxContainer/SaveButton").connect(&"pressed", self.save_pressed)
get_node(^"VBoxContainer/LoadButton").connect(&"pressed", self.load_pressed)
get_node(^"SaveMaterialDialog").connect(&"file_selected", self.save_file_selected)
get_node(^"LoadMaterialDialog").connect(&"file_selected", self.load_file_selected)
RenderingServer.canvas_item_set_clip(get_canvas_item(), true)
func save_pressed():
get_node("SaveMaterialDialog").popup_centered()
get_node(^"SaveMaterialDialog").popup_centered()
func load_pressed():
get_node("LoadMaterialDialog").popup_centered()
get_node(^"LoadMaterialDialog").popup_centered()
func apply_pressed():
@@ -32,7 +32,7 @@ func apply_pressed():
var material = _silly_resource_from_values().make_material()
# Go through the selected nodes and see if they have the "set_surface_material"
# function (which only MeshInstance has by default). If they do, then set the material
# function (which only MeshInstance3D has by default). If they do, then set the material
# to the silly material.
for node in selected_nodes:
if node.has_method("set_surface_material"):
@@ -71,9 +71,9 @@ func load_file_selected(path):
file.close()
return false
get_node("VBoxContainer/AlbedoColorPicker").color = silly_resource.albedo_color
get_node("VBoxContainer/MetallicSlider").value = silly_resource.metallic_strength
get_node("VBoxContainer/RoughnessSlider").value = silly_resource.roughness_strength
get_node(^"VBoxContainer/AlbedoColorPicker").color = silly_resource.albedo_color
get_node(^"VBoxContainer/MetallicSlider").value = silly_resource.metallic_strength
get_node(^"VBoxContainer/RoughnessSlider").value = silly_resource.roughness_strength
# Close the file and return true (success!)
file.close()
@@ -85,9 +85,9 @@ func load_file_selected(path):
func _silly_resource_from_values():
# Get the values from the sliders and color picker
var color = get_node("VBoxContainer/AlbedoColorPicker").color
var metallic = get_node("VBoxContainer/MetallicSlider").value
var roughness = get_node("VBoxContainer/RoughnessSlider").value
var color = get_node(^"VBoxContainer/AlbedoColorPicker").color
var metallic = get_node(^"VBoxContainer/MetallicSlider").value
var roughness = get_node(^"VBoxContainer/RoughnessSlider").value
# Make a new silly resource (which in this case actually is a node) and initialize it
var silly_resource = silly_material_resource.new()
silly_resource.init()

View File

@@ -3,9 +3,9 @@
[ext_resource path="res://addons/material_creator/material_creator.gd" type="Script" id=1]
[node name="Material Creator Plugin" type="Panel"]
margin_right = 220.0
margin_bottom = 340.0
rect_min_size = Vector2( 210, 410 )
offset_right = 220.0
offset_bottom = 340.0
rect_min_size = Vector2(210, 410)
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
@@ -15,95 +15,95 @@ __meta__ = {
anchor_left = 0.5
anchor_right = 0.5
anchor_bottom = 1.0
margin_left = -100.0
margin_right = 100.0
rect_min_size = Vector2( 0, 400 )
offset_left = -100.0
offset_right = 100.0
rect_min_size = Vector2(0, 400)
[node name="DockName" type="Label" parent="VBoxContainer"]
margin_right = 200.0
margin_bottom = 30.0
rect_min_size = Vector2( 200, 30 )
offset_right = 200.0
offset_bottom = 30.0
rect_min_size = Vector2(200, 30)
custom_constants/shadow_as_outline = 1
text = "Material creator"
align = 1
valign = 2
[node name="AlbedoLabel" type="Label" parent="VBoxContainer"]
margin_top = 34.0
margin_right = 200.0
margin_bottom = 64.0
rect_min_size = Vector2( 200, 30 )
offset_top = 34.0
offset_right = 200.0
offset_bottom = 64.0
rect_min_size = Vector2(200, 30)
text = "Albedo color"
align = 1
valign = 2
[node name="AlbedoColorPicker" type="ColorPickerButton" parent="VBoxContainer"]
margin_top = 68.0
margin_right = 200.0
margin_bottom = 98.0
rect_min_size = Vector2( 200, 30 )
color = Color( 1, 1, 1, 1 )
offset_top = 68.0
offset_right = 200.0
offset_bottom = 98.0
rect_min_size = Vector2(200, 30)
color = Color(1, 1, 1, 1)
[node name="MetallicLabel" type="Label" parent="VBoxContainer"]
margin_top = 102.0
margin_right = 200.0
margin_bottom = 132.0
rect_min_size = Vector2( 200, 30 )
offset_top = 102.0
offset_right = 200.0
offset_bottom = 132.0
rect_min_size = Vector2(200, 30)
text = "Metallic strength"
align = 1
valign = 2
[node name="MetallicSlider" type="HSlider" parent="VBoxContainer"]
margin_top = 136.0
margin_right = 200.0
margin_bottom = 166.0
rect_min_size = Vector2( 200, 30 )
offset_top = 136.0
offset_right = 200.0
offset_bottom = 166.0
rect_min_size = Vector2(200, 30)
max_value = 1.0
step = 0.05
[node name="RoughnessLabel" type="Label" parent="VBoxContainer"]
margin_top = 170.0
margin_right = 200.0
margin_bottom = 200.0
rect_min_size = Vector2( 200, 30 )
offset_top = 170.0
offset_right = 200.0
offset_bottom = 200.0
rect_min_size = Vector2(200, 30)
text = "Roughness strength"
align = 1
valign = 2
[node name="RoughnessSlider" type="HSlider" parent="VBoxContainer"]
margin_top = 204.0
margin_right = 200.0
margin_bottom = 234.0
rect_min_size = Vector2( 200, 30 )
offset_top = 204.0
offset_right = 200.0
offset_bottom = 234.0
rect_min_size = Vector2(200, 30)
max_value = 1.0
step = 0.05
ticks_on_borders = true
[node name="HSeparator" type="HSeparator" parent="VBoxContainer"]
margin_top = 238.0
margin_right = 200.0
margin_bottom = 258.0
rect_min_size = Vector2( 200, 20 )
offset_top = 238.0
offset_right = 200.0
offset_bottom = 258.0
rect_min_size = Vector2(200, 20)
[node name="ApplyButton" type="Button" parent="VBoxContainer"]
margin_top = 262.0
margin_right = 200.0
margin_bottom = 312.0
rect_min_size = Vector2( 200, 50 )
offset_top = 262.0
offset_right = 200.0
offset_bottom = 312.0
rect_min_size = Vector2(200, 50)
text = "Apply material"
[node name="SaveButton" type="Button" parent="VBoxContainer"]
margin_top = 316.0
margin_right = 200.0
margin_bottom = 366.0
rect_min_size = Vector2( 200, 50 )
offset_top = 316.0
offset_right = 200.0
offset_bottom = 366.0
rect_min_size = Vector2(200, 50)
text = "Save material"
[node name="LoadButton" type="Button" parent="VBoxContainer"]
margin_top = 370.0
margin_right = 200.0
margin_bottom = 420.0
rect_min_size = Vector2( 200, 50 )
offset_top = 370.0
offset_right = 200.0
offset_bottom = 420.0
rect_min_size = Vector2(200, 50)
text = "Load material"
clip_text = true
@@ -111,8 +111,8 @@ clip_text = true
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_bottom = -10.0
rect_min_size = Vector2( 0, 50 )
offset_bottom = -10.0
rect_min_size = Vector2(0, 50)
text = "Load silly material and
apply to selected node(s)"
align = 1
@@ -120,20 +120,20 @@ valign = 1
autowrap = true
[node name="SaveMaterialDialog" type="FileDialog" parent="."]
margin_left = 150.0
margin_top = 20.0
margin_right = 600.0
margin_bottom = 360.0
offset_left = 150.0
offset_top = 20.0
offset_right = 600.0
offset_bottom = 360.0
resizable = true
filters = PoolStringArray( "*.silly_mat" )
filters = PackedStringArray("*.silly_mat")
[node name="LoadMaterialDialog" type="FileDialog" parent="."]
margin_left = 150.0
margin_top = 20.0
margin_right = 600.0
margin_bottom = 360.0
rect_min_size = Vector2( 200, 100 )
offset_left = 150.0
offset_top = 20.0
offset_right = 600.0
offset_bottom = 360.0
rect_min_size = Vector2(200, 100)
window_title = "Open a File"
resizable = true
mode = 0
filters = PoolStringArray( "*.silly_mat" )
filters = PackedStringArray("*.silly_mat")

View File

@@ -8,13 +8,13 @@
# This example should be replaced when EditorImportPlugin and EditorExportPlugin are both
# fully working and you can save custom resources.
tool
@tool
extends EditorPlugin
var io_material_dialog
func _enter_tree():
io_material_dialog = preload("res://addons/material_creator/material_dock.tscn").instance()
io_material_dialog = preload("res://addons/material_creator/material_dock.tscn").instantiate()
io_material_dialog.editor_interface = get_editor_interface()
add_control_to_dock(DOCK_SLOT_LEFT_UL, io_material_dialog)

View File

@@ -1,4 +1,4 @@
tool
@tool
extends Node
# NOTE: in theory this would extend from resource, but until saving and loading resources
@@ -30,13 +30,15 @@ func make_json():
json_dict["metallic_strength"] = metallic_strength
json_dict["roughness_strength"] = roughness_strength
return to_json(json_dict)
return JSON.new().stringify(json_dict)
# Convert the passed in string to a json dictonary, and then
# fill in our data.
func from_json(json_dict_as_string):
var json_dict = parse_json(json_dict_as_string)
var json = JSON.new()
json.parse(json_dict_as_string)
var json_dict = json.get_data()
albedo_color.r = json_dict["albedo_color"]["r"]
albedo_color.g = json_dict["albedo_color"]["g"]
@@ -46,9 +48,9 @@ func from_json(json_dict_as_string):
roughness_strength = json_dict["roughness_strength"]
# Make a SpatialMaterial using our variables.
# Make a StandardMaterial3D using our variables.
func make_material():
var mat = SpatialMaterial.new()
var mat = StandardMaterial3D.new()
mat.albedo_color = albedo_color
mat.metallic = metallic_strength