示例#1
0
        private SaveableData ToSaveableData()
        {
            var obj = new SaveableData {
                Width                                 = Width,
                Height                                = Height,
                SoftwareDownsize                      = SoftwareDownsize,
                CameraPosition                        = CameraPosition.ToArray(),
                CameraLookAt                          = CameraLookAt.ToArray(),
                CameraFov                             = CameraFov,
                AlignCar                              = AlignCar,
                AlignCameraHorizontally               = AlignCameraHorizontally,
                AlignCameraHorizontallyOffset         = AlignCameraHorizontallyOffset,
                AlignCameraHorizontallyOffsetRelative = AlignCameraHorizontallyOffsetRelative,
                AlignCameraVertically                 = AlignCameraVertically,
                AlignCameraVerticallyOffset           = AlignCameraVerticallyOffset,
                AlignCameraVerticallyOffsetRelative   = AlignCameraVerticallyOffsetRelative,
                SteerDeg                              = SteerDeg,
                HeadlightsEnabled                     = HeadlightsEnabled,
                BrakeLightsEnabled                    = BrakeLightsEnabled,
                LeftDoorOpen                          = LeftDoorOpen,
                RightDoorOpen                         = RightDoorOpen,
                ShowDriver                            = ShowDriver,
            };

            Save(obj);
            return(obj);
        }
示例#2
0
 protected void Load(SaveableData o)
 {
     LoadSize(o);
     LoadCamera(o);
     LoadCar(o);
     base.Load(o);
 }
示例#3
0
 protected virtual void Save(SaveableData result)
 {
     result.Penalties          = Penalties;
     result.JumpStartPenalty   = JumpStartPenalty;
     result.LapsNumber         = LapsNumber;
     result.RaceGridSerialized = RaceGridViewModel.ExportToPresetData();
 }
示例#4
0
 protected void Load(SaveableData o)
 {
     LoadQuality(o);
     LoadScene(o);
     LoadHdr(o);
     LoadExtra(o);
 }
示例#5
0
 protected SaveableData Save(SaveableData data)
 {
     base.Save(data);
     data.GhostCar          = GhostCar;
     data.GhostCarAdvantage = GhostCarAdvantage;
     return(data);
 }
示例#6
0
 protected SaveableData Save(SaveableData data)
 {
     data.Penalties        = Penalties;
     data.PlayerBallast    = PlayerBallast;
     data.PlayerRestrictor = PlayerRestrictor;
     return(data);
 }
 protected override void InitializeSaveable() {
     Saveable = new SaveHelper<SaveableData>("__QuickDrive_Trackday", () => {
         var r = new SaveableData();
         Save(r);
         return r;
     }, Load, Reset);
     Saveable.RegisterUpgrade<OldSaveableData>(OldSaveableData.Test, Load);
 }
示例#8
0
 protected void LoadExtra(SaveableData o)
 {
     Renderer.MaterialsReflectiveness = o.MaterialsReflectiveness;
     Renderer.BloomRadiusMultiplier   = o.BloomRadiusMultiplier;
     Renderer.PcssSceneScale          = o.PcssSceneScale;
     Renderer.PcssLightScale          = o.PcssLightScale;
     Renderer.AoOpacity = o.SsaoOpacity;
 }
示例#9
0
 protected override void InitializeSaveable()
 {
     Saveable = new SaveHelper <SaveableData>("__QuickDrive_Drag", () => {
         var r = new SaveableData();
         Save(r);
         return(r);
     }, Load, Reset);
 }
 protected override void InitializeSaveable()
 {
     Saveable = new SaveHelper <SaveableData>("__QuickDrive_Weekend", () => {
         var r = new SaveableData();
         Save(r);
         return(r);
     }, Load, Reset);
     Saveable.RegisterUpgrade <OldSaveableData>(QuickDrive_Race.ViewModel.OldSaveableData.Test, Load);
 }
示例#11
0
 /// <summary>
 /// Will be called in constuctor!
 /// </summary>
 protected virtual void InitializeSaveable()
 {
     Saveable = new SaveHelper <SaveableData>("__QuickDrive_Race", () => {
         var r = new SaveableData();
         Save(r);
         return(r);
     }, Load, Reset);
     Saveable.RegisterUpgrade <OldSaveableData>(OldSaveableData.Test, Load);
 }
示例#12
0
 protected void LoadCar(SaveableData o)
 {
     SteerDeg           = o.SteerDeg;
     HeadlightsEnabled  = o.HeadlightsEnabled;
     BrakeLightsEnabled = o.BrakeLightsEnabled;
     LeftDoorOpen       = o.LeftDoorOpen;
     RightDoorOpen      = o.RightDoorOpen;
     ShowDriver         = o.ShowDriver;
 }
