Push project up
This commit is contained in:
15
globals/globals.gd
Normal file
15
globals/globals.gd
Normal file
@@ -0,0 +1,15 @@
|
||||
extends Node
|
||||
|
||||
|
||||
var game_data: GameData
|
||||
var multiplayer_data: MultiplayerData
|
||||
|
||||
|
||||
func cache_invalidate_load_resource(target: String) -> Resource:
|
||||
# NOTE: Deep replace version b/c we don't want to use an autoloads
|
||||
# that does this replasce before any nodes actually load.
|
||||
ResourceLoader.load(target, "", ResourceLoader.CACHE_MODE_REPLACE_DEEP)
|
||||
|
||||
# NOTE: Let prior call propigate naturally. (Unsure when...)
|
||||
# Enforce new script/node from pck called here.
|
||||
return ResourceLoader.load(target, "", ResourceLoader.CACHE_MODE_IGNORE_DEEP)
|
||||
1
globals/globals.gd.uid
Normal file
1
globals/globals.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://biu64hvcxb1su
|
||||
68
globals/message_bus.gd
Normal file
68
globals/message_bus.gd
Normal file
@@ -0,0 +1,68 @@
|
||||
extends Node
|
||||
|
||||
|
||||
var message_types: Dictionary[String, Array] = {}
|
||||
|
||||
|
||||
func subscribe(id: String, callback: Callable) -> void:
|
||||
if not message_types.has(id):
|
||||
message_types.set(id, Array())
|
||||
|
||||
message_types.get(id).append(callback)
|
||||
|
||||
|
||||
func clear_voided_listeners() -> void:
|
||||
for mtype in message_types.keys():
|
||||
var mlisteners: Array = message_types.get(mtype)
|
||||
for mlistener in mlisteners:
|
||||
if mlistener.is_valid(): continue
|
||||
mlisteners.erase(mlistener)
|
||||
|
||||
|
||||
func emit_local(id: String, data: Variant, expand: bool = false) -> void:
|
||||
emit_propagation(id, data, expand)
|
||||
|
||||
|
||||
# TODO: Need to actually validate client request. Also, message bus is more
|
||||
# about server talking to clients than clients to server. I.E, reducing
|
||||
# the number of needed @rpc method decorator bindings.
|
||||
@rpc("any_peer", "call_remote", "reliable")
|
||||
func emit_request(id: String, data: Variant, expand: bool = false) -> void:
|
||||
if not multiplayer.is_server(): return
|
||||
if not message_types.has(id):
|
||||
push_error("'%s' not an existing message type to handle...", [id])
|
||||
return
|
||||
|
||||
emit_propagation(id, data, expand)
|
||||
|
||||
@rpc("authority", "call_local", "reliable")
|
||||
func emit_propagation(id: String, data: Variant, expand: bool = false) -> void:
|
||||
if not message_types.has(id):
|
||||
push_error("'%s' not an existing message type to handle...", [id])
|
||||
return
|
||||
|
||||
for callback: Callable in message_types.get(id):
|
||||
if data == null:
|
||||
callback.call()
|
||||
continue
|
||||
|
||||
if not expand:
|
||||
callback.call(data)
|
||||
else:
|
||||
callback.callv(data)
|
||||
|
||||
@rpc("authority", "call_remote", "reliable")
|
||||
func emit_propagation_clients_only(id: String, data: Variant, expand: bool = false) -> void:
|
||||
if not message_types.has(id):
|
||||
push_error("'%s' not an existing message type to handle...", [id])
|
||||
return
|
||||
|
||||
for callback: Callable in message_types.get(id):
|
||||
if data == null:
|
||||
callback.call()
|
||||
continue
|
||||
|
||||
if not expand:
|
||||
callback.call(data)
|
||||
else:
|
||||
callback.callv(data)
|
||||
1
globals/message_bus.gd.uid
Normal file
1
globals/message_bus.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dgkbelaqw2a2g
|
||||
Reference in New Issue
Block a user