-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton_saveimage.gd
More file actions
76 lines (58 loc) · 1.91 KB
/
Button_saveimage.gd
File metadata and controls
76 lines (58 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
extends Button
@onready var g_node_send = $"../../HBoxContainer/Button_send"
@onready var g_node_config = $"../../../../Node_pulse_config"
@onready var g_node_fdsave = $"../../../../FileDialog_save"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func save_last_to_path(path:String):
if g_node_send.g_last_raw == null:
print("nothing generated")
return false
else:
var f = null
#if g_node_config.g_filetype == "png":
#f = FileAccess.open("./temp/temp_image.png", FileAccess.WRITE)
#else: # jpg
#f = FileAccess.open("./temp/temp_image.jpg", FileAccess.WRITE)
# store the bytes
f = FileAccess.open(path, FileAccess.WRITE)
# should error check.. TODO:
for byte in g_node_send.g_last_raw:
f.store_8(byte)
f.close()
return true
func return_from_dialog(path):
print("*** returned from save:", path)
save_last_to_path(path)
pass
func _on_button_up():
# TODO: add in save_last_to_path
# save_last_to_path("./temp/temp_image.jpg")
# set filters on filedialog depending on what format we are allowing for gen
if g_node_send.g_last_raw == null:
print("nothing generated")
return
if g_node_send.g_last_ext == "png":
g_node_fdsave.filters = PackedStringArray(["*.png"])
else: # jpg
g_node_fdsave.filters = PackedStringArray(["*.jpg"])
g_node_fdsave.g_cur_action = "saveimage"
g_node_fdsave.show()
return
if g_node_send.g_last_raw == null:
print("nothing generated")
else:
var f = null
if g_node_send.g_last_ext == "png":
f = FileAccess.open("./temp/temp_image.png", FileAccess.WRITE)
else: # jpg
f = FileAccess.open("./temp/temp_image.jpg", FileAccess.WRITE)
# store the bytes
for byte in g_node_send.g_last_raw:
f.store_8(byte)
f.close()
pass # Replace with function body.