示例#13
0
        public override void Clone(SaveableData Data)
        {
            base.Clone(Data);
            Power preset = Data as Power;

            if (preset != null)
            {
                _value = preset.Value;
            }
        }
示例#14
0
        protected void LoadHdr(SaveableData o)
        {
            Renderer.ColorGradingData = o.ColorGradingData;

            Renderer.UseColorGrading = o.UseColorGrading;
            Renderer.ToneMapping     = o.ToneMapping;

            Renderer.ToneExposure   = o.ToneExposure;
            Renderer.ToneGamma      = o.ToneGamma;
            Renderer.ToneWhitePoint = o.ToneWhitePoint;
        }
        public override void Clone(SaveableData Data)
        {
            SaveAbleMapping otherMapping = Data as SaveAbleMapping;

            _mappings = new KeyValuePreset();
            otherMapping.Mappings.SyncDic();

            foreach (string key in otherMapping.Mappings.Keys)
            {
                _mappings.PushItem(key, otherMapping.Mappings.GetValue(key));
            }
        }
示例#16
0
    /// <summary>
    /// Assigns data after it has been loaded from file.
    /// @param the data class that has been loaded from file
    /// </summary>
    /// <param name="data"></param>
    private void AssignValues(SaveableData data)
    {
        _timeAndCalendarLink.CurrentDay    = data.stats.currentDay;
        _timeAndCalendarLink.CurrentMonth  = data.stats.currentMonth;
        _timeAndCalendarLink.CurrentYear   = data.stats.currentYear;
        _timeAndCalendarLink.CurrentMinute = data.stats.currentMinute;
        _timeAndCalendarLink.CurrentHour   = data.stats.currentHour;

        _economyManagerLink.CurrentCash = data.stats.playerMoney;
        _playerManagerLink.PlayerName   = data.stats.playerName;
        _playerManagerLink.ArcadeName   = data.stats.arcadeName;
    }
示例#17
0
        /*public static SaveableData LoadAmbientShadowParams() {
         *  if (!ValuesStorage.Contains(KeySavedData)) {
         *      return new SaveableData();
         *  }
         *
         *  try {
         *      return JsonConvert.DeserializeObject<SaveableData>(ValuesStorage.GetString(KeySavedData));
         *  } catch (Exception e) {
         *      Logging.Warning(e);
         *      return new SaveableData();
         *  }
         * }*/

        private void Load(SaveableData o)
        {
            Diffusion       = o.AmbientShadowDiffusion;
            Brightness      = o.AmbientShadowBrightness;
            Iterations      = o.AmbientShadowIterations;
            HideWheels      = o.AmbientShadowHideWheels;
            Fade            = o.AmbientShadowFade;
            CorrectLighting = o.AmbientShadowCorrectLighting;
            PoissonSampling = o.AmbientShadowPoissonSampling;
            ExtraBlur       = o.AmbientShadowExtraBlur;
            UpDelta         = o.AmbientShadowUpDelta;
            BodyMultiplier  = o.AmbientShadowBodyMultiplier;
            WheelMultiplier = o.AmbientShadowWheelMultiplier;
        }
