You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.7 KiB
64 lines
1.7 KiB
extends Control
|
|
|
|
export var default_width = 500
|
|
export var default_height = 500
|
|
export var default_spacing = 5
|
|
|
|
var data = {
|
|
width = default_width,
|
|
height = default_height,
|
|
spacing = default_spacing
|
|
}
|
|
|
|
var poisson_disc_sampling: PoissonDiscSampling = PoissonDiscSampling.new()
|
|
var points = []
|
|
|
|
signal new_poisson(points)
|
|
|
|
func _ready():
|
|
reset_options(default_width, default_height, default_spacing)
|
|
pass
|
|
|
|
func reset_options(width, height, spacing):
|
|
$HBoxContainer/Properties/width/width_edit.text = str(width)
|
|
$HBoxContainer/Properties/height/height_edit.text = str(height)
|
|
$HBoxContainer/Properties/spacing/spacing_edit.text = str(spacing)
|
|
|
|
func set_data(width, height, spacing):
|
|
data.width = width
|
|
data.height = height
|
|
data.spacing = spacing
|
|
|
|
func _on_Button_pressed():
|
|
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)
|
|
reset_options(new_data.width, new_data.height, new_data.spacing)
|
|
points = file.get_var()
|
|
emit_signal("new_poisson", points)
|
|
|