| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL.Models; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.Assertions; |
| | 7 | |
|
| | 8 | | namespace DCL |
| | 9 | | { |
| | 10 | | public static class DataStore_WorldObjects_Extensions |
| | 11 | | { |
| 1 | 12 | | private static bool VERBOSE = false; |
| 1 | 13 | | private static ILogger logger = new Logger(Debug.unityLogger.logHandler) { filterLogType = VERBOSE ? LogType.Log |
| | 14 | |
|
| | 15 | | public static void AddScene( this DataStore_WorldObjects self, string sceneId ) |
| | 16 | | { |
| 501 | 17 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 496 | 18 | | self.sceneData.Add(sceneId, new DataStore_WorldObjects.SceneData()); |
| 501 | 19 | | } |
| | 20 | |
|
| | 21 | | public static void RemoveScene( this DataStore_WorldObjects self, string sceneId ) |
| | 22 | | { |
| 220 | 23 | | if (self.sceneData.ContainsKey(sceneId)) |
| 218 | 24 | | self.sceneData.Remove(sceneId); |
| 220 | 25 | | } |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Add owner to the excluded owners list. |
| | 29 | | /// </summary> |
| | 30 | | /// <param name="self"></param> |
| | 31 | | /// <param name="sceneId"></param> |
| | 32 | | /// <param name="ownerId"></param> |
| | 33 | | [Obsolete("This feature is only used by the SmartItem component and will have to be deprecated on the future. Pl |
| | 34 | | public static void AddExcludedOwner(this DataStore_WorldObjects self, string sceneId, string ownerId) |
| | 35 | | { |
| 8 | 36 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 0 | 37 | | return; |
| | 38 | |
|
| 8 | 39 | | self.sceneData[sceneId].ignoredOwners.Add(ownerId); |
| 8 | 40 | | self.sceneData[sceneId].owners.Remove(ownerId); |
| 8 | 41 | | } |
| | 42 | |
|
| | 43 | | [Obsolete("This feature is only used by the SmartItem component and will have to be deprecated on the future. Pl |
| | 44 | | public static void RemoveExcludedOwner(this DataStore_WorldObjects self, string sceneId, string ownerId) |
| | 45 | | { |
| 4 | 46 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 0 | 47 | | return; |
| | 48 | |
|
| 4 | 49 | | self.sceneData[sceneId].ignoredOwners.Remove(ownerId); |
| 4 | 50 | | } |
| | 51 | |
|
| | 52 | | public static void AddTexture(this DataStore_WorldObjects self, string sceneId, string ownerId, Texture texture) |
| | 53 | | { |
| 60 | 54 | | var r = new Rendereable(); |
| 60 | 55 | | r.textures.Add(texture); |
| 60 | 56 | | r.ownerId = ownerId; |
| 60 | 57 | | AddRendereable(self, sceneId, r); |
| 60 | 58 | | } |
| | 59 | |
|
| | 60 | | public static void RemoveTexture(this DataStore_WorldObjects self, string sceneId, string ownerId, Texture textu |
| | 61 | | { |
| 34 | 62 | | var r = new Rendereable(); |
| 34 | 63 | | r.textures.Add(texture); |
| 34 | 64 | | r.ownerId = ownerId; |
| 34 | 65 | | RemoveRendereable(self, sceneId, r); |
| 34 | 66 | | } |
| | 67 | |
|
| | 68 | | public static void AddMaterial(this DataStore_WorldObjects self, string sceneId, string ownerId, Material materi |
| | 69 | | { |
| 60 | 70 | | var r = new Rendereable(); |
| 60 | 71 | | r.materials.Add(material); |
| 60 | 72 | | r.ownerId = ownerId; |
| 60 | 73 | | AddRendereable(self, sceneId, r); |
| 60 | 74 | | } |
| | 75 | |
|
| | 76 | | public static void RemoveMaterial(this DataStore_WorldObjects self, string sceneId, string ownerId, Material mat |
| | 77 | | { |
| 90 | 78 | | var r = new Rendereable(); |
| 90 | 79 | | r.materials.Add(material); |
| 90 | 80 | | r.ownerId = ownerId; |
| 90 | 81 | | RemoveRendereable(self, sceneId, r); |
| 90 | 82 | | } |
| | 83 | |
|
| | 84 | |
|
| | 85 | | public static void AddRendereable( this DataStore_WorldObjects self, string sceneId, Rendereable rendereable ) |
| | 86 | | { |
| 451 | 87 | | if (rendereable == null) |
| | 88 | | { |
| 0 | 89 | | logger.Log( $"Trying to add null rendereable! (id: {sceneId})"); |
| 0 | 90 | | return; |
| | 91 | | } |
| | 92 | |
|
| 451 | 93 | | if (string.IsNullOrEmpty(sceneId)) |
| | 94 | | { |
| 0 | 95 | | logger.LogWarning($"AddRendereable", $"invalid sceneId! (id: {sceneId})"); |
| 0 | 96 | | return; |
| | 97 | | } |
| | 98 | |
|
| 451 | 99 | | if (string.IsNullOrEmpty(rendereable.ownerId)) |
| | 100 | | { |
| 0 | 101 | | logger.LogError($"AddRendereable", $"invalid ownerId! Make sure to assign ownerId to the given rendereab |
| 0 | 102 | | return; |
| | 103 | | } |
| | 104 | |
|
| 451 | 105 | | var sceneData = self.sceneData[sceneId]; |
| | 106 | |
|
| 451 | 107 | | if ( sceneData.ignoredOwners.Contains(rendereable.ownerId)) |
| 8 | 108 | | return; |
| | 109 | |
|
| 443 | 110 | | sceneData.materials.AddRefCount(rendereable.materials); |
| 443 | 111 | | sceneData.meshes.AddRefCount(rendereable.meshes); |
| 443 | 112 | | sceneData.textures.AddRefCount(rendereable.textures); |
| 443 | 113 | | sceneData.renderers.Add(rendereable.renderers); |
| 443 | 114 | | sceneData.owners.Add(rendereable.ownerId); |
| 443 | 115 | | sceneData.triangles.Set( sceneData.triangles.Get() + rendereable.totalTriangleCount); |
| 443 | 116 | | } |
| | 117 | |
|
| | 118 | | public static void RemoveRendereable( this DataStore_WorldObjects self, string sceneId, Rendereable rendereable |
| | 119 | | { |
| 270 | 120 | | if ( rendereable == null ) |
| | 121 | | { |
| 0 | 122 | | logger.Log( $"Trying to remove null rendereable! (id: {sceneId})"); |
| 0 | 123 | | return; |
| | 124 | | } |
| | 125 | |
|
| 270 | 126 | | if ( string.IsNullOrEmpty(sceneId) || !self.sceneData.ContainsKey(sceneId) ) |
| | 127 | | { |
| 3 | 128 | | logger.LogWarning($"RemoveRendereable", $"invalid sceneId! (id: {sceneId})"); |
| 3 | 129 | | return; |
| | 130 | | } |
| | 131 | |
|
| 267 | 132 | | if (string.IsNullOrEmpty(rendereable.ownerId)) |
| | 133 | | { |
| 0 | 134 | | logger.LogError($"AddRendereable", $"invalid ownerId! Make sure to assign ownerId to the given rendereab |
| 0 | 135 | | return; |
| | 136 | | } |
| | 137 | |
|
| 267 | 138 | | var sceneData = self.sceneData[sceneId]; |
| | 139 | |
|
| 267 | 140 | | if ( sceneData.ignoredOwners.Contains(rendereable.ownerId)) |
| 8 | 141 | | return; |
| | 142 | |
|
| 259 | 143 | | sceneData.materials.RemoveRefCount(rendereable.materials); |
| 259 | 144 | | sceneData.meshes.RemoveRefCount(rendereable.meshes); |
| 259 | 145 | | sceneData.textures.RemoveRefCount(rendereable.textures); |
| 259 | 146 | | sceneData.renderers.Remove(rendereable.renderers); |
| 259 | 147 | | sceneData.owners.Remove(rendereable.ownerId); |
| 259 | 148 | | sceneData.triangles.Set( sceneData.triangles.Get() - rendereable.totalTriangleCount); |
| 259 | 149 | | } |
| | 150 | | } |
| | 151 | | } |