示例#18
0
        protected SaveableData Save([NotNull] SaveableData obj)
        {
            obj.AmbientDownColor = AmbientDownColor;
            obj.AmbientUpColor   = AmbientUpColor;
            obj.BackgroundColor  = BackgroundColor;
            obj.LightColor       = LightColor;

            obj.MsaaMode      = MsaaMode.IntValue ?? -1;
            obj.SsaaMode      = SsaaMode.IntValue ?? -1;
            obj.ShadowMapSize = ShadowMapSize.IntValue ?? -1;

            obj.ShowroomId       = (Showroom as ShowroomObject)?.Id;
            obj.ColorGradingData = Renderer.UseColorGrading ? Renderer.ColorGradingData : null;

            obj.CubemapAmbient            = Renderer.CubemapAmbient;
            obj.CubemapAmbientWhite       = Renderer.CubemapAmbientWhite;
            obj.ReflectionCubemapAtCamera = Renderer.ReflectionCubemapAtCamera;
            obj.ReflectionsWithShadows    = Renderer.ReflectionsWithShadows;
            obj.EnableShadows             = Renderer.EnableShadows;
            obj.FlatMirror        = Renderer.FlatMirror;
            obj.FlatMirrorBlurred = Renderer.FlatMirrorBlurred;
            obj.UseBloom          = Renderer.UseBloom;
            obj.UseColorGrading   = Renderer.UseColorGrading;
            obj.UseFxaa           = Renderer.UseFxaa;
            obj.UsePcss           = Renderer.UsePcss;
            obj.UseSmaa           = Renderer.UseSmaa;
            obj.UseAo             = Renderer.UseAo;
            obj.UseSslr           = Renderer.UseSslr;

            obj.ToneMapping = Renderer.ToneMapping;
            obj.AoType      = Renderer.AoType;

            obj.AmbientBrightness        = Renderer.AmbientBrightness;
            obj.BackgroundBrightness     = Renderer.BackgroundBrightness;
            obj.FlatMirrorReflectiveness = Renderer.FlatMirrorReflectiveness;
            obj.LightBrightness          = Renderer.LightBrightness;
            obj.Lightθ = LightθDeg;
            obj.Lightφ = LightφDeg;
            obj.MaterialsReflectiveness = Renderer.MaterialsReflectiveness;
            obj.ToneExposure            = Renderer.ToneExposure;
            obj.ToneGamma             = Renderer.ToneGamma;
            obj.ToneWhitePoint        = Renderer.ToneWhitePoint;
            obj.BloomRadiusMultiplier = Renderer.BloomRadiusMultiplier;

            obj.PcssSceneScale = Renderer.PcssSceneScale;
            obj.PcssLightScale = Renderer.PcssLightScale;
            obj.SsaoOpacity    = Renderer.AoOpacity;
            return(obj);
        }
示例#19
0
    /// <summary>
    /// Loads the @param file from disk and overwrites the current instantiation of the SaveableData class.
    /// This function will destroy all machines and customers in the current level, then reinstantiate the ones contained in the @param file from disk.
    /// ANY MACHINE OR CUSTOMER THAT HAS NOT BEEN SAVED BEFORE THIS FUNCTION IS CALLED WILL BE DELETED AND UNRECOVERABLE.
    /// This function will also update the pathfinding grid once it is finished, to allow the AI to navigate the new level layout.
    /// </summary>
    public void LoadScene(string saveFileName)
    {
        string fullSavePath = SavePath + saveFileName + FILE_EXTENSION;

        GameManager.Instance.SceneManagerLink.GetComponent <LevelInteraction>().ClearObjectParent();
        GameManager.Instance.ScriptHolderLink.GetComponent <CustomerManager>().ClearCustomerParent();
        GameManager.Instance.ScriptHolderLink.GetComponent <CustomerManager>().LoadClearLists();
        saveData = SaveGame.Load <SaveableData>(fullSavePath, saveData);
        AssignValues(saveData);
        instantiatedObjectParent   = GameObject.Find("Level/Placed Objects");
        instantiatedCustomerParent = GameObject.Find("Customers");
        CreateObjects();
        CreateCustomers();
        GameManager.Instance.PathingGridManagerLink.GetComponent <PathingGridSetup>().UpdateGrid();
    }
示例#20
0
        protected void LoadQuality(SaveableData o)
        {
            MsaaMode      = MsaaModes.GetByIdOrDefault <SettingEntry, int?>(o.MsaaMode);
            SsaaMode      = SsaaModesExtended.GetByIdOrDefault <SettingEntry, int?>(o.SsaaMode);
            ShadowMapSize = ShadowResolutions.GetByIdOrDefault <SettingEntry, int?>(o.ShadowMapSize);

            Renderer.EnableShadows = o.EnableShadows;
            Renderer.UseBloom      = o.UseBloom;
            Renderer.UseFxaa       = o.UseFxaa;
            Renderer.UsePcss       = o.UsePcss;
            Renderer.UseSmaa       = o.UseSmaa;
            Renderer.UseAo         = o.UseAo;
            Renderer.UseSslr       = o.UseSslr;

            Renderer.AoType = o.AoType;
        }
示例#21
0
            protected virtual void Load(SaveableData o)
            {
                Penalties        = o.Penalties ?? true;
                JumpStartPenalty = o.JumpStartPenalty ?? Game.JumpStartPenaltyType.None;
                LapsNumber       = o.LapsNumber ?? 2;

                if (o.RaceGridSerialized != null)
                {
                    RaceGridViewModel.ImportFromPresetData(o.RaceGridSerialized);
                }
                else
                {
                    Logging.Warning("Race grid data missing");
                    RaceGridViewModel.Reset();
                }
            }
