| | 1 | | using DCL; |
| | 2 | | using DCLServices.WearablesCatalogService; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | | using UnityEngine; |
| | 7 | |
|
| | 8 | | namespace DCLServices.CameraReelService |
| | 9 | | { |
| | 10 | | [Serializable] |
| | 11 | | public class ScreenshotMetadata |
| | 12 | | { |
| | 13 | | public string userName; |
| | 14 | | public string userAddress; |
| | 15 | | public string dateTime; |
| | 16 | | public string realm; |
| | 17 | | public Scene scene; |
| | 18 | | public VisiblePerson[] visiblePeople; |
| | 19 | |
|
| | 20 | | private static bool isWorld => DataStore.i.common.isWorld.Get(); |
| | 21 | | private static string realmName => DataStore.i.realm.realmName.Get(); |
| | 22 | |
|
| | 23 | | public static ScreenshotMetadata Create(DataStore_Player player, IAvatarsLODController avatarsLODController, Cam |
| | 24 | | { |
| | 25 | | Player ownPlayer = player.ownPlayer.Get(); |
| | 26 | | Vector2Int playerPosition = player.playerGridPosition.Get(); |
| | 27 | |
|
| | 28 | | var metadata = new ScreenshotMetadata |
| | 29 | | { |
| | 30 | | userName = UserProfileController.userProfilesCatalog.Get(ownPlayer.id).userName, |
| | 31 | | userAddress = ownPlayer.id, |
| | 32 | | dateTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString(), |
| | 33 | | realm = realmName, |
| | 34 | | scene = new Scene |
| | 35 | | { |
| | 36 | | name = isWorld? $"World {realmName}" : MinimapMetadata.GetMetadata().GetSceneInfo(playerPosition.x, |
| | 37 | | location = new Location(playerPosition), |
| | 38 | | }, |
| | 39 | | visiblePeople = GetVisiblePeoplesMetadata( |
| | 40 | | visiblePlayers: CalculateVisiblePlayersInFrustum(ownPlayer, avatarsLODController, screenshotCamera)) |
| | 41 | | }; |
| | 42 | |
|
| | 43 | | return metadata; |
| | 44 | | } |
| | 45 | |
|
| | 46 | | private static VisiblePerson[] GetVisiblePeoplesMetadata(List<Player> visiblePlayers) |
| | 47 | | { |
| | 48 | | var visiblePeople = new VisiblePerson[visiblePlayers.Count]; |
| | 49 | | UserProfileDictionary userProfilesCatalog = UserProfileController.userProfilesCatalog; |
| | 50 | |
|
| | 51 | | for (var i = 0; i < visiblePlayers.Count; i++) |
| | 52 | | { |
| | 53 | | UserProfile profile = userProfilesCatalog.Get(visiblePlayers[i].id); |
| | 54 | |
|
| | 55 | | visiblePeople[i] = new VisiblePerson |
| | 56 | | { |
| | 57 | | userName = profile.userName, |
| | 58 | | userAddress = profile.userId, |
| | 59 | | isGuest = profile.isGuest, |
| | 60 | |
|
| | 61 | | wearables = FilterNonBaseWearables(profile.avatar.wearables), |
| | 62 | | }; |
| | 63 | | } |
| | 64 | |
|
| | 65 | | return visiblePeople; |
| | 66 | | } |
| | 67 | |
|
| | 68 | | private static string[] FilterNonBaseWearables(List<string> avatarWearables) => |
| | 69 | | avatarWearables.Where(wearable => !wearable.StartsWith(IWearablesCatalogService.BASE_WEARABLES_COLLECTION_ID |
| | 70 | |
|
| | 71 | | private static List<Player> CalculateVisiblePlayersInFrustum(Player player, IAvatarsLODController avatarsLODCont |
| | 72 | | { |
| | 73 | | var list = new List<Player>(); |
| | 74 | | Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(screenshotCamera); |
| | 75 | |
|
| | 76 | | foreach (IAvatarLODController lodController in avatarsLODController.LodControllers.Values) |
| | 77 | | if (!lodController.IsInvisible && GeometryUtility.TestPlanesAABB(frustumPlanes, lodController.player.col |
| | 78 | | list.Add(lodController.player); |
| | 79 | |
|
| | 80 | | if (GeometryUtility.TestPlanesAABB(frustumPlanes, player.collider.bounds)) |
| | 81 | | list.Add(player); |
| | 82 | |
|
| | 83 | | return list; |
| | 84 | | } |
| | 85 | |
|
| | 86 | | public DateTime GetLocalizedDateTime() |
| | 87 | | { |
| | 88 | | if (!long.TryParse(dateTime, out long unixTimestamp)) return new DateTime(); |
| | 89 | | return DateTimeOffset.FromUnixTimeSeconds(unixTimestamp).ToLocalTime().DateTime; |
| | 90 | | } |
| | 91 | |
|
| | 92 | | public DateTime GetStartOfTheMonthDate() |
| | 93 | | { |
| | 94 | | DateTime localizedDateTime = GetLocalizedDateTime(); |
| | 95 | | return new DateTime(localizedDateTime.Year, localizedDateTime.Month, 1); |
| | 96 | | } |
| | 97 | | } |
| | 98 | |
|
| | 99 | | [Serializable] |
| | 100 | | public class Scene |
| | 101 | | { |
| | 102 | | public string name; |
| | 103 | | public Location location; |
| | 104 | | } |
| | 105 | |
|
| | 106 | | [Serializable] |
| | 107 | | public class Location |
| | 108 | | { |
| | 109 | | public string x; |
| | 110 | | public string y; |
| | 111 | |
|
| 0 | 112 | | public Location(Vector2Int position) |
| | 113 | | { |
| 0 | 114 | | x = position.x.ToString(); |
| 0 | 115 | | y = position.y.ToString(); |
| 0 | 116 | | } |
| | 117 | | } |
| | 118 | |
|
| | 119 | | [Serializable] |
| | 120 | | public class VisiblePerson |
| | 121 | | { |
| | 122 | | public string userName; |
| | 123 | | public string userAddress; |
| | 124 | | public bool isGuest; |
| | 125 | |
|
| | 126 | | public string[] wearables; |
| | 127 | | } |
| | 128 | | } |