Esempio n. 1
0
        public SaveableVehicle CreateInfo(Vehicle vehicle)
        {
            var saveableVehicle = new SaveableVehicle();

            saveableVehicle.Handle               = vehicle.Handle;
            saveableVehicle.VehicleName          = vehicle.DisplayName;
            saveableVehicle.Vehicle              = (uint)vehicle.Model.Hash;
            saveableVehicle.DirtLevel            = vehicle.DirtLevel;
            saveableVehicle.PrimaryColor         = vehicle.PrimaryColor;
            saveableVehicle.SecondaryColor       = vehicle.PrimaryColor;
            saveableVehicle.DashboardColor       = vehicle.DashboardColor;
            saveableVehicle.Position             = vehicle.Position;
            saveableVehicle.Rotation             = vehicle.Rotation;
            saveableVehicle.BodyHealth           = vehicle.BodyHealth;
            saveableVehicle.Health               = vehicle.Health;
            saveableVehicle.EngineHealth         = vehicle.EngineHealth;
            saveableVehicle.EngineRunning        = vehicle.EngineRunning;
            saveableVehicle.LeftHeadlightBroken  = vehicle.LeftHeadLightBroken;
            saveableVehicle.RightHeadlightBroken = vehicle.RightHeadLightBroken;
            saveableVehicle.Livery               = vehicle.Livery;
            saveableVehicle.LightsOn             = vehicle.LightsOn;
            saveableVehicle.WindowTint           = vehicle.WindowTint;
            saveableVehicle.RoofState            = vehicle.RoofState;
            saveableVehicle.WheelType            = vehicle.WheelType;
            return(saveableVehicle);
        }
        public static void RemoveVehicle(SaveableVehicle saveableVehicle)
        {
            //Gooi een exception waneer het basispad niet is geinitialiseerd
            ThrowExceptionWhenBasePathDoesNotExist();

            //Haal opgeslagen auto's op
            var vehicles = GetVehicles().ToList();

            //Verwijder de auto om te verwijderen uit de lijst van opgeslagen auto's
            vehicles.RemoveAll(x => x == saveableVehicle);

            //Sla de auto's weer in het bestand
            ConvertAndWriteVehiclesToFile(vehicles);
        }
        public static void SaveVehicle(SaveableVehicle saveableVehicle)
        {
            //Gooi een exception waneer het basispad niet is geinitialiseerd
            ThrowExceptionWhenBasePathDoesNotExist();

            //Haal opgeslagen auto's op
            var vehicles = GetVehicles().ToList();

            //Voeg auto om op te slaan toe aan de andere opgeslagen auto's
            vehicles.Add(saveableVehicle);

            //Zet de opgeslagen auto's om naar json
            var json = JsonConvert.SerializeObject(vehicles, new JsonSerializerSettings
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            //Schrijf de json string naar het bestand
            File.WriteAllText(GetFilePath(), json);
        }
Esempio n. 4
0
        public Vehicle CreateVehicleFromData(SaveableVehicle data)
        {
            var vehicle = World.CreateVehicle(new Model((int)data.Vehicle), data.Position);

            vehicle.DirtLevel      = data.DirtLevel;
            vehicle.PrimaryColor   = data.PrimaryColor;
            vehicle.SecondaryColor = data.PrimaryColor;
            vehicle.DashboardColor = data.DashboardColor;
            vehicle.Position       = data.Position;
            vehicle.Rotation       = data.Rotation;
            vehicle.BodyHealth     = data.BodyHealth;
            vehicle.EngineHealth   = data.EngineHealth;
            vehicle.EngineRunning  = data.EngineRunning;
            vehicle.Livery         = data.Livery;
            vehicle.LightsOn       = data.LightsOn;
            vehicle.WindowTint     = data.WindowTint;
            vehicle.RoofState      = data.RoofState;
            vehicle.WheelType      = data.WheelType;
            vehicle.IsPersistent   = true;
            return(vehicle);
        }
Esempio n. 5
0
        void onMainMenuItemSelect(UIMenu sender, UIMenuItem item, int index)
        {
            if (item == loadVehicles)
            {
                SaveableVehicle[] saveVehicles = new SaveableVehicle[0];
                try
                {
                    //Haal opgeslagen auto's op
                    saveVehicles = JsonVehicleStorage.GetVehicles();
                }
                catch (Exception e)
                {
                    UI.Notify(e.Message);
                }

                try
                {
                    foreach (var saveVehicle in saveVehicles)
                    {
                        //Zet opgeslagen auto's om naar GTA objecten en creëer ze in het spel
                        Vehicle vehicle = null;
                        try
                        {
                            vehicle = _vehicleUtilities.CreateVehicleFromData(saveVehicle);
                        }
                        catch (Exception e)
                        {
                            UI.Notify(e.Message);
                        }

                        if (vehicle == null)
                        {
                            return;
                        }

                        //Sla auto op in de opgeslagen auto lijst
                        savedVehicles.Add(vehicle);

                        try
                        {
                            var blip = Function.Call <Blip>(Hash.ADD_BLIP_FOR_ENTITY, vehicle); // Sets blip on vehicle
                            blip.IsShortRange = true;
                            Function.Call(Hash.SET_BLIP_SPRITE, blip, 225);                     // Sets vehicle blip icon
                            Function.Call(Hash.SET_BLIP_DISPLAY, blip, 2);                      // Displays the blip icon
                        }
                        catch (Exception e)
                        {
                            UI.Notify(e.Message);
                        }
                    }
                }
                catch (Exception e)
                {
                    UI.Notify(e.Message);
                }
            }

            if (item == unsaveButton)
            {
                while (savedVehicles.Count > 0)
                {
                    Vehicle listVehicle = savedVehicles[savedVehicles.Count - 1];
                    savedVehicles.Remove(listVehicle);

                    var saveableVehicle = _vehicleUtilities.CreateInfo(listVehicle);

                    JsonVehicleStorage.RemoveVehicle(saveableVehicle);

                    listVehicle.IsPersistent = false;
                    listVehicle.CurrentBlip.Remove();
                    listVehicle.Delete();
                }

                UI.Notify("All Vehicles Unsaved and Removed");
            }

            if (item == exitButton)
            {
                mainMenu.GoBack();
            }
        }