예제 #1
0
파일: kOSProcessor.cs 프로젝트: EbbiDos/KOS
        public void Update()
        {
            if (bootFileChoice != bootFileChoiceLast)
            {
                var temp = new Archive();
                var files = temp.GetFileList();
                var maxchoice = 0;
                for (var i = 0; i < files.Count; ++i)
                {
                    if (!files[i].Name.StartsWith("boot",StringComparison.InvariantCultureIgnoreCase)) continue;
                    maxchoice++;
                    if (bootFileChoiceLast < 0)
                    {
                        // find previous
                        if (files[i].Name == bootFile) {
                            bootFileChoice = i;
                            bootFileChoiceLast = i;
                        }
                    }
                    if (i == bootFileChoice) {
                        bootFile = files[i].Name;
                   }
                }
                var field = Fields["bootFileChoice"];
                if (field != null)
                {
                    field.guiName = bootFile;
                    var ui = field.uiControlEditor as UI_FloatRange;
                        if (ui != null) {
                            ui.maxValue = maxchoice;
                            ui.controlEnabled = maxchoice > 0;
                            field.guiActiveEditor = maxchoice > 0;
                            bootFileChoiceLast = bootFileChoice;
                        }
                }
            }

            if (shared == null) return;

            if (part.State == PartStates.DEAD)
            {
                Mode = Modes.OFF;
                return;
            }

            if (shared != null && shared.Vessel != vessel)
            {
                shared.Vessel = vessel;
            }

            if (Mode == Modes.READY)
            {
                if (shared.UpdateHandler != null) shared.UpdateHandler.UpdateObservers(Time.deltaTime);
                UpdateParts();
            }

            ProcessElectricity(part, TimeWarp.fixedDeltaTime);
        }
예제 #2
0
파일: kOSProcessor.cs 프로젝트: WazWaz/KOS
        public void Update()
        {
            if (bootFileChoice != bootFileChoiceLast)
            {
                var temp = new Archive();
                var files = temp.GetFileList();
                var maxchoice = 0;
                for (var i = 0; i < files.Count; ++i)
                {
                    if (!files[i].Name.StartsWith("boot",StringComparison.InvariantCultureIgnoreCase)) continue;
                    maxchoice++;
                    if (bootFileChoiceLast < 0)
                    {
                        // find previous
                        if (files[i].Name == bootFile) {
                            bootFileChoice = i;
                            bootFileChoiceLast = i;
                        }
                    }
                    if (i == bootFileChoice) {
                        bootFile = files[i].Name;
                   }
                }
                var field = Fields["bootFileChoice"];
                if (field != null)
                {
                    field.guiName = bootFile;
                    var ui = field.uiControlEditor as UI_FloatRange;
                        if (ui != null) {
                            ui.maxValue = maxchoice;
                            ui.controlEnabled = maxchoice > 0;
                            field.guiActiveEditor = maxchoice > 0;
                            bootFileChoiceLast = bootFileChoice;
                        }
                }
            }

            double cr;
            if (vessel == null)
            {
                // Vessel not available in Editor.
                var parts = new List<Part>();
                parts.AddRange(part.localRoot.FindChildParts<Part>(true));
                cr = VesselUtils.GetCommRange(parts);
            } else {
                cr = VesselUtils.GetCommRange(vessel);
            }

            commRange = Math.Round(cr / 1000) + "km";

            if (vessel == null)
            {
                // In edtior, give more useful value.
                var bestdistance = 0.0;
                var kerbin = FlightGlobals.getMainBody();
                foreach (var body in FlightGlobals.Bodies)
                {
                    if (body.name == "Sun")
                        continue;
                    if (body.referenceBody != kerbin.referenceBody && body.referenceBody != kerbin)
                        continue;
                    var maxdistance = body.orbit.semiMajorAxis;
                    if (body.referenceBody != kerbin)
                        maxdistance += kerbin.orbit.semiMajorAxis;
                    if (maxdistance > bestdistance && maxdistance < cr)
                    {
                        bestdistance = maxdistance;
                        commRange = body.name;
                    }
                }
            }

            if (shared == null) return;

            if (part.State == PartStates.DEAD)
            {
                Mode = Modes.OFF;
                return;
            }

            if (shared != null && shared.Vessel != vessel)
            {
                shared.Vessel = vessel;
            }

            if (Mode == Modes.READY)
            {
                if (shared.UpdateHandler != null) shared.UpdateHandler.UpdateObservers(Time.deltaTime);
                UpdateParts();
            }

            ProcessElectricity(part, TimeWarp.fixedDeltaTime);
        }