| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL.Controllers; |
| | 3 | | using DCL.Emotes; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Threading; |
| | 7 | |
|
| | 8 | | namespace AvatarAssets |
| | 9 | | { |
| | 10 | | public static class SceneEmoteHelper |
| | 11 | | { |
| | 12 | | public const string SCENE_EMOTE_PREFIX = "urn:decentraland:off-chain:scene-emote:"; |
| | 13 | |
|
| | 14 | | public static bool TryGenerateEmoteId(IParcelScene scene, string emoteFilePath, bool loop, out string emoteId) |
| | 15 | | { |
| 0 | 16 | | if (scene.contentProvider.TryGetContentHash(emoteFilePath, out string emoteHash)) |
| | 17 | | { |
| 0 | 18 | | emoteId = $"{SCENE_EMOTE_PREFIX}{emoteHash}-{(loop ? "true" : "false")}"; |
| 0 | 19 | | return true; |
| | 20 | | } |
| | 21 | |
|
| 0 | 22 | | emoteId = string.Empty; |
| 0 | 23 | | return false; |
| | 24 | | } |
| | 25 | |
|
| | 26 | | public static bool TryGetDataFromEmoteId(string emoteId, out string emoteHash, out bool loop) |
| | 27 | | { |
| | 28 | | try |
| | 29 | | { |
| 0 | 30 | | ReadOnlySpan<char> prefixRemoved = emoteId.AsSpan().Slice(SCENE_EMOTE_PREFIX.Length, emoteId.Length - SC |
| 0 | 31 | | int loopSeparator = prefixRemoved.LastIndexOf('-'); |
| 0 | 32 | | emoteHash = prefixRemoved.Slice(0, loopSeparator).ToString(); |
| | 33 | |
|
| 0 | 34 | | var loopSpan = prefixRemoved.Slice(loopSeparator + 1, 4); |
| 0 | 35 | | loop = loopSpan.Equals("true", StringComparison.InvariantCultureIgnoreCase); |
| | 36 | |
|
| 0 | 37 | | return true; |
| | 38 | | } |
| 0 | 39 | | catch (Exception _) |
| | 40 | | { |
| 0 | 41 | | emoteHash = string.Empty; |
| 0 | 42 | | loop = false; |
| 0 | 43 | | } |
| | 44 | |
|
| 0 | 45 | | return false; |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | public static bool IsSceneEmote(string emoteId) => |
| 0 | 49 | | emoteId.Contains(SCENE_EMOTE_PREFIX, StringComparison.OrdinalIgnoreCase); |
| | 50 | | } |
| | 51 | | } |