示例#22
0
 /// <summary>
 /// Retrieves the data stored inside of a save file
 /// </summary>
 /// <param name="fullFilePath"></param>
 /// <returns></returns>
 private SaveableData GetSaveFile(string fullFilePath)
 {
     if (File.Exists(fullFilePath))
     {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream      fs = File.Open(fullFilePath, FileMode.Open);
         saveData = (SaveableData)bf.Deserialize(fs);
         fs.Close();
         return(saveData);
     }
     else
     {
         Debug.LogError("Failed to save to file " + fullFilePath);
         return(null);
     }
 }
示例#23
0
        public override void Clone(SaveableData Data)
        {
            NodalEditorPreferences clonePrefs = Data as NodalEditorPreferences;

            if (clonePrefs != null)
            {
                mCheckCycles      = clonePrefs.CheckCycles;
                mShowHoveredLinks = clonePrefs.ShowHoveredLinks;

                mMagnetic          = clonePrefs.Magnetic;
                mShowGrid          = clonePrefs.ShowGrid;
                mShowRootPorts     = clonePrefs.ShowRootPorts;
                mShowCompoundPorts = clonePrefs.ShowCompoundPorts;
                mShowMap           = clonePrefs.ShowMap;
                mMapWidth          = clonePrefs.MapWidth;
                mGridSpacing       = clonePrefs.GridSpacing;
                mMinimumZoom       = clonePrefs.MinimumZoom;
                mMaximumZoom       = clonePrefs.MaximumZoom;
                mShowNodeTips      = clonePrefs.ShowNodeTips;

                mNodePortsFont        = clonePrefs.NodePortsFont;
                mNodePortsFontColor   = clonePrefs.NodePortsFontColor;
                mNodeLabelFont        = clonePrefs.NodeLabelFont;
                mNodeLabelFontColor   = clonePrefs.NodeLabelFontColor;
                mCompoundPadFont      = clonePrefs.CompoundPadFont;
                mCompoundPadFontColor = clonePrefs.CompoundPadFontColor;

                mBackgroundColor  = clonePrefs.BackgroundColor;
                mCompoundPadColor = clonePrefs.CompoundPadColor;
                mGridColor        = clonePrefs.GridColor;

                mDefaultLinkColor = clonePrefs.DefaultLinkColor;

                mDefaultNodeColor         = clonePrefs.DefaultNodeColor;
                mDefaultSelectedNodeColor = clonePrefs.DefaultSelectedNodeColor;

                mDefaultCompoundColor         = clonePrefs.DefaultCompoundColor;
                mDefaultSelectedCompoundColor = clonePrefs.DefaultSelectedCompoundColor;
                //mLinksStates = clonePrefs.mLinksStates;

                mLinksCategories = clonePrefs.LinksCategories;
                mNodeCategories  = clonePrefs.NodeCategories;
                mNodeStates      = clonePrefs.NodeStates;
            }
        }
示例#24
0
        public override void Clone(SaveableData Data)
        {
            Animation anim = Data as Animation;

            if (anim != null)
            {
                _name             = anim.Name;
                _curves           = anim.Curves;
                _type             = anim.Type;
                _paramHolder      = anim.ParamHolder;
                _customName       = anim.CustomName;
                _priority         = anim.Priority;
                _ignorePriorities = anim.IgnorePriorities;
                _split            = anim.Split;
                _embed            = anim.Embed;
                _category         = anim.Category;
                _tags             = new List <string>(anim.Tags);
            }
        }
示例#25
0
        protected void LoadCamera(SaveableData o)
        {
            _cameraBusy = true;

            try {
                CameraPosition.Set(o.CameraPosition);
                CameraLookAt.Set(o.CameraLookAt);
                CameraFov = o.CameraFov;
                AlignCar  = o.AlignCar;
                AlignCameraHorizontally               = o.AlignCameraHorizontally;
                AlignCameraHorizontallyOffset         = o.AlignCameraHorizontallyOffset;
                AlignCameraHorizontallyOffsetRelative = o.AlignCameraHorizontallyOffsetRelative;
                AlignCameraVertically               = o.AlignCameraVertically;
                AlignCameraVerticallyOffset         = o.AlignCameraVerticallyOffset;
                AlignCameraVerticallyOffsetRelative = o.AlignCameraVerticallyOffsetRelative;
            } finally {
                _cameraBusy = false;
                UpdateCamera();
            }
        }
