Skip to content

Commit 7e7f87a

Browse files
gk98selementbound
andauthored
refactor: More static types (#420)
Co-authored-by: Tamás Gálffy <ezittgtx@gmail.com>
1 parent c0f987d commit 7e7f87a

21 files changed

Lines changed: 192 additions & 192 deletions

addons/netfox.extras/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.extras"
44
description="Game-specific utilities for Netfox"
55
author="Tamas Galffy and contributors"
6-
version="1.24.8"
6+
version="1.24.9"
77
script="netfox-extras.gd"

addons/netfox.internals/logger.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static func make_setting(name: String) -> Dictionary:
5050
"hint_string": "All,Trace,Debug,Info,Warning,Error,None"
5151
}
5252

53-
static func register_tag(tag: Callable, priority: int = 0):
53+
static func register_tag(tag: Callable, priority: int = 0) -> void:
5454
# Save tag
5555
if not _tags.has(priority):
5656
_tags[priority] = [tag]

addons/netfox.internals/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.internals"
44
description="Shared internals for netfox addons"
55
author="Tamas Galffy and contributors"
6-
version="1.24.8"
6+
version="1.24.9"
77
script="plugin.gd"

addons/netfox.noray/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="netfox.noray"
44
description="Bulletproof your connectivity with noray integration for netfox"
55
author="Tamas Galffy and contributors"
6-
version="1.24.8"
6+
version="1.24.9"
77
script="netfox-noray.gd"

addons/netfox/interpolators.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ class Interpolator:
66
var apply: Callable
77

88
static func make(is_applicable: Callable, apply: Callable) -> Interpolator:
9-
var result = Interpolator.new()
9+
var result := Interpolator.new()
1010
result.is_applicable = is_applicable
1111
result.apply = apply
1212
return result
1313

