예제 #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
 static ExtendedData()
 {
     SRCallbacks.OnSaveGameLoaded += (s) =>
     {
         foreach (var v in worldSaveData)
         {
             SaveRegistry.GetSaveInfo(v.Key)?.WorldDataLoad(v.Value);
         }
     };
 }
예제 #3
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);
                }
            }
        }