示例#26
0
    public static void Save()
    {
        BinaryFormatter data = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/gameSave.dat");

        SaveableData saveData = new SaveableData();

        //-----------------------Saving Data---------------------------------------------
        Hashtable dataToSave = new Hashtable();

        dataToSave.Add("finishedTutorial", CampaignData.GetFinishedTutorial());
        dataToSave.Add("viewedAbilityMatchInstructions", CampaignData.ViewedMatchAbilityInstructions());
        dataToSave.Add("allBoardLevels", CampaignData.GetAllLevelsDictionary());
        dataToSave.Add("heroesUnlocked", CampaignData.GetAllHeroBoardsDictionary());
        dataToSave.Add("boardStarCounts", CampaignData.GetAllBoardStarCounts());

        //-----------------------Done Saving---------------------------------------------
        data.Serialize(file, dataToSave);
        file.Close();
        //Debug.Log("Saved here: " + Application.persistentDataPath);
    }
        /// <summary>
        /// Initialize the preference form
        /// </summary>
        /// <param name="inName">Name of the preference to edit</param>
        /// <param name="inPrefObject">The SaveableData, as an object to keep it undetermined for PropertyGrid</param>
        /// <param name="baseFolder">Base folder for saving files</param>
        /// <param name="baseFileName">Base File Name for saving files</param>
        /// <param name="alternateContent">Alternate editor for the preference</param>
        public void Init(string inName, object inPrefObject, string baseFolder, string baseFileName, AlternateSaveAbleEditor alternateContent)
        {
            Data = inPrefObject as SaveableData;
            DirectoryInfo baseFolderInfo = new DirectoryInfo(baseFolder);

            if (!baseFolderInfo.Exists)
            {
                baseFolderInfo.Create();
            }

            if (Data != null && baseFolderInfo.Exists)
            {
                BaseFolder   = baseFolder;
                BaseFileName = baseFileName;

                Text = inName;
                if (alternateContent != null)
                {
                    HasDefaults  = alternateContent.HasDefaults();
                    AllowPresets = alternateContent.AllowPresets();

                    PrefPropertyGrid.Visible = false;
                    alternateContent.Init(Data);
                    Width  = alternateContent.Width;
                    Height = alternateContent.Height;
                    Controls.Add(alternateContent);
                    alternateContent.Dock = DockStyle.Fill;
                    alternateContent.BringToFront();
                }
                else
                {
                    PrefPropertyGrid.Visible        = true;
                    PrefPropertyGrid.SelectedObject = inPrefObject;
                }
            }

            Changed = false;
        }
示例#28
0
        protected void LoadScene(SaveableData o)
        {
            LoadShowroom(o.ShowroomId).Forget();

            AmbientDownColor = o.AmbientDownColor;
            AmbientUpColor   = o.AmbientUpColor;
            BackgroundColor  = o.BackgroundColor;
            LightColor       = o.LightColor;

            Renderer.CubemapAmbient            = o.CubemapAmbient;
            Renderer.CubemapAmbientWhite       = o.CubemapAmbientWhite;
            Renderer.ReflectionCubemapAtCamera = o.ReflectionCubemapAtCamera;
            Renderer.ReflectionsWithShadows    = o.ReflectionsWithShadows;
            Renderer.FlatMirror        = o.FlatMirror;
            Renderer.FlatMirrorBlurred = o.FlatMirrorBlurred;

            Renderer.AmbientBrightness        = o.AmbientBrightness;
            Renderer.BackgroundBrightness     = o.BackgroundBrightness;
            Renderer.FlatMirrorReflectiveness = o.FlatMirrorReflectiveness;
            Renderer.LightBrightness          = o.LightBrightness;
            LightθDeg = o.Lightθ;
            LightφDeg = o.Lightφ;
        }
示例#29
0
 protected virtual void Save(SaveableData result) {}
示例#30
0
 /// <summary>
 /// Will be called in constuctor!
 /// </summary>
 protected virtual void InitializeSaveable() {
     Saveable = new SaveHelper<SaveableData>("__QuickDrive_GridTest", () => {
         var r = new SaveableData();
         Save(r);
         return r;
     }, Load, Reset);
 }
示例#31
0
 protected virtual void Save(SaveableData result) {
     result.Penalties = Penalties;
     result.JumpStartPenalty = JumpStartPenalty;
     result.LapsNumber = LapsNumber;
     result.RaceGridSerialized = RaceGridViewModel.ExportToPresetData();
 }
示例#32
0
            protected virtual void Load(SaveableData o) {
                Penalties = o.Penalties ?? true;
                JumpStartPenalty = o.JumpStartPenalty ?? Game.JumpStartPenaltyType.None;
                LapsNumber = o.LapsNumber ?? 2;

                if (o.RaceGridSerialized != null) {
                    RaceGridViewModel.ImportFromPresetData(o.RaceGridSerialized);
                } else {
                    Logging.Warning("Race grid data missing");
                    RaceGridViewModel.Reset();
                }
            }
