public override void Execute(SharedObjects shared) { double argument = GetDouble(PopValueAssert(shared)); AssertArgBottomAndConsume(shared); string result = new string((char) argument, 1); ReturnValue = new StringValue(result); }
public void CanPreserveCase() { var testValue = "FooBar"; var sv = new StringValue(testValue); Assert.AreEqual(testValue, sv.ToString()); }
public void CanToString() { var testValue = "foobar"; var sv = new StringValue(testValue); Assert.AreEqual(testValue, sv.ToString()); }
public BooleanValue CheckAddonAvailable(StringValue value) { if (!string.IsNullOrEmpty(value) && shared.AddonManager.AllAddons.ContainsKey(value)) { return shared.AddonManager.AllAddons[value].Available(); } return BooleanValue.False; }
public BooleanValue CheckHasAddon(StringValue value) { if (!string.IsNullOrEmpty(value) && shared.AddonManager.AllAddons.ContainsKey(value)) { return BooleanValue.True; } return BooleanValue.False; }
public void CanAddAsString() { bool b = true; string string1 = "foo"; var str1 = new StringValue(string1); var bv = new BooleanValue(b); var strResult = str1 + bv; string stringResult = string1 + b.ToString(); Assert.AreEqual(stringResult, (string)strResult); }
public void CanGetIndex() { var testValue = "FooBarFooBar"; var findChar = 0; var expectedIndex = new StringValue("F"); var sv = new StringValue(testValue); //Case Sensitive Assert.AreEqual(expectedIndex, sv.GetIndex(0)); }
public void CanAddAsString() { double d1 = 10.5; string string1 = "foo"; var str1 = new StringValue(string1); var s1 = ScalarValue.Create(d1); var strResult = str1 + s1; string stringResult = string1 + d1.ToString(); Assert.AreEqual(stringResult, (string)strResult); }
public override void Execute(SharedObjects shared) { string alarmNotes = PopValueAssert(shared).ToString(); string alarmName = PopValueAssert(shared).ToString(); double alarmUT = GetDouble(PopValueAssert(shared)); string alarmType = PopValueAssert(shared).ToString(); //alarm type is read-only, you cannot change it afterwards AssertArgBottomAndConsume(shared); if (KACWrapper.APIReady) { KACWrapper.KACAPI.AlarmTypeEnum newAlarmType; try { newAlarmType = (KACWrapper.KACAPI.AlarmTypeEnum)Enum.Parse(typeof(KACWrapper.KACAPI.AlarmTypeEnum), alarmType); } catch (ArgumentException) { SafeHouse.Logger.LogWarning(string.Format("Failed parsing {0} into KACAPI.AlarmTypeEnum", alarmType)); //failed parsing alarmType, defaulting to Raw newAlarmType = KACWrapper.KACAPI.AlarmTypeEnum.Raw; } string alarmId = KACWrapper.KAC.CreateAlarm(newAlarmType, alarmName, alarmUT); SafeHouse.Logger.Log(string.Format("Trying to create KAC Alarm, UT={0}, Name={1}, Type= {2}", alarmUT, alarmName, alarmType)); if (!string.IsNullOrEmpty(alarmId)) { //if the alarm was made get the object so we can update it KACWrapper.KACAPI.KACAlarm alarm = KACWrapper.KAC.Alarms.First(z => z.ID == alarmId); //Now update some of the other properties alarm.Notes = alarmNotes; alarm.AlarmAction = KACWrapper.KACAPI.AlarmActionEnum.PauseGame; alarm.VesselID = shared.Vessel.id.ToString(); var result = new KACAlarmWrapper(alarm); ReturnValue = result; } else { ReturnValue = new StringValue(string.Empty); SafeHouse.Logger.Log(string.Format("Failed creating KAC Alarm, UT={0}, Name={1}, Type= {2}", alarmUT, alarmName, alarmType)); } } else { //KAC integration not present. ReturnValue = new StringValue(string.Empty); throw new KOSUnavailableAddonException("addAlarm()", "Kerbal Alarm Clock"); } }
public void CanEndsWith() { var testValue = "FooBar"; var sv = new StringValue(testValue); //Case Sensitive Assert.IsTrue(sv.EndsWith(testValue)); //Case Insensitive Assert.IsTrue(sv.EndsWith(testValue.ToLower())); Assert.IsTrue(sv.EndsWith(testValue.ToUpper())); }
private void SetAlarmAction(StringValue newAlarmAction) { try { var result = (KACWrapper.KACAPI.AlarmActionEnum)Enum.Parse(typeof(KACWrapper.KACAPI.AlarmActionEnum), newAlarmAction); alarm.AlarmAction = result; } catch (ArgumentException) { SafeHouse.Logger.LogWarning(string.Format("Failed parsing {0} into KACAPI.AlarmActionEnum", newAlarmAction)); } }
public void CanFindLastAt() { var testValue = "FooBarFooBar"; var findChar = "F"; var expectedIndex = 6; var sv = new StringValue(testValue); //Case Sensitive Assert.AreEqual(expectedIndex, sv.FindLastAt(findChar, 8)); //Case Insensitive Assert.AreEqual(expectedIndex, sv.FindLastAt(findChar.ToLower(), 8)); }
protected new Structure GetKSPFieldValue(StringValue suffixName) { if (Equals(suffixName, new StringValue(RTTargetField))) { var api = RemoteTechHook.Instance; Guid guid = api.GetAntennaTarget(partModule.part); if (guid.Equals(api.GetNoTargetGuid())) { return new StringValue(NoTargetString); } else if (guid.Equals(api.GetActiveVesselGuid())) { return new StringValue(ActiveVesselString); } else { IEnumerable<string> groundStations = api.GetGroundStations(); foreach (var groundStation in groundStations) { if (guid.Equals(api.GetGroundStationGuid(groundStation))) { return new StringValue(groundStation); } } } foreach (var body in FlightGlobals.Bodies) { if (api.GetCelestialBodyGuid(body).Equals(guid)) { return new BodyTarget(body, shared); } } foreach (var vessel in FlightGlobals.Vessels) { if (vessel.id.Equals(guid)) { return new VesselTarget(vessel, shared); } } // just print the guid if we can't figure out what it is return new StringValue(guid.ToString()); } return base.GetKSPFieldValue(suffixName); }
public void CanSerializeLexicons() { var lex = new Lexicon(); var nested = new Lexicon(); lex[new StringValue("key1")] = new StringValue("value1"); lex[new StringValue("2")] = new ScalarIntValue(10); lex[new ScalarIntValue(2)] = new ScalarIntValue(11); // make sure int 2 is different than string "2" lex[new StringValue("key3")] = nested; nested[new StringValue("nested1")] = new StringValue("nested1value"); nested[new StringValue("nested2")] = new StringValue("nested2value"); var lines = new string[] { "LEXICON of 4 items:", "[\"key1\"] = \"value1\"", "[\"2\"] = 10", "[2] = 11", "[\"key3\"] = LEXICON of 2 items:", " [\"nested1\"] = \"nested1value\"", " [\"nested2\"] = \"nested2value\""}; Assert.AreEqual(string.Join(Environment.NewLine, lines), Serialize(lex)); }
public void CanSerializeLexicons() { var lex = new Lexicon(); var nested = new Lexicon(); lex[new StringValue("key1")] = new StringValue("value1"); lex[new StringValue("key2")] = new ScalarIntValue(1); lex[new StringValue("key3")] = nested; nested[new StringValue("nested1")] = new StringValue("nested1value"); nested[new StringValue("nested2")] = new StringValue("nested2value"); Lexicon deserialized = Deserialize(Serialize(lex)) as Lexicon; Assert.AreEqual(new StringValue("value1"), deserialized[new StringValue("key1")]); Assert.AreEqual(new ScalarIntValue(1), deserialized[new StringValue("key2")]); Assert.IsTrue(deserialized[new StringValue("key3")] is Lexicon); Assert.AreEqual(new StringValue("nested1value"), (deserialized[new StringValue("key3")] as Lexicon)[new StringValue("nested1")]); }
public void CanTestContains() { var stack = new StackValue(); var zedObject = new StringValue("abc"); InvokeDelegate(stack, "PUSH", zedObject); var firstObject = ScalarIntValue.One; InvokeDelegate(stack, "PUSH", firstObject); var secondObject = ScalarIntValue.Two; var thirdObject = new ScalarIntValue(4); var length = InvokeDelegate(stack, "LENGTH"); Assert.AreEqual(ScalarIntValue.Two, length); Assert.IsTrue((BooleanValue)InvokeDelegate(stack, "CONTAINS", zedObject)); Assert.IsTrue((BooleanValue)InvokeDelegate(stack, "CONTAINS", firstObject)); Assert.IsFalse((BooleanValue)InvokeDelegate(stack, "CONTAINS", secondObject)); Assert.IsFalse((BooleanValue)InvokeDelegate(stack, "CONTAINS", thirdObject)); }
public void CanTestContains() { var queue = new QueueValue(); var zedObject = new StringValue("abc"); InvokeDelegate(queue, "PUSH", zedObject); var firstObject = new StringValue("def"); InvokeDelegate(queue, "PUSH", firstObject); var secondObject = new StringValue("xyz"); var thirdObject = ScalarIntValue.Zero; var length = InvokeDelegate(queue, "LENGTH"); Assert.AreEqual(ScalarIntValue.Two, length); Assert.IsTrue((BooleanValue)InvokeDelegate(queue, "CONTAINS", zedObject)); Assert.IsTrue((BooleanValue)InvokeDelegate(queue, "CONTAINS", firstObject)); Assert.IsFalse((BooleanValue)InvokeDelegate(queue, "CONTAINS", secondObject)); Assert.IsFalse((BooleanValue)InvokeDelegate(queue, "CONTAINS", thirdObject)); }
public void CanSetLexiconIndex() { Encapsulation.Structure index = new StringValue("foo"); var lex = new Lexicon(); lex.Add(index, new StringValue("bar")); cpu.PushStack(lex); cpu.PushStack(index); const string VALUE = "fizz"; cpu.PushStack(VALUE); var opcode = new OpcodeSetIndex(); opcode.Execute(cpu); Assert.AreEqual(1, lex.Count); Assert.AreNotEqual("bar", lex[new StringValue("foo")]); }
/// <summary> /// Trigger whatever action the PartModule has attached to this Action, given the kOS name for the action. /// Warning - it probably triggers the entire action group that is attached to this action if there is one, /// not just the action on this one part. /// <br/><br/> /// NOTE: After kOS 0.15.5, this ability is limited by career progress of the VAB/SPH. /// </summary> /// <param name="suffixName"></param> /// <param name="param">true = activate, false = de-activate</param> private void CallKSPAction(StringValue suffixName, BooleanValue param) { ThrowIfNotCPUVessel(); BaseAction act = GetAction(suffixName); if (act == null) throw new KOSLookupFailException("ACTION", suffixName, this); string careerReason; if (!Career.CanDoActions(out careerReason)) throw new KOSLowTechException("use :DOACTION", careerReason); act.Invoke(new KSPActionParam(act.actionGroup, (param ? KSPActionType.Activate : KSPActionType.Deactivate))); }
/// <summary> /// Set a KSPField with the kOS suffix name given to the new value given. /// </summary> /// <param name="suffixName"></param> /// <param name="newValue"></param> protected virtual void SetKSPFieldValue(StringValue suffixName, Structure newValue) { ThrowIfNotCPUVessel(); BaseField field = GetField(suffixName); if (field == null) throw new KOSLookupFailException("FIELD", suffixName, this); if (!FieldIsVisible(field)) throw new KOSLookupFailException("FIELD", suffixName, this, true); KOSException except; if (IsLegalValue(field, ref newValue, out except)) { object convertedValue = Convert.ChangeType(newValue, field.FieldInfo.FieldType); field.SetValue(convertedValue, partModule); } else { throw except; } }
/// <summary> /// Get a KSPField with the kOS suffix name given. /// </summary> /// <param name="suffixName"></param> /// <returns></returns> protected Structure GetKSPFieldValue(StringValue suffixName) { BaseField field = GetField(suffixName); if (field == null) throw new KOSLookupFailException("FIELD", suffixName, this); if (!FieldIsVisible(field)) throw new KOSLookupFailException("FIELD", suffixName, this, true); Structure obj = FromPrimitiveWithAssert(field.GetValue(partModule)); return obj; }
private void RetypeVessel(StringValue value) { Vessel.vesselType = value.ToString().ToEnum<VesselType>(); }
/// <summary> /// Determine if the Partmodule has this KSPEvent on it, which is publicly /// usable by a kOS script: /// </summary> /// <param name="eventName">The event name to search for</param> /// <returns>true if it is on the PartModule, false if it is not</returns> public BooleanValue HasEvent(StringValue eventName) { return EventIsVisible(GetEvent(eventName)); }
private ListValue GetPartsTagged(StringValue tagName) { return PartValueFactory.Construct(GetRawPartsTagged(tagName), Shared); }
private ListValue GetPartsInGroup(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(); if (matchGroup == KSPActionGroup.None) return kScriptParts; foreach (global::Part p in Vessel.parts) { // See if any of the parts' actions are this action group: bool hasPartAction = p.Actions.Any(a => a.actionGroup.Equals(matchGroup)); if (hasPartAction) { kScriptParts.Add(PartValueFactory.Construct(p, Shared)); continue; } var modules = p.Modules.Cast<PartModule>(); bool hasModuleAction = modules.Any(pm => pm.Actions.Any(a => a.actionGroup.Equals(matchGroup))); if (hasModuleAction) { kScriptParts.Add(PartValueFactory.Construct(p, Shared)); } } return kScriptParts; }
public StringValue(StringValue stringValue) { internalString = stringValue.ToString(); StringInitializeSuffixes(); }
/// <summary> /// Trigger whatever code the PartModule has attached to this Event, given the kOS name for the suffix. /// </summary> /// <param name="suffixName"></param> private void CallKSPEvent(StringValue suffixName) { ThrowIfNotCPUVessel(); BaseEvent evt = GetEvent(suffixName); if (evt == null) throw new KOSLookupFailException("EVENT", suffixName, this); if (!EventIsVisible(evt)) throw new KOSLookupFailException("EVENT", suffixName, this, true); if (RemoteTechHook.IsAvailable()) { RemoteTechHook.Instance.InvokeOriginalEvent(evt); } else { evt.Invoke(); } }
/// <summary> /// Determine if the Partmodule has this KSPAction on it, which is publicly /// usable by a kOS script: /// </summary> /// <param name="actionName">The action name to search for</param> /// <returns>true if it is on the PartModule, false if it is not</returns> public BooleanValue HasAction(StringValue actionName) { return partModule.Actions.Any(kspAction => string.Equals(kspAction.guiName, actionName, StringComparison.CurrentCultureIgnoreCase)); }
private ListValue GetPartsTitled(StringValue partTitle) { return PartValueFactory.Construct(GetRawPartsTitled(partTitle), Shared); }
/// <summary> /// Determine if the Partmodule has this KSPField on it, which is publicly /// usable by a kOS script at the moment: /// </summary> /// <param name="fieldName">The field to search for</param> /// <returns>true if it is on the PartModule, false if it is not</returns> public virtual BooleanValue HasField(StringValue fieldName) { return FieldIsVisible(GetField(fieldName)); }
private void RenameVessel(StringValue value) { if (Vessel.IsValidVesselName(value)) { Vessel.vesselName = value; } }