/* Called when an asset is saved */ public void OnAssetSaved(string name, object asset, out Dictionary <string, byte[]> userData) { Debug.Log("TMPE: OnAssetSaved"); userData = null; if (!LoadingExtension.IsInAssetEditor) { return; } BuildingInfo info = asset as BuildingInfo; if (info == null) { return; } bool success = true; TmpeAssetData data = new TmpeAssetData(); data.Segments = BuildingDecorationPatch.m_pendingSegments; Configuration config = SerializableDataExtension.CreateConfiguration(ref success); userData = new Dictionary <string, byte[]>(); // ??? !!! SerializableDataExtension.OnBeforeGameSaved(ref success); data.TmpeConfiguration = SerializableDataExtension.Serialize(config, ref success); SerializableDataExtension.OnAfterGameSaved(ref success); if (!success) { return; } if (BuildingDecorationPatch.m_pendingSegments?.Count > 0) { userData.Add(SerializableDataExtension.DataId + segmentsString, SerializableDataExtension.Serialize <List <IdentificationTool.AssetSegment> >(data.Segments, ref success)); userData.Add(SerializableDataExtension.DataId + dataString, data.TmpeConfiguration); AssetDataManager.Instance.AssetsWithData[IdentificationTool.GetNameWithoutPrefix(info.name)] = data; } }
public static List <IdentificationTool.AssetSegment> m_pendingSegments; // Segments pending to be saved public static void ProcessNewPaths(List <ushort> segments, BuildingInfo info) { try { #if DEBUG Debug.Log("Loading TMPE settings..."); #endif TmpeAssetData data = AssetDataManager.Instance.AssetsWithData[IdentificationTool.GetNameWithoutPrefix(info.name)]; Debug.Log("Hoooray! Tmpe settings loaded"); Configuration config = SerializableDataExtension.DeserializeData(data.TmpeConfiguration, out bool error); if (error) { throw new Exception("Tmpe: Failed to deserialize data"); } /* We identify the old ids with the new ids */ IdentificationTool.CreateDictionaries(segments, data.Segments, out Dictionary <ushort, ushort> segmentPairs, out Dictionary <ushort, ushort> nodePairs, out Dictionary <uint, uint> lanePairs); IdentificationTool.TranslateGameConfiguration(config, segmentPairs, nodePairs, lanePairs); /*SerializableDataExtension.LoadDataState(config, out bool error2); * if (error2) * throw new Exception("Tmpe: error when applying loaded data");*/ /* Apply settings after some time elapses (hack) */ ProvisionalDataLoader.StartTimer(config); } catch (Exception ex) { #if DEBUG Debug.Log(ex); #endif } }
/* Called when the savegame/asset is loading. Does not work when Loading Screen mod is enabled due to a bug */ public void OnAssetLoaded(string name, object asset, Dictionary <string, byte[]> userData) { BuildingInfo info = asset as BuildingInfo; if (info != null) { try { TmpeAssetData data = new TmpeAssetData(); data.TmpeConfiguration = userData[SerializableDataExtension.DataId + dataString]; //data.TmpeConfiguration = SerializableDataExtension.DeserializeData(userData[SerializableDataExtension.DataId + dataString], out bool error); data.Segments = Deserialize <List <IdentificationTool.AssetSegment> >(userData[SerializableDataExtension.DataId + segmentsString]); AssetDataManager.Instance.AssetsWithData[IdentificationTool.GetNameWithoutPrefix(info.name)] = data; #if DEBUG Debug.Log("Successfully deserialized TMPE asset data (" + info.name + ")"); #endif } catch (Exception e) { Debug.Log(e); } } }