Skip to content

Commit

Permalink
Merge pull request #46 from averagebrine/main
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexejhero authored Jan 12, 2025
2 parents 69e8979 + 20f6625 commit 03c002e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
54 changes: 50 additions & 4 deletions Godot/addons/neuro-sdk/messages/api/incoming_data.gd
Original file line number Diff line number Diff line change
@@ -1,18 +1,64 @@
class_name IncomingData


var _data: Dictionary

func _init(data: Dictionary):

func _init(data: Dictionary) -> void:
_data = data


func get_full_data() -> Dictionary:
return _data.duplicate(true)


func get_string(name: String, default: String = "") -> String:
var value = _data.get(name, default)
if typeof(value) != TYPE_STRING:
if value is not String:
value = default

return value


func get_number(name: String, default: float = 0.0) -> float:
return get_float(name, default)


func get_object(name: String, default: Dictionary = {}) -> IncomingData:
var value = _data.get(name, {})
if typeof(value) != TYPE_DICTIONARY:
var value = _data.get(name, default)
if value is not Dictionary:
value = default

return IncomingData.new(value)


func get_array(name: String, default: Array) -> Array:
var value = _data.get(name, default)
if value is not Array:
value = default

return value


func get_boolean(name: String, default: bool = false) -> bool:
var value = _data.get(name, default)
if value is not bool:
value = default

return value


func get_int(name: String, default: int = 0) -> int:
var value = _data.get(name, default)
if value is not int and value is not float:
value = default

return int(value)


func get_float(name: String, default: float = 0.0) -> float:
var value = _data.get(name, default)
if value is not int and value is not float:
value = default

return float(value)
9 changes: 6 additions & 3 deletions Godot/addons/neuro-sdk/messages/api/outgoing_message.gd
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
class_name OutgoingMessage


func _get_command() -> String:
push_error("OutgoingMessage._get_command() is not implemented.")
return "invalid"

# Returns Dictionary | null
func _get_data():
return null

func _get_data() -> Dictionary:
return {}


func merge(_other: OutgoingMessage) -> bool:
return false


func get_ws_message() -> WsMessage:
return WsMessage.new(_get_command(), _get_data(), NeuroSdkConfig.game)
17 changes: 10 additions & 7 deletions Godot/addons/neuro-sdk/messages/api/ws_message.gd
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
class_name WsMessage


var command: String
var data
var data: Dictionary
var game: String

func _init(command_: String, data_, game_: String):
command = command_
data = data_
game = game_

func _init(_command: String, _data: Dictionary, _game: String):
command = _command
data = _data
game = _game


func get_data() -> Dictionary:
if data == null:
if data.is_empty():
return {
"command": command,
"game": game,
"game": game
}

return {
Expand Down
2 changes: 1 addition & 1 deletion Godot/addons/neuro-sdk/websocket/websocket.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func _process(delta) -> void:
_ws_reconnect()

func _ws_start() -> void:
push_warning("Initializing Websocket connection")
print("Initializing Websocket connection")

if _socket != null:
var state: int = _socket.get_ready_state();
Expand Down

0 comments on commit 03c002e

Please sign in to comment.