39 lines
1.1 KiB
GDScript
39 lines
1.1 KiB
GDScript
extends Node
|
|
class_name Player
|
|
|
|
@export var session_id: int = 0
|
|
@export var player_name: String = ""
|
|
@export var player_pronouns: String = ""
|
|
|
|
@export var current_prompt: Dictionary = {}:
|
|
set(val):
|
|
if val != current_prompt:
|
|
current_prompt = val
|
|
prompt_changed.emit(current_prompt)
|
|
|
|
signal prompt_changed(prompt: Dictionary)
|
|
signal prompt_answered(answer: String)
|
|
|
|
@rpc("any_peer", "call_local", "reliable")
|
|
func claim_authority(peer_id: int) -> void:
|
|
set_multiplayer_authority(peer_id, true)
|
|
|
|
func send_prompt(prompt: Dictionary) -> void:
|
|
_send_prompt.rpc(JSON.stringify(prompt))
|
|
pass
|
|
|
|
@rpc("any_peer", "call_local", "reliable")
|
|
func _send_prompt(json_prompt: String) -> void:
|
|
pass
|
|
if !current_prompt.is_empty():
|
|
submit_prompt_answer.rpc(1,"")
|
|
current_prompt = JSON.parse_string(json_prompt)
|
|
print("Player %d prompt received: \"%s\"" % [session_id, current_prompt["text"]])
|
|
|
|
@rpc("any_peer", "call_remote", "reliable")
|
|
func submit_prompt_answer(answer: String) -> void:
|
|
#current_prompt = null
|
|
current_prompt.clear()
|
|
prompt_answered.emit(answer)
|
|
print("Player %d answer received: \"%s\"" % [session_id, answer])
|