mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Added a new WorldGeneratorSettings resource which can store and load in world generator related classes from folders.
This commit is contained in:
parent
9cac983ff5
commit
4ff14380a1
@ -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")
|
||||
|
@ -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.")
|
||||
|
||||
|
@ -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"
|
||||
|
21
game/world_generator/continents/test_continent.gd
Normal file
21
game/world_generator/continents/test_continent.gd
Normal file
@ -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"
|
||||
|
20
game/world_generator/subzones/test_subzone.gd
Normal file
20
game/world_generator/subzones/test_subzone.gd
Normal file
@ -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"
|
20
game/world_generator/zones/test_zone.gd
Normal file
20
game/world_generator/zones/test_zone.gd
Normal file
@ -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"
|
9
game/world_generator_settings.tres
Normal file
9
game/world_generator_settings.tres
Normal file
@ -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/" )
|
Loading…
Reference in New Issue
Block a user