Ejemplo n.º 1
0
        private static SolarPanelData LoadModuleDeployableSolarPanel(int partIndex, ProtoPartSnapshot protoPartSnapshot, VesselData vesselData, Part protoPart)
        {
            var moduleDeployableSolarPanels = protoPart?.FindModulesImplementing <ModuleDeployableSolarPanel>();

            if (moduleDeployableSolarPanels is null || moduleDeployableSolarPanels.Any() == false)
            {
                return(null);
            }

            List <ProtoPartModuleSnapshot> protoPartModuleSnapshots = protoPartSnapshot.modules.Where(m => m.moduleName == nameof(ModuleDeployableSolarPanel)).ToList();

            var solarPanelData = new SolarPanelData
            {
                PartIndex                   = partIndex,
                ProtoPart                   = protoPart,
                ProtoPartSnapshot           = protoPartSnapshot,
                PersistentPartId            = protoPartSnapshot.persistentId,
                ProtoPartModuleSnapshots    = protoPartModuleSnapshots,
                ModuleDeployableSolarPanels = moduleDeployableSolarPanels
            };

            // calculate tweakScale multiplier
            if (vesselData.PartSizeMultipliers.TryGetValue(protoPartSnapshot.persistentId, out double partSizeMultiplier))
            {
                double?tweakScaleExponent = TweaksSaleHelper.GetTweakScaleExponent(nameof(ModuleDeployableSolarPanel), "chargeRate");

                if (tweakScaleExponent != null)
                {
                    solarPanelData.ChargeRateMultiplier = Math.Pow(partSizeMultiplier, tweakScaleExponent.Value);
                }
            }

            for (int i = 0; i < moduleDeployableSolarPanels.Count; i++)
            {
                var moduleDeployableSolarPanel = moduleDeployableSolarPanels[i];
                var protoPartModuleSnapshot    = protoPartModuleSnapshots[i];

                moduleDeployableSolarPanel.deployState = (ModuleDeployablePart.DeployState)Enum.Parse(typeof(ModuleDeployablePart.DeployState), protoPartModuleSnapshot.moduleValues.GetValue(nameof(moduleDeployableSolarPanel.deployState)));
            }

            // store data
            vesselData.SolarPanels.Add(protoPartSnapshot.persistentId, solarPanelData);

            return(solarPanelData);
        }
Ejemplo n.º 2
0
        private static ModuleResourceConverterData LoadModuleResourceConverters(int partIndex, ProtoPartSnapshot protoPartSnapshot, VesselData vesselData, Part protoPart)
        {
            var moduleResourceConverter = protoPart?.FindModulesImplementing <ModuleResourceConverter>();

            if (moduleResourceConverter is null || moduleResourceConverter.Any() == false)
            {
                return(null);
            }

            List <int> protoPartModuleSnapshotIndexes = new List <int>();
            List <ProtoPartModuleSnapshot> protoPartModuleSnapshots = new List <ProtoPartModuleSnapshot>();

            for (int i = 0; i < protoPartSnapshot.modules.Count; i++)
            {
                ProtoPartModuleSnapshot protoPartModuleSnapshot = protoPartSnapshot.modules[i];

                if (protoPartModuleSnapshot.moduleName == nameof(ModuleResourceConverter))
                {
                    protoPartModuleSnapshotIndexes.Add(i);
                    protoPartModuleSnapshots.Add(protoPartModuleSnapshot);
                }
            }

            var resourceConverterData = new ModuleResourceConverterData
            {
                PartIndex                      = partIndex,
                ProtoPart                      = protoPart,
                ProtoPartSnapshot              = protoPartSnapshot,
                PersistentPartId               = protoPartSnapshot.persistentId,
                ModuleResourceConverters       = moduleResourceConverter,
                ProtoPartModuleSnapshotIndexes = protoPartModuleSnapshotIndexes
            };

            // calculate tweakScale multipliers
            if (vesselData.PartSizeMultipliers.TryGetValue(protoPartSnapshot.persistentId, out double partSizeMultiplier))
            {
                var tweakScaleExponents = TweaksSaleHelper.GetTweakScaleExponents(nameof(ModuleResourceConverter));

                if (tweakScaleExponents.Exponents.TryGetValue("inputList", out double inputExponent))
                {
                    resourceConverterData.InputMultiplier = Math.Pow(partSizeMultiplier, inputExponent);
                }

                if (tweakScaleExponents.Exponents.TryGetValue("outputList", out double outExponent))
                {
                    resourceConverterData.OutputMultiplier = Math.Pow(partSizeMultiplier, outExponent);
                }

                if (tweakScaleExponents.Exponents.TryGetValue("reqList", out double reqExponent))
                {
                    resourceConverterData.ReqMultiplier = Math.Pow(partSizeMultiplier, reqExponent);
                }
            }

            // readout persistent data
            for (int i = 0; i < moduleResourceConverter.Count; i++)
            {
                ModuleResourceConverter resourceConverter       = moduleResourceConverter[i];
                ProtoPartModuleSnapshot protoPartModuleSnapshot = protoPartModuleSnapshots[protoPartModuleSnapshotIndexes[i]];

                resourceConverter.IsActivated     = bool.Parse(protoPartModuleSnapshot.moduleValues.GetValue(nameof(resourceConverter.IsActivated)));
                resourceConverter.EfficiencyBonus = float.Parse(protoPartModuleSnapshot.moduleValues.GetValue(nameof(resourceConverter.EfficiencyBonus)));
            }

            vesselData.ResourceConverters.Add(protoPartSnapshot.persistentId, resourceConverterData);

            return(resourceConverterData);
        }
