internal SelectVariable(ConfigNode node) { name = node.GetValue("name"); foreach (ConfigNode sourceVarNode in node.GetNodes("VARIABLE_DEFINITION")) { bool reverseVal; VariableOrNumberRange vonr = ProcessSourceNode(sourceVarNode, out reverseVal); sourceVariables.Add(vonr); reverse.Add(reverseVal); VariableOrNumber val = VariableOrNumber.Instantiate(sourceVarNode.GetValue("value")); result.Add(val); } if (node.HasValue("defaultValue")) { VariableOrNumber val = VariableOrNumber.Instantiate(node.GetValue("defaultValue")); result.Add(val); } else { throw new Exception(string.Format("Select variable {0} is missing its defaultValue", name)); } if (sourceVariables.Count == 0) { throw new ArgumentException("Did not find any VARIABLE_DEFINITION nodes in RPM_SELECT_VARIABLE", name); } }
public MappedVariable(ConfigNode node) { if (!node.HasValue("mappedVariable") || !node.HasValue("mappedRange") || !node.HasValue("sourceVariable") || !node.HasValue("sourceRange")) { throw new ArgumentException("MappedVariable missing required values"); } string sourceVariableStr = node.GetValue("sourceVariable"); string sourceRange = node.GetValue("sourceRange"); string[] sources = sourceRange.Split(','); if (sources.Length != 2) { throw new ArgumentException("MappedVariable sourceRange does not have exactly two values"); } sourceVariable = new VariableOrNumberRange(sourceVariableStr, sources[0], sources[1]); mappedVariable = node.GetValue("mappedVariable"); string[] destinations = node.GetValue("mappedRange").Split(','); if (destinations.Length != 2) { throw new ArgumentException("MappedVariable mappedRange does not have exactly two values"); } mappedExtent1 = VariableOrNumber.Instantiate(destinations[0]); mappedExtent2 = VariableOrNumber.Instantiate(destinations[1]); }
internal MathVariable(ConfigNode node) { name = node.GetValue("name"); string[] sources = node.GetValues("sourceVariable"); for (int i = 0; i < sources.Length; ++i) { VariableOrNumber sv = VariableOrNumber.Instantiate(sources[i]); sourceVariables.Add(sv); } if (sourceVariables.Count == 0) { throw new ArgumentException("Did not find any SOURCE_VARIABLE nodes in RPM_CUSTOM_VARIABLE", name); } string oper = node.GetValue("operator"); if (oper == Operator.NONE.ToString()) { op = Operator.NONE; } else if (oper == Operator.ADD.ToString()) { op = Operator.ADD; } else if (oper == Operator.SUBTRACT.ToString()) { op = Operator.SUBTRACT; } else if (oper == Operator.MULTIPLY.ToString()) { op = Operator.MULTIPLY; } else if (oper == Operator.DIVIDE.ToString()) { op = Operator.DIVIDE; } else if (oper == Operator.MAX.ToString()) { op = Operator.MAX; } else if (oper == Operator.MIN.ToString()) { op = Operator.MIN; } else { throw new ArgumentException("Found an invalid operator type in RPM_CUSTOM_VARIABLE", oper); } }
public DataSet(ConfigNode node) { Vector4 packedPosition = ConfigNode.ParseVector4(node.GetValue("borderPosition")); position.x = packedPosition.x; position.y = packedPosition.y; size.x = packedPosition.z; size.y = packedPosition.w; if (node.HasValue("borderColor")) { color = ConfigNode.ParseColor32(node.GetValue("borderColor")); } if (node.HasValue("borderWidth")) { lineWidth = int.Parse(node.GetValue("borderWidth")); } string graphTypeStr = node.GetValue("graphType").Trim(); if (graphTypeStr == GraphType.VerticalUp.ToString()) { graphType = GraphType.VerticalUp; } else if (graphTypeStr == GraphType.VerticalDown.ToString()) { graphType = GraphType.VerticalDown; } else if (graphTypeStr == GraphType.VerticalSplit.ToString()) { graphType = GraphType.VerticalSplit; } else if (graphTypeStr == GraphType.HorizontalRight.ToString()) { graphType = GraphType.HorizontalRight; } else if (graphTypeStr == GraphType.HorizontalLeft.ToString()) { graphType = GraphType.HorizontalLeft; } else if (graphTypeStr == GraphType.HorizontalSplit.ToString()) { graphType = GraphType.HorizontalSplit; } else if (graphTypeStr == GraphType.Lamp.ToString()) { graphType = GraphType.Lamp; } else { throw new ArgumentException("Unknown 'graphType' in DATA_SET"); } if (node.HasValue("passiveColor")) { passiveColor = ConfigNode.ParseColor32(node.GetValue("passiveColor")); } if (node.HasValue("activeColor")) { activeColor = ConfigNode.ParseColor32(node.GetValue("activeColor")); } string[] token = node.GetValue("scale").Split(','); scale[0] = VariableOrNumber.Instantiate(token[0]); scale[1] = VariableOrNumber.Instantiate(token[1]); variableName = node.GetValue("variableName").Trim(); if (node.HasValue("reverse")) { if (!bool.TryParse(node.GetValue("reverse"), out reverse)) { throw new ArgumentException("So is 'reverse' true or false?"); } } if (node.HasValue("threshold")) { threshold = ConfigNode.ParseVector2(node.GetValue("threshold")); } if (threshold != Vector2.zero) { thresholdMode = true; float min = Mathf.Min(threshold.x, threshold.y); float max = Mathf.Max(threshold.x, threshold.y); threshold.x = min; threshold.y = max; if (node.HasValue("flashingDelay")) { flashingDelay = float.Parse(node.GetValue("flashingDelay")); flashingDelay = Mathf.Max(flashingDelay, 0.0f); } } fillTopLeftCorner = position + new Vector2((float)lineWidth, (float)lineWidth); fillSize = (size - new Vector2((float)(2 * lineWidth), (float)(2 * lineWidth))); }
internal HorizontalBar(ConfigNode node, float screenWidth, float screenHeight, int drawingLayer, Shader displayShader, GameObject cameraBody) { JUtil.LogMessage(this, "Configuring for {0}", node.GetValue("name")); if (!node.HasValue("variableName")) { throw new Exception("HorizontalBar " + node.GetValue("name") + " missing variableName"); } variable = VariableOrNumber.Instantiate(node.GetValue("variableName")); if (!node.HasValue("texture")) { throw new Exception("HorizontalBar " + node.GetValue("name") + " missing texture"); } Texture2D tex = GameDatabase.Instance.GetTexture(node.GetValue("texture"), false); if (tex == null) { throw new Exception("HorizontalBar " + node.GetValue("name") + " texture " + node.GetValue("texture") + " can't be loaded."); } tex.wrapMode = TextureWrapMode.Clamp; if (node.HasValue("useLog10") && bool.TryParse(node.GetValue("useLog10"), out useLog10) == false) { // I think this is redundant useLog10 = false; } if (!node.HasValue("scale")) { throw new Exception("HorizontalBar " + node.GetValue("name") + " missing scale"); } scale = ConfigNode.ParseVector2(node.GetValue("scale")); if (useLog10) { scale.x = JUtil.PseudoLog10(scale.x); scale.y = JUtil.PseudoLog10(scale.y); } if (!node.HasValue("textureSize")) { throw new Exception("HorizontalBar " + node.GetValue("name") + " missing textureSize"); } if (!float.TryParse(node.GetValue("textureSize"), out textureSize)) { throw new Exception("HorizontalBar " + node.GetValue("name") + " failed parsing textureSize"); } textureSize = 0.5f * textureSize / (float)tex.width; if (!node.HasValue("textureLimit")) { throw new Exception("HorizontalBar " + node.GetValue("name") + " missing textureLimit"); } textureLimit = ConfigNode.ParseVector2(node.GetValue("textureLimit")); textureLimit.x = 1.0f - textureLimit.x / (float)tex.width; textureLimit.y = 1.0f - textureLimit.y / (float)tex.width; if (!node.HasValue("position")) { throw new Exception("HorizontalBar " + node.GetValue("name") + " missing position"); } Vector4 position = ConfigNode.ParseVector4(node.GetValue("position")); if (node.HasValue("enablingVariable") && node.HasValue("enablingVariableRange")) { string[] range = node.GetValue("enablingVariableRange").Split(','); if (range.Length != 2) { throw new Exception("HorizontalBar " + node.GetValue("name") + " has an invalid enablingVariableRange"); } enablingVariable = new VariableOrNumberRange(node.GetValue("enablingVariable").Trim(), range[0].Trim(), range[1].Trim()); } barObject = JUtil.CreateSimplePlane("HorizontalBar" + node.GetValue("name"), new Vector2(0.5f * position.z, 0.5f * position.w), new Rect(0.0f, 0.0f, 1.0f, 1.0f), drawingLayer); Material barMaterial = new Material(displayShader); barMaterial.color = Color.white; barMaterial.mainTexture = tex; // Position in camera space has (0, 0) in the center, so we need to // translate everything appropriately. Y is odd since the coordinates // supplied are Left-Handed (0Y on top, growing down), not RH. barObject.transform.position = new Vector3(position.x + 0.5f * (position.z - screenWidth), 0.5f * (screenHeight - position.w) - position.y, 1.4f); barObject.GetComponent <Renderer>().material = barMaterial; barObject.transform.parent = cameraBody.transform; JUtil.ShowHide(true, barObject); }
public VariableOrNumberRange(string sourceVariable, string range1, string range2) { sourceValue = VariableOrNumber.Instantiate(sourceVariable); lowerBound = VariableOrNumber.Instantiate(range1); upperBound = VariableOrNumber.Instantiate(range2); }
public void Start() { if (HighLogic.LoadedSceneIsEditor) { return; } try { if (string.IsNullOrEmpty(perPodPersistenceName)) { JUtil.LogErrorMessage(this, "perPodPersistenceName must be defined"); return; } if (string.IsNullOrEmpty(defaultValue)) { JUtil.LogErrorMessage(this, "defaultValue must be defined"); return; } if (stepSize < 0.0f) { stepSize = 0.0f; } //JUtil.LogMessage(this, "Start(): {0}, {1}, {2}, {3}, {4}", perPodPersistenceName, defaultValue, minValue, maxValue, stepSize); if (!string.IsNullOrEmpty(minValue)) { minRange = VariableOrNumber.Instantiate(minValue); //JUtil.LogMessage(this, "Created lower bound variable"); } if (!string.IsNullOrEmpty(maxValue)) { maxRange = VariableOrNumber.Instantiate(maxValue); //JUtil.LogMessage(this, "Created upper bound variable"); } if ((minRange == null || maxRange == null) && loopInput == true) { JUtil.LogErrorMessage(this, "Overriding loopInput - minValue or maxValue is missing"); loopInput = false; } RPMVesselComputer comp = RPMVesselComputer.Instance(vessel); if (!comp.HasPersistentVariable(perPodPersistenceName)) { //JUtil.LogMessage(this, "Initializing per pod persistence value {0}", perPodPersistenceName); VariableOrNumber von = VariableOrNumber.Instantiate(defaultValue); float value; if (von.Get(out value, comp)) { if (stepSize > 0.0f) { float remainder = value % stepSize; value -= remainder; } comp.SetPersistentVariable(perPodPersistenceName, value); } else { JUtil.LogErrorMessage(this, "Failed to evaluate default value of {0} for {1}", defaultValue, perPodPersistenceName); return; } } ConfigNode moduleConfig = null; foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP")) { if (node.GetValue("name") == internalProp.propName) { moduleConfig = node.GetNodes("MODULE")[moduleID]; ConfigNode[] inputNodes = moduleConfig.GetNodes("USERINPUTSET"); for (int i = 0; i < inputNodes.Length; i++) { try { numericInputs.Add(new NumericInput(inputNodes[i], internalProp)); //JUtil.LogMessage(this, "Added USERINPUTSET {0}", inputNodes[i].GetValue("switchTransform")); } catch (ArgumentException e) { JUtil.LogErrorMessage(this, "Error in building prop number {1} - {0}", e.Message, internalProp.propID); } } break; } } enabled = true; } catch { JUtil.AnnoyUser(this); enabled = false; throw; } }
internal MathVariable(ConfigNode node) { name = node.GetValue("name"); int maxParameters = int.MaxValue; string oper = node.GetValue("operator"); if (oper == Operator.NONE.ToString()) { op = Operator.NONE; indexOperator = false; } else if (oper == Operator.ADD.ToString()) { op = Operator.ADD; indexOperator = false; } else if (oper == Operator.SUBTRACT.ToString()) { op = Operator.SUBTRACT; indexOperator = false; } else if (oper == Operator.MULTIPLY.ToString()) { op = Operator.MULTIPLY; indexOperator = false; } else if (oper == Operator.DIVIDE.ToString()) { op = Operator.DIVIDE; indexOperator = false; } else if (oper == Operator.MAX.ToString()) { op = Operator.MAX; indexOperator = false; } else if (oper == Operator.MIN.ToString()) { op = Operator.MIN; indexOperator = false; } else if (oper == Operator.POWER.ToString()) { op = Operator.POWER; indexOperator = false; } else if (oper == Operator.ANGLEDELTA.ToString()) { op = Operator.ANGLEDELTA; indexOperator = false; maxParameters = 2; } else if (oper == Operator.ATAN2.ToString()) { op = Operator.ATAN2; indexOperator = false; maxParameters = 2; } else if (oper == Operator.MAXINDEX.ToString()) { op = Operator.MAXINDEX; indexOperator = true; } else if (oper == Operator.MININDEX.ToString()) { op = Operator.MININDEX; indexOperator = true; } else { throw new ArgumentException("Found an invalid operator type in RPM_CUSTOM_VARIABLE", oper); } string[] sources = node.GetValues("sourceVariable"); int numIndices = Math.Min(sources.Length, maxParameters); for (int i = 0; i < numIndices; ++i) { VariableOrNumber sv = VariableOrNumber.Instantiate(sources[i]); sourceVariables.Add(sv); } if (sourceVariables.Count == 0) { throw new ArgumentException("Did not find any SOURCE_VARIABLE nodes in RPM_CUSTOM_VARIABLE", name); } }
public VariableAnimationSet(ConfigNode node, InternalProp thisProp) { part = thisProp.part; if (!node.HasData) { throw new ArgumentException("No data?!"); } string[] tokens = { }; if (node.HasValue("scale")) { tokens = node.GetValue("scale").Split(','); } if (tokens.Length != 2) { throw new ArgumentException("Could not parse 'scale' parameter."); } if (node.HasValue("variableName")) { string variableName; variableName = node.GetValue("variableName").Trim(); scaleEnds[2] = VariableOrNumber.Instantiate(variableName); } else if (node.HasValue("stateMethod")) { RPMVesselComputer comp = RPMVesselComputer.Instance(part.vessel); string stateMethod = node.GetValue("stateMethod").Trim(); Func <bool> stateFunction = (Func <bool>)comp.GetMethod(stateMethod, thisProp, typeof(Func <bool>)); if (stateFunction != null) { scaleEnds[2] = VariableOrNumber.Instantiate("PLUGIN_" + stateMethod); } else { throw new ArgumentException("Unrecognized stateMethod"); } } else { throw new ArgumentException("Missing variable name."); } scaleEnds[0] = VariableOrNumber.Instantiate(tokens[0]); scaleEnds[1] = VariableOrNumber.Instantiate(tokens[1]); // That takes care of the scale, now what to do about that scale: if (node.HasValue("reverse")) { if (!bool.TryParse(node.GetValue("reverse"), out reverse)) { throw new ArgumentException("So is 'reverse' true or false?"); } } if (node.HasValue("animationName")) { animationName = node.GetValue("animationName"); if (node.HasValue("animationSpeed")) { animationSpeed = float.Parse(node.GetValue("animationSpeed")); if (reverse) { animationSpeed = -animationSpeed; } } else { animationSpeed = 0.0f; } Animation[] anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(animationName) : thisProp.FindModelAnimators(animationName); if (anims.Length > 0) { onAnim = anims[0]; onAnim.enabled = true; onAnim[animationName].speed = 0; onAnim[animationName].normalizedTime = reverse ? 1f : 0f; looping = node.HasValue("loopingAnimation"); if (looping) { onAnim[animationName].wrapMode = WrapMode.Loop; onAnim.wrapMode = WrapMode.Loop; onAnim[animationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { onAnim[animationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } onAnim.Play(); alwaysActive = node.HasValue("animateExterior"); } else { throw new ArgumentException("Animation could not be found."); } if (node.HasValue("stopAnimationName")) { stopAnimationName = node.GetValue("stopAnimationName"); anims = node.HasValue("animateExterior") ? thisProp.part.FindModelAnimators(stopAnimationName) : thisProp.FindModelAnimators(stopAnimationName); if (anims.Length > 0) { offAnim = anims[0]; offAnim.enabled = true; offAnim[stopAnimationName].speed = 0; offAnim[stopAnimationName].normalizedTime = reverse ? 1f : 0f; if (looping) { offAnim[stopAnimationName].wrapMode = WrapMode.Loop; offAnim.wrapMode = WrapMode.Loop; offAnim[stopAnimationName].speed = animationSpeed; mode = Mode.LoopingAnimation; } else { offAnim[stopAnimationName].wrapMode = WrapMode.Once; mode = Mode.Animation; } } } } else if (node.HasValue("activeColor") && node.HasValue("passiveColor") && node.HasValue("coloredObject")) { if (node.HasValue("colorName")) { colorName = node.GetValue("colorName"); } passiveColor = ConfigNode.ParseColor32(node.GetValue("passiveColor")); activeColor = ConfigNode.ParseColor32(node.GetValue("activeColor")); colorShiftRenderer = thisProp.FindModelComponent <Renderer>(node.GetValue("coloredObject")); colorShiftRenderer.material.SetColor(colorName, reverse ? activeColor : passiveColor); mode = Mode.Color; } else if (node.HasValue("controlledTransform") && node.HasValue("localRotationStart") && node.HasValue("localRotationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialRotation = controlledTransform.localRotation; if (node.HasValue("longPath")) { longPath = true; vectorStart = ConfigNode.ParseVector3(node.GetValue("localRotationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localRotationEnd")); } else { rotationStart = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationStart"))); rotationEnd = Quaternion.Euler(ConfigNode.ParseVector3(node.GetValue("localRotationEnd"))); } mode = Mode.Rotation; } else if (node.HasValue("controlledTransform") && node.HasValue("localTranslationStart") && node.HasValue("localTranslationEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialPosition = controlledTransform.localPosition; vectorStart = ConfigNode.ParseVector3(node.GetValue("localTranslationStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localTranslationEnd")); mode = Mode.Translation; } else if (node.HasValue("controlledTransform") && node.HasValue("localScaleStart") && node.HasValue("localScaleEnd")) { controlledTransform = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()); initialScale = controlledTransform.localScale; vectorStart = ConfigNode.ParseVector3(node.GetValue("localScaleStart")); vectorEnd = ConfigNode.ParseVector3(node.GetValue("localScaleEnd")); mode = Mode.Scale; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureShiftStart") && node.HasValue("textureShiftEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).renderer.material; textureLayer = node.GetValue("textureLayers"); textureShiftStart = ConfigNode.ParseVector2(node.GetValue("textureShiftStart")); textureShiftEnd = ConfigNode.ParseVector2(node.GetValue("textureShiftEnd")); mode = Mode.TextureShift; } else if (node.HasValue("controlledTransform") && node.HasValue("textureLayers") && node.HasValue("textureScaleStart") && node.HasValue("textureScaleEnd")) { affectedMaterial = thisProp.FindModelTransform(node.GetValue("controlledTransform").Trim()).renderer.material; textureLayer = node.GetValue("textureLayers"); textureScaleStart = ConfigNode.ParseVector2(node.GetValue("textureScaleStart")); textureScaleEnd = ConfigNode.ParseVector2(node.GetValue("textureScaleEnd")); mode = Mode.TextureScale; } else { throw new ArgumentException("Cannot initiate any of the possible action modes."); } if (node.HasValue("threshold")) { threshold = ConfigNode.ParseVector2(node.GetValue("threshold")); } resourceAmount = 0.0f; if (threshold != Vector2.zero) { thresholdMode = true; float min = Mathf.Min(threshold.x, threshold.y); float max = Mathf.Max(threshold.x, threshold.y); threshold.x = min; threshold.y = max; if (node.HasValue("flashingDelay")) { flashingDelay = double.Parse(node.GetValue("flashingDelay")); } if (node.HasValue("alarmSound")) { alarmSoundVolume = 0.5f; if (node.HasValue("alarmSoundVolume")) { alarmSoundVolume = float.Parse(node.GetValue("alarmSoundVolume")); } audioOutput = JUtil.SetupIVASound(thisProp, node.GetValue("alarmSound"), alarmSoundVolume, false); if (node.HasValue("alarmMustPlayOnce")) { if (!bool.TryParse(node.GetValue("alarmMustPlayOnce"), out alarmMustPlayOnce)) { throw new ArgumentException("So is 'alarmMustPlayOnce' true or false?"); } } if (node.HasValue("alarmShutdownButton")) { SmarterButton.CreateButton(thisProp, node.GetValue("alarmShutdownButton"), AlarmShutdown); } if (node.HasValue("alarmSoundLooping")) { if (!bool.TryParse(node.GetValue("alarmSoundLooping"), out alarmSoundLooping)) { throw new ArgumentException("So is 'alarmSoundLooping' true or false?"); } audioOutput.audio.loop = alarmSoundLooping; } } if (node.HasValue("resourceAmount")) { resourceAmount = float.Parse(node.GetValue("resourceAmount")); } TurnOff(); } }