示例#33
0
 protected void Load(SaveableData data)
 {
     Penalties        = data.Penalties;
     PlayerBallast    = data.PlayerBallast;
     PlayerRestrictor = data.PlayerRestrictor;
 }
示例#34
0
 protected override void InitializeSaveable() {
     Saveable = new SaveHelper<SaveableData>("__QuickDrive_Weekend", () => {
         var r = new SaveableData();
         Save(r);
         return r;
     }, Load, Reset);
     Saveable.RegisterUpgrade<OldSaveableData>(QuickDrive_Race.ViewModel.OldSaveableData.Test, Load);
 }
示例#35
0
        public RaceGridViewModel(bool ignoreStartingPosition = false) {
            IgnoreStartingPosition = ignoreStartingPosition;

            _saveable = new SaveHelper<SaveableData>(KeySaveable, () => {
                var data = new SaveableData {
                    ModeId = Mode.Id,
                    FilterValue = FilterValue,
                    ShuffleCandidates = ShuffleCandidates,
                    AiLevelFixed = AiLevelFixed,
                    AiLevelArrangeRandom = AiLevelArrangeRandom,
                    AiLevelArrangeReverse = AiLevelArrangeReverse,
                    AiLevel = AiLevel,
                    AiLevelMin = AiLevelMin,
                    OpponentsNumber = OpponentsNumber,
                    StartingPosition = StartingPosition,
                };

                if (Mode == BuiltInGridMode.CandidatesManual) {
                    var priority = false;
                    data.CarIds = NonfilteredList.Select(x => {
                        if (x.CandidatePriority != 1) priority = true;
                        return x.Car.Id;
                    }).ToArray();

                    if (priority) {
                        data.CandidatePriorities = NonfilteredList.Select(x => x.CandidatePriority).ToArray();
                    }
                } else if (Mode == BuiltInGridMode.Custom) {
                    data.CarIds = NonfilteredList.Where(x => !x.SpecialEntry).Select(x => x.Car.Id).ToArray();
                }

                if (data.CarIds != null) {
                    var filtered = NonfilteredList.Where(x => !x.SpecialEntry).ToList();

                    if (filtered.Any(x => x.AiLevel.HasValue)) {
                        data.AiLevels = filtered.Select(x => x.AiLevel ?? -1).ToArray();
                    }

                    if (filtered.Any(x => x.Name != null)) {
                        data.Names = filtered.Select(x => x.Name).ToArray();
                    }

                    if (filtered.Any(x => x.Nationality != null)) {
                        data.Nationalities = filtered.Select(x => x.Nationality).ToArray();
                    }

                    if (filtered.Any(x => x.CarSkin != null)) {
                        data.SkinIds = filtered.Select(x => x.CarSkin?.Id).ToArray();
                    }
                }

                return data;
            }, data => {
                ShuffleCandidates = data.ShuffleCandidates ?? true;
                AiLevelFixed = data.AiLevelFixed ?? false;
                AiLevelArrangeRandom = data.AiLevelArrangeRandomly.HasValue ? (data.AiLevelArrangeRandomly.Value ? 1d : 0d) :
                        data.AiLevelArrangeRandom ?? 0.1d;
                AiLevelArrangeReverse = data.AiLevelArrangeReverse ?? false;
                AiLevel = data.AiLevel ?? 95;
                AiLevelMin = data.AiLevelMin ?? 85;

                FilterValue = data.FilterValue;
                ErrorMessage = null;

                var mode = Modes.GetByIdOrDefault<IRaceGridMode>(data.ModeId);
                if (mode == null) {
                    NonfatalError.NotifyBackground(ToolsStrings.RaceGrid_GridModeIsMissing,
                            string.Format(ToolsStrings.RaceGrid_GridModeIsMissing_Commentary, data.ModeId));
                    Mode = BuiltInGridMode.SameCar;
                } else {
                    Mode = mode;
                }

                if (Mode.CandidatesMode) {
                    if (Mode == BuiltInGridMode.CandidatesManual && data.CarIds != null) {
                        // TODO: Async?
                        NonfilteredList.ReplaceEverythingBy(data.CarIds.Select(x => CarsManager.Instance.GetById(x)).Select((x, i) => {
                            if (x == null) return null;

                            var aiLevel = data.AiLevels?.ElementAtOrDefault(i);
                            var carSkinId = data.SkinIds?.ElementAtOrDefault(i);
                            return new RaceGridEntry(x) {
                                CandidatePriority = data.CandidatePriorities?.ElementAtOr(i, 1) ?? 1,
                                AiLevel = aiLevel >= 0 ? aiLevel : (int?)null,
                                Name = data.Names?.ElementAtOrDefault(i),
                                Nationality = data.Nationalities?.ElementAtOrDefault(i),
                                CarSkin = carSkinId != null ? x.GetSkinById(carSkinId) : null,
                            };
                        }).NonNull());
                    } else {
                        NonfilteredList.Clear();
                    }

                    SetOpponentsNumberInternal(data.OpponentsNumber ?? 7);
                } else {
                    NonfilteredList.ReplaceEverythingBy(data.CarIds?.Select(x => CarsManager.Instance.GetById(x)).Select((x, i) => {
                        if (x == null) return null;

                        var aiLevel = data.AiLevels?.ElementAtOrDefault(i);
                        var carSkinId = data.SkinIds?.ElementAtOrDefault(i);

                        return new RaceGridEntry(x) {
                            AiLevel = aiLevel >= 0 ? aiLevel : null,
                            Name = data.Names?.ElementAtOrDefault(i),
                            Nationality = data.Nationalities?.ElementAtOrDefault(i),
                            CarSkin = carSkinId != null ? x.GetSkinById(carSkinId) : null,
                        };
                    }).NonNull() ?? new RaceGridEntry[0]);
                }
                
                StartingPosition = data.StartingPosition ?? 7;
                FinishLoading();
            }, Reset);

            _presetsHelper = new PresetsMenuHelper();

            _randomGroup = new HierarchicalGroup(ToolsStrings.RaceGrid_Random);
            UpdateRandomModes();

            Modes = new HierarchicalGroup {
                BuiltInGridMode.SameCar,
                _randomGroup,
                BuiltInGridMode.Custom,
                _presetsHelper.Create(PresetableKeyValue, p => {
                    ImportFromPresetData(p.ReadData());
                }, ControlsStrings.Common_Presets)
            };

            NonfilteredList.CollectionChanged += OnCollectionChanged;
            FilteredView = new BetterListCollectionView(NonfilteredList) { CustomSort = this };

            // _saveable.Initialize();
            FilesStorage.Instance.Watcher(ContentCategory.GridTypes).Update += OnGridTypesUpdate;
        }
