Esempio n. 1
0
        public void SaveProject()
        {
            AaronProject aaronProject = GetCurrentProject();

            foreach (var item in this.GetChangedItems())
            {
                item.Changed = false;
                switch (item)
                {
                case AaronCarRecord aaronCarRecord:
                    File.WriteAllText(Path.Combine(aaronProject.CarsDirectory, aaronCarRecord.CarTypeName + ".json"),
                                      Serialization.Serialize(aaronCarRecord));
                    break;

                case AaronCarPartCollection carPartCollection:
                    var fileName   = Path.Combine(aaronProject.CarPartsDirectory, $"{carPartCollection.Name}.json");
                    var serialized = Serialization.Serialize(carPartCollection);

                    File.WriteAllText(fileName, serialized);
                    break;

                case AaronPresetCar aaronPresetCar:
                    File.WriteAllText(
                        Path.Combine(aaronProject.PresetCarsDirectory, $"{aaronPresetCar.PresetName}.xml"),
                        PresetConverter.ConvertAaronPresetToServerXML(aaronPresetCar).DataContractSerializeObject());
                    break;

                case AaronPresetSkinRecord aaronPresetSkinRecord:
                    File.WriteAllText(
                        Path.Combine(aaronProject.PresetSkinsDirectory, $"{aaronPresetSkinRecord.PresetName}.json"),
                        Serialization.Serialize(aaronPresetSkinRecord));
                    break;

                case AaronDataTable aaronDataTable:
                    File.WriteAllText(
                        Path.Combine(aaronProject.DataTablesDirectory, $"{aaronDataTable.Name}.json"),
                        Serialization.Serialize(aaronDataTable));
                    break;
                }
            }
        }
Esempio n. 2
0
        public string GenerateProject(string directory)
        {
            AaronProject aaronProject = new AaronProject();

            aaronProject.Version              = AaronProjectVersion;
            aaronProject.CarsDirectory        = Path.Combine(directory, "Cars");
            aaronProject.CarPartsDirectory    = Path.Combine(directory, "CarParts");
            aaronProject.PresetCarsDirectory  = Path.Combine(directory, "PresetCars");
            aaronProject.PresetSkinsDirectory = Path.Combine(directory, "PresetSkins");
            aaronProject.DataTablesDirectory  = Path.Combine(directory, "DataTables");
            aaronProject.OutputFilePath       = Path.Combine(directory, "bin", "GlobalC.lzc");
            aaronProject.SlotOverrideData     = _carPartService.GetSlotOverrideData();

            Directory.CreateDirectory(directory);
            Directory.CreateDirectory(aaronProject.CarsDirectory);
            Directory.CreateDirectory(aaronProject.CarPartsDirectory);
            Directory.CreateDirectory(aaronProject.PresetCarsDirectory);
            Directory.CreateDirectory(aaronProject.PresetSkinsDirectory);
            Directory.CreateDirectory(aaronProject.DataTablesDirectory);
            Directory.CreateDirectory(Path.Combine(directory, "bin"));

            var projectPath = Path.Combine(directory, "project.aproj");

            File.WriteAllText(projectPath, Serialization.Serialize(aaronProject));

            DebugTiming.BeginTiming("ExportCars");
            foreach (var aaronCarRecord in _carService.GetCars())
            {
                File.WriteAllText(Path.Combine(aaronProject.CarsDirectory, aaronCarRecord.CarTypeName + ".json"),
                                  Serialization.Serialize(aaronCarRecord));
            }
            DebugTiming.EndTiming("ExportCars");

            DebugTiming.BeginTiming("ExportCarParts");

            {
                var carPartCollections = _carPartService.GetCarPartCollections();

                foreach (var carPartCollection in carPartCollections)
                {
                    var fileName   = Path.Combine(aaronProject.CarPartsDirectory, $"{carPartCollection.Name}.json");
                    var serialized = Serialization.Serialize(carPartCollection);

                    File.WriteAllText(fileName, serialized);
                }
            }

            DebugTiming.EndTiming("ExportCarParts");

            DebugTiming.BeginTiming("ExportPresets");

            foreach (var aaronPresetCar in _presetCarService.GetPresetCars())
            {
                File.WriteAllText(
                    Path.Combine(aaronProject.PresetCarsDirectory, $"{aaronPresetCar.PresetName}.xml"),
                    PresetConverter.ConvertAaronPresetToServerXML(aaronPresetCar).DataContractSerializeObject());
            }

            DebugTiming.EndTiming("ExportPresets");

            DebugTiming.BeginTiming("ExportPresetSkins");

            foreach (var aaronPresetSkinRecord in _presetSkinService.GetPresetSkins())
            {
                File.WriteAllText(
                    Path.Combine(aaronProject.PresetSkinsDirectory, $"{aaronPresetSkinRecord.PresetName}.json"),
                    Serialization.Serialize(aaronPresetSkinRecord));
            }

            DebugTiming.EndTiming("ExportPresetSkins");

            DebugTiming.BeginTiming("ExportDataTables");

            foreach (var aaronDataTable in _dataTableService.GetDataTables())
            {
                File.WriteAllText(
                    Path.Combine(aaronProject.DataTablesDirectory, $"{aaronDataTable.Name}.json"),
                    Serialization.Serialize(aaronDataTable));
            }

            DebugTiming.EndTiming("ExportDataTables");

            File.WriteAllText(Path.Combine(directory, "strings.json"), Serialization.Serialize(_carPartService.GetStrings()));

            return(projectPath);
        }