Ejemplo n.º 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;
         }
     }
 }
Ejemplo n.º 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!");
            }
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 5
0
 public void OnSelected(Identifiable.Id id, int slot)
 {
     if (DataModel.slots[slot].Count == 0)
     {
         return;
     }
     potentialId  = id;
     potentialTag = DataModel.PeekDataForSlot(slot);
 }
Ejemplo n.º 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));
         }
     }
 }
Ejemplo n.º 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!");
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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
             });
         }
     }
 }
Ejemplo n.º 14
0
 public static CompoundDataPiece GetPieceForParticipantFromRoot(ExtendedData.Participant p, CompoundDataPiece piece)
 {
     return(GetPieceForParticipantFromRoot(GetModForParticipant(p).ModInfo.Id, p, piece));
 }
Ejemplo n.º 15
0
 public static CompoundDataPiece GetPieceForParticipantFromRoot(string modid, ExtendedData.Participant p, CompoundDataPiece piece)
 {
     return(GetPieceForParticipant(p, GetPieceForMod(modid, piece)));
 }
Ejemplo n.º 16
0
 public static CompoundDataPiece GetPieceForParticipant(Type participantType, CompoundDataPiece piece)
 {
     return(GetPieceForParticipant(GetParticipantName(participantType), piece));
 }
Ejemplo n.º 17
0
 public static CompoundDataPiece GetPieceForParticipant(ExtendedData.Participant p, CompoundDataPiece piece)
 {
     return(GetPieceForParticipant(p.GetType(), piece));
 }
Ejemplo n.º 18
0
 public static int GetModPieceCount(CompoundDataPiece root)
 {
     return(root.DataList.Count);
 }
Ejemplo n.º 19
0
 public static CompoundDataPiece GetPieceForParticipant(string participantName, CompoundDataPiece piece)
 {
     return(piece.GetCompoundPiece(participantName));
 }
Ejemplo n.º 20
0
 public void PushDataForSlot(int index, CompoundDataPiece data)
 {
     slots[index].PushTop(data);
 }
Ejemplo n.º 21
0
 public static int GetParticipantCount(CompoundDataPiece modPiece)
 {
     return(modPiece.DataList.Count);
 }
Ejemplo n.º 22
0
 public bool IsDataValid(CompoundDataPiece piece)
 {
     return(piece.HasPiece("top"));
 }
Ejemplo n.º 23
0
        public void SetData(CompoundDataPiece piece)
        {
            dataPiece = piece;

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