mirror of
https://github.com/Relintai/godot-resources-as-sheets-plugin.git
synced 2024-11-14 15:17:20 +01:00
Change script gen to CRLF due to chaotic magic
(because suddenly builtin scripts started breaking)
This commit is contained in:
parent
9eb9462484
commit
42368023f4
@ -109,28 +109,9 @@ func _create_prop_editors():
|
|||||||
|
|
||||||
|
|
||||||
func _generate_class(save_script = true):
|
func _generate_class(save_script = true):
|
||||||
var new_script = GDScript.new()
|
import_data.new_script = import_data.generate_script(entries, save_script)
|
||||||
if save_script and import_data.script_classname != "":
|
|
||||||
new_script.source_code = "class_name " + import_data.script_classname + " \nextends Resource\n\n"
|
|
||||||
|
|
||||||
else:
|
|
||||||
new_script.source_code = "extends Resource\n\n"
|
|
||||||
|
|
||||||
# Enums
|
|
||||||
import_data.uniques = import_data.get_uniques(entries)
|
|
||||||
for i in import_data.prop_types.size():
|
|
||||||
if import_data.prop_types[i] == SpreadsheetImport.PropType.ENUM:
|
|
||||||
new_script.source_code += import_data.create_enum_for_prop(i)
|
|
||||||
|
|
||||||
# Properties
|
|
||||||
for i in import_data.prop_names.size():
|
|
||||||
if import_data.prop_names[i] != "resource_path" && import_data.prop_names[i] != "resource_name":
|
|
||||||
new_script.source_code += import_data.create_property_line_for_prop(i)
|
|
||||||
|
|
||||||
import_data.new_script = new_script
|
|
||||||
new_script.reload()
|
|
||||||
if save_script:
|
if save_script:
|
||||||
ResourceSaver.save(import_data.edited_path.get_basename() + ".gd", new_script)
|
ResourceSaver.save(import_data.edited_path.get_basename() + ".gd", import_data.new_script)
|
||||||
# Because when instanced, objects have a copy of the script
|
# Because when instanced, objects have a copy of the script
|
||||||
import_data.new_script = load(import_data.edited_path.get_basename() + ".gd")
|
import_data.new_script = load(import_data.edited_path.get_basename() + ".gd")
|
||||||
|
|
||||||
|
@ -118,36 +118,37 @@ func property_to_string(value, col_index : int) -> String:
|
|||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
func create_property_line_for_prop(col_index : int):
|
func create_property_line_for_prop(col_index : int) -> String:
|
||||||
var result = "export var " + prop_names[col_index] + " :"
|
var result = "export var " + prop_names[col_index] + " :"
|
||||||
match prop_types[col_index]:
|
match prop_types[col_index]:
|
||||||
PropType.STRING:
|
PropType.STRING:
|
||||||
return result + "= \"\"\n"
|
return result + "= \"\"\r\n"
|
||||||
|
|
||||||
PropType.BOOL:
|
PropType.BOOL:
|
||||||
return result + "= false\n"
|
return result + "= false\r\n"
|
||||||
|
|
||||||
PropType.REAL:
|
PropType.REAL:
|
||||||
return result + "= 0.0\n"
|
return result + "= 0.0\r\n"
|
||||||
|
|
||||||
PropType.INT:
|
PropType.INT:
|
||||||
return result + "= 0\n"
|
return result + "= 0\r\n"
|
||||||
|
|
||||||
PropType.COLOR:
|
PropType.COLOR:
|
||||||
return result + "= Color.white\n"
|
return result + "= Color.white\r\n"
|
||||||
|
|
||||||
PropType.OBJECT:
|
PropType.OBJECT:
|
||||||
return result + " Resource\n"
|
return result + " Resource\r\n"
|
||||||
|
|
||||||
PropType.ENUM:
|
PropType.ENUM:
|
||||||
return result.replace(
|
return result.replace(
|
||||||
"export var",
|
"export var",
|
||||||
"export(" + _escape_forbidden_enum_names(
|
"export(" + _escape_forbidden_enum_names(
|
||||||
TextEditingUtils\
|
prop_names[col_index].capitalize()\
|
||||||
.string_snake_to_naming_case(prop_names[col_index])\
|
|
||||||
.replace(" ", "")
|
.replace(" ", "")
|
||||||
) + ") var"
|
) + ") var"
|
||||||
) + "= 0\n"
|
) + "= 0\r\n"
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
func _escape_forbidden_enum_names(string : String) -> String:
|
func _escape_forbidden_enum_names(string : String) -> String:
|
||||||
@ -164,14 +165,13 @@ func _escape_forbidden_enum_names(string : String) -> String:
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
func create_enum_for_prop(col_index):
|
func create_enum_for_prop(col_index) -> String:
|
||||||
var result := (
|
var result := (
|
||||||
"enum "
|
"enum "
|
||||||
+ _escape_forbidden_enum_names(
|
+ _escape_forbidden_enum_names(
|
||||||
TextEditingUtils\
|
prop_names[col_index].capitalize()\
|
||||||
.string_snake_to_naming_case(prop_names[col_index])\
|
|
||||||
.replace(" ", "")
|
.replace(" ", "")
|
||||||
) + " {\n"
|
) + " {\r\n"
|
||||||
)
|
)
|
||||||
for k in uniques[col_index]:
|
for k in uniques[col_index]:
|
||||||
result += (
|
result += (
|
||||||
@ -179,12 +179,37 @@ func create_enum_for_prop(col_index):
|
|||||||
+ k # Enum Entry
|
+ k # Enum Entry
|
||||||
+ " = "
|
+ " = "
|
||||||
+ str(uniques[col_index][k]) # Value
|
+ str(uniques[col_index][k]) # Value
|
||||||
+ ",\n"
|
+ ",\r\n"
|
||||||
)
|
)
|
||||||
result += "\tMAX,\n}\n\n"
|
result += "\tMAX,\r\n}\r\n\r\n"
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
func generate_script(entries, has_classname = true) -> GDScript:
|
||||||
|
var source = ""
|
||||||
|
if has_classname and script_classname != "":
|
||||||
|
source = "class_name " + script_classname + " \r\nextends Resource\r\n\r\n"
|
||||||
|
|
||||||
|
else:
|
||||||
|
source = "extends Resource\r\n\r\n"
|
||||||
|
|
||||||
|
# Enums
|
||||||
|
uniques = get_uniques(entries)
|
||||||
|
for i in prop_types.size():
|
||||||
|
if prop_types[i] == PropType.ENUM:
|
||||||
|
source += create_enum_for_prop(i)
|
||||||
|
|
||||||
|
# Properties
|
||||||
|
for i in prop_names.size():
|
||||||
|
if (prop_names[i] != "resource_path") and (prop_names[i] != "resource_name"):
|
||||||
|
source += create_property_line_for_prop(i)
|
||||||
|
|
||||||
|
var created_script = GDScript.new()
|
||||||
|
created_script.source_code = source
|
||||||
|
created_script.reload()
|
||||||
|
return created_script
|
||||||
|
|
||||||
|
|
||||||
func strings_to_resource(strings : Array):
|
func strings_to_resource(strings : Array):
|
||||||
var new_res = new_script.new()
|
var new_res = new_script.new()
|
||||||
for j in min(prop_names.size(), strings.size()):
|
for j in min(prop_names.size(), strings.size()):
|
||||||
|
Loading…
Reference in New Issue
Block a user