diff --git a/game/addons/world_generator/plugin.gd b/game/addons/world_generator/plugin.gd index 1d80a917..8bd48db2 100644 --- a/game/addons/world_generator/plugin.gd +++ b/game/addons/world_generator/plugin.gd @@ -1,6 +1,8 @@ tool extends EditorPlugin +var SWorldGeneratorSettings = preload("res://addons/world_generator/resources/world_generator_settings.gd") + var SWorldGenBaseResource = preload("res://addons/world_generator/resources/world_gen_base_resource.gd") var SWorldGenWorld = preload("res://addons/world_generator/resources/world_gen_world.gd") var SContinent = preload("res://addons/world_generator/resources/continent.gd") @@ -13,6 +15,8 @@ var editor_scene = null var tool_button : ToolButton = null func _enter_tree(): + add_custom_type("WorldGeneratorSettings", "Resource", SWorldGeneratorSettings, null) + add_custom_type("WorldGenBaseResource", "Resource", SWorldGenBaseResource, null) #Don't change the base to "WorldGenBaseResource" else it will complain about a non-existant class #Also it works perfectly like this @@ -27,6 +31,8 @@ func _enter_tree(): tool_button.hide() func _exit_tree(): + remove_custom_type("WorldGeneratorSettings") + remove_custom_type("WorldGenBaseResource") remove_custom_type("WorldGenWorld") remove_custom_type("Continent") diff --git a/game/addons/world_generator/resources/world_generator_settings.gd b/game/addons/world_generator/resources/world_generator_settings.gd new file mode 100644 index 00000000..91a01aa6 --- /dev/null +++ b/game/addons/world_generator/resources/world_generator_settings.gd @@ -0,0 +1,88 @@ +tool +extends Resource +class_name WorldGeneratorSettings + +export(PoolStringArray) var continent_class_folders : PoolStringArray +export(PoolStringArray) var zone_class_folders : PoolStringArray +export(PoolStringArray) var subzone_class_folders : PoolStringArray + +enum WorldGeneratorScriptType { + CONTINENT = 0, + ZONE = 1, + SUBZONE = 2, +}; + +func evaluate_scripts(script_type : int, tree : Tree) -> void: + if (script_type == WorldGeneratorScriptType.CONTINENT): + evaluate_continent_scripts(tree) + elif (script_type == WorldGeneratorScriptType.ZONE): + evaluate_zone_scripts(tree) + elif (script_type == WorldGeneratorScriptType.SUBZONE): + evaluate_subzone_scripts(tree) + +func evaluate_continent_scripts(tree : Tree) -> void: + tree.clear() + + var root : TreeItem = tree.create_item() + root.set_text(0, "Continent") + root.set_meta("class_name", "Continent") + + for s in continent_class_folders: + evaluate_folder(s, tree, root) + + root.select(0) + +func evaluate_zone_scripts(tree : Tree) -> void: + tree.clear() + + var root : TreeItem = tree.create_item() + root.set_text(0, "Zone") + root.set_meta("class_name", "Zone") + + for s in zone_class_folders: + evaluate_folder(s, tree, root) + + root.select(0) + +func evaluate_subzone_scripts(tree : Tree) -> void: + tree.clear() + + var root : TreeItem = tree.create_item() + root.set_text(0, "SubZone") + root.set_meta("class_name", "SubZone") + + for s in subzone_class_folders: + evaluate_folder(s, tree, root) + + root.select(0) + +func evaluate_folder(folder : String, tree : Tree, root : TreeItem) -> void: + var ti : TreeItem = null + + var dir = Directory.new() + if dir.open(folder) == OK: + dir.list_dir_begin() + var file_name = dir.get_next() + while file_name != "": + if !dir.current_is_dir(): + #print("Found file: " + file_name) + + if !ti: + var n : String = folder.substr(folder.find_last("/") + 1) + + if n != "": + ti = tree.create_item(root) + ti.set_text(0, n) + else: + ti = root + + var e : TreeItem = tree.create_item(ti) + + e.set_text(0, file_name.get_file()) + e.set_meta("file", folder + "/" + file_name) + + file_name = dir.get_next() + else: + print("An error occurred when trying to access the path.") + + diff --git a/game/project.godot b/game/project.godot index cf578ecf..8b7958e5 100644 --- a/game/project.godot +++ b/game/project.godot @@ -255,6 +255,11 @@ _global_script_classes=[ { "path": "res://addons/world_generator/resources/world_gen_world.gd" }, { "base": "Resource", +"class": "WorldGeneratorSettings", +"language": "GDScript", +"path": "res://addons/world_generator/resources/world_generator_settings.gd" +}, { +"base": "Resource", "class": "Zone", "language": "GDScript", "path": "res://addons/world_generator/resources/zone.gd" @@ -309,6 +314,7 @@ _global_script_class_icons={ "UIWindowModule": "", "WorldGenBaseResource": "", "WorldGenWorld": "", +"WorldGeneratorSettings": "", "Zone": "" } Node="input/actionbar_5_11" diff --git a/game/world_generator/continents/test_continent.gd b/game/world_generator/continents/test_continent.gd new file mode 100644 index 00000000..a737283c --- /dev/null +++ b/game/world_generator/continents/test_continent.gd @@ -0,0 +1,21 @@ +tool +extends Continent + +func get_editor_rect_border_color() -> Color: + return Color(0.8, 0.8, 0.8, 1) + +func get_editor_rect_color() -> Color: + return Color(0.8, 0.8, 0.8, 0.9) + +func get_editor_rect_border_size() -> int: + return 2 + +func get_editor_font_color() -> Color: + return Color(0, 0, 0, 1) + +func get_editor_class() -> String: + return "TestContinent" + +func get_editor_additional_text() -> String: + return "TestContinent" + diff --git a/game/world_generator/subzones/test_subzone.gd b/game/world_generator/subzones/test_subzone.gd new file mode 100644 index 00000000..8fccf3b2 --- /dev/null +++ b/game/world_generator/subzones/test_subzone.gd @@ -0,0 +1,20 @@ +tool +extends SubZone + +func get_editor_rect_border_color() -> Color: + return Color(0.8, 0.8, 0.8, 1) + +func get_editor_rect_color() -> Color: + return Color(0.8, 0.8, 0.8, 0.9) + +func get_editor_rect_border_size() -> int: + return 2 + +func get_editor_font_color() -> Color: + return Color(0, 0, 0, 1) + +func get_editor_class() -> String: + return "TestSubZone" + +func get_editor_additional_text() -> String: + return "TestSubZone" diff --git a/game/world_generator/zones/test_zone.gd b/game/world_generator/zones/test_zone.gd new file mode 100644 index 00000000..5e78f1f9 --- /dev/null +++ b/game/world_generator/zones/test_zone.gd @@ -0,0 +1,20 @@ +tool +extends Zone + +func get_editor_rect_border_color() -> Color: + return Color(0.8, 0.8, 0.8, 1) + +func get_editor_rect_color() -> Color: + return Color(0.8, 0.8, 0.8, 0.9) + +func get_editor_rect_border_size() -> int: + return 2 + +func get_editor_font_color() -> Color: + return Color(0, 0, 0, 1) + +func get_editor_class() -> String: + return "TestZone" + +func get_editor_additional_text() -> String: + return "TestZone" diff --git a/game/world_generator_settings.tres b/game/world_generator_settings.tres new file mode 100644 index 00000000..1f038213 --- /dev/null +++ b/game/world_generator_settings.tres @@ -0,0 +1,9 @@ +[gd_resource type="Resource" load_steps=2 format=2] + +[ext_resource path="res://addons/world_generator/resources/world_generator_settings.gd" type="Script" id=1] + +[resource] +script = ExtResource( 1 ) +continent_class_folders = PoolStringArray( "res://world_generator/continents/" ) +zone_class_folders = PoolStringArray( "res://world_generator/zones/" ) +subzone_class_folders = PoolStringArray( "res://world_generator/subzones/" )