internal static void Push(ModdedSaveData data) { foreach (var actorData in GetAllData(SceneContext.Instance.GameModel)) { foreach (CompoundDataPiece modPiece in actorData.Value.DataList) { var mod = SRModLoader.GetMod(modPiece.key); var seg = data.GetSegmentForMod(mod); var newCompound = new CompoundDataPiece("root"); foreach (var dat in modPiece.DataList) { newCompound.DataList.Add(dat); } seg.extendedData.Add(new ExtendedDataTree() { dataPiece = newCompound, longIdentifier = actorData.Key.longID, stringIdentifier = actorData.Key.stringID ?? "", idType = ExtendedDataTree.IdentifierType.ACTOR }); } } foreach (var pair in worldSaveData) { SaveRegistry.GetSaveInfo(pair.Key).WorldDataSave(pair.Value); if (pair.Value.DataList.Count > 0) { data.GetSegmentForMod(pair.Key).extendedWorldData = pair.Value; } } }
public override void ReadData(BinaryReader reader) { bool isOld = ModdedSaveData.LATEST_READ_VERSION < 4; int number = reader.ReadInt32(); if (number >= 3) { isOld = false; } if (number >= 3) { number -= 3; } idType = (IdentifierType)number; if (!isOld) { Version = reader.ReadInt32(); } longIdentifier = reader.ReadInt64(); stringIdentifier = isOld ? "" : reader.ReadString(); dataPiece = DataPiece.Deserialize(reader) as CompoundDataPiece; if (dataPiece == null) { throw new Exception("Invalid top level datapiece!"); } }
/// <summary> /// Instantiate an an Actor with the given data /// </summary> /// <param name="prefab"></param> /// <param name="id"></param> /// <param name="pos"></param> /// <param name="rot"></param> /// <param name="data"></param> /// <returns></returns> public static GameObject InstantiateActorWithData(GameObject prefab, RegionRegistry.RegionSetId id, Vector3 pos, Quaternion rot, CompoundDataPiece data) { long actorId; SceneContext.Instance.GameModel.nextActorId = (actorId = SceneContext.Instance.GameModel.nextActorId) + 1L; return(InstantiateActorWithData(actorId, prefab, id, pos, rot, data)); }
public override void ReadData(CompoundDataPiece piece) { configured = true; foreach (var v in Genome.AllTraits.Select(x => x.FullID).Where(x => !piece.DataList.Any(y => y.key == x))) { toConfigure.Add(v); } base.ReadData(piece); }
public void OnSelected(Identifiable.Id id, int slot) { if (DataModel.slots[slot].Count == 0) { return; } potentialId = id; potentialTag = DataModel.PeekDataForSlot(slot); }
public static void ApplyDataToGameObject(GameObject obj, CompoundDataPiece piece) { foreach (var participant in obj.GetComponents <Participant>()) { if (HasValidDataForParticipant(participant, piece)) { participant.ReadData(ExtendedDataUtils.GetPieceForParticipantFromRoot(participant, piece)); } } }
public void Read(BinaryReader reader) { idType = (IdentifierType)reader.ReadInt32(); identifier = reader.ReadInt64(); dataPiece = DataPiece.Deserialize(reader) as CompoundDataPiece; if (dataPiece == null) { throw new Exception("Invalid top level data piece!"); } }
public static CompoundDataPiece ReadDataFromGameObject(GameObject obj) { var newCompound = new CompoundDataPiece("root"); foreach (var participant in obj.GetComponents <Participant>()) { participant.WriteData(ExtendedDataUtils.GetPieceForParticipantFromRoot(participant, newCompound)); } return(newCompound); }
public void WriteGenome(CompoundDataPiece piece) { foreach (var v in Traits) { if (!v.ShouldBeSaved) { continue; } v.Processor.SerializeTrait(v, piece.GetCompoundPiece(v.Processor.FullID)); } }
public void ReadGenome(CompoundDataPiece piece) { foreach (var v in piece.DataList.Cast <CompoundDataPiece>()) { var trait = Traits.FirstOrDefault(x => x.Processor.FullID == v.key); if (trait == null) { break; } trait.Processor.DeserializeTrait(trait, v); } }
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 CullMissingModsFromData(CompoundDataPiece piece) { List <DataPiece> toRemove = new List <DataPiece>(); foreach (var v in piece.DataList) { if (SRModLoader.GetMod(v.key) == null) { toRemove.Add(v); } } foreach (var v in toRemove) { piece.DataList.Remove(v); } }
internal static void Push(ModdedSaveData data) { foreach (var actorData in extendedActorData) { foreach (CompoundDataPiece modPiece in actorData.Value.DataList) { var mod = SRModLoader.GetMod(modPiece.key); var seg = data.GetSegmentForMod(mod); var newCompound = new CompoundDataPiece("root"); foreach (var dat in modPiece.DataList) { newCompound.DataList.Add(dat); } seg.extendedData.Add(new ExtendedDataTree() { dataPiece = newCompound, identifier = actorData.Key, idType = ExtendedDataTree.IdentifierType.ACTOR }); } } }
public static CompoundDataPiece GetPieceForParticipantFromRoot(ExtendedData.Participant p, CompoundDataPiece piece) { return(GetPieceForParticipantFromRoot(GetModForParticipant(p).ModInfo.Id, p, piece)); }
public static CompoundDataPiece GetPieceForParticipantFromRoot(string modid, ExtendedData.Participant p, CompoundDataPiece piece) { return(GetPieceForParticipant(p, GetPieceForMod(modid, piece))); }
public static CompoundDataPiece GetPieceForParticipant(Type participantType, CompoundDataPiece piece) { return(GetPieceForParticipant(GetParticipantName(participantType), piece)); }
public static CompoundDataPiece GetPieceForParticipant(ExtendedData.Participant p, CompoundDataPiece piece) { return(GetPieceForParticipant(p.GetType(), piece)); }
public static int GetModPieceCount(CompoundDataPiece root) { return(root.DataList.Count); }
public static CompoundDataPiece GetPieceForParticipant(string participantName, CompoundDataPiece piece) { return(piece.GetCompoundPiece(participantName)); }
public void PushDataForSlot(int index, CompoundDataPiece data) { slots[index].PushTop(data); }
public static int GetParticipantCount(CompoundDataPiece modPiece) { return(modPiece.DataList.Count); }
public bool IsDataValid(CompoundDataPiece piece) { return(piece.HasPiece("top")); }
public void SetData(CompoundDataPiece piece) { dataPiece = piece; SetColors(); }
public void InitData(CompoundDataPiece piece) { piece.SetPiece("top", new Color(Random.value, Random.value, Random.value, Random.value)); piece.SetPiece("middle", new Color(Random.value, Random.value, Random.value, Random.value)); piece.SetPiece("bottom", new Color(Random.value, Random.value, Random.value, Random.value)); }
public void OnExtendedActorDataLoaded(ActorModel model, GameObject obj, CompoundDataPiece piece) { onExtendedActorDataLoaded?.Invoke(model, obj, piece); }
static bool HasValidDataForParticipant(Participant p, CompoundDataPiece piece) { var modid = ExtendedDataUtils.GetModForParticipant(p)?.ModInfo.Id ?? "srml"; return(piece.HasPiece(modid) && piece.GetCompoundPiece(modid).HasPiece(ExtendedDataUtils.GetParticipantName(p))); }
public static CompoundDataPiece GetPieceForParticipant <T>(CompoundDataPiece piece) where T : ExtendedData.Participant { return(GetPieceForParticipant(typeof(T), piece)); }
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)); }
public static CompoundDataPiece GetPieceForMod(String modid, CompoundDataPiece piece) { return(piece.GetCompoundPiece(modid)); }
public void ClearSelected() { potentialId = Identifiable.Id.NONE; potentialTag = null; }