diff options
| author | dam <dam@gudinoff> | 2022-04-18 09:06:19 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-04-18 09:06:19 +0000 |
| commit | 79691f93bab7aa093bb606bfb80d2b4b236ee091 (patch) | |
| tree | 6e90c6601893895d7640f478f0cad402cc7590b4 /main.gd | |
| parent | 697e1ba3c4cb0a96c4584f1553de368d46287ab7 (diff) | |
| parent | ee31a9a3d387121030a5f4503adeac5816d7726f (diff) | |
| download | surgery-log-1.0.tar.zst surgery-log-1.0.zip | |
Merge godot branch.v1.0
Diffstat (limited to 'main.gd')
| -rw-r--r-- | main.gd | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -0,0 +1,65 @@ +extends Control + +var power_throttle_timeout: float + +onready var popup := get_node("/root/main/popup") as ModalPopup +onready var file_picker := get_node("/root/main/file_picker") as FileDialog +onready var stage := get_node("/root/main/stage") as Stage +onready var database := get_node("/root/main/database") as Database +onready var controls_sensible_to_keyboard := [ + self, + file_picker, +] + + +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) + + +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 + + 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 _notification(what: int): + if what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST: + if popup.visible: + popup.call_deferred("dismiss") + elif file_picker.visible: + file_picker.hide() + elif stage.visible: + stage.discard_action() + elif database.selected_idx != -1: + database.clear_selection() + else: + get_tree().quit() + + |
