public static void Deserialize(byte[] data)
        {
            if (data == null)
            {
                Log.Debug($"NCState.Deserialize(data=null)");
                Instance = new NCState();
            }
            else
            {
                Log.Debug($"NCState.Deserialize(data): data.Length={data?.Length}");
                Instance = SerializationUtil.Deserialize(data, default) as NCState;
                if (Instance?.Version != null)   //2.1.1 or above
                {
                    Log.Debug("Deserializing V" + Instance.Version);
                    SerializationUtil.DeserializationVersion = new Version(Instance.Version);
                }
                else
                {
                    // 2.0
                    Log.Debug("Deserializing version 2.0");
                    Instance.Version    = "2.0";
                    Instance.GameConfig = GameConfigT.LoadGameDefault; // for the sake of feature proofing.
                    Instance.GameConfig.UnviversalSlopeFixes = true;   // in this version I do apply slope fixes.
                }
            }
            Log.Debug($"setting UnviversalSlopeFixes to {Instance.GameConfig.UnviversalSlopeFixes}");
            Settings.GameConfig = Instance.GameConfig;
            Settings.UpdateGameSettings();
            var version = new Version(Instance.Version);

            SegmentEndManager.Deserialize(Instance.SegmentEndManagerData, version);
            NodeManager.Deserialize(Instance.NodeManagerData, version);
        }
Example #2
0
 public static byte[] Serialize()
 {
     Instance = new NCState {
         NodeManagerData       = NodeManager.Serialize(),
         SegmentEndManagerData = SegmentEndManager.Serialize(),
         GameConfig            = Settings.GameConfig,
     };
     return(SerializationUtil.Serialize(Instance));
 }
        public static byte[] Serialize()
        {
            NodeManager.ValidateAndHeal(false);
            Instance = new NCState {
                NodeManagerData       = NodeManager.Serialize(),
                SegmentEndManagerData = SegmentEndManager.Serialize(),
                GameConfig            = Settings.GameConfig,
            };

            Log.Debug("NCState.Serialize(): saving UnviversalSlopeFixes as " +
                      Instance.GameConfig.UnviversalSlopeFixes);

            return(SerializationUtil.Serialize(Instance));
        }
 public override void OnLoadData()
 {
     byte[] data = serializableDataManager.LoadData(DATA_ID);
     if (data != null)
     {
         LoadingVersion = 2;
         NCState.Deserialize(data);
     }
     else
     {
         // convert to new version
         LoadingVersion = 1;
         data           = serializableDataManager.LoadData(DATA_ID1)
                          ?? serializableDataManager.LoadData(DATA_ID0);
         NodeManager.Deserialize(data, new Version(1, 0));
     }
 }
 public override void OnSaveData()
 {
     byte[] data = NCState.Serialize();
     serializableDataManager.SaveData(DATA_ID, data);
 }