예제 #1
0
 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;
         }
     }
 }
예제 #2
0
        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!");
            }
        }
예제 #3
0
        /// <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);
 }
예제 #5
0
 public void OnSelected(Identifiable.Id id, int slot)
 {
     if (DataModel.slots[slot].Count == 0)
     {
         return;
     }
     potentialId  = id;
     potentialTag = DataModel.PeekDataForSlot(slot);
 }
예제 #6
0
 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));
         }
     }
 }
예제 #7
0
 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!");
     }
 }
예제 #8
0
        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);
        }
예제 #9
0
 public void WriteGenome(CompoundDataPiece piece)
 {
     foreach (var v in Traits)
     {
         if (!v.ShouldBeSaved)
         {
             continue;
         }
         v.Processor.SerializeTrait(v, piece.GetCompoundPiece(v.Processor.FullID));
     }
 }
예제 #10
0
 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);
     }
 }
예제 #11
0
        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);
                }
            }
        }
예제 #12
0
        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);
            }
        }
예제 #13
0
 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
             });
         }
     }
 }
예제 #14
0
 public static CompoundDataPiece GetPieceForParticipantFromRoot(ExtendedData.Participant p, CompoundDataPiece piece)
 {
     return(GetPieceForParticipantFromRoot(GetModForParticipant(p).ModInfo.Id, p, piece));
 }
예제 #15
0
 public static CompoundDataPiece GetPieceForParticipantFromRoot(string modid, ExtendedData.Participant p, CompoundDataPiece piece)
 {
     return(GetPieceForParticipant(p, GetPieceForMod(modid, piece)));
 }
예제 #16
0
 public static CompoundDataPiece GetPieceForParticipant(Type participantType, CompoundDataPiece piece)
 {
     return(GetPieceForParticipant(GetParticipantName(participantType), piece));
 }
예제 #17
0
 public static CompoundDataPiece GetPieceForParticipant(ExtendedData.Participant p, CompoundDataPiece piece)
 {
     return(GetPieceForParticipant(p.GetType(), piece));
 }
예제 #18
0
 public static int GetModPieceCount(CompoundDataPiece root)
 {
     return(root.DataList.Count);
 }
예제 #19
0
 public static CompoundDataPiece GetPieceForParticipant(string participantName, CompoundDataPiece piece)
 {
     return(piece.GetCompoundPiece(participantName));
 }
예제 #20
0
 public void PushDataForSlot(int index, CompoundDataPiece data)
 {
     slots[index].PushTop(data);
 }
예제 #21
0
 public static int GetParticipantCount(CompoundDataPiece modPiece)
 {
     return(modPiece.DataList.Count);
 }
예제 #22
0
 public bool IsDataValid(CompoundDataPiece piece)
 {
     return(piece.HasPiece("top"));
 }
예제 #23
0
        public void SetData(CompoundDataPiece piece)
        {
            dataPiece = piece;

            SetColors();
        }
예제 #24
0
 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));
 }
예제 #25
0
 public void OnExtendedActorDataLoaded(ActorModel model, GameObject obj, CompoundDataPiece piece)
 {
     onExtendedActorDataLoaded?.Invoke(model, obj, piece);
 }
예제 #26
0
        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)));
        }
예제 #27
0
 public static CompoundDataPiece GetPieceForParticipant <T>(CompoundDataPiece piece) where T : ExtendedData.Participant
 {
     return(GetPieceForParticipant(typeof(T), piece));
 }
예제 #28
0
 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));
 }
예제 #29
0
 public static CompoundDataPiece GetPieceForMod(String modid, CompoundDataPiece piece)
 {
     return(piece.GetCompoundPiece(modid));
 }
예제 #30
0
 public void ClearSelected()
 {
     potentialId  = Identifiable.Id.NONE;
     potentialTag = null;
 }