aboutsummaryrefslogtreecommitdiff
path: root/main.gd
blob: 7962d52717fd7f5e321e683e8339e608222c34e7 (plain)
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
extends Control

var power_throttle_timeout: float

onready var file_picker		:= get_node("/root/main/file_picker") as FileDialog
onready var confirm_action	:= get_node("/root/main/confirm_action") as ConfirmationDialog
onready var controls_sensible_to_keyboard := [
	self,
	file_picker,
	confirm_action,
]


func _init():
	Physics2DServer.set_active(false)
	PhysicsServer.set_active(false)
	
	if OS.get_name() == "Android":
		var permissions := Array(OS.get_granted_permissions())
		if permissions.has("android.permission.READ_EXTERNAL_STORAGE") == false \
			or permissions.has("android.permission.WRITE_EXTERNAL_STORAGE") == false:
			OS.request_permissions()



func _ready():
	Input.set_use_accumulated_input(false)
	confirm_action.get_cancel().connect("pressed", self, "dialog_cancelled", ["confirmed"])
	file_picker.get_cancel().connect("pressed", self, "dialog_cancelled", ["file_selected"])


func _process(delta: float):
	var keyboard_height: int = OS.get_virtual_keyboard_height()
	for it in controls_sensible_to_keyboard:
		it.margin_bottom = -keyboard_height
	
	# ~1650 fps with database using ItemList
	Engine.target_fps = 0
	OS.vsync_enabled = false
	OS.set_window_title("%03d" % [Engine.get_frames_per_second()])
	return
	
	if power_throttle_timeout > 0.0:
		power_throttle_timeout -= delta
	else:
		Engine.target_fps = 10


func _input(event: InputEvent):
	Engine.target_fps = 0
	power_throttle_timeout = 3.5


func _unhandled_input(event: InputEvent):
	Engine.target_fps = 0
	power_throttle_timeout = 3.5


func dialog_cancelled(confirmation_signal_name: String):
	var confirmation_handlers = confirm_action.get_signal_connection_list(confirmation_signal_name)
	for it in confirmation_handlers:
		confirm_action.disconnect(it.signal, it.target, it.method)