14-
static var DEFAULT_INTERPOLATOR = Interpolator.make(
14+
static var DEFAULT_INTERPOLATOR := Interpolator.make(
1515
func (v): return true,
1616
func (a, b, f): return a if f < 0.5 else b
1717
)
@@ -24,7 +24,7 @@ static var default_apply: Callable = func(a, b, f): a if f < 0.5 else b
2424
## New interpolators are pushed to the front of the list, making them have
2525
## precedence over existing ones. This can be useful in case you want to override
2626
## the built-in interpolators.
27-
static func register(is_applicable: Callable, apply: Callable):
27+
static func register(is_applicable: Callable, apply: Callable) -> void:
2828
interpolators.push_front(Interpolator.make(is_applicable, apply))
2929

3030
## Find the appropriate interpolator for the given value.
@@ -45,7 +45,7 @@ static func find_for(value) -> Callable:
4545
static func interpolate(a, b, f: float):
4646
return find_for(a).call(a, b, f)
4747

48-
static func _static_init():
48+
static func _static_init() -> void:
4949
# Register built-in interpolators
5050
# Float
5151
register(

addons/netfox/netfox.gd

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@tool
22
extends EditorPlugin
33

4-
const ROOT = "res://addons/netfox"
5-
var SETTINGS = [
4+
const ROOT := "res://addons/netfox"
5+
var SETTINGS: Array[Dictionary] = [
66
{
77
# Setting this to false will make Netfox keep its settings even when
88
# disabling the plugin. Useful for developing the plugin.
@@ -125,7 +125,7 @@ var SETTINGS = [
125125
}
126126
]
127127

128-
const AUTOLOADS = [
128+
const AUTOLOADS: Array[Dictionary] = [
129129
{
130130
"name": "NetworkTime",
131131
"path": ROOT + "/network-time.gd"
@@ -148,7 +148,7 @@ const AUTOLOADS = [
148148
}
149149
]
150150

151-
const TYPES = [
151+
const TYPES: Array[Dictionary] = [
152152
{
153153
"name": "RollbackSynchronizer",
154154
"base": "Node",
@@ -179,8 +179,8 @@ func _enter_tree():
179179
for type in TYPES:
180180
add_custom_type(type.name, type.base, load(type.script), load(type.icon))
181181

182-
func _exit_tree():
183-
if ProjectSettings.get_setting("netfox/general/clear_settings", false):
182+
func _exit_tree() -> void:
183+
if ProjectSettings.get_setting(&"netfox/general/clear_settings", false):
184184
for setting in SETTINGS:
185185
remove_setting(setting)
186186

@@ -190,7 +190,7 @@ func _exit_tree():
190190
for type in TYPES:
191191
remove_custom_type(type.name)
192192

193-
func add_setting(setting: Dictionary):
193+
func add_setting(setting: Dictionary) -> void:
194194
if ProjectSettings.has_setting(setting.name):
195195
return
196196

@@ -203,7 +203,7 @@ func add_setting(setting: Dictionary):
203203
"hint_string": setting.get("hint_string", "")
204204
})
205205

206-
func remove_setting(setting: Dictionary):
206+
func remove_setting(setting: Dictionary) -> void:
207207
if not ProjectSettings.has_setting(setting.name):
208208
return
209209

addons/netfox/network-events.gd

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ var enabled: bool:
5050

5151
var _is_server: bool = false
5252
var _multiplayer: MultiplayerAPI
53-
var _enabled = false
53+
var _enabled: bool = false
5454

5555
## Check if we're running as server.
5656
func is_server() -> bool:
5757
if multiplayer == null:
5858
return false
5959

60-
var peer = multiplayer.multiplayer_peer
60+
var peer := multiplayer.multiplayer_peer
6161
if peer == null:
6262
return false
6363

@@ -72,10 +72,10 @@ func is_server() -> bool:
7272

7373
return true
7474

75-
func _ready():
75+
func _ready() -> void:
7676
_NetfoxLogger.register_tag(func(): return "#%d" % multiplayer.get_unique_id(), -99)
7777

78-
enabled = ProjectSettings.get_setting("netfox/events/enabled", true)
78+
enabled = ProjectSettings.get_setting(&"netfox/events/enabled", true)
7979

8080
# Automatically start ticking when entering multiplayer and stop when
8181
# leaving multiplayer
@@ -84,7 +84,7 @@ func _ready():
8484
on_client_start.connect(func(id): NetworkTime.start())
8585
on_client_stop.connect(NetworkTime.stop)
8686

87-
func _process(_delta):
87+
func _process(_delta: float) -> void:
8888
if multiplayer != _multiplayer:
8989
_disconnect_handlers(_multiplayer)
9090
_connect_handlers(multiplayer)
@@ -100,7 +100,7 @@ func _process(_delta):
100100
_is_server = false
101101
on_server_stop.emit()
102102

103-
func _connect_handlers(mp: MultiplayerAPI):
103+
func _connect_handlers(mp: MultiplayerAPI) -> void:
104104
if mp == null:
105105
return
106106

@@ -109,7 +109,7 @@ func _connect_handlers(mp: MultiplayerAPI):
109109
mp.peer_connected.connect(_handle_peer_connected)
110110
mp.peer_disconnected.connect(_handle_peer_disconnected)
111111

112-
func _disconnect_handlers(mp: MultiplayerAPI):
112+
func _disconnect_handlers(mp: MultiplayerAPI) -> void:
113113
if mp == null:
114114
return
115115

@@ -118,19 +118,19 @@ func _disconnect_handlers(mp: MultiplayerAPI):
118118
mp.peer_connected.disconnect(_handle_peer_connected)
119119
mp.peer_disconnected.disconnect(_handle_peer_disconnected)
120120

121-
func _handle_connected_to_server():
121+
func _handle_connected_to_server() -> void:
122122
on_client_start.emit(multiplayer.get_unique_id())
123123

124-
func _handle_server_disconnected():
124+
func _handle_server_disconnected() -> void:
125125
on_client_stop.emit()
126126

127-
func _handle_peer_connected(id: int):
127+
func _handle_peer_connected(id: int) -> void:
128128
on_peer_join.emit(id)
129129

130-
func _handle_peer_disconnected(id: int):
130+
func _handle_peer_disconnected(id: int) -> void:
131131
on_peer_leave.emit(id)
132132

133-
func _set_enabled(enable: bool):
133+
func _set_enabled(enable: bool) -> void:
134134
if _enabled and not enable:
135135
_disconnect_handlers(_multiplayer)
136136
_multiplayer = null

addons/netfox/network-performance.gd

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static var _logger: _NetfoxLogger = _NetfoxLogger.for_netfox("NetworkPerformance
4242
## ( see [method OS.is_debug_build] ). [br]
4343
## Can be forced on with the [code]netfox_perf[/code] feature tag. [br]
4444
## Can be forced off with the [code]netfox_noperf[/code] feature tag.
45-
func is_enabled():
45+
func is_enabled() -> bool:
4646
if OS.has_feature("netfox_noperf"):
4747
return false
4848

@@ -103,19 +103,19 @@ func get_sent_state_props_count() -> int:
103103
func get_sent_state_props_ratio() -> float:
104104
return _sent_state_props / maxf(1., _full_state_props)
105105

106-
func push_full_state(state: Dictionary):
106+
func push_full_state(state: Dictionary) -> void:
107107
_full_state_props_accum += state.size()
108108

109-
func push_full_state_broadcast(state: Dictionary):
109+
func push_full_state_broadcast(state: Dictionary) -> void:
110110
_full_state_props_accum += state.size() * (multiplayer.get_peers().size() - 1)
111111

112-
func push_sent_state(state: Dictionary):
112+
func push_sent_state(state: Dictionary) -> void:
113113
_sent_state_props_accum += state.size()
114114

115-
func push_sent_state_broadcast(state: Dictionary):
115+
func push_sent_state_broadcast(state: Dictionary) -> void:
116116
_sent_state_props_accum += state.size() * (multiplayer.get_peers().size() - 1)
117117

118-
func _ready():
118+
func _ready() -> void:
119119
if not is_enabled():
120120
_logger.debug("Network performance disabled")
121121
return
@@ -141,14 +141,14 @@ func _ready():
141141
NetworkRollback.on_process_tick.connect(_on_rollback_tick)
142142
NetworkRollback.after_loop.connect(_after_rollback_loop)
143143

144-
func _before_tick_loop():
144+
func _before_tick_loop() -> void:
145145
_network_loop_start = _time()
146146
_network_ticks_accum = 0
147147

148-
func _on_network_tick(_dt, _t):
148+
func _on_network_tick(_dt, _t) -> void:
149149
_network_ticks_accum += 1
150150

151-
func _after_tick_loop():
151+
func _after_tick_loop() -> void:
152152
_network_loop_duration = _time() - _network_loop_start
153153
_network_ticks = _network_ticks_accum
154154

@@ -158,15 +158,15 @@ func _after_tick_loop():
158158
_sent_state_props = _sent_state_props_accum
159159
_sent_state_props_accum = 0
160160

161-
func _before_rollback_loop():
161+
func _before_rollback_loop() -> void:
162162
_rollback_loop_start = _time()
163163
_rollback_ticks_accum = 0
164164
_rollback_nodes_simulated_accum = 0
165165

166-
func _on_rollback_tick(_t):
166+
func _on_rollback_tick(_t: int) -> void:
167167
_rollback_ticks_accum += 1
168168

169-
func _after_rollback_loop():
169+
func _after_rollback_loop() -> void:
170170
_rollback_loop_duration = _time() - _rollback_loop_start
171171
_rollback_ticks = _rollback_ticks_accum
172172
_rollback_nodes_simulated = _rollback_nodes_simulated_accum

0 commit comments

Comments
 (0)