Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions addons/gaea/editor/editor_settings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const LINE_CURVATURE := "gaea/graph/line_curvature"
const LINE_THICKNESS := "gaea/graph/line_thickness"
const MINIMAP_OPACITY := "gaea/graph/minimap_opacity"
const GRID_PATTERN := "gaea/graph/grid_pattern"
const PREVIEW_RESOLUTION := "gaea/graph/preview/preview_resolution"
const PREVIEW_MAX_SIMULATION_SIZE := "gaea/graph/preview/max_simulation_size"
const OUTPUT_TITLE_COLOR := "gaea/graph/output_title_color"
const COLOR_BASE := "gaea/graph/slot_colors/%s"
const ICON_BASE := "gaea/graph/slot_icons/%s"
Expand Down Expand Up @@ -51,6 +53,12 @@ func add_settings() -> void:
"hint": PROPERTY_HINT_ENUM,
"hint_string": "Lines,Dots"
})
_add_setting(PREVIEW_RESOLUTION, 64, {
"type": TYPE_INT
})
_add_setting(PREVIEW_MAX_SIMULATION_SIZE, 128, {
"type": TYPE_INT
})

_add_setting(OUTPUT_TITLE_COLOR, Color("632639"), {"type": TYPE_COLOR, "hint": PROPERTY_HINT_COLOR_NO_ALPHA})

Expand Down Expand Up @@ -131,3 +139,13 @@ static func get_minimap_opacity() -> float:
static func get_grid_pattern() -> int:
var editor_interface = Engine.get_singleton("EditorInterface")
return editor_interface.get_editor_settings().get_setting(GRID_PATTERN)


static func get_preview_resolution() -> int:
var editor_interface = Engine.get_singleton("EditorInterface")
return editor_interface.get_editor_settings().get_setting(PREVIEW_RESOLUTION)


static func get_preview_max_simulation_size() -> int:
var editor_interface = Engine.get_singleton("EditorInterface")
return editor_interface.get_editor_settings().get_setting(PREVIEW_MAX_SIMULATION_SIZE)
36 changes: 28 additions & 8 deletions addons/gaea/graph/components/preview_texture.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ func _ready() -> void:
if is_part_of_edited_scene():
return

expand_mode = EXPAND_FIT_HEIGHT
stretch_mode = STRETCH_SCALE
expand_mode = EXPAND_FIT_HEIGHT_PROPORTIONAL
stretch_mode = STRETCH_KEEP_ASPECT

await get_tree().process_frame

texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST

slider_container = HBoxContainer.new()
Expand Down Expand Up @@ -47,8 +50,8 @@ func _ready() -> void:

get_parent().add_child(slider_container)

texture = ImageTexture.create_from_image(Image.create_empty(RESOLUTION.x, RESOLUTION.y, true, Image.FORMAT_RGBA8))

var preview_resolution = GaeaEditorSettings.get_preview_resolution()
texture = ImageTexture.create_from_image(Image.create_empty(preview_resolution, preview_resolution, true, Image.FORMAT_RGBA8))

func toggle(for_output: StringName) -> void:
if not get_parent().visible:
Expand All @@ -68,23 +71,40 @@ func update() -> void:
if not is_visible_in_tree():
return

var resolution: Vector2i = RESOLUTION
var preview_resolution := GaeaEditorSettings.get_preview_resolution()
var resolution: Vector2i
if is_instance_valid(node.generator):
resolution = resolution.min(Vector2i(node.generator.world_size.x, node.generator.world_size.y))
var x = mini(preview_resolution, node.generator.world_size.x)
var ratio = minf(2.0, float(node.generator.world_size.y) / float(node.generator.world_size.x))
resolution = Vector2i(preview_resolution, roundi(float(x) * ratio))
else:
resolution = Vector2i(preview_resolution, preview_resolution)

var preview_max_sim := GaeaEditorSettings.get_preview_max_simulation_size()
var sim_size:Vector3
match (node.resource._get_preview_simulation_size()):
GaeaNodeResource.SimSize.WORLD:
sim_size = node.generator.world_size.mini(preview_max_sim)
_: # GaeaNodeReousrce.SimSize.Preview is the default
sim_size = Vector3(resolution.x, resolution.y, 1)

var data: Dictionary = node.resource.traverse(
selected_output,
AABB(Vector3.ZERO, Vector3(resolution.x, resolution.y, 1)),
AABB(Vector3.ZERO, sim_size),
node.generator.data
).get("value", {})

node.generator.data.cache.clear()

var sim_center:Vector3i = sim_size / 2
var res_center:Vector3i = Vector3i(resolution.x, resolution.y, 0) / 2
var sim_offset := sim_center.max(res_center) - sim_center.min(res_center)

var image: Image = Image.create_empty(resolution.x, resolution.y, true, Image.FORMAT_RGBA8)
for x: int in resolution.x:
for y: int in resolution.y:
var color: Color
var value = data.get(Vector3i(x, y, 0))
var value = data.get(Vector3i(x, y, 0) + sim_offset)
if value == null:
continue
match node.resource.get_output_port_type(selected_output):
Expand Down
16 changes: 16 additions & 0 deletions addons/gaea/graph/graph_nodes/node_resource.gd
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ var tree_name_override: String = "": set = set_tree_name_override
@export_storage var default_value_overrides: Dictionary[StringName, Variant]
@export_storage var default_enum_value_overrides: Dictionary[int, int]

## Used in [_get_preview_simulation_size].
enum SimSize
{
PREVIEW,
WORLD
}

func notify_argument_list_changed() -> void:
argument_list_changed.emit()
Expand Down Expand Up @@ -119,6 +125,11 @@ func get_enums_count() -> int:
return _get_enums_count()


## Public version of [_get_preview_simulation_size]. Prefer to override that method over this one.
func get_preview_simulation_size() -> SimSize:
return SimSize.PREVIEW


## Public version of [method _get_enum_options]. Prefer to override that method over this one.
func get_enum_options(idx: int) -> Dictionary:
return _get_enum_options(idx)
Expand Down Expand Up @@ -236,6 +247,11 @@ func _get_enums_count() -> int:
return 0


## Override this method to change what simulation size to use in previews. Returns a [SimSize].
func _get_preview_simulation_size() -> SimSize:
return SimSize.PREVIEW


## Override this method to define the options available for the added enums.[br][br]
## The returned [Dictionary] should be [code]{String: int}[/code]. Built-in enums can be used directly.
func _get_enum_options(idx: int) -> Dictionary:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ func _get_output_port_type(_output_name: StringName) -> GaeaValue.Type:
return GaeaValue.Type.DATA


func _get_preview_simulation_size() -> SimSize:
return SimSize.WORLD


func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictionary[Vector3i, float]:
_log_data(_output_port, graph)
var axis_type: AxisType = get_enum_selection(0) as AxisType

var _starting_position: Vector3 = _get_arg(&"starting_position", area, graph)
Expand Down Expand Up @@ -137,9 +142,10 @@ func _get_data(_output_port: StringName, area: AABB, graph: GaeaGraph) -> Dictio
_add_walker(walker.pos, _walkers)

if rng.randf() <= direction_change_chance:
var direction:int = rng.rand_weighted(rotation_weights.values())
walker.dir = walker.dir.rotated(
Vector3(0, 0, 1) if axis_type == AxisType.XY else Vector3(0, 1, 0),
rotation_weights.keys()[rng.rand_weighted(rotation_weights.values())]
rotation_weights.keys()[direction]
).round()

if rng.randf() <= bigger_room_chance:
Expand Down
Loading