示例#36
0
 protected virtual void Load(SaveableData o) {}
示例#37
0
        public RaceGridViewModel(bool ignoreStartingPosition = false, [CanBeNull] string keySaveable = KeySaveable)
        {
            IgnoreStartingPosition = ignoreStartingPosition;

            _saveable = new SaveHelper <SaveableData>(keySaveable, () => {
                var data = new SaveableData {
                    ModeId                = Mode.Id,
                    FilterValue           = FilterValue,
                    ShuffleCandidates     = ShuffleCandidates,
                    AiLevelFixed          = AiLevelFixed,
                    AiLevelArrangeRandom  = AiLevelArrangeRandom,
                    AiLevelArrangeReverse = AiLevelArrangeReverse,
                    AiLevel               = AiLevel,
                    AiLevelMin            = AiLevelMin,
                    OpponentsNumber       = OpponentsNumber,
                    StartingPosition      = StartingPosition,
                };

                if (Mode == BuiltInGridMode.CandidatesManual)
                {
                    var priority = false;
                    data.CarIds  = NonfilteredList.Select(x => {
                        if (x.CandidatePriority != 1)
                        {
                            priority = true;
                        }
                        return(x.Car.Id);
                    }).ToArray();

                    if (priority)
                    {
                        data.CandidatePriorities = NonfilteredList.Select(x => x.CandidatePriority).ToArray();
                    }
                }
                else if (Mode == BuiltInGridMode.Custom)
                {
                    data.CarIds = NonfilteredList.Where(x => !x.SpecialEntry).Select(x => x.Car.Id).ToArray();
                }

                if (data.CarIds != null)
                {
                    var filtered = NonfilteredList.Where(x => !x.SpecialEntry).ToList();

                    if (filtered.Any(x => x.AiLevel.HasValue))
                    {
                        data.AiLevels = filtered.Select(x => x.AiLevel ?? -1).ToArray();
                    }

                    if (filtered.Any(x => x.Name != null))
                    {
                        data.Names = filtered.Select(x => x.Name).ToArray();
                    }

                    if (filtered.Any(x => x.Nationality != null))
                    {
                        data.Nationalities = filtered.Select(x => x.Nationality).ToArray();
                    }

                    if (filtered.Any(x => x.CarSkin != null))
                    {
                        data.SkinIds = filtered.Select(x => x.CarSkin?.Id).ToArray();
                    }
                }

                return(data);
            }, data => {
                ShuffleCandidates    = data.ShuffleCandidates ?? true;
                AiLevelFixed         = data.AiLevelFixed ?? false;
                AiLevelArrangeRandom = data.AiLevelArrangeRandomly.HasValue ? (data.AiLevelArrangeRandomly.Value ? 1d : 0d) :
                                       data.AiLevelArrangeRandom ?? 0.1d;
                AiLevelArrangeReverse = data.AiLevelArrangeReverse ?? false;
                AiLevel    = data.AiLevel ?? 95;
                AiLevelMin = data.AiLevelMin ?? 85;

                FilterValue  = data.FilterValue;
                ErrorMessage = null;

                var mode = Modes.GetByIdOrDefault <IRaceGridMode>(data.ModeId);
                if (mode == null)
                {
                    NonfatalError.NotifyBackground(ToolsStrings.RaceGrid_GridModeIsMissing,
                                                   string.Format(ToolsStrings.RaceGrid_GridModeIsMissing_Commentary, data.ModeId));
                    Mode = BuiltInGridMode.SameCar;
                }
                else
                {
                    Mode = mode;
                }

                if (Mode.CandidatesMode)
                {
                    if (Mode == BuiltInGridMode.CandidatesManual && data.CarIds != null)
                    {
                        // TODO: Async?
                        NonfilteredList.ReplaceEverythingBy(data.CarIds.Select(x => CarsManager.Instance.GetById(x)).Select((x, i) => {
                            if (x == null)
                            {
                                return(null);
                            }

                            var aiLevel   = data.AiLevels?.ElementAtOrDefault(i);
                            var carSkinId = data.SkinIds?.ElementAtOrDefault(i);
                            return(new RaceGridEntry(x)
                            {
                                CandidatePriority = data.CandidatePriorities?.ElementAtOr(i, 1) ?? 1,
                                AiLevel = aiLevel >= 0 ? aiLevel : (int?)null,
                                Name = data.Names?.ElementAtOrDefault(i),
                                Nationality = data.Nationalities?.ElementAtOrDefault(i),
                                CarSkin = carSkinId != null ? x.GetSkinById(carSkinId) : null,
                            });
                        }).NonNull());
                    }
                    else
                    {
                        NonfilteredList.Clear();
                    }

                    SetOpponentsNumberInternal(data.OpponentsNumber ?? 7);
                }
                else
                {
                    NonfilteredList.ReplaceEverythingBy(data.CarIds?.Select(x => CarsManager.Instance.GetById(x)).Select((x, i) => {
                        if (x == null)
                        {
                            return(null);
                        }

                        var aiLevel   = data.AiLevels?.ElementAtOrDefault(i);
                        var carSkinId = data.SkinIds?.ElementAtOrDefault(i);

                        return(new RaceGridEntry(x)
                        {
                            AiLevel = aiLevel >= 0 ? aiLevel : null,
                            Name = data.Names?.ElementAtOrDefault(i),
                            Nationality = data.Nationalities?.ElementAtOrDefault(i),
                            CarSkin = carSkinId != null ? x.GetSkinById(carSkinId) : null,
                        });
                    }).NonNull() ?? new RaceGridEntry[0]);
                }

                StartingPosition = data.StartingPosition ?? 7;
                FinishLoading();
            }, Reset);

            _presetsHelper = new PresetsMenuHelper();

            _randomGroup = new HierarchicalGroup(ToolsStrings.RaceGrid_Random);
            UpdateRandomModes();

            Modes = new HierarchicalGroup {
                BuiltInGridMode.SameCar,
                _randomGroup,
                BuiltInGridMode.Custom,
                _presetsHelper.Create(PresetableKeyValue, p => {
                    ImportFromPresetData(p.ReadData());
                }, ControlsStrings.Common_Presets)
            };

            NonfilteredList.CollectionChanged   += OnCollectionChanged;
            NonfilteredList.ItemPropertyChanged += OnItemPropertyChanged;
            FilteredView = new BetterListCollectionView(NonfilteredList)
            {
                CustomSort = this
            };

            // _saveable.Initialize();
            FilesStorage.Instance.Watcher(ContentCategory.GridTypes).Update += OnGridTypesUpdate;
        }
示例#38
0
 protected void LoadSize(SaveableData o)
 {
     Width            = o.Width;
     Height           = o.Height;
     SoftwareDownsize = o.SoftwareDownsize;
 }