Updated the addons.

This commit is contained in:
Relintai 2022-02-20 23:50:33 +01:00
parent e2e27c56d4
commit 8b72e02c2c
5 changed files with 58 additions and 367 deletions

View File

@ -1,13 +1,14 @@
tool tool
extends FileDialog extends FileDialog
var canvas #var canvas
var file_path = "" var file_path = ""
func _enter_tree(): #func _enter_tree():
canvas = get_parent().find_node("Canvas") #canvas = get_parent().find_node("Canvas")
#canvas = get_parent().paint_canvas
func _ready(): func _ready():
@ -37,6 +38,7 @@ func _on_SaveFileDialog_confirmed():
func save_file(): func save_file():
var image = Image.new() var image = Image.new()
var canvas = get_parent().paint_canvas
image.create(canvas.canvas_width, canvas.canvas_height, true, Image.FORMAT_RGBA8) image.create(canvas.canvas_width, canvas.canvas_height, true, Image.FORMAT_RGBA8)
image.lock() image.lock()

View File

@ -0,0 +1,32 @@
tool
extends Reference
class_name WorldGenRaycast
var current_index : int = -1
var base_resources : Array = Array()
var local_positions : PoolVector2Array = PoolVector2Array()
var local_uvs : PoolVector2Array = PoolVector2Array()
func get_local_position() -> Vector2:
return local_positions[current_index]
func get_local_uv() -> Vector2:
return local_uvs[current_index]
# WorldGenBaseResource (can't explicitly add -> cyclic dependency)
func get_resource():
return base_resources[current_index]
func next() -> bool:
current_index += 1
return base_resources.size() > current_index
func size() -> int:
return base_resources.size()
# base_resource -> WorldGenBaseResource
func add_data(base_resource, local_pos : Vector2, local_uv : Vector2) -> void:
base_resources.append(base_resource)
local_positions.append(local_pos)
local_uvs.append(local_uv)

View File

@ -104,16 +104,16 @@ func _setup_terra_library(library, pseed : int) -> void:
func generate_terra_chunk(chunk, pseed : int, spawn_mobs: bool) -> void: func generate_terra_chunk(chunk, pseed : int, spawn_mobs: bool) -> void:
var p : Vector2 = Vector2(chunk.get_position_x(), chunk.get_position_z()) var p : Vector2 = Vector2(chunk.get_position_x(), chunk.get_position_z())
var stack : Array = get_hit_stack(p) var raycast : WorldGenRaycast = get_hit_stack(p)
if stack.size() == 0: if raycast.size() == 0:
_generate_terra_chunk_fallback(chunk, pseed, spawn_mobs) _generate_terra_chunk_fallback(chunk, pseed, spawn_mobs)
return return
for i in range(stack.size()): while raycast.next():
stack[i]._generate_terra_chunk(chunk, pseed, spawn_mobs, stack, i) raycast.get_resource()._generate_terra_chunk(chunk, pseed, spawn_mobs, raycast)
func _generate_terra_chunk(chunk, pseed : int, spawn_mobs: bool, stack : Array, stack_index : int) -> void: func _generate_terra_chunk(chunk, pseed : int, spawn_mobs: bool, raycast : WorldGenRaycast) -> void:
pass pass
func _generate_terra_chunk_fallback(chunk, pseed : int, spawn_mobs: bool) -> void: func _generate_terra_chunk_fallback(chunk, pseed : int, spawn_mobs: bool) -> void:
@ -128,31 +128,33 @@ func generate_map(pseed : int) -> Image:
return img return img
func add_to_map(var img : Image, pseed : int) -> void: func add_to_map(img : Image, pseed : int) -> void:
_add_to_map(img, pseed) _add_to_map(img, pseed)
for c in get_content(): for c in get_content():
if c: if c:
c.add_to_map(img, pseed) c.add_to_map(img, pseed)
func _add_to_map(var img : Image, pseed : int) -> void: func _add_to_map(img : Image, pseed : int) -> void:
pass pass
func get_hit_stack(var pos : Vector2) -> Array: func get_hit_stack(pos : Vector2, raycast : WorldGenRaycast = null) -> WorldGenRaycast:
var r : Rect2 = get_rect() var r : Rect2 = get_rect()
var local_pos : Vector2 = pos - rect.position var local_pos : Vector2 = pos - rect.position
r.position = Vector2() r.position = Vector2()
var result : Array = Array() if !raycast:
raycast = WorldGenRaycast.new()
if r.has_point(local_pos): if r.has_point(local_pos):
result.append(self) var local_uv : Vector2 = local_pos / rect.size
raycast.add_data(self, local_pos, local_uv)
for c in get_content(): for c in get_content():
if c: if c:
result.append_array(c.get_hit_stack(local_pos)) c.get_hit_stack(local_pos, raycast)
return result return raycast
func get_editor_rect_border_color() -> Color: func get_editor_rect_border_color() -> Color:
return Color(1, 1, 1, 1) return Color(1, 1, 1, 1)

