Integrate per-save identity and interaction UI
This commit is contained in:
parent
ac82a28f3b
commit
4fda6e97f6
58 changed files with 3471 additions and 461 deletions
|
|
@ -16,6 +16,7 @@ signal profile_snapshot_changed(
|
|||
display_name: String,
|
||||
appearance: Dictionary,
|
||||
)
|
||||
signal profile_title_changed(peer_id: int, title: String)
|
||||
|
||||
var _session: NetworkSession
|
||||
var _preferences: NetworkProfilePreferences
|
||||
|
|
@ -26,6 +27,7 @@ var _pending_voice_ids: Dictionary[String, String] = {}
|
|||
var _pending_speech_speed_ids: Dictionary[String, String] = {}
|
||||
var _pending_call_ids: Dictionary[String, String] = {}
|
||||
var _pending_sample_set_ids: Dictionary[String, String] = {}
|
||||
var _pending_titles: Dictionary[String, String] = {}
|
||||
var _host_pending_apply: Dictionary[String, Dictionary] = {}
|
||||
var _latest_check_id: String = ""
|
||||
var _latest_check_name: String = ""
|
||||
|
|
@ -42,6 +44,16 @@ func setup(
|
|||
_appearance_store = appearance_store
|
||||
_spawn_service = spawn_service
|
||||
_appearance_store.load_preferences()
|
||||
if not _preferences.profile_changed.is_connected(
|
||||
_on_local_profile_store_changed
|
||||
):
|
||||
_preferences.profile_changed.connect(_on_local_profile_store_changed)
|
||||
if not _appearance_store.appearance_changed.is_connected(
|
||||
_on_local_appearance_store_changed
|
||||
):
|
||||
_appearance_store.appearance_changed.connect(
|
||||
_on_local_appearance_store_changed
|
||||
)
|
||||
_session.peer_authenticated.connect(_on_peer_authenticated)
|
||||
_session.peer_removed.connect(_on_peer_removed)
|
||||
_session.peer_display_name_changed.connect(_on_peer_display_name_changed)
|
||||
|
|
@ -51,6 +63,20 @@ func setup(
|
|||
_apply_local_voice_to_avatar()
|
||||
|
||||
|
||||
func _on_local_profile_store_changed() -> void:
|
||||
_apply_local_voice_to_avatar()
|
||||
|
||||
|
||||
func _on_local_appearance_store_changed() -> void:
|
||||
var snapshot: Dictionary = _appearance_store.get_snapshot()
|
||||
var local_peer_id: int = (
|
||||
_session.get_local_peer_id() if _session != null else 1
|
||||
)
|
||||
_apply_to_avatar(local_peer_id, snapshot)
|
||||
if _session != null:
|
||||
_session.set_local_appearance_snapshot(snapshot)
|
||||
|
||||
|
||||
func reload_persisted_profile() -> bool:
|
||||
if (
|
||||
not _preferences.load_or_create()
|
||||
|
|
@ -66,6 +92,10 @@ func get_persisted_name() -> String:
|
|||
return _preferences.display_name
|
||||
|
||||
|
||||
func get_persisted_title() -> String:
|
||||
return _preferences.title
|
||||
|
||||
|
||||
func get_persisted_appearance() -> Dictionary:
|
||||
return _appearance_store.get_snapshot()
|
||||
|
||||
|
|
@ -107,6 +137,7 @@ func preview_appearance(appearance: Dictionary) -> bool:
|
|||
local_peer_id,
|
||||
_preferences.display_name,
|
||||
snapshot,
|
||||
_preferences.title,
|
||||
)
|
||||
var authorization := _make_appearance_preview_authorization(snapshot)
|
||||
var local_record := _session.get_peer_record(local_peer_id)
|
||||
|
|
@ -179,10 +210,16 @@ func apply_profile(
|
|||
speech_speed_id: String = VoiceProfilesType.DEFAULT_SPEED_ID,
|
||||
call_id: String = VoiceProfilesType.DEFAULT_CALL_ID,
|
||||
sample_set_id: String = VoiceProfilesType.DEFAULT_SAMPLE_SET_ID,
|
||||
player_title: String = "",
|
||||
) -> bool:
|
||||
var clean_name := display_name.strip_edges()
|
||||
var clean_title := (
|
||||
_preferences.title
|
||||
if player_title.is_empty() else player_title.strip_edges()
|
||||
)
|
||||
if (
|
||||
not NetworkProfilePreferences.is_valid_display_name(clean_name)
|
||||
or not NetworkProfilePreferences.is_valid_title(clean_title)
|
||||
or not CharacterCustomizationCatalog.validate_snapshot(appearance)
|
||||
or not VoiceProfilesType.is_valid(voice_id)
|
||||
or not VoiceProfilesType.is_valid_speed(speech_speed_id)
|
||||
|
|
@ -196,6 +233,7 @@ func apply_profile(
|
|||
"request_id": request_id,
|
||||
"session_id": _session.get_session_id() if _session != null else "",
|
||||
"display_name": clean_name,
|
||||
"player_title": clean_title,
|
||||
"appearance": appearance.duplicate(true),
|
||||
"use_anyway": use_anyway,
|
||||
"sender_fingerprint": _session.get_local_identity_fingerprint(),
|
||||
|
|
@ -208,6 +246,7 @@ func apply_profile(
|
|||
_pending_speech_speed_ids[request_id] = speech_speed_id
|
||||
_pending_call_ids[request_id] = call_id
|
||||
_pending_sample_set_ids[request_id] = sample_set_id
|
||||
_pending_titles[request_id] = clean_title
|
||||
if _session == null or not _session.is_gameplay_session_active():
|
||||
_apply_local_result(request_id, true, "", false, PackedStringArray())
|
||||
elif _session.is_host():
|
||||
|
|
@ -303,6 +342,7 @@ func submit_appearance_preview(data: Dictionary) -> void:
|
|||
sender_id,
|
||||
record.display_name,
|
||||
appearance,
|
||||
record.title,
|
||||
)
|
||||
_apply_to_avatar(sender_id, appearance)
|
||||
_broadcast_appearance_preview_to_supported_peers(sender_id, appearance)
|
||||
|
|
@ -310,6 +350,7 @@ func submit_appearance_preview(data: Dictionary) -> void:
|
|||
|
||||
func _process_apply_request(peer_id: int, data: Dictionary) -> void:
|
||||
var display_name: String = str(data["display_name"]).strip_edges()
|
||||
var player_title: String = str(data["player_title"]).strip_edges()
|
||||
var conflict: bool = _name_conflicts(peer_id, display_name)
|
||||
var accepted: bool = not conflict or bool(data["use_anyway"])
|
||||
var suggestions: PackedStringArray = (
|
||||
|
|
@ -325,7 +366,8 @@ func _process_apply_request(peer_id: int, data: Dictionary) -> void:
|
|||
if accepted:
|
||||
_host_pending_apply[str(data["request_id"])] = {
|
||||
"peer_id": peer_id,
|
||||
"display_name": display_name,
|
||||
"display_name": display_name,
|
||||
"player_title": player_title,
|
||||
"appearance": Dictionary(data["appearance"]).duplicate(true),
|
||||
"authorization": {
|
||||
"request_id": data["request_id"],
|
||||
|
|
@ -356,8 +398,11 @@ func confirm_profile_saved(request_id: String) -> void:
|
|||
return
|
||||
_host_pending_apply.erase(request_id)
|
||||
var display_name: String = str(pending["display_name"])
|
||||
var player_title: String = str(pending["player_title"])
|
||||
var appearance: Dictionary = Dictionary(pending["appearance"])
|
||||
_session.apply_canonical_profile(sender_id, display_name, appearance)
|
||||
_session.apply_canonical_profile(
|
||||
sender_id, display_name, appearance, player_title
|
||||
)
|
||||
var record: PeerRegistry.PeerRecord = _session.get_peer_record(sender_id)
|
||||
if record != null:
|
||||
record.profile_authorization = pending.get("authorization", {}).duplicate(true)
|
||||
|
|
@ -365,6 +410,7 @@ func confirm_profile_saved(request_id: String) -> void:
|
|||
broadcast_profile_snapshot.rpc(
|
||||
sender_id,
|
||||
display_name,
|
||||
player_title,
|
||||
appearance,
|
||||
pending.get("authorization", {}),
|
||||
)
|
||||
|
|
@ -405,10 +451,12 @@ func _apply_local_result(
|
|||
_pending_speech_speed_ids.erase(request_id)
|
||||
_pending_call_ids.erase(request_id)
|
||||
_pending_sample_set_ids.erase(request_id)
|
||||
_pending_titles.erase(request_id)
|
||||
conflict_result.emit(request_id, conflict, suggestions)
|
||||
apply_finished.emit(false, message)
|
||||
return
|
||||
var previous_name := _preferences.display_name
|
||||
var previous_title := _preferences.title
|
||||
var previous_voice_id := _preferences.voice_id
|
||||
var previous_speech_speed_id := _preferences.speech_speed_id
|
||||
var previous_call_id := _preferences.call_id
|
||||
|
|
@ -429,18 +477,24 @@ func _apply_local_result(
|
|||
request_id,
|
||||
VoiceProfilesType.DEFAULT_SAMPLE_SET_ID,
|
||||
)
|
||||
var requested_title: String = _pending_titles.get(
|
||||
request_id,
|
||||
NetworkProfilePreferences.DEFAULT_TITLE,
|
||||
)
|
||||
if not _preferences.set_profile_identity(
|
||||
str(request["display_name"]),
|
||||
requested_voice_id,
|
||||
requested_speech_speed_id,
|
||||
requested_call_id,
|
||||
requested_sample_set_id,
|
||||
requested_title,
|
||||
):
|
||||
_pending_apply.erase(request_id)
|
||||
_pending_voice_ids.erase(request_id)
|
||||
_pending_speech_speed_ids.erase(request_id)
|
||||
_pending_call_ids.erase(request_id)
|
||||
_pending_sample_set_ids.erase(request_id)
|
||||
_pending_titles.erase(request_id)
|
||||
apply_finished.emit(false, "Profile could not be saved.")
|
||||
return
|
||||
if not _appearance_store.save_snapshot(request["appearance"]):
|
||||
|
|
@ -450,12 +504,14 @@ func _apply_local_result(
|
|||
previous_speech_speed_id,
|
||||
previous_call_id,
|
||||
previous_sample_set_id,
|
||||
previous_title,
|
||||
)
|
||||
_pending_apply.erase(request_id)
|
||||
_pending_voice_ids.erase(request_id)
|
||||
_pending_speech_speed_ids.erase(request_id)
|
||||
_pending_call_ids.erase(request_id)
|
||||
_pending_sample_set_ids.erase(request_id)
|
||||
_pending_titles.erase(request_id)
|
||||
apply_finished.emit(false, "Profile could not be saved.")
|
||||
return
|
||||
_pending_apply.erase(request_id)
|
||||
|
|
@ -463,6 +519,7 @@ func _apply_local_result(
|
|||
_pending_speech_speed_ids.erase(request_id)
|
||||
_pending_call_ids.erase(request_id)
|
||||
_pending_sample_set_ids.erase(request_id)
|
||||
_pending_titles.erase(request_id)
|
||||
if _session != null:
|
||||
_session.set_local_appearance_snapshot(_appearance_store.get_snapshot())
|
||||
if _session != null and _session.is_gameplay_session_active():
|
||||
|
|
@ -471,6 +528,7 @@ func _apply_local_result(
|
|||
_session.get_local_peer_id(),
|
||||
_preferences.display_name,
|
||||
_appearance_store.get_snapshot(),
|
||||
_preferences.title,
|
||||
)
|
||||
var record := _session.get_peer_record(
|
||||
_session.get_local_peer_id()
|
||||
|
|
@ -480,6 +538,7 @@ func _apply_local_result(
|
|||
broadcast_profile_snapshot.rpc(
|
||||
_session.get_local_peer_id(),
|
||||
_preferences.display_name,
|
||||
_preferences.title,
|
||||
_appearance_store.get_snapshot(),
|
||||
request,
|
||||
)
|
||||
|
|
@ -499,11 +558,13 @@ func _apply_local_result(
|
|||
func broadcast_profile_snapshot(
|
||||
peer_id: int,
|
||||
display_name: String,
|
||||
player_title: String,
|
||||
appearance: Dictionary,
|
||||
authorization: Dictionary = {},
|
||||
) -> void:
|
||||
if (
|
||||
not NetworkProfilePreferences.is_valid_display_name(display_name)
|
||||
or not NetworkProfilePreferences.is_valid_title(player_title)
|
||||
or not CharacterCustomizationCatalog.validate_snapshot(appearance)
|
||||
):
|
||||
return
|
||||
|
|
@ -514,12 +575,16 @@ func broadcast_profile_snapshot(
|
|||
display_name,
|
||||
appearance,
|
||||
authorization,
|
||||
player_title,
|
||||
)
|
||||
):
|
||||
return
|
||||
_session.apply_canonical_profile(peer_id, display_name, appearance)
|
||||
_session.apply_canonical_profile(
|
||||
peer_id, display_name, appearance, player_title
|
||||
)
|
||||
_apply_to_avatar(peer_id, appearance)
|
||||
profile_snapshot_changed.emit(peer_id, display_name, appearance.duplicate(true))
|
||||
profile_title_changed.emit(peer_id, player_title)
|
||||
|
||||
|
||||
@rpc("authority", "call_remote", "reliable", NetworkProfileProtocol.RELIABLE_CHANNEL)
|
||||
|
|
@ -533,7 +598,9 @@ func broadcast_appearance_preview(
|
|||
if record == null:
|
||||
return
|
||||
var snapshot := CharacterCustomizationCatalog.sanitized_snapshot(appearance)
|
||||
_session.apply_canonical_profile(peer_id, record.display_name, snapshot)
|
||||
_session.apply_canonical_profile(
|
||||
peer_id, record.display_name, snapshot, record.title
|
||||
)
|
||||
_apply_to_avatar(peer_id, snapshot)
|
||||
profile_snapshot_changed.emit(
|
||||
peer_id,
|
||||
|
|
@ -575,6 +642,7 @@ func _on_peer_authenticated(peer_id: int, _display_name: String) -> void:
|
|||
peer_id,
|
||||
existing_id,
|
||||
record.display_name,
|
||||
record.title,
|
||||
record.appearance_snapshot,
|
||||
record.profile_authorization,
|
||||
)
|
||||
|
|
@ -638,6 +706,7 @@ func _on_session_state_changed(state: NetworkSession.State) -> void:
|
|||
_pending_speech_speed_ids.clear()
|
||||
_pending_call_ids.clear()
|
||||
_pending_sample_set_ids.clear()
|
||||
_pending_titles.clear()
|
||||
_host_pending_apply.clear()
|
||||
_latest_check_id = ""
|
||||
_latest_check_name = ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue