public static GameObject InstantiateActorWithData(long actorId, GameObject prefab, RegionRegistry.RegionSetId id, Vector3 pos, Quaternion rot, CompoundDataPiece data) { preparedData.Add(DataIdentifier.GetActorIdentifier(actorId), new PreparedData() { Data = data, SourceType = PreparedData.PreparationSource.SPAWN }); return(SceneContext.Instance.GameModel.InstantiateActor(actorId, prefab, id, pos, rot, false, false)); }
static IEnumerable <KeyValuePair <DataIdentifier, CompoundDataPiece> > GetAllData(GameModel model) { foreach (var v in model.actors) { if (v.Value?.transform == null) { continue; } yield return(new KeyValuePair <DataIdentifier, CompoundDataPiece>(DataIdentifier.GetActorIdentifier(v.Key), ReadDataFromGameObject(v.Value.transform.gameObject))); } }
public static void Prefix(GameModel __instance, long actorId, GameObject gameObj, bool skipNotify) { var potentialTag = PersistentAmmoManager.GetPotentialDataTag(gameObj); if (potentialTag != null) { ExtendedData.preparedData[DataIdentifier.GetActorIdentifier(actorId)] = new ExtendedData.PreparedData() { SourceType = ExtendedData.PreparedData.PreparationSource.AMMO, Data = potentialTag }; } }
internal static void Pull(ModdedSaveData data) { Clear(); foreach (var mod in data.segments) { Debug.Log($"mod {mod.modid} has {mod.extendedData.Count} extended actor datas"); foreach (var extendedDataTree in mod.extendedData) { switch (extendedDataTree.idType) { case ExtendedDataTree.IdentifierType.ACTOR: var identifier = DataIdentifier.GetActorIdentifier(extendedDataTree.longIdentifier); PreparedData pdata; if (!preparedData.TryGetValue(identifier, out pdata)) { pdata = new PreparedData() { Data = new CompoundDataPiece("root"), SourceType = PreparedData.PreparationSource.SPAWN }; preparedData[identifier] = pdata; } extendedDataTree.dataPiece.DataList.Do((x) => pdata.Data.GetCompoundPiece(mod.modid).DataList.Add(x)); break; default: throw new NotImplementedException(); } } var actualMod = SRModLoader.GetMod(mod.modid); if (actualMod == null) { continue; } worldSaveData.Add(actualMod, mod.extendedWorldData); SaveRegistry.GetSaveInfo(actualMod).WorldDataPreLoad(mod.extendedWorldData); } foreach (var v in SRModLoader.GetMods()) { if (!worldSaveData.ContainsKey(v)) { var newData = new CompoundDataPiece("root"); worldSaveData.Add(v, newData); SaveRegistry.GetSaveInfo(v).WorldDataPreLoad(newData); } } }
internal static void OnRegisterActor(GameModel model, long actorId, GameObject gameObject, bool skipNotify) { if (Identifiable.GetId(gameObject) == Identifiable.Id.NONE) { return; } var actorIdentifier = DataIdentifier.GetActorIdentifier(actorId); if (preparedData.TryGetValue(actorIdentifier, out var pdata)) { var data = pdata.Data; foreach (var saveInfoPair in SaveRegistry.modToSaveInfo) { if (data.HasPiece(saveInfoPair.Key.ModInfo.Id)) { saveInfoPair.Value.OnExtendedActorDataLoaded(model.actors[actorId], gameObject, ExtendedDataUtils.GetPieceForMod(saveInfoPair.Key.ModInfo.Id, data)); } } ApplyDataToGameObject(gameObject, data); preparedData.Remove(actorIdentifier); } }