Ejemplo n.º 3
0
        private static ModuleGeneratorData LoadModuleGenerator(int partIndex, ProtoPartSnapshot protoPartSnapshot, VesselData vesselData, Part protoPart)
        {
            var moduleGenerators = protoPart?.FindModulesImplementing <ModuleGenerator>();

            if (moduleGenerators is null || moduleGenerators.Any() == false)
            {
                return(null);
            }

            List <int> protoPartModuleSnapshotIndexes = new List <int>();
            List <ProtoPartModuleSnapshot> protoPartModuleSnapshots = new List <ProtoPartModuleSnapshot>();

            for (int i = 0; i < protoPartSnapshot.modules.Count; i++)
            {
                ProtoPartModuleSnapshot protoPartModuleSnapshot = protoPartSnapshot.modules[i];

                if (protoPartModuleSnapshot.moduleName == nameof(ModuleGenerator))
                {
                    protoPartModuleSnapshotIndexes.Add(i);
                    protoPartModuleSnapshots.Add(protoPartModuleSnapshot);
                }
            }

            var moduleGeneratorData = new ModuleGeneratorData
            {
                PartIndex         = partIndex,
                ProtoPart         = protoPart,
                ProtoPartSnapshot = protoPartSnapshot,
                PersistentPartId  = protoPartSnapshot.persistentId,
                ProtoPartModuleSnapshotIndexes = protoPartModuleSnapshotIndexes,
                ModuleGenerators = moduleGenerators
            };

            // calculate tweakScale multiplier
            if (vesselData.PartSizeMultipliers.TryGetValue(protoPartSnapshot.persistentId, out double partSizeMultiplier))
            {
                var tweakScaleExponents = TweaksSaleHelper.GetTweakScaleExponents(nameof(ModuleGenerator));

                if (tweakScaleExponents.Exponents.TryGetValue("outputResources.rate", out double outputExponent))
                {
                    moduleGeneratorData.OutputMultiplier = Math.Pow(partSizeMultiplier, outputExponent);
                }

                if (tweakScaleExponents.Exponents.TryGetValue("inputResources.rate", out double inputExponent))
                {
                    moduleGeneratorData.InputMultiplier = Math.Pow(partSizeMultiplier, inputExponent);
                }
            }

            // readout persistent data
            for (int i = 0; i < moduleGenerators.Count; i++)
            {
                ModuleGenerator         moduleGenerator         = moduleGenerators[i];
                ProtoPartModuleSnapshot protoPartModuleSnapshot = protoPartModuleSnapshots[i];

                moduleGenerator.generatorIsActive = bool.Parse(protoPartModuleSnapshot.moduleValues.GetValue(nameof(moduleGenerator.generatorIsActive)));
                moduleGenerator.throttle          = float.Parse(protoPartModuleSnapshot.moduleValues.GetValue(nameof(moduleGenerator.throttle)));
            }

            vesselData.Generators.Add(protoPartSnapshot.persistentId, moduleGeneratorData);

            return(moduleGeneratorData);
        }