public static string StringArrayToProcessOperations(string systemCopyBuffer, ref List <InputOperator> ProcessOperations) { int count = 0; try { var list = new List <InputOperator>(); // Make a new one, for in case there is an error foreach (string s in systemCopyBuffer.Replace("--", "") // Remove double negatives (or just long even lines of --) .Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)) // Split by separator, keep empty entries for incrementing count only { string source = s; count++; int comment = source.IndexOf('#'); // Comment character if (comment != -1) { source = source.Substring(0, comment); } if (string.IsNullOrWhiteSpace(source)) { continue; } list.Add(InputOperator.FromString(source)); } ProcessOperations.Clear(); // No error, clear and ProcessOperations = list; return("Pasted"); } catch (Exception E) { Console.WriteLine(E); return("Line " + count.ToString() + ":\n" + E.Message); } }
public string SetToBlockMover(ModuleBlockMover blockMover) { blockMover.SetDirty(); blockMover.SetMinLimit(minValueLimit ?? 0f); blockMover.SetMaxLimit(maxValueLimit ?? blockMover.TrueLimitVALUE); blockMover.MAXVELOCITY = maxVelocity.HasValue ? velocity.Value : blockMover.MAXVELOCITY; if (targetValue.HasValue) { blockMover.VALUE = targetValue.Value; } if (velocity.HasValue) { blockMover.VELOCITY = velocity.Value; } if (jointStrength.HasValue) { blockMover.SPRSTR = jointStrength.Value; } if (jointDampen.HasValue) { blockMover.SPRDAM = jointDampen.Value; } if (moverType.HasValue) { blockMover.moverType = moverType.Value; } blockMover.CannotBeFreeJoint = blockMover.CannotBeFreeJoint; if (lockOffsetParent.HasValue) { blockMover.LockJointBackPush = lockOffsetParent.Value; } return(InputOperator.StringArrayToProcessOperations(ToString(), ref blockMover.ProcessOperations)); }
public static InputOperator FromString(string source) { var result = new InputOperator(); source = source.ToLower().Replace("do ", "#do#").Replace(" ", "").Replace("\t", ""); // Highlight DO separator and remove spacing if (source == "endif") // ENDIF statement { result.m_InputType = InputType.AlwaysOn; result.m_OperationType = OperationType.EndIf; } else if (source == "else") // ENDIF statement { result.m_InputType = InputType.AlwaysOn; result.m_OperationType = OperationType.ElseThen; } else if (source.StartsWith("if(")) // IF statement { result.m_OperationType = OperationType.IfThen; source = source.Substring(3, source.Length - 4); //remove ')', compensate for `if(` string condition = source.Substring(0, source.LastIndexOf(',')); ParseInputFromString(result, condition); string strength = source.Substring(condition.Length + 1); if (!float.TryParse(strength, out float fstrength)) { throw new FormatException("Cannot parse strength parameter '" + strength + "'"); } result.m_Strength = fstrength; } else if (source.StartsWith("orif(")) // OR IF statement { result.m_OperationType = OperationType.OrThen; source = source.Substring(5, source.Length - 6); //remove ')', compensate for `orif(` string condition = source.Substring(0, source.LastIndexOf(',')); ParseInputFromString(result, condition); string strength = source.Substring(condition.Length + 1); if (!float.TryParse(strength, out float fstrength)) { throw new FormatException("Cannot parse strength parameter '" + strength + "'"); } result.m_Strength = fstrength; } else { int dosep = source.IndexOf("#do#"); if (dosep == 0) // No condition defined, always on { result.m_InputType = InputType.AlwaysOn; } else { ParseInputFromString(result, source.Substring(0, dosep)); // Get input type and parameters } ParseOperationFromString(result, source.Substring(dosep + 4)); // Cut down to action } return(result); }
static void ParseOperationFromString(InputOperator obj, string source) { int pindex = source.IndexOf('('); string key = source.Substring(0, pindex); if (!Enum.TryParse(key, true, out OperationType operationType)) { throw new ArgumentException("Operation '" + key + "' does not exist in OperationType"); } obj.m_OperationType = operationType; source = source.Substring(pindex + 1).TrimEnd(')'); if (source.Length != 0) { if (!float.TryParse(source, out float param)) { throw new FormatException("Cannot parse parameter '" + source + "'"); } obj.m_Strength = param; } }
static void ParseInputFromString(InputOperator obj, string source) { int pindex = source.IndexOf('('); string key = source.Substring(0, pindex); if (!Enum.TryParse(key, true, out InputType inputType)) { throw new ArgumentException("Condition '" + key + "' does not exist in InputType"); } obj.m_InputType = inputType; var parameters = source.Substring(pindex + 1).TrimEnd(')').Split(','); pindex = 0; // Repurpose as parameter var iT = UIInputPairs[inputType]; if (!iT.HideInputKey) { if (parameters.Length <= pindex || string.IsNullOrEmpty(parameters[0])) { throw new FormatException("Expected Key parameter"); } if (!Enum.TryParse(parameters[0], true, out KeyCode keyCode)) { throw new ArgumentException("Key Parameter '" + parameters[0] + "' does not exist in KeyCode"); } obj.m_InputKey = keyCode; pindex++; } if (!iT.HideParam) { if (parameters.Length <= pindex || string.IsNullOrEmpty(parameters[pindex])) { throw new FormatException("Expected Value parameter"); } if (!float.TryParse(parameters[pindex], out float param)) { throw new FormatException("Cannot parse parameter '" + parameters[pindex] + "'"); } obj.m_InputParam = param; } }
public static void ConvertSerialToBlockMover(SerialData serialData, ModuleBlockMover blockMover) { string ProcessList; blockMover.SetDirty(); blockMover.moverType = ModuleBlockMover.MoverType.Static; blockMover.LockJointBackPush = true; blockMover.LOCALINPUT = serialData.Local; blockMover._CENTERLIMIT = serialData.Stretch != 0 ? serialData.Stretch / 2f : blockMover.HalfLimitVALUE; blockMover._EXTENTLIMIT = blockMover._CENTERLIMIT; blockMover.UseLIMIT = serialData.Stretch != 0 && serialData.Stretch != blockMover.TrueLimitVALUE; blockMover.VELOCITY = 0f; blockMover.VALUE = serialData.IsOpen ? serialData.Stretch : 0f; blockMover.PVALUE = blockMover.VALUE; var mode = GetMode(serialData.Toggle, serialData.Invert, serialData.PreferState); ProcessList = ModeToProcessFormat[(int)mode]; ProcessList = ProcessList.Replace("<Input>", serialData.Input.ToString()); ProcessList = ProcessList.Replace("<Extent>", (serialData.Stretch == 0 ? blockMover.TrueLimitVALUE : serialData.Stretch).ToString()); ProcessList = ProcessList.Replace("<ToggleState>", serialData.IsOpen ? "1" : "-1"); InputOperator.StringArrayToProcessOperations(ProcessList, ref blockMover.ProcessOperations); }
public static void ConvertSerialToBlockMover(SerialData serialData, ModuleBlockMover blockMover) { string ProcessList; blockMover.SetDirty(); blockMover.moverType = ModuleBlockMover.MoverType.Static; blockMover.LockJointBackPush = true; blockMover.LOCALINPUT = serialData.Local; blockMover._CENTERLIMIT = serialData.minRestrict; blockMover._EXTENTLIMIT = serialData.rangeRestrict;// / 2f; blockMover.UseLIMIT = serialData.Restrict && serialData.rangeRestrict != 0f; blockMover.VELOCITY = 0f; blockMover.VALUE = serialData.Angle; blockMover.PVALUE = serialData.Angle; blockMover.MAXVELOCITY = serialData.Speed; switch (serialData.mode) { case Mode.Positional: if (serialData.StartDelay != 0f) { ProcessList = PositionalDelay; } else { ProcessList = Positional; } break; case Mode.Directional: blockMover.VELOCITY = serialData.Direction * serialData.Speed; if (serialData.CWDelay + serialData.CCWDelay != 0f) { ProcessList = DirectionalDelay; } else { ProcessList = Directional; } break; case Mode.Speed: blockMover.VELOCITY = serialData.Direction * serialData.Speed; if (serialData.StartDelay != 0f) { ProcessList = SpeedDelay; } else { ProcessList = Speed; } break; case Mode.OnOff: blockMover.VELOCITY = serialData.Direction * serialData.Speed; if (serialData.Restrict) { if (serialData.CWDelay + serialData.CCWDelay != 0f) { ProcessList = OnOffLimitDelay; } else { ProcessList = OnOffLimit; } } else { if (serialData.StartDelay != 0f) { ProcessList = OnOffDelay; } else { ProcessList = OnOff; } } break; case Mode.Aim: if (serialData.StartDelay != 0f) { ProcessList = TargetDelay; } else { ProcessList = Target; } break; case Mode.Turning: blockMover.VELOCITY = serialData.Direction * serialData.Speed; if (serialData.Restrict) { if (serialData.StartDelay != 0f) { ProcessList = TurningLimitDelay; } else { ProcessList = TurningLimit; } } else { if (serialData.StartDelay != 0f) { ProcessList = TurningDelay; } else { ProcessList = Turning; } } break; case Mode.AimAtPlayer: ProcessList = AimAtPlayer; break; case Mode.Throttle: blockMover.VELOCITY = serialData.Direction * serialData.Speed; if (serialData.StartDelay != 0f) { ProcessList = ThrottleDelay; } else { ProcessList = Throttle; } break; case Mode.AimAtVelocity: blockMover.VELOCITY = serialData.Direction * serialData.Speed; ProcessList = AimAtVelocity; break; case Mode.Cycle: blockMover.VELOCITY = serialData.Direction * serialData.Speed; if (serialData.Restrict) { if (serialData.StartDelay != 0f || serialData.CCWDelay != 0f || serialData.CWDelay != 0f) { ProcessList = CycleLimitDelay; } else { ProcessList = CycleLimit; } } else { if (serialData.StartDelay != 0f || serialData.CCWDelay != 0f || serialData.CWDelay != 0f) { ProcessList = CycleDelay; } else { ProcessList = Cycle; } } break; default: Console.WriteLine("ModuleSwivel.ConvertSerialToBlockMover() : Cannot deserialize " + serialData.mode.ToString() + ", missing conversion!"); ProcessList = ""; break; } ProcessList = ProcessList.Replace("<KeyR>", serialData.Input1.ToString()); ProcessList = ProcessList.Replace("<KeyL>", serialData.Input2.ToString()); ProcessList = ProcessList.Replace("<SD>", ((serialData.StartDelay / serialData.Speed) * Time.fixedDeltaTime).ToString()); ProcessList = ProcessList.Replace("<CWD>", ((serialData.CWDelay / serialData.Speed) * Time.fixedDeltaTime).ToString()); ProcessList = ProcessList.Replace("<CCWD>", ((serialData.CCWDelay / serialData.Speed) * Time.fixedDeltaTime).ToString()); ProcessList = ProcessList.Replace("<Speed>", serialData.Speed.ToString()); ProcessList = ProcessList.Replace("<Smooth>", (serialData.Speed * 0.025f).ToString()); // Position += (Direction +- 0.025f) * Speed ProcessList = ProcessList.Replace("<Smooth2>", (serialData.Speed * 0.05f).ToString()); ProcessList = ProcessList.Replace("<LimitC>", blockMover._CENTERLIMIT.ToString()); ProcessList = ProcessList.Replace("<LimitL>", (((blockMover.MINVALUELIMIT + 900) % 360) - 180).ToString()); ProcessList = ProcessList.Replace("<LimitR>", (((blockMover.MAXVALUELIMIT + 900) % 360) - 180).ToString()); InputOperator.StringArrayToProcessOperations(ProcessList, ref blockMover.ProcessOperations); }