コード例 #1
0
        public override void Execute(SharedObjects shared)
        {
            object processorTagOrVolume = PopValueAssert(shared, true);

            AssertArgBottomAndConsume(shared);

            kOSProcessor processor;

            if (processorTagOrVolume is Volume)
            {
                processor = shared.ProcessorMgr.GetProcessor(processorTagOrVolume as Volume);
            }
            else if (processorTagOrVolume is string || processorTagOrVolume is StringValue)
            {
                processor = shared.ProcessorMgr.GetProcessor(processorTagOrVolume.ToString());
            }
            else
            {
                throw new KOSInvalidArgumentException("processor", "processorId", "String or Volume expected");
            }

            if (processor == null)
            {
                throw new KOSInvalidArgumentException("processor", "processorId", "Processor with that volume or name was not found");
            }

            ReturnValue = PartModuleFieldsFactory.Construct(processor, shared);
        }
コード例 #2
0
        public ListValue GetModulesNamed(StringValue modName)
        {
            List <PartModule> result = new List <PartModule>();

            StaticFindModulesInBranch(this.Part, m => String.Equals(m.moduleName, modName, StringComparison.CurrentCultureIgnoreCase), result);
            return(PartModuleFieldsFactory.Construct(result, Shared));
        }
コード例 #3
0
 private PartModuleFields GetModuleIndex(ScalarValue moduleIndex)
 {
     if (moduleIndex < Part.Modules.Count)
     {
         return(PartModuleFieldsFactory.Construct(Part.Modules.GetModule(moduleIndex), Shared));
     }
     throw new KOSLookupFailException("module", string.Format("MODULEINDEX[{0}]", moduleIndex), this);
 }
コード例 #4
0
        private ListValue GetModulesNamed(StringValue modName)
        {
            // This is slow - maybe there should be a faster lookup string hash, but
            // KSP's data model seems to have not implemented it:
            IEnumerable <PartModule> modules = Vessel.parts
                                               .SelectMany(p => p.Modules.Cast <PartModule>()
                                                           .Where(pMod => String.Equals(pMod.moduleName, modName, StringComparison.CurrentCultureIgnoreCase)));

            return(PartModuleFieldsFactory.Construct(modules, Shared));
        }
コード例 #5
0
 private PartModuleFields GetModule(StringValue modName)
 {
     foreach (PartModule mod in Part.Modules)
     {
         if (string.Equals(mod.moduleName, modName, StringComparison.OrdinalIgnoreCase))
         {
             return(PartModuleFieldsFactory.Construct(mod, Shared));
         }
     }
     throw new KOSLookupFailException("module", modName.ToUpper(), this);
 }
コード例 #6
0
ファイル: PartValue.cs プロジェクト: victorb/KOS
 private PartModuleFields GetModule(string modName)
 {
     foreach (PartModule mod in Part.Modules)
     {
         Debug.Log("Does \"" + mod.moduleName.ToUpper() + "\" == \"" + modName.ToUpper() + "\"?");
         if (String.Equals(mod.moduleName, modName, StringComparison.CurrentCultureIgnoreCase))
         {
             Debug.Log("yes it does");
             return(PartModuleFieldsFactory.Construct(mod, shared));
         }
     }
     throw new KOSLookupFailException("module", modName.ToUpper(), this);
 }
コード例 #7
0
        private ListValue GetModulesInGroup(StringValue groupName)
        {
            var    matchGroup = KSPActionGroup.None;
            string upperName  = groupName.ToUpper();

            // TODO: later refactor:  put this in a Dictionary lookup instead, and then share it
            // by both this code and the code in ActionGroup.cs:
            if (upperName == "SAS")
            {
                matchGroup = KSPActionGroup.SAS;
            }
            if (upperName == "GEAR")
            {
                matchGroup = KSPActionGroup.Gear;
            }
            if (upperName == "LIGHTS")
            {
                matchGroup = KSPActionGroup.Light;
            }
            if (upperName == "BRAKES")
            {
                matchGroup = KSPActionGroup.Brakes;
            }
            if (upperName == "RCS")
            {
                matchGroup = KSPActionGroup.RCS;
            }
            if (upperName == "ABORT")
            {
                matchGroup = KSPActionGroup.Abort;
            }
            if (upperName == "AG1")
            {
                matchGroup = KSPActionGroup.Custom01;
            }
            if (upperName == "AG2")
            {
                matchGroup = KSPActionGroup.Custom02;
            }
            if (upperName == "AG3")
            {
                matchGroup = KSPActionGroup.Custom03;
            }
            if (upperName == "AG4")
            {
                matchGroup = KSPActionGroup.Custom04;
            }
            if (upperName == "AG5")
            {
                matchGroup = KSPActionGroup.Custom05;
            }
            if (upperName == "AG6")
            {
                matchGroup = KSPActionGroup.Custom06;
            }
            if (upperName == "AG7")
            {
                matchGroup = KSPActionGroup.Custom07;
            }
            if (upperName == "AG8")
            {
                matchGroup = KSPActionGroup.Custom08;
            }
            if (upperName == "AG9")
            {
                matchGroup = KSPActionGroup.Custom09;
            }
            if (upperName == "AG10")
            {
                matchGroup = KSPActionGroup.Custom10;
            }

            ListValue kScriptParts = new ListValue();

            // This is almost identical to the logic in GetPartsInGroup and it might be a nice idea
            // later to merge them somehow:
            //
            if (matchGroup == KSPActionGroup.None)
            {
                return(kScriptParts);
            }

            foreach (global::Part p in Vessel.parts)
            {
                foreach (PartModule pm in p.Modules)
                {
                    if (pm.Actions.Any(a => a.actionGroup.Equals(matchGroup)))
                    {
                        kScriptParts.Add(PartModuleFieldsFactory.Construct(pm, Shared));
                    }
                }
            }

            return(kScriptParts);
        }
コード例 #8
0
        public override void Execute(SharedObjects shared)
        {
            string listType = PopValueAssert(shared).ToString();
            var    list     = new ListValue();

            switch (listType)
            {
            case "bodies":
                foreach (CelestialBody cBody in FlightGlobals.fetch.bodies)
                {
                    list.Add(BodyTarget.CreateOrGetExisting(cBody, shared));
                }
                break;

            case "targets":
                foreach (var vessel in FlightGlobals.Vessels)
                {
                    if (vessel == shared.Vessel)
                    {
                        continue;
                    }
                    list.Add(VesselTarget.CreateOrGetExisting(vessel, shared));
                }
                break;

            case "resources":
            case "parts":
            case "engines":
            case "sensors":
            case "elements":
            case "dockingports":
                list = shared.Vessel.PartList(listType, shared);
                break;

            case "files":
                list = ListValue.CreateList(shared.VolumeMgr.CurrentDirectory.ListAsLexicon().Values.ToList());
                break;

            case "volumes":
                list = ListValue.CreateList(shared.VolumeMgr.Volumes.Values.ToList());
                break;

            case "processors":
                list = ListValue.CreateList(shared.ProcessorMgr.processors.Values.ToList().Select(processor => PartModuleFieldsFactory.Construct(processor, shared)));
                break;

            case "fonts":
                foreach (Font f in Resources.FindObjectsOfTypeAll <Font>())
                {
                    list.Add(new StringValue(f.name));
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            AssertArgBottomAndConsume(shared);

            ReturnValue = list;
        }