|
|
|
|
@ -3,9 +3,12 @@ extends Control |
|
|
|
|
export var default_width = 500 |
|
|
|
|
export var default_height = 500 |
|
|
|
|
export var default_spacing = 5 |
|
|
|
|
var width = default_width |
|
|
|
|
var height = default_height |
|
|
|
|
var spacing = default_spacing |
|
|
|
|
|
|
|
|
|
var data = { |
|
|
|
|
width = default_width, |
|
|
|
|
height = default_height, |
|
|
|
|
spacing = default_spacing |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var poisson_disc_sampling: PoissonDiscSampling = PoissonDiscSampling.new() |
|
|
|
|
var points = [] |
|
|
|
|
@ -13,16 +16,48 @@ var points = [] |
|
|
|
|
signal new_poisson(points) |
|
|
|
|
|
|
|
|
|
func _ready(): |
|
|
|
|
$HBoxContainer/Properties/width/width_edit.text = str(default_width) |
|
|
|
|
$HBoxContainer/Properties/height/height_edit.text = str(default_height) |
|
|
|
|
$HBoxContainer/Properties/spacing/spacing_edit.text = str(default_spacing) |
|
|
|
|
reset_options(str(default_width), str(default_height), str(default_spacing)) |
|
|
|
|
pass |
|
|
|
|
|
|
|
|
|
func reset_options(width, height, spacing): |
|
|
|
|
$HBoxContainer/Properties/width/width_edit.text = width |
|
|
|
|
$HBoxContainer/Properties/height/height_edit.text = height |
|
|
|
|
$HBoxContainer/Properties/spacing/spacing_edit.text = spacing |
|
|
|
|
|
|
|
|
|
func set_data(width, height, spacing): |
|
|
|
|
data.width = width |
|
|
|
|
data.height = height |
|
|
|
|
data.spacing = spacing |
|
|
|
|
|
|
|
|
|
func _on_Button_pressed(): |
|
|
|
|
width = int($HBoxContainer/Properties/width/width_edit.text) |
|
|
|
|
height = int($HBoxContainer/Properties/height/height_edit.text) |
|
|
|
|
spacing = int($HBoxContainer/Properties/spacing/spacing_edit.text) |
|
|
|
|
var rect = Rect2(Vector2(0, 0), Vector2(width, height)) |
|
|
|
|
points = poisson_disc_sampling.generate_points(spacing, rect, 20) |
|
|
|
|
set_data( |
|
|
|
|
int($HBoxContainer/Properties/width/width_edit.text), |
|
|
|
|
int($HBoxContainer/Properties/height/height_edit.text), |
|
|
|
|
int($HBoxContainer/Properties/spacing/spacing_edit.text) |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var rect = Rect2(Vector2(0, 0), Vector2(data.width, data.height)) |
|
|
|
|
points = poisson_disc_sampling.generate_points(data.spacing, rect, 20) |
|
|
|
|
emit_signal("new_poisson", points) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_save_pressed(): |
|
|
|
|
$SaveFileDialog.popup() |
|
|
|
|
|
|
|
|
|
func _on_SaveFileDialog_file_selected(path): |
|
|
|
|
var file = File.new() |
|
|
|
|
file.open(path, 2) |
|
|
|
|
file.store_var(data) |
|
|
|
|
file.store_var(points) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_open_pressed(): |
|
|
|
|
$OpenFileDialog.popup() |
|
|
|
|
|
|
|
|
|
func _on_OpenFileDialog_file_selected(path): |
|
|
|
|
var file = File.new() |
|
|
|
|
file.open(path, 1) |
|
|
|
|
var new_data = file.get_var() |
|
|
|
|
set_data(new_data.width, new_data.height, new_data.spacing) |
|
|
|
|
points = file.get_var() |
|
|
|
|
emit_signal("new_poisson", points) |
|
|
|
|
|