save + load

pull/4/head
Valentin Stark 3 years ago
parent 2523700b09
commit a040767dae
  1. BIN
      50
  2. 57
      Poisson.gd
  3. 21
      Poisson.tscn
  4. 2
      Previsualisation.gd
  5. BIN
      a
  6. 1
      rien
  7. BIN
      test/5000
  8. BIN
      test/gros
  9. 1
      truc
  10. BIN
      truc2
  11. BIN
      truc3
  12. BIN
      truc4

BIN
50

Binary file not shown.

@ -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)

@ -89,5 +89,26 @@ margin_bottom = 502.0
[node name="Previsualisation" type="TextureRect" parent="ScrollContainer"]
script = ExtResource( 2 )
[node name="SaveFileDialog" type="FileDialog" parent="."]
margin_left = 83.0
margin_top = 133.0
margin_right = 649.0
margin_bottom = 505.0
window_title = "Enregistrer un fichier"
access = 2
[node name="OpenFileDialog" type="FileDialog" parent="."]
margin_left = 83.0
margin_top = 133.0
margin_right = 649.0
margin_bottom = 505.0
window_title = "Ouvrir un fichier"
mode = 0
access = 2
[connection signal="new_poisson" from="." to="ScrollContainer/Previsualisation" method="_on_Control_new_poisson"]
[connection signal="pressed" from="HBoxContainer/Properties/generate" to="." method="_on_Button_pressed"]
[connection signal="pressed" from="HBoxContainer/Properties/open" to="." method="_on_open_pressed"]
[connection signal="pressed" from="HBoxContainer/Properties/save" to="." method="_on_save_pressed"]
[connection signal="file_selected" from="SaveFileDialog" to="." method="_on_SaveFileDialog_file_selected"]
[connection signal="file_selected" from="OpenFileDialog" to="." method="_on_OpenFileDialog_file_selected"]

@ -4,7 +4,7 @@ var image
func create_image(points):
image = Image.new()
image.create(get_parent().get_parent().width, get_parent().get_parent().height, false, Image.FORMAT_RGBA8)
image.create(get_parent().get_parent().data.width, get_parent().get_parent().data.height, false, Image.FORMAT_RGBA8)
image.fill(Color.white)
image.lock()
for point in points:

BIN
a

Binary file not shown.

@ -0,0 +1 @@
[]

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

BIN
truc2

Binary file not shown.

BIN
truc3

Binary file not shown.

BIN
truc4

Binary file not shown.
Loading…
Cancel
Save