Exemplo n.º 1
0
 public override object GetSuffix(string suffixName)
 {
     switch (suffixName)
     {
         case "NAME":
             return Part.name;
         case "STAGE":
             return Part.inverseStage;
         case "UID":
             return Part.uid;
         case "RESOURCES":
             var resources = new ListValue();
             foreach (PartResource resource in Part.Resources)
             {
                 resources.Add(new ResourceValue(resource));
             }
             return resources;
         case "MODULES":
             var modules = new ListValue();
             foreach (var module in Part.Modules)
             {
                 modules.Add(module.GetType());
             }
             return modules;
         case "TARGETABLE":
             return Part.Modules.OfType<ITargetable>().Any();
         case "SHIP":
             return new VesselTarget(Part.vessel);
     }
     return base.GetSuffix(suffixName);
 }
Exemplo n.º 2
0
Arquivo: Addon.cs Projeto: CalebJ2/KOS
        private ListValue GetServoGroups()
        {
            var list = new ListValue();

            if (!IRWrapper.APIReady)
            {
                throw new KOSUnavailableAddonException("IR:GROUPS", "Infernal Robotics");
            }

            var controlGroups = IRWrapper.IRController.ServoGroups;

            if (controlGroups == null)
            {
                //Control Groups are somehow null, just return the empty list
                return list;
            }

            foreach (IRWrapper.IControlGroup cg in controlGroups)
            {
                if (cg.Vessel == null || cg.Vessel == shared.Vessel)
                    list.Add(new IRControlGroupWrapper(cg, shared));
            }

            return list;
        }
Exemplo n.º 3
0
Arquivo: Addon.cs Projeto: CalebJ2/KOS
        private ListValue GetAllServos()
        {
            var list = new ListValue();

            if (!IRWrapper.APIReady)
            {
                throw new KOSUnavailableAddonException("IR:ALLSERVOS", "Infernal Robotics");
            }

            var controlGroups = IRWrapper.IRController.ServoGroups;

            if (controlGroups == null)
            {
                //Control Groups are somehow null, just return the empty list
                return list;
            }

            foreach (IRWrapper.IControlGroup cg in controlGroups)
            {
                if (cg.Servos == null || (cg.Vessel!=null && cg.Vessel != shared.Vessel))
                    continue;

                foreach (IRWrapper.IServo s in cg.Servos)
                {
                    list.Add (new IRServoWrapper (s, shared));
                }
            }

            return list;
        }
Exemplo n.º 4
0
        public void CanSerializeLists()
        {
            var list = new ListValue();
            var nested = new ListValue();

            list.Add(new StringValue("item1"));
            list.Add(new ScalarIntValue(2));
            list.Add(nested);

            nested.Add(new StringValue("nested1"));

            ListValue deserialized = Deserialize(Serialize(list)) as ListValue;

            Assert.AreEqual(new StringValue("item1"), deserialized[0]);
            Assert.AreEqual(new ScalarIntValue(2), deserialized[1]);
            Assert.IsTrue(deserialized[2] is ListValue);
        }
        public void CanShallowPrintListInLexicon()
        {
            var list = new ListValue();
            list.Add("First In List");
            list.Add("Second In List");
            list.Add("Last In List");

            var lexicon = new Lexicon<object, object>();
            lexicon.Add("list", list);
            lexicon.Add("not list", 2);

            var result = lexicon.ToString();

            Assert.IsTrue(result.Contains("LEXICON of 2 items"));
            Assert.IsTrue(result.Contains("  [\"list\"]= LIST of 3 items"));
            Assert.IsFalse(result.Contains("Last In List"));
        }
Exemplo n.º 6
0
        public void CanGetCorrectListIndex()
        {
            var list = new ListValue();
            list.Add("bar");
            list.Add("foo");
            list.Add("fizz");
            cpu.PushStack(list);

            const int INDEX = 1;
            cpu.PushStack(INDEX);

            var opcode = new OpcodeGetIndex();

            opcode.Execute(cpu);

            Assert.AreEqual(3, list.Count);
            Assert.AreEqual("foo", cpu.PopStack());
        }
