示例#1
0
        private static void RegisterGenericRescalable(Type resc, Type arg)
        {
            var c = resc.GetConstructor(new[] { arg });

            if (c != null)
            {
                Func <PartModule, IRescalable> creator = (PartModule pm) => (IRescalable)c.Invoke(new[] { pm });

                TweakScaleUpdater.RegisterUpdater(arg, creator);
            }
        }
示例#2
0
        private static void RegisterGenericRescalable(Type resc, Type arg)
        {
            ConstructorInfo c = resc.GetConstructor(new[] { arg });

            if (c == null)
            {
                return;
            }
            Func <PartModule, IRescalable> creator = pm => (IRescalable)c.Invoke(new object[] { pm });

            TweakScaleUpdater.RegisterUpdater(arg, creator);
        }
示例#3
0
        /// <summary>
        /// Sets up values from ScaleType, creates updaters, and sets up initial values.
        /// </summary>
        protected virtual void Setup()
        {
            if (part.partInfo == null)
            {
                return;
            }

            if (_setupRun)
            {
                return;
            }

            _prefabPart = PartLoader.getPartInfoByName(part.partInfo.name).partPrefab;

            _updaters = TweakScaleUpdater.CreateUpdaters(part).ToArray();

            var doUpdate = currentScale < 0f;

            SetupFromConfig(ScaleType = new ScaleType(ModuleNode));

            if (doUpdate)
            {
                tweakScale = currentScale = defaultScale;
                DryCost    = (float)(part.partInfo.cost - _prefabPart.Resources.Cast <PartResource>().Aggregate(0.0, (a, b) => a + b.maxAmount * b.info.unitCost));
                if (DryCost < 0)
                {
                    DryCost = 0;
                }
            }

            if (!isFreeScale && ScaleFactors.Length != 0)
            {
                tweakName  = Tools.ClosestIndex(tweakScale, ScaleFactors);
                tweakScale = ScaleFactors[tweakName];
            }
            if (!doUpdate && IsRescaled())
            {
                UpdateByWidth(false, true);
                try
                {
                    CallUpdaters();
                }
                catch (Exception exception)
                {
                    Tools.LogWf("Exception on Rescale: {0}", exception);
                    _setupRun = true;
                }
            }
            _setupRun = true;
        }
示例#4
0
        /// <summary>
        /// Sets up values from ScaleType, creates updaters, and sets up initial values.
        /// </summary>
        protected virtual void Setup()
        {
            if (_setupRun)
            {
                return;
            }
            _prefabPart = part.partInfo.partPrefab;
            _updaters   = TweakScaleUpdater.CreateUpdaters(part).ToArray();

            ScaleType = (_prefabPart.Modules["TweakScale"] as TweakScale).ScaleType;
            SetupFromConfig(ScaleType);

            if (!isFreeScale && ScaleFactors.Length != 0)
            {
                tweakName  = Tools.ClosestIndex(tweakScale, ScaleFactors);
                tweakScale = ScaleFactors[tweakName];
            }

            if (IsRescaled)
            {
                ScalePart(false, true);
                try
                {
                    CallUpdaters();
                }
                catch (Exception exception)
                {
                    Tools.LogWf("Exception on Rescale: {0}", exception);
                }
            }
            else
            {
                DryCost = (float)(part.partInfo.cost - _prefabPart.Resources.Cast <PartResource>().Aggregate(0.0, (a, b) => a + b.maxAmount * b.info.unitCost));
                if (part.Modules.Contains("FSfuelSwitch"))
                {
                    ignoreResourcesForCost = true;
                }

                if (DryCost < 0)
                {
                    Debug.LogError("TweakScale: part=" + part.name + ", DryCost=" + DryCost.ToString());
                    DryCost = 0;
                }
            }
            _setupRun = true;
        }
示例#5
0
        /// <summary>
        /// Sets up values from config, creates updaters, and sets up initial values.
        /// </summary>
        protected virtual void Setup()
        {
            if (part.partInfo == null)
            {
                return;
            }

            prefabPart = PartLoader.getPartInfoByName(part.partInfo.name).partPrefab;

            updaters = TweakScaleUpdater.createUpdaters(part).ToArray();

            SetupFromConfig(config = new ScaleConfig(moduleNode));


            var doUpdate = currentScale < 0f;

            if (doUpdate)
            {
                tweakScale = currentScale = defaultScale;
                dryCost    = (float)(part.partInfo.cost - prefabPart.Resources.Cast <PartResource>().Aggregate(0.0, (a, b) => a + b.maxAmount * b.info.unitCost));
                if (dryCost < 0)
                {
                    dryCost = 0;
                }
            }

            if (!isFreeScale && scaleFactors.Length != 0)
            {
                tweakName  = Tools.ClosestIndex(tweakScale, scaleFactors);
                tweakScale = scaleFactors[tweakName];
            }

            if (!doUpdate)
            {
                updateByWidth(false);
                foreach (var updater in updaters)
                {
                    updater.OnRescale(scalingFactor);
                }
            }
        }
示例#6
0
        protected virtual void Setup(Part part)
        {
            Log.dbg("Setup {0}", this.InstanceID);

            {
                Part prefab = part.partInfo.partPrefab;
                ScaleType = (prefab.Modules["TweakScale"] as TweakScale).ScaleType;
                SetupFromConfig(ScaleType);
                this.scaler = PartDB.Scaler.Create(prefab, part, ScaleType, this);                     // This need to be reworked. I calling this twice. :(

                part.OnEditorAttach        += OnEditorAttach;
                this.wasOnEditorAttachAdded = true;
            }

            _updaters = TweakScaleUpdater.CreateUpdaters(part).ToArray();
            this.SetupCrewManifest();

            if (!isFreeScale && ScaleFactors.Length != 0)
            {
                tweakName  = Tools.ClosestIndex(tweakScale, ScaleFactors);
                tweakScale = ScaleFactors[tweakName];
            }
        }