-
Notifications
You must be signed in to change notification settings - Fork 0
/
GMaster.gd
87 lines (64 loc) · 2.38 KB
/
GMaster.gd
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
77
78
79
80
81
82
83
84
85
86
87
extends Node
class_name GMaster
@export var move_multiplier : float = 5
@export var initialize_client : bool = false
@export var initialize_server : bool = false
var new_pos : Vector2
var moving_cursor = false
var last_touch_start = Vector2.ZERO
var server : GServer
var client : GClient
var ui_panel : GUIMainPanel
var thread : Thread
var is_running_in_editor = OS.has_feature("editor")
var is_running_in_mobile : bool = OS.get_name() == "Android"
var _tray : GXTraypp
# Called when the node enters the scene tree for the first time.
func _ready():
if not is_running_in_editor:
initialize_client = false
initialize_server = false
server = $Server as GServer
client = $Client as GClient
ui_panel = $UIMainPanel as GUIMainPanel
$UIMainPanel/MarginContainer/Control/PanelTouchPad/TextureRectCursorSimulator/LabelSimulationAction.text = ""
if !is_running_in_mobile || initialize_server:
server.initialize(self)
thread = Thread.new()
thread.start(_start_system_tray.bind($GXTraypp))
$GXTraypp.on_receive_exit_request.connect(exit_game)
if is_running_in_editor:
server.on_receive_move_cursor_request.connect(_on_receive_move_request)
if is_running_in_mobile || initialize_client:
ui_panel.initialize(client)
client.initialize()
client.try_connect_client(GConfig.host,GConfig.port)
func _input(ev):
if ev is InputEventMouseMotion:
return
if ev is InputEventKey and ev.keycode == KEY_SPACE and ev.pressed:
print("debug action")
return
if is_running_in_editor && ev is InputEventKey:
match (ev as InputEventKey).keycode:
KEY_W:
client.send_cursor_movement(Vector2.ZERO, Vector2.UP)
KEY_A:
client.send_cursor_movement(Vector2.ZERO, Vector2.LEFT)
KEY_S:
client.send_cursor_movement(Vector2.ZERO, Vector2.DOWN)
KEY_D:
client.send_cursor_movement(Vector2.ZERO, Vector2.RIGHT)
func _on_receive_move_request(offset: Vector2):
var cursor_simulator = $UIMainPanel/MarginContainer/Control/PanelTouchPad/TextureRectCursorSimulator
cursor_simulator.set_position(cursor_simulator.position + offset * move_multiplier)
func _start_system_tray(tray: GXTraypp):
_tray = tray
var icon_path = ProjectSettings.globalize_path("res://images/icon.ico")
print("Starting system tray, icon: ", icon_path)
_tray.add_to_system_tray("Godouse", icon_path)
func _exit_tree():
_tray.stop_system_tray()
thread.wait_to_finish()
func exit_game():
get_tree().quit()