Exemplo n.º 7
0
        public void CanGetDoubleIndex()
        {
            var list = new ListValue();
            list.Add(new StringValue("bar"));
            list.Add(new StringValue("foo"));
            list.Add(new StringValue("fizz"));
            cpu.PushStack(list);

            const double INDEX = 2.5;
            cpu.PushStack(INDEX);

            var opcode = new OpcodeGetIndex();

            opcode.Execute(cpu);

            Assert.AreEqual(3, list.Count());
            Assert.AreEqual(new StringValue("fizz"), cpu.PopStack());
        }
Exemplo n.º 8
0
 public static ListValue PartsToList(IEnumerable<global::Part> parts)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         toReturn.Add(new PartValue(part));
     }
     return toReturn;
 }
Exemplo n.º 9
0
 private object BuildPatchList()
 {
     var list = new ListValue();
     var orbit = orbitRef;
     while (orbit.nextPatch != null && list.Count >= PATCHES_LIMIT)
     {
         list.Add(new OrbitInfo(orbit, vesselRef));
     }
     return list;
 }
Exemplo n.º 10
0
 public static new ListValue PartsToList(IEnumerable<global::Part> parts)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         foreach (PartModule module in part.Modules)
         {
             var engineModule = module as ModuleEngines;
             if (engineModule != null)
             {
                 toReturn.Add(new EngineValue(part, engineModule));
             }
             var engineModuleFx = module as ModuleEnginesFX;
             if (engineModuleFx != null)
             {
                 toReturn.Add(new EngineValue(part, engineModuleFx));
             }
         }
     }
     return toReturn;
 }
Exemplo n.º 11
0
 public static ListValue PartsToList(IEnumerable<global::Part> parts, SharedObjects sharedObj)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         foreach (PartModule module in part.Modules)
         {
             var sensor = module as ModuleEnviroSensor;
             if (sensor == null) continue;
             toReturn.Add(new SensorValue(part, sensor, sharedObj));
         }
     }
     return toReturn;
 }
Exemplo n.º 12
0
 public static ListValue PartsToList(IEnumerable<global::Part> parts, SharedObjects sharedObj)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         foreach (PartModule module in part.Modules)
         {
             var dockingNode = module as ModuleDockingNode;
             if (dockingNode != null)
             {
                 toReturn.Add(new DockingPortValue(dockingNode, sharedObj));
             }
         }
     }
     return toReturn;
 }
Exemplo n.º 13
0
 public static ListValue PartsToList(IEnumerable<global::Part> parts, SharedObjects sharedObj)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         foreach (PartModule module in part.Modules)
         {
             var engines = module as ModuleEngines;
             if (engines != null)
             {
                 toReturn.Add(new EngineValue(part, new ModuleEngineAdapter(engines), sharedObj));
             }
         }
     }
     return toReturn;
 }
Exemplo n.º 14
0
 public static new ListValue PartsToList(IEnumerable<global::Part> parts)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         foreach (PartModule module in part.Modules)
         {
             UnityEngine.Debug.Log("Module Found: "+ module);
             var dockingNode = module as ModuleDockingNode;
             if (dockingNode != null)
             {
                 toReturn.Add(new DockingPortValue(dockingNode));
             }
         }
     }
     return toReturn;
 }
Exemplo n.º 15
0
        private ListValue GetAlarms()
        {
            var list = new ListValue();

            if (!KACWrapper.APIReady)
            {
                return list;
            }

            //Get the list of alarms from the KAC Object
            KACWrapper.KACAPI.KACAlarmList alarms = KACWrapper.KAC.Alarms;

            foreach (KACWrapper.KACAPI.KACAlarm alarm in alarms)
            {
                list.Add(new KACAlarmWrapper(alarm));
            }
            return list;
        }
Exemplo n.º 16
0
        public void CanSetListIndex()
        {
            var list = new ListValue();
            list.Add(new StringValue("bar"));
            cpu.PushStack(list);

            const int INDEX = 0;
            cpu.PushStack(INDEX);

            const string VALUE = "foo";
            cpu.PushStack(VALUE);

            var opcode = new OpcodeSetIndex();

            opcode.Execute(cpu);

            Assert.AreEqual(1, list.Count());
            Assert.AreNotEqual(new StringValue("bar"), list[0]);
            Assert.AreEqual(new StringValue("foo"), list[0]);
        }