View File

@ -1,351 +0,0 @@
[gd_resource type="Resource" load_steps=40 format=2]
[ext_resource path="res://addons/world_generator/resources/world_gen_world.gd" type="Script" id=1]
[ext_resource path="res://addons/world_generator/resources/continent.gd" type="Script" id=2]
[ext_resource path="res://addons/world_generator/resources/zone.gd" type="Script" id=3]
[ext_resource path="res://addons/world_generator/resources/subzone.gd" type="Script" id=4]
[ext_resource path="res://world_generator/continents/test_continent.gd" type="Script" id=5]
[ext_resource path="res://world_generator/zones/test_zone.gd" type="Script" id=6]
[ext_resource path="res://world_generator/subzones/test_subzone.gd" type="Script" id=7]
[sub_resource type="Resource" id=14]
resource_name = "qwe"
script = ExtResource( 4 )
rect = Rect2( 21, 25, 150, 79 )
locked = false
[sub_resource type="Resource" id=15]
resource_name = "we"
script = ExtResource( 4 )
rect = Rect2( 7, 9, 54, 34 )
locked = false
[sub_resource type="Resource" id=34]
resource_name = "yy"
script = ExtResource( 7 )
rect = Rect2( 66, 11, 100, 91 )
locked = false
[sub_resource type="Resource" id=8]
resource_name = "asdasr"
script = ExtResource( 3 )
rect = Rect2( 35, 21, 191.4, 127.8 )
locked = false
subzones = [ SubResource( 14 ), SubResource( 15 ), SubResource( 34 ) ]
[sub_resource type="Resource" id=13]
resource_name = "qqq"
script = ExtResource( 3 )
rect = Rect2( 17, 59, 200.4, 52 )
locked = false
subzones = [ ]
[sub_resource type="Resource" id=24]
resource_name = "trtrtr"
script = ExtResource( 3 )
rect = Rect2( 0, 0, 57.1, 45.8 )
locked = false
subzones = [ ]
[sub_resource type="GDScript" id=25]
script/source = "tool
extends \"res://addons/world_generator/resources/world_gen_base_resource.gd\"
class_name Zone
export(Array) var subzones : Array
func get_content() -> Array:
return subzones
func set_content(arr : Array) -> void:
subzones = arr
func create_content(item_name : String = \"\") -> void:
var subzone : SubZone = SubZone.new()
subzone.resource_name = item_name
var r : Rect2 = get_rect()
r.position = Vector2()
r.size.x /= 10.0
r.size.y /= 10.0
subzone.set_rect(r)
add_content(subzone)
func add_content(entry : WorldGenBaseResource) -> void:
subzones.append(entry)
emit_changed()
func remove_content_entry(entry : WorldGenBaseResource) -> void:
for i in range(subzones.size()):
if subzones[i] == entry:
subzones.remove(i)
emit_changed()
return
func setup_property_inspector(inspector) -> void:
.setup_property_inspector(inspector)
"
[sub_resource type="Resource" id=26]
resource_name = "trtrtr (Duplicate)"
script = SubResource( 25 )
rect = Rect2( 64, 6, 158.1, 39.8 )
locked = false
subzones = [ ]
[sub_resource type="Resource" id=32]
resource_name = "tttte"
script = ExtResource( 3 )
rect = Rect2( 103, 28, 100, 100 )
locked = false
subzones = [ ]
[sub_resource type="Resource" id=35]
resource_name = "yu"
script = ExtResource( 6 )
rect = Rect2( 88, 21, 100, 100 )
locked = false
subzones = [ ]
[sub_resource type="Resource" id=1]
resource_name = "wwww"
script = ExtResource( 2 )
rect = Rect2( 163, 35, 241, 158 )
zones = [ SubResource( 8 ), SubResource( 13 ), SubResource( 24 ), SubResource( 26 ), SubResource( 32 ), SubResource( 35 ) ]
[sub_resource type="Resource" id=2]
resource_name = "efefef"
script = ExtResource( 2 )
rect = Rect2( 107, 271, 100, 49 )
[sub_resource type="Resource" id=3]
resource_name = "grgrg"
script = ExtResource( 2 )
rect = Rect2( 498, 185, 100, 100 )
[sub_resource type="Resource" id=9]
resource_name = "asd"
script = ExtResource( 3 )
rect = Rect2( 528, 34, 0, 0 )
locked = false
subzones = [ ]
[sub_resource type="Resource" id=10]
resource_name = "qqq"
script = ExtResource( 3 )
rect = Rect2( 528, 34, 0, 0 )
locked = false
subzones = [ ]
[sub_resource type="Resource" id=4]
resource_name = "qwdasd"
script = ExtResource( 2 )
rect = Rect2( 522, 29, 63, 54 )
zones = [ SubResource( 9 ), SubResource( 10 ) ]
[sub_resource type="Resource" id=11]
resource_name = "q"
script = ExtResource( 3 )
rect = Rect2( 14, 11, 53, 59 )
locked = false
subzones = [ ]
[sub_resource type="Resource" id=5]
resource_name = "qwe"
script = ExtResource( 2 )
rect = Rect2( 473, 331, 100, 100 )
zones = [ SubResource( 11 ) ]
[sub_resource type="GDScript" id=16]
script/source = "tool
extends \"res://addons/world_generator/resources/world_gen_base_resource.gd\"
class_name Continent
export(Array) var zones : Array
func get_content() -> Array:
return zones
func set_content(arr : Array) -> void:
zones = arr
func create_content(item_name : String = \"\") -> void:
var zone : Zone = Zone.new()
zone.resource_name = item_name
var r : Rect2 = get_rect()
r.position = Vector2()
r.size.x /= 10.0
r.size.y /= 10.0
zone.set_rect(r)
add_content(zone)
func add_content(entry : WorldGenBaseResource) -> void:
zones.append(entry)
emit_changed()
func remove_content_entry(entry : WorldGenBaseResource) -> void:
for i in range(zones.size()):
if zones[i] == entry:
zones.remove(i)
emit_changed()
return
func setup_property_inspector(inspector) -> void:
.setup_property_inspector(inspector)
"
[sub_resource type="Resource" id=17]
resource_name = "qwetwwqasd"
script = SubResource( 16 )
rect = Rect2( 473, 331, 100, 100 )
locked = false
zones = [ SubResource( 11 ) ]
[sub_resource type="GDScript" id=18]
script/source = "tool
extends \"res://addons/world_generator/resources/world_gen_base_resource.gd\"
class_name Continent
export(Array) var zones : Array
func get_content() -> Array:
return zones
func set_content(arr : Array) -> void:
zones = arr
func create_content(item_name : String = \"\") -> void:
var zone : Zone = Zone.new()
zone.resource_name = item_name
var r : Rect2 = get_rect()
r.position = Vector2()
r.size.x /= 10.0
r.size.y /= 10.0
zone.set_rect(r)
add_content(zone)
func add_content(entry : WorldGenBaseResource) -> void:
zones.append(entry)
emit_changed()
func remove_content_entry(entry : WorldGenBaseResource) -> void:
for i in range(zones.size()):
if zones[i] == entry:
zones.remove(i)
emit_changed()
return
func setup_property_inspector(inspector) -> void:
.setup_property_inspector(inspector)
"
[sub_resource type="Resource" id=19]
resource_name = "qwesat"
script = SubResource( 18 )
rect = Rect2( 613, 346, 100, 100 )
locked = false
zones = [ SubResource( 11 ) ]
[sub_resource type="Resource" id=20]
resource_name = "ggg"
script = ExtResource( 2 )
rect = Rect2( 26, 51, 100, 100 )
[sub_resource type="GDScript" id=21]
script/source = "tool
extends \"res://addons/world_generator/resources/world_gen_base_resource.gd\"
class_name Continent
export(Array) var zones : Array
func get_content() -> Array:
return zones
func set_content(arr : Array) -> void:
zones = arr
func create_content(item_name : String = \"\") -> void:
var zone : Zone = Zone.new()
zone.resource_name = item_name
var r : Rect2 = get_rect()
r.position = Vector2()
r.size.x /= 10.0
r.size.y /= 10.0
zone.set_rect(r)
add_content(zone)
func add_content(entry : WorldGenBaseResource) -> void:
zones.append(entry)
emit_changed()
func remove_content_entry(entry : WorldGenBaseResource) -> void:
for i in range(zones.size()):
if zones[i] == entry:
zones.remove(i)
emit_changed()
return
func setup_property_inspector(inspector) -> void:
.setup_property_inspector(inspector)
"
[sub_resource type="Resource" id=22]
resource_name = "ggg (Duplicate)"
script = SubResource( 21 )
rect = Rect2( 33, 181, 100, 100 )
locked = false
zones = [ ]
[sub_resource type="Resource" id=23]
resource_name = "eeqqq"
script = ExtResource( 2 )
rect = Rect2( 256, 365, 100, 100 )
[sub_resource type="Resource" id=27]
resource_name = "asd"
script = ExtResource( 2 )
rect = Rect2( 337, 79, 100, 100 )
[sub_resource type="Resource" id=28]
resource_name = "asd"
script = ExtResource( 2 )
rect = Rect2( 244, 234, 100, 100 )
[sub_resource type="Resource" id=29]
script = ExtResource( 2 )
rect = Rect2( 377, 69, 284, 238 )
[sub_resource type="Resource" id=30]
resource_name = "tttttt"
script = ExtResource( 2 )
rect = Rect2( 188, 225, 233, 259 )
[sub_resource type="Resource" id=31]
resource_name = "ttttyuqtttt"
script = ExtResource( 2 )
rect = Rect2( 339, 76, 220, 170 )
[sub_resource type="Resource" id=33]
resource_name = "qttt"
script = ExtResource( 5 )
rect = Rect2( 99, 78, 213, 105 )
locked = false
zones = [ ]
[resource]
resource_name = "asdasdsse"
script = ExtResource( 1 )
rect = Rect2( 0, 0, 1000, 1000 )
locked = false
continents = [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ), SubResource( 17 ), SubResource( 19 ), SubResource( 20 ), SubResource( 22 ), SubResource( 23 ), SubResource( 27 ), SubResource( 28 ), SubResource( 29 ), SubResource( 30 ), SubResource( 31 ), SubResource( 33 ) ]

View File

@ -269,6 +269,11 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://addons/world_generator/resources/world_gen_base_resource.gd" "path": "res://addons/world_generator/resources/world_gen_base_resource.gd"
}, { }, {
"base": "Reference",
"class": "WorldGenRaycast",
"language": "GDScript",
"path": "res://addons/world_generator/raycast/world_gen_raycast.gd"
}, {
"base": "Resource", "base": "Resource",
"class": "WorldGenWorld", "class": "WorldGenWorld",
"language": "GDScript", "language": "GDScript",
@ -337,6 +342,7 @@ _global_script_class_icons={
"UIGuiChildModule": "", "UIGuiChildModule": "",
"UIWindowModule": "", "UIWindowModule": "",
"WorldGenBaseResource": "", "WorldGenBaseResource": "",
"WorldGenRaycast": "",
"WorldGenWorld": "", "WorldGenWorld": "",
"WorldGeneratorSettings": "", "WorldGeneratorSettings": "",
"Zone": "" "Zone": ""
@ -383,7 +389,7 @@ window/size/ui_scale_touch=1.0
[editor_plugins] [editor_plugins]
enabled=PoolStringArray( "res://addons/Godoxel/plugin.cfg", "res://addons/color-palette/plugin.cfg", "res://addons/data_manager/plugin.cfg", "res://addons/mat_maker_gd/plugin.cfg", "res://addons/tile_generator/plugin.cfg", "res://addons/world_generator/plugin.cfg" ) enabled=PoolStringArray( "res://addons/Godoxel/plugin.cfg", "res://addons/color-palette/plugin.cfg", "res://addons/data_manager/plugin.cfg", "res://addons/mat_maker_gd/plugin.cfg", "res://addons/tile_generator/plugin.cfg" )
[ess] [ess]