| | 1 | | using DCL; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Models; |
| | 4 | | using Decentraland.Common; |
| | 5 | | using Decentraland.Sdk.Ecs6; |
| | 6 | | using System; |
| | 7 | | using System.Runtime.CompilerServices; |
| | 8 | | using UnityEngine; |
| | 9 | | using Quaternion = UnityEngine.Quaternion; |
| | 10 | | using Ray = DCL.Models.Ray; |
| | 11 | | using Vector3 = UnityEngine.Vector3; |
| | 12 | |
|
| | 13 | | namespace MainScripts.DCL.Components |
| | 14 | | { |
| | 15 | | public static class SDK6DataMapExtensions |
| | 16 | | { |
| | 17 | | public static Color AsUnityColor(this ECS6Color4 color4) => |
| 0 | 18 | | new (color4.R, color4.G, color4.B, color4.HasA ? color4.A : 1f); |
| | 19 | |
|
| | 20 | | public static Color AsUnityColor(this Color3 color3) => |
| 0 | 21 | | new (color3.R, color3.G, color3.B); |
| | 22 | |
|
| | 23 | | public static Vector3 AsUnityVector3(this Decentraland.Common.Vector3 vector3) => |
| 0 | 24 | | new (vector3.X, vector3.Y, vector3.Z); |
| | 25 | |
|
| | 26 | | public static Quaternion AsUnityQuaternion(this Decentraland.Common.Quaternion quaternion) => |
| 0 | 27 | | new (quaternion.X, quaternion.Y, quaternion.Z, quaternion.W); |
| | 28 | |
|
| | 29 | | public static UIValue FromProtobuf(UIValue defaultValue, UiValue uiValue) => |
| 0 | 30 | | new () |
| | 31 | | { |
| | 32 | | value = uiValue.HasValue ? uiValue.Value : defaultValue.value, |
| | 33 | | type = uiValue.HasType ? (UIValue.Unit)uiValue.Type : defaultValue.type, |
| | 34 | | }; |
| | 35 | |
|
| | 36 | | public static QueuedSceneMessage_Scene SceneMessageFromSdk6Message(EntityAction action, int sceneNumber) => |
| 0 | 37 | | new () |
| | 38 | | { |
| | 39 | | type = QueuedSceneMessage.Type.SCENE_MESSAGE, |
| | 40 | | method = MapMessagingMethodType(action), |
| | 41 | | sceneNumber = sceneNumber, |
| | 42 | | payload = ExtractPayload(from: action, sceneNumber), |
| | 43 | | tag = action.Tag, |
| | 44 | | }; |
| | 45 | |
|
| | 46 | | private static object ExtractPayload(EntityAction from, int sceneNumber) |
| | 47 | | { |
| 0 | 48 | | return from.Payload.PayloadCase switch |
| | 49 | | { |
| 0 | 50 | | EntityActionPayload.PayloadOneofCase.InitMessagesFinished => new Protocol.SceneReady(), |
| 0 | 51 | | EntityActionPayload.PayloadOneofCase.OpenExternalUrl => new Protocol.OpenExternalUrl { url = from |
| 0 | 52 | | EntityActionPayload.PayloadOneofCase.OpenNftDialog => new Protocol.OpenNftDialog |
| | 53 | | { |
| | 54 | | contactAddress = from.Payload.OpenNftDialog.AssetContractAddress, |
| | 55 | | comment = from.Payload.OpenNftDialog.Comment, |
| | 56 | | tokenId = from.Payload.OpenNftDialog.TokenId, |
| | 57 | | }, |
| 0 | 58 | | EntityActionPayload.PayloadOneofCase.CreateEntity => new Protocol.CreateEntity { entityId = from. |
| 0 | 59 | | EntityActionPayload.PayloadOneofCase.RemoveEntity => new Protocol.RemoveEntity { entityId = from. |
| 0 | 60 | | EntityActionPayload.PayloadOneofCase.AttachEntityComponent => new Protocol.SharedComponentAttach |
| | 61 | | { |
| | 62 | | entityId = from.Payload.AttachEntityComponent.EntityId, |
| | 63 | | id = from.Payload.AttachEntityComponent.Id, |
| | 64 | | name = from.Payload.AttachEntityComponent.Name, |
| | 65 | | }, |
| 0 | 66 | | EntityActionPayload.PayloadOneofCase.ComponentRemoved => new Protocol.EntityComponentDestroy |
| | 67 | | { |
| | 68 | | entityId = from.Payload.ComponentRemoved.EntityId, |
| | 69 | | name = from.Payload.ComponentRemoved.Name, |
| | 70 | | }, |
| 0 | 71 | | EntityActionPayload.PayloadOneofCase.SetEntityParent => new Protocol.SetEntityParent |
| | 72 | | { |
| | 73 | | entityId = from.Payload.SetEntityParent.EntityId, |
| | 74 | | parentId = from.Payload.SetEntityParent.ParentId, |
| | 75 | | }, |
| 0 | 76 | | EntityActionPayload.PayloadOneofCase.Query => new QueryMessage { payload = CreateRaycastPayload(f |
| 0 | 77 | | EntityActionPayload.PayloadOneofCase.ComponentCreated => new Protocol.SharedComponentCreate |
| | 78 | | { |
| | 79 | | id = from.Payload.ComponentCreated.Id, |
| | 80 | | classId = from.Payload.ComponentCreated.ClassId, |
| | 81 | | name = from.Payload.ComponentCreated.Name, |
| | 82 | | }, |
| 0 | 83 | | EntityActionPayload.PayloadOneofCase.ComponentDisposed => new Protocol.SharedComponentDispose { i |
| | 84 | |
|
| 0 | 85 | | EntityActionPayload.PayloadOneofCase.ComponentUpdated => from.Payload.ComponentUpdated, |
| 0 | 86 | | EntityActionPayload.PayloadOneofCase.UpdateEntityComponent => from.Payload.UpdateEntityComponent, |
| | 87 | |
|
| 0 | 88 | | EntityActionPayload.PayloadOneofCase.None => null, |
| 0 | 89 | | _ => throw new SwitchExpressionException($"Unknown payload type for sdk6 protobuf message {from.P |
| | 90 | | }; |
| | 91 | | } |
| | 92 | |
|
| | 93 | | private static RaycastQuery CreateRaycastPayload(EntityAction action, int sceneNumber) |
| | 94 | | { |
| 0 | 95 | | RaycastType raycastType = action.Payload.Query.Payload.QueryType switch |
| | 96 | | { |
| 0 | 97 | | "HitFirst" => RaycastType.HIT_FIRST, |
| 0 | 98 | | "HitAll" => RaycastType.HIT_ALL, |
| 0 | 99 | | "HitFirstAvatar" => RaycastType.HIT_FIRST_AVATAR, |
| 0 | 100 | | "HitAllAvatars" => RaycastType.HIT_ALL_AVATARS, |
| 0 | 101 | | _ => RaycastType.NONE, |
| | 102 | | }; |
| | 103 | |
|
| 0 | 104 | | var ray = new Ray |
| | 105 | | { |
| | 106 | | origin = action.Payload.Query.Payload.Ray.Origin.AsUnityVector3(), |
| | 107 | | direction = action.Payload.Query.Payload.Ray.Direction.AsUnityVector3(), |
| | 108 | | distance = action.Payload.Query.Payload.Ray.Distance, |
| | 109 | | }; |
| | 110 | |
|
| 0 | 111 | | return new RaycastQuery |
| | 112 | | { |
| | 113 | | id = action.Payload.Query.Payload.QueryId, |
| | 114 | | raycastType = raycastType, |
| | 115 | | ray = ray, |
| | 116 | | sceneNumber = sceneNumber, |
| | 117 | | }; |
| | 118 | | } |
| | 119 | |
|
| | 120 | | private static string MapMessagingMethodType(EntityAction action) => |
| 0 | 121 | | action.Payload.PayloadCase switch |
| | 122 | | { |
| 0 | 123 | | EntityActionPayload.PayloadOneofCase.InitMessagesFinished => MessagingTypes.INIT_DONE, |
| 0 | 124 | | EntityActionPayload.PayloadOneofCase.OpenExternalUrl => MessagingTypes.OPEN_EXTERNAL_URL, |
| 0 | 125 | | EntityActionPayload.PayloadOneofCase.OpenNftDialog => MessagingTypes.OPEN_NFT_DIALOG, |
| 0 | 126 | | EntityActionPayload.PayloadOneofCase.CreateEntity => MessagingTypes.ENTITY_CREATE, |
| 0 | 127 | | EntityActionPayload.PayloadOneofCase.RemoveEntity => MessagingTypes.ENTITY_DESTROY, |
| 0 | 128 | | EntityActionPayload.PayloadOneofCase.AttachEntityComponent => MessagingTypes.SHARED_COMPONENT_ATTACH, |
| 0 | 129 | | EntityActionPayload.PayloadOneofCase.ComponentRemoved => MessagingTypes.ENTITY_COMPONENT_DESTROY, |
| 0 | 130 | | EntityActionPayload.PayloadOneofCase.SetEntityParent => MessagingTypes.ENTITY_REPARENT, |
| 0 | 131 | | EntityActionPayload.PayloadOneofCase.Query => MessagingTypes.QUERY, |
| 0 | 132 | | EntityActionPayload.PayloadOneofCase.ComponentCreated => MessagingTypes.SHARED_COMPONENT_CREATE, |
| 0 | 133 | | EntityActionPayload.PayloadOneofCase.ComponentDisposed => MessagingTypes.SHARED_COMPONENT_DISPOSE, |
| 0 | 134 | | EntityActionPayload.PayloadOneofCase.UpdateEntityComponent => MessagingTypes.PB_ENTITY_COMPONENT_CREATE_ |
| 0 | 135 | | EntityActionPayload.PayloadOneofCase.ComponentUpdated => MessagingTypes.PB_SHARED_COMPONENT_UPDATE, |
| 0 | 136 | | EntityActionPayload.PayloadOneofCase.None => null, |
| 0 | 137 | | _ => throw new ArgumentOutOfRangeException(), |
| | 138 | | }; |
| | 139 | | } |
| | 140 | | } |