Exemplo n.º 17
0
        public void CanSetListIndexWithDouble()
        {
            var list = new ListValue();
            list.Add("bar");
            cpu.PushStack(list);

            const double INDEX = 0.0d;
            cpu.PushStack(INDEX);

            const string VALUE = "foo";
            cpu.PushStack(VALUE);
            
            var opcode = new OpcodeSetIndex();

            opcode.Execute(cpu);

            Assert.AreEqual(1, list.Count);
            Assert.AreNotEqual("bar", list[0]);
            Assert.AreEqual("foo", list[0]);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Return a list of all the strings of all KSPfields registered to this PartModule
        /// which are currently showing on the part's RMB menu, without formating.
        /// </summary>
        /// <returns>List of all the strings field names.</returns>
        protected virtual ListValue AllFieldNames()
        {
            var returnValue = new ListValue();

            IEnumerable<BaseField> visibleFields = partModule.Fields.Cast<BaseField>().Where(FieldIsVisible);

            foreach (BaseField field in visibleFields)
            {
                returnValue.Add(new StringValue(field.guiName.ToLower()));
            }
            return returnValue;
        }
Exemplo n.º 19
0
        private object BuildPatchList()
        {
            var list = new ListValue();
            var orb = orbit;
            while (true)
            {
                if (orb == null)
                {
                    break;
                }

                if (orb.nextPatch != null && !orb.nextPatch.activePatch)
                {
                    break;
                }

                list.Add(new OrbitInfo(orb, shared ));
                orb = orb.nextPatch;
            }
            return list;
        }
Exemplo n.º 20
0
        public void WillThrowOnNonIntListIndex()
        {
            var list = new ListValue();
            list.Add("bar");
            cpu.PushStack(list);

            const string INDEX = "fizz";
            cpu.PushStack(INDEX);

            const string VALUE = "foo";
            cpu.PushStack(VALUE);
            
            var opcode = new OpcodeSetIndex();

            opcode.Execute(cpu);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Return a list of all the KSPEvents the module has in it which are currently
        /// visible on the RMB menu.
        /// </summary>
        /// <returns></returns>
        private ListValue AllEvents(string formatter)
        {
            var returnValue = new ListValue();

            IEnumerable<BaseEvent> visibleEvents = partModule.Events.Where(EventIsVisible);

            foreach (BaseEvent kspEvent in visibleEvents)
            {
                returnValue.Add(new StringValue(string.Format(formatter,
                                              "callable",
                                              kspEvent.guiName.ToLower(),
                                              "KSPEvent")));
            }
            return returnValue;
        }
Exemplo n.º 22
0
        /// <summary>
        /// Return a list of all the KSPActions the module has in it.
        /// </summary>
        /// <returns></returns>
        private ListValue AllActions(string formatter)
        {
            var returnValue = new ListValue();

            foreach (BaseAction kspAction in partModule.Actions)
            {
                returnValue.Add(new StringValue(string.Format(formatter,
                                              "callable",
                                              kspAction.guiName.ToLower(),
                                              "KSPAction")));
            }
            return returnValue;
        }
Exemplo n.º 23
0
        public void CanGetListIndex()
        {
            var list = new ListValue();
            list.Add(new StringValue("bar"));
            cpu.PushStack(list);

            const int INDEX = 0;
            cpu.PushStack(INDEX);

            var opcode = new OpcodeGetIndex();

            opcode.Execute(cpu);

            Assert.AreEqual(1, list.Count());
            Assert.AreEqual(new StringValue("bar"), cpu.PopStack());
        }
Exemplo n.º 24
0
        /// <summary>
        /// Return a list of all the strings of all KSPfields registered to this PartModule
        /// which are currently showing on the part's RMB menu.
        /// </summary>
        /// <returns>List of all the strings field names.</returns>
        protected virtual ListValue AllFields(string formatter)
        {
            var returnValue = new ListValue();

            IEnumerable<BaseField> visibleFields = partModule.Fields.Cast<BaseField>().Where(FieldIsVisible);

            foreach (BaseField field in visibleFields)
            {
                returnValue.Add(new StringValue(string.Format(formatter,
                                              IsEditable(field) ? "settable" : "get-only",
                                              field.guiName.ToLower(),
                                              Utilities.Utils.KOSType(field.FieldInfo.FieldType))));
            }
            return returnValue;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Return a list of all the KSPActions the module has in it, without formatting.
        /// </summary>
        /// <returns>List of Action Names</returns>
        private ListValue AllActionNames()
        {
            var returnValue = new ListValue();

            foreach (BaseAction kspAction in partModule.Actions)
            {
                returnValue.Add(new StringValue(kspAction.guiName.ToLower()));
            }
            return returnValue;
        }
Exemplo n.º 26
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 "rcs":
            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;
        }
Exemplo n.º 27
0
        /// <summary>
        /// Return a list of all the KSPEvents the module has in it which are currently
        /// visible on the RMB menu, without formatting.
        /// </summary>
        /// <returns>List of Event Names</returns>
        private ListValue AllEventNames()
        {
            var returnValue = new ListValue();

            IEnumerable<BaseEvent> visibleEvents = partModule.Events.Where(EventIsVisible);

            foreach (BaseEvent kspEvent in visibleEvents)
            {
                returnValue.Add(new StringValue(kspEvent.guiName.ToLower()));
            }
            return returnValue;
        }
Exemplo n.º 28
0
        public ListValue GetAllModes()
        {
            var toReturn = new ListValue();
            if (MultiMode)
            {
                toReturn.Add(new StringValue(MMengine.primaryEngineID));
                toReturn.Add(new StringValue(MMengine.secondaryEngineID));
            }
            else
            {
                toReturn.Add(new StringValue("Single mode"));
            }

            return toReturn;
        }
Exemplo n.º 29
0
        /// <summary>
        /// Build a list of all the KSP things (fields, events, actions) that
        /// this class will support as a suffix on this instance.
        /// </summary>
        /// <returns>list of all the suffixes except the hardcoded ones in GetSuffix()</returns>
        private ListValue AllThings()
        {
            const string FORMATTER = "({0}) {1}, is {2}";
            var all = new ListValue();

            // We appear to have not implemented a concatenator or range add for
            // our ListValue type.  Thus the for-loops below:
            ListValue fields = AllFields(FORMATTER);
            ListValue events = AllEvents(FORMATTER);
            ListValue actions = AllActions(FORMATTER);
            foreach (Structure field in fields)
            {
                all.Add(field);
            }
            foreach (Structure kspevent in events)
            {
                all.Add(kspevent);
            }
            foreach (Structure action in actions)
            {
                all.Add(action);
            }
            return all;
        }
Exemplo n.º 30
0
 public static ListValue PartsToList(IEnumerable<global::Part> parts, SharedObjects sharedObj)
 {
     var toReturn = new ListValue();
     foreach (var part in parts)
     {
         var multiModeEngines = part.Modules.GetModules<MultiModeEngine>();
         if (multiModeEngines.Count > 0)
             toReturn.Add(new EngineValue(part, multiModeEngines.First(), sharedObj));
         else
         {
             var moduleEngines = part.Modules.GetModules<ModuleEngines>();
             if (moduleEngines.Count > 0)
                 toReturn.Add(new EngineValue(part, new ModuleEngineAdapter(moduleEngines.First()), sharedObj));
         }
     }
     return toReturn;
 }
Exemplo n.º 31
0
        /// <summary>
        /// Creates a complex example of a nested list of lists and other
        /// things, to use in some of the tests to prove complex example cases.
        /// Returns a list that looks like so:
        /// <pre>
        /// list {
        ///     100,
        ///     200,
        ///     list {
        ///         list {
        ///             "inner string 1",
        ///             2
        ///         },
        ///         "string,one.two",
        ///         "string,one.three"
        ///     },
        ///     list {
        ///         "string,two.one",
        ///         "string,two.two"
        ///     },
        ///     "String, outer value"
        /// }
        /// </pre>
        /// This should be sufficiently complex to work with for testing a variety of cases.
        /// 
        /// </summary>
        /// <returns>A list containing the description above</returns>
        private ListValue MakeNestedExample()
        {
            const string OUTER_STRING = "String, outer value";

            ListValue list = new ListValue();
            ListValue innerList1 = new ListValue();
            ListValue innerList2 = new ListValue();
            ListValue innerInnerList = new ListValue
            {
                new StringValue("inner string 1"),
                new ScalarIntValue(2)
            };

            innerList1.Add( innerInnerList );
            innerList1.Add( new StringValue("string,one.two") );
            innerList1.Add( new StringValue("string,one.three") );

            innerList2.Add( new StringValue("string,two.one") );
            innerList2.Add( new StringValue("string,two.two") );

            InvokeDelegate(list,"ADD", new ScalarIntValue(100));
            InvokeDelegate(list,"ADD", new ScalarIntValue(200));
            InvokeDelegate(list,"ADD", innerList1);
            InvokeDelegate(list,"ADD", innerList2);
            InvokeDelegate(list,"ADD", OUTER_STRING);

            return list;
        }
Exemplo n.º 32
0
        public static IDataValue NativeValueToDataValue(ServerProcess process, NativeValue nativeValue)
        {
            NativeScalarValue nativeScalar = nativeValue as NativeScalarValue;

            if (nativeScalar != null)
            {
                return(new Scalar(process.ValueManager, (IScalarType)NativeTypeNameToDataType(process.DataTypes, nativeScalar.DataTypeName), nativeScalar.Value));
            }

            NativeListValue nativeList = nativeValue as NativeListValue;

            if (nativeList != null)
            {
                // Create and fill the list
                ListValue list = new ListValue(process.ValueManager, (ListType)NativeValueToDataType(process, nativeValue), nativeList.Elements == null ? null : new NativeList());
                if (nativeList.Elements != null && nativeList.Elements.Length > 0)
                {
                    for (int index = 0; index < nativeList.Elements.Length; index++)
                    {
                        list.Add(NativeValueToDataValue(process, nativeList.Elements[index]));
                    }
                }

                return(list);
            }

            NativeRowValue nativeRow = nativeValue as NativeRowValue;

            if (nativeRow != null)
            {
                Row row = new Row(process.ValueManager, new Schema.RowType(NativeColumnsToColumns(process.DataTypes, nativeRow.Columns)));
                if (nativeRow.Values == null)
                {
                    row.AsNative = null;
                }
                else
                {
                    for (int index = 0; index < nativeRow.Values.Length; index++)
                    {
                        row[index] = NativeValueToDataValue(process, nativeRow.Values[index]);
                    }
                }
                return(row);
            }

            NativeTableValue nativeTable = nativeValue as NativeTableValue;

            if (nativeTable != null)
            {
                NativeTable internalTable = new NativeTable(process.ValueManager, NativeTableToTableVar(process, nativeTable));
                TableValue  table         = new TableValue(process.ValueManager, internalTable.TableType, internalTable);
                if (nativeTable.Rows == null)
                {
                    table.AsNative = null;
                }
                else
                {
                    bool[] valueTypes = new bool[internalTable.TableType.Columns.Count];
                    for (int index = 0; index < internalTable.TableType.Columns.Count; index++)
                    {
                        valueTypes[index] = internalTable.TableType.Columns[index].DataType is IScalarType;
                    }

                    for (int index = 0; index < nativeTable.Rows.Length; index++)
                    {
                        Row row = new Row(process.ValueManager, internalTable.RowType);
                        try
                        {
                            for (int columnIndex = 0; columnIndex < nativeTable.Rows[index].Length; columnIndex++)
                            {
                                if (valueTypes[columnIndex])
                                {
                                    row[columnIndex] = nativeTable.Rows[index][columnIndex];
                                }
                                else
                                {
                                    row[columnIndex] = NativeValueToDataValue(process, (NativeValue)nativeTable.Rows[index][columnIndex]);
                                }
                            }

                            internalTable.Insert(process.ValueManager, row);
                        }
                        catch (Exception)
                        {
                            row.Dispose();
                            throw;
                        }
                    }
                }
                return(table);
            }

            throw new NotSupportedException(String.Format("Unknown native value type: \"{0}\".", nativeValue.GetType().Name));
        }