Exemplo n.º 1
0
        private bool IsPartMatchesPrefab(KSPe.ConfigNodeWithSteroids node)
        {
            float prefabDefaultScale  = this.scaler.prefab.Modules.GetModule <TweakScale>(0).defaultScale;
            float currentDefaultScale = node.GetValue <float>("defaultScale", prefabDefaultScale);

            return(Math.Abs(prefabDefaultScale - currentDefaultScale) < 0.001f);
        }
 private static void LoadConfig(KSPe.IO.ReadableConfigNode configNode)
 {
     KSPe.ConfigNodeWithSteroids settings = KSPe.ConfigNodeWithSteroids.from(configNode.Node);
     GlobalRange      = settings.GetValue <int>("GlobalRange", GlobalRange);
     CamFixMultiplier = settings.GetValue <float>("CamFixMultiplier", CamFixMultiplier);
     ModEnabled       = settings.GetValue <bool>("ModEnabled", ModEnabled);
 }
        private static void LoadConstants(KSPe.ConfigNodeWithSteroids config)
        {
            reinforceAttachNodes             = config.GetValue <bool>("reinforceAttachNodes", reinforceAttachNodes);
            multiPartAttachNodeReinforcement = config.GetValue <bool>("multiPartAttachNodeReinforcement", multiPartAttachNodeReinforcement);
            reinforceDecouplersFurther       = config.GetValue <bool>("reinforceDecouplersFurther", reinforceDecouplersFurther);
            reinforceLaunchClampsFurther     = config.GetValue <bool>("reinforceLaunchClampsFurther", reinforceLaunchClampsFurther);
            useVolumeNotArea = config.GetValue <bool>("useVolumeNotArea", useVolumeNotArea);

            angularDriveSpring    = config.GetValue <float>("angularDriveSpring", angularDriveSpring);
            angularDriveDamper    = config.GetValue <float>("angularDriveDamper", angularDriveDamper);
            angularMaxForceFactor = config.GetValue <float>("angularMaxForceFactor", angularMaxForceFactor);
            if (angularMaxForceFactor < 0)
            {
                angularMaxForceFactor = float.MaxValue;
            }

            breakForceMultiplier  = config.GetValue <float>("breakForceMultiplier", breakForceMultiplier);
            breakTorqueMultiplier = config.GetValue <float>("breakTorqueMultiplier", breakTorqueMultiplier);

            breakStrengthPerArea = config.GetValue <float>("breakStrengthPerArea", breakStrengthPerArea);
            breakTorquePerMOI    = config.GetValue <float>("breakTorquePerMOI", breakTorquePerMOI);

            decouplerAndClampJointStrength = config.GetValue <float>("decouplerAndClampJointStrength", decouplerAndClampJointStrength);
            if (decouplerAndClampJointStrength < 0)
            {
                decouplerAndClampJointStrength = float.PositiveInfinity;
            }

            stiffeningExtensionMassRatioThreshold = config.GetValue <float>("stiffeningExtensionMassRatioThreshold", stiffeningExtensionMassRatioThreshold);

            massForAdjustment = config.GetValue <float>("massForAdjustment", massForAdjustment);

            foreach (ConfigNode c in config.GetNodes("Exempt"))
            {
                KSPe.ConfigNodeWithSteroids node = KSPe.ConfigNodeWithSteroids.from(c);

                if (node.HasValue("PartType"))
                {
                    exemptPartTypes.Add(node.GetValue <string>("PartType"));
                }

                if (node.HasValue("ModuleType"))
                {
                    exemptModuleTypes.Add(node.GetValue <string>("ModuleType"));
                }

                if (node.HasValue("DecouplerStiffeningExtensionType"))
                {
                    decouplerStiffeningExtensionType.Add(node.GetValue <string>("DecouplerStiffeningExtensionType"));
                }
            }
            ;

            debug = config.GetValue <bool>("debug", debug);
        }
Exemplo n.º 4
0
        // ConfigNodeWithSteroids is not complete yet, lots of work to do!
        // So I had to give the source node to be fixed together the fancy one with some nice helpers,
        // as it currently doesn't updates the node used to create it (by design, the idea is to create an
        // "commit" command - so exception handling would be made easier.
        private ConfigNode FixPartScaling(ConfigNode source, KSPe.ConfigNodeWithSteroids node)
        {
            float prefabDefaultScale = this.scaler.prefab.Modules.GetModule <TweakScale>(0).defaultScale;
            float craftDefaultScale  = node.GetValue <float>("defaultScale", prefabDefaultScale);
            float craftScale         = node.GetValue <float>("currentScale", prefabDefaultScale);
            float craftRelativeScale = craftScale / craftDefaultScale;
            float newCurrentScale    = prefabDefaultScale * craftRelativeScale;

            source.SetValue("currentScale", newCurrentScale);
            source.SetValue("defaultScale", prefabDefaultScale);

            Log.warn("Invalid defaultScale! Craft {0} had the part {1} defaultScale changed from {2:F3} to {3:F3} and was rescaled to {4:F3}"
                     , this.scaler.part.craftID, this.InstanceID
                     , craftDefaultScale, prefabDefaultScale, newCurrentScale
                     );
            return(source);
        }
Exemplo n.º 5
0
        public override void OnLoad(ConfigNode node)
        {
            Log.dbg("OnLoad {0}", this.InstanceID);

            base.OnLoad(node);

            if (null == part.partInfo)
            {
                // Loading of the prefab from the part config
                this.SetupPrefab(part);
            }
            else
            {
                this.Setup(part);

                // Loading of the part from a saved craft
                tweakScale = currentScale;
                if (HighLogic.LoadedSceneIsEditor)
                {
                    // That's the problem - somewhere in the not so near past, KSP implemented a stunt called
                    // UpgradePipeline. This thing acts after the PartModule's OnLoad handler, and it injects
                    // back default values from prefab into the part on loading. This was intended to allow older
                    // savegames to be loaded on newer KSP (as it would inject default values on missing atributes
                    // present only on the new KSP version - or to reset new defaults when things changed internally),
                    // but also ended up trashing changes and atributes only available on runtime for some custom modules.
                    // So we need to check and upgrade things **before** KSP mangles them, otherwise the old values will
                    // be trashed by KSP and we will not be able to detect and fix the old data ourselves.
                    {   // Act only on craft loadings from file.
                        KSPe.ConfigNodeWithSteroids cn = KSPe.ConfigNodeWithSteroids.from(node);
                        if (!this.IsPartMatchesPrefab(cn))
                        {
                            this.FixPartScaling(node, cn);
                        }
                    }
                }
                this.RestoreScaleIfNeededAndUpdate();
                this.enabled = this.active && this.IsScaled;
            }
        }
        public static void LoadSettings()
        {
            Log.info("NavUtil: Loading Settings");
            if (SETTINGS.IsLoadable)
            {
                SETTINGS.Load();
            }

            KSPe.ConfigNodeWithSteroids settings = SETTINGS.NodeWithSteroids;
            GlobalVariables.Settings.hsiGUIscale        = settings.GetValue <float>("guiScale", 0.5f);
            GlobalVariables.Settings.enableFineLoc      = settings.GetValue <bool>("enableFineLoc", true);
            GlobalVariables.Settings.enableWindowsInIVA = settings.GetValue <bool>("enableWindowsInIVA", true);
            GlobalVariables.Settings.loadCustom_rwyCFG  = settings.GetValue <bool>("loadCustom_rwyCFG", true);
            GlobalVariables.Settings.useBlizzy78ToolBar = settings.GetValue <bool>("useBlizzy78ToolBar", false);
            GlobalVariables.Settings.hsiPosition.x      = settings.GetValue <float>("hsiPositionX", 220f);
            GlobalVariables.Settings.hsiPosition.y      = settings.GetValue <float>("hsiPositionY", 500f);
            //GlobalVariables.Settings.hsiPosition.width = settings.GetValue<float>("hsiPositionWidth",???f);
            //GlobalVariables.Settings.hsiPosition.height = settings.GetValue<float>("hsiPositionHeight", ???f);
            GlobalVariables.Settings.rwyEditorGUI.x = settings.GetValue <float>("rwyEditorGUIX", 387f);
            GlobalVariables.Settings.rwyEditorGUI.y = settings.GetValue <float>("rwyEditorGUIY", 132f);
            //GlobalVariables.Settings.rwyEditorGUI.width = settings.GetValue<float>("rwyEditorGUIWidth", ???f);
            //GlobalVariables.Settings.rwyEditorGUI.height = settings.GetValue<float>("rwyEditorGUIHeight", ???f);
            GlobalVariables.Settings.settingsGUI.x       = settings.GetValue <float>("settingsGUIX", 75f);
            GlobalVariables.Settings.settingsGUI.y       = settings.GetValue <float>("settingsGUIY", 75f);
            GlobalVariables.Settings.hideNavBallWaypoint = settings.GetValue <bool>("hideNavBallWaypoint", false);
            //GlobalVariables.Settings.settingsGUI.width = settings.GetValue<float>("settingsGUIWidth", ???f);
            //GlobalVariables.Settings.settingsGUI.height = settings.GetValue<float>("settingsGUIHeight", ???f);
            {
#if DEBUG
                bool debugMode = settings.GetValue <bool>("debug", true);
#else
                bool debugMode = settings.GetValue <bool>("debug", false);
#endif
                Log.debuglevel = debugMode ? 5 : 3;
            }
        }