private bool ValidateFunction(GenericFunction term, out StyleValueFunction func) { func = StyleValueFunction.Unknown; if (term.Arguments.Length == 0) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.MissingFunctionArgument, string.Format(glossary.missingFunctionArgument, term.Name), m_CurrentLine); return(false); } if (term.Name == k_VariableFunctionName) { func = StyleValueFunction.Var; return(ValidateVarFunction(term)); } try { func = StyleValueFunctionExtension.FromUssString(term.Name); } catch (System.Exception) { var prop = m_Builder.currentProperty; m_Errors.AddValidationWarning(string.Format(glossary.unknownFunction, term.Name, prop.name), prop.line); return(false); } return(true); }
private bool ValidateFunction(GenericFunction term, out StyleValueFunction func) { func = StyleValueFunction.Unknown; if (term.Arguments.Length == 0) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.MissingFunctionArgument, term.Name); return(false); } if (term.Name == k_VariableFunctionName) { func = StyleValueFunction.Var; return(ValidateVarFunction(term)); } try { func = StyleValueFunctionExtension.FromUssString(term.Name); } catch (Exception) { var prop = m_Builder.currentProperty; m_Errors.AddValidationWarning($"Unknown function {term.Name} in declaration {prop.name}: {term.Name}", prop.line); return(false); } return(true); }
// Applies the provided function to some or _all of the pool's game objects. public void ForEach(GenericFunction p_func, bool p_activeOnly) { for (int i = 0; i < _all.Count; i++) { GameObject l_obj = _all[i] as GameObject; if (!p_activeOnly || l_obj.activeInHierarchy) { p_func(l_obj); } } }
public static List <T> GenericFilter <T>(List <T> list, GenericFunction <T> function) { List <T> result = new List <T>(); foreach (T item in list) { if (function(item)) { result.Add(item); } } return(result); }
protected void VisitResourceFunction(GenericFunction funcTerm) { var argTerm = funcTerm.Arguments.FirstOrDefault() as PrimitiveTerm; if (argTerm == null) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.MissingFunctionArgument, funcTerm.Name); return; } string path = argTerm.Value as string; m_Builder.AddValue(path, StyleValueType.ResourcePath); }
protected override void RenderGenericFunction(GenericFunction genericFunction) { var visibility = genericFunction.AccessModifier.ToString().ToLower(); var rt = genericFunction.ReturnType; var name = genericFunction.Name; var args = string.Join(", ", genericFunction.Arguments.Select(a => RenderGenericVariableDefinition(a))); WriteIndented($"{visibility} {rt} {name}({args})"); WriteIndented("{"); _indentLevel++; WriteIndented(genericFunction.Body); _indentLevel--; WriteIndented("}"); }
static void Main(string[] args) { IFunction executable = new GenericFunction("cmd.exe"); executable // Set parameters .SetParameters("/C dir %WORKINGDIR") // Set value for each alias to be used with next execute() .SetAlias("%WORKINGDIR", @".\") // Set output stream to get live informations on execution (console) .SetStream(Console.OpenStandardOutput()) // Set working directory .SetWorkingDirectory(@"..\") // Execute the chain .Execute(); }
private static void Main(string[] args) { Console.SetWindowSize(110, 30); Console.Title = "Soy Nelson v1 app"; Console.WriteLine("========== Hola Developer ==========="); try { GenericFunction.LeerArchivo(); } catch (Exception ex) { Console.WriteLine("\n"); Console.WriteLine(ex.Message); Console.ReadKey(); } }
private bool ValidateVarFunction(GenericFunction term) { var argc = term.Arguments.Length; var arg = term.Arguments[0]; bool foundVar = false; bool foundComma = false; for (int i = 0; i < argc; i++) { arg = term.Arguments[i]; if (arg.GetType() == typeof(Whitespace)) { continue; } // First arg is always a variable if (!foundVar) { var variableTerm = term.Arguments[i] as PrimitiveTerm; string varName = variableTerm?.Value as string; if (string.IsNullOrEmpty(varName)) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, "Variable name is missing"); return(false); } else if (!varName.StartsWith("--")) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, $"Variable {varName} is missing '--' prefix"); return(false); } if (varName.Length < 3) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, "Variable name is empty"); return(false); } foundVar = true; } else if (arg.GetType() == typeof(Comma)) { if (foundComma) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, "Too many function arguments"); return(false); } foundComma = true; ++i; if (i >= argc) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, "Empty function argument"); return(false); } } else if (!foundComma) { string msg = "Expected ','"; while (arg.GetType() == typeof(Whitespace) && i + 1 < argc) { arg = term.Arguments[++i]; } if (arg.GetType() != typeof(Whitespace)) { msg = $"{msg} got {arg}"; } m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, msg); return(false); } } return(true); }
// TODO: organise Keyboard.cs /// <summary> /// Creates or modifies a hotkey. /// </summary> /// <param name="KeyName">Name of the hotkey's activation key including any modifier symbols.</param> /// <param name="Label">The name of the function or label whose contents will be executed when the hotkey is pressed. /// This parameter can be left blank if <paramref name="KeyName"/> already exists as a hotkey, /// in which case its label will not be changed. This is useful for changing only the <paramref name="Options"/>. /// </param> /// <param name="Options"> /// <list type="bullet"> /// <item><term>UseErrorLevel</term>: <description>skips the warning dialog and sets <see cref="ErrorLevel"/> if there was a problem.</description></item> /// <item><term>On</term>: <description>the hotkey becomes enabled.</description></item> /// <item><term>Off</term>: <description>the hotkey becomes disabled.</description></item> /// <item><term>Toggle</term>: <description>the hotkey is set to the opposite state (enabled or disabled).</description></item> /// </list> /// </param> /*public static void Hotkey(string KeyName, string Label, string Options) * { * * }*/ /// <summary> /// Creates or modifies a hotkey. /// </summary> /// <param name="KeyName">Name of the hotkey's activation key including any modifier symbols.</param> /// <param name="Method">A function to be executed when the hotkey is pressed. /// This parameter can be left blank if <paramref name="KeyName"/> already exists as a hotkey, /// in which case its label will not be changed. This is useful for changing only the <paramref name="Options"/>. /// </param> /// <param name="Options"> /// <list type="bullet"> /// <item><term>UseErrorLevel</term>: <description>skips the warning dialog and sets <see cref="ErrorLevel"/> if there was a problem.</description></item> /// <item><term>On</term>: <description>the hotkey becomes enabled.</description></item> /// <item><term>Off</term>: <description>the hotkey becomes disabled.</description></item> /// <item><term>Toggle</term>: <description>the hotkey is set to the opposite state (enabled or disabled).</description></item> /// </list> /// </param> public static void Hotkey(string KeyName, string Label, string Options) { #region Conditions int win = -1; switch (KeyName.ToLowerInvariant()) { case Keyword_IfWinActive: win = 0; break; case Keyword_IfWinExist: win = 1; break; case Keyword_IfWinNotActive: win = 2; break; case Keyword_IfWinNotExit: win = 3; break; } if (win != -1) { var cond = new string[4, 2]; cond[win, 0] = Label; // title cond[win, 1] = Options; // text keyCondition = new GenericFunction(delegate { return(HotkeyPrecondition(cond)); }); return; } #endregion #region Options InitKeyboardHook(); bool?enabled = true; foreach (var option in ParseOptions(Options)) { switch (option.ToLowerInvariant()) { case Keyword_On: enabled = true; break; case Keyword_Off: enabled = false; break; case Keyword_Toggle: enabled = null; break; case Keyword_UseErrorLevel: break; default: switch (option[0]) { case 'B': case 'b': case 'P': case 'p': case 'T': case 't': break; default: ErrorLevel = 10; break; } break; } } #endregion #region Modify Keyboard.HotkeyDefinition key; try { key = Keyboard.HotkeyDefinition.Parse(KeyName); } catch (ArgumentException) { ErrorLevel = 2; return; } string id = KeyName; key.Name = id; if (keyCondition != null) { id += "_" + keyCondition.GetHashCode().ToString("X"); } if (hotkeys.ContainsKey(id)) { if (enabled == null) { hotkeys[id].Enabled = !hotkeys[id].Enabled; } else { hotkeys[id].Enabled = enabled == true; } switch (Label.ToLowerInvariant()) { case Keyword_On: hotkeys[id].Enabled = true; break; case Keyword_Off: hotkeys[id].Enabled = true; break; case Keyword_Toggle: hotkeys[id].Enabled = !hotkeys[id].Enabled; break; } } else { var method = FindLocalMethod(Label); if (method == null) { ErrorLevel = 1; return; } key.Proc = (GenericFunction)Delegate.CreateDelegate(typeof(GenericFunction), method); key.Precondition = keyCondition; hotkeys.Add(id, key); keyboardHook.Add(key); } #endregion }
protected abstract void RenderGenericFunction(GenericFunction genericFunction);
// Applies the provided function to some or all of the pool's game objects. public void ForEach(GenericFunction func, bool activeOnly) { for(var i = 0; i < all.Count; i++) { GameObject obj = all[i] as GameObject; if(!activeOnly || obj.activeInHierarchy) { func(obj); } } }
internal static void VisitValue(StyleSheetImportErrors errors, StyleSheetBuilder ssb, Term term) { PrimitiveTerm primitiveTerm = term as PrimitiveTerm; HtmlColor htmlColor = term as HtmlColor; GenericFunction genericFunction = term as GenericFunction; TermList termList = term as TermList; if (term == Term.Inherit) { ssb.AddValue(StyleValueKeyword.Inherit); } else if (primitiveTerm != null) { string text = term.ToString(); UnitType primitiveType = primitiveTerm.PrimitiveType; switch (primitiveType) { case UnitType.String: { string value = text.Trim(new char[] { '\'', '"' }); ssb.AddValue(value, StyleValueType.String); goto IL_F9; } case UnitType.Uri: IL_63: if (primitiveType != UnitType.Number && primitiveType != UnitType.Pixel) { errors.AddSemanticError(StyleSheetImportErrorCode.UnsupportedUnit, primitiveTerm.ToString()); return; } ssb.AddValue(primitiveTerm.GetFloatValue(UnitType.Pixel).Value); goto IL_F9; case UnitType.Ident: { StyleValueKeyword keyword; if (StyleSheetImporterImpl.TryParseKeyword(text, out keyword)) { ssb.AddValue(keyword); } else { ssb.AddValue(text, StyleValueType.Enum); } goto IL_F9; } } goto IL_63; IL_F9 :; } else if (htmlColor != null) { Color value2 = new Color((float)htmlColor.R / 255f, (float)htmlColor.G / 255f, (float)htmlColor.B / 255f, (float)htmlColor.A / 255f); ssb.AddValue(value2); } else if (genericFunction != null) { primitiveTerm = (genericFunction.Arguments.FirstOrDefault <Term>() as PrimitiveTerm); if (genericFunction.Name == "resource" && primitiveTerm != null) { string value3 = primitiveTerm.Value as string; ssb.AddValue(value3, StyleValueType.ResourcePath); } else { errors.AddSemanticError(StyleSheetImportErrorCode.UnsupportedFunction, genericFunction.Name); } } else if (termList != null) { foreach (Term current in termList) { StyleSheetImporterImpl.VisitValue(errors, ssb, current); } } else { errors.AddInternalError(term.GetType().Name); } }
private bool ValidateVarFunction(GenericFunction term) { var argc = term.Arguments.Length; var arg = term.Arguments[0]; bool foundVar = false; bool foundComma = false; for (int i = 0; i < argc; i++) { arg = term.Arguments[i]; if (arg.GetType() == typeof(Whitespace)) { continue; } // First arg is always a variable if (!foundVar) { var variableTerm = term.Arguments[i] as PrimitiveTerm; string varName = variableTerm?.Value as string; if (string.IsNullOrEmpty(varName)) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, glossary.missingVariableName, m_CurrentLine); return(false); } if (!varName.StartsWith("--")) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, string.Format(glossary.missingVariablePrefix, varName), m_CurrentLine); return(false); } if (varName.Length < 3) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, glossary.emptyVariableName, m_CurrentLine); return(false); } foundVar = true; } else if (arg.GetType() == typeof(Comma)) { if (foundComma) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, glossary.tooManyFunctionArguments, m_CurrentLine); return(false); } foundComma = true; ++i; if (i >= argc) { m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, glossary.emptyFunctionArgument, m_CurrentLine); return(false); } } else if (!foundComma) { string token = ""; while (arg.GetType() == typeof(Whitespace) && i + 1 < argc) { arg = term.Arguments[++i]; } if (arg.GetType() != typeof(Whitespace)) { token = arg.ToString(); } m_Errors.AddSemanticError(StyleSheetImportErrorCode.InvalidVarFunction, string.Format(glossary.unexpectedTokenInFunction, token), m_CurrentLine); return(false); } } return(true); }
public override PlayerRecord LevelUp(int levelMax, int hpMax, int statusMax) { //hp atk def dex wis mdef int targetLevel = (m_Exp / 100) + 1; if (m_Level < levelMax && m_Hp > 0 && targetLevel > m_Level) { List <LevelProp> lvprops = new List <LevelProp>(); for (int i = 0; i < (int)LevelProp.max; i++) { lvprops.Add((LevelProp)i); } lvprops = GenericFunction.Shuffle(lvprops); int upCount = Random.Range(1, 5); int addHP = 0; int addAtk = 0; int addDef = 0; int addDex = 0; int addWis = 0; int addMDef = 0; m_Level++; int addValue = 0; for (int i = 0; i < upCount; i++) { addValue = Random.Range(1, 3); switch (lvprops[i]) { case LevelProp.hp: addValue = addHP = Mathf.Min(m_MaxHP + addValue, hpMax) - m_MaxHP; break; case LevelProp.atk: addValue = addAtk = Mathf.Min(m_Atk + addValue, statusMax) - m_Atk; break; case LevelProp.def: addValue = addDef = Mathf.Min(m_Def + addValue, statusMax) - m_Def; break; case LevelProp.dex: addValue = addDex = Mathf.Min(m_Dex + addValue, statusMax) - m_Dex; break; case LevelProp.wis: addValue = addWis = Mathf.Min(m_Wis + addValue, statusMax) - m_Wis; break; case LevelProp.mdef: addValue = addMDef = Mathf.Min(m_MDef + addValue, statusMax) - m_MDef; break; } if (addValue == 0 && upCount <= (int)LevelProp.max) { upCount++; } } return(new PlayerRecord(addHP, 0, addAtk, addDef, addWis, addDex, addMDef)); } return(null); }
// TODO: organise Keyboard.cs /// <summary> /// Creates or modifies a hotkey. /// </summary> /// <param name="KeyName">Name of the hotkey's activation key including any modifier symbols.</param> /// <param name="Label">The name of the function or label whose contents will be executed when the hotkey is pressed. /// This parameter can be left blank if <paramref name="KeyName"/> already exists as a hotkey, /// in which case its label will not be changed. This is useful for changing only the <paramref name="Options"/>. /// </param> /// <param name="Options"> /// <list type="bullet"> /// <item><term>UseErrorLevel</term>: <description>skips the warning dialog and sets <see cref="ErrorLevel"/> if there was a problem.</description></item> /// <item><term>On</term>: <description>the hotkey becomes enabled.</description></item> /// <item><term>Off</term>: <description>the hotkey becomes disabled.</description></item> /// <item><term>Toggle</term>: <description>the hotkey is set to the opposite state (enabled or disabled).</description></item> /// </list> /// </param> public static void Hotkey(string KeyName, string Label, string Options) { #region Conditions int win = -1; switch (KeyName.ToLowerInvariant()) { case Keyword_IfWinActive: win = 0; break; case Keyword_IfWinExist: win = 1; break; case Keyword_IfWinNotActive: win = 2; break; case Keyword_IfWinNotExit: win = 3; break; } if (win != -1) { var cond = new string[4, 2]; cond[win, 0] = Label; // title cond[win, 1] = Options; // text keyCondition = new GenericFunction(delegate { return HotkeyPrecondition(cond); }); return; } #endregion #region Options InitKeyboardHook(); bool? enabled = true; foreach (var option in ParseOptions(Options)) { switch (option.ToLowerInvariant()) { case Keyword_On: enabled = true; break; case Keyword_Off: enabled = false; break; case Keyword_Toggle: enabled = null; break; case Keyword_UseErrorLevel: break; default: switch (option[0]) { case 'B': case 'b': case 'P': case 'p': case 'T': case 't': break; default: ErrorLevel = 10; break; } break; } } #endregion #region Modify Keyboard.HotkeyDefinition key; try { key = Keyboard.HotkeyDefinition.Parse(KeyName); } catch (ArgumentException) { ErrorLevel = 2; return; } string id = KeyName; key.Name = id; if (keyCondition != null) id += "_" + keyCondition.GetHashCode().ToString("X"); if (hotkeys.ContainsKey(id)) { if (enabled == null) hotkeys[id].Enabled = !hotkeys[id].Enabled; else hotkeys[id].Enabled = enabled == true; switch (Label.ToLowerInvariant()) { case Keyword_On: hotkeys[id].Enabled = true; break; case Keyword_Off: hotkeys[id].Enabled = true; break; case Keyword_Toggle: hotkeys[id].Enabled = !hotkeys[id].Enabled; break; } } else { var method = FindLocalMethod(Label); if (method == null) { ErrorLevel = 1; return; } key.Proc = (GenericFunction)Delegate.CreateDelegate(typeof(GenericFunction), method); key.Precondition = keyCondition; hotkeys.Add(id, key); keyboardHook.Add(key); } #endregion }
public static GenericFunction ParseFunction(IList <MathAtom> atoms) { var function = new GenericFunction() { Name = string.Empty, Inputs = new List <Entity.Variable>() }; // Find where the equality operator is int idxOfEquals = atoms.IndexOf(atoms.First(a => a is Relation)); // Figure out which kind of function this is if (atoms[0] is Variable) { // Simple function.RequestedType = FunctionType.Scalar; // Convert the scalar function to a 1D vector-valued function var expressionParts = atoms.Skip(idxOfEquals + 1).ToArray(); Inner vector; if (expressionParts.Length == 1 && expressionParts[0] is Inner inner) { // Output is already expressed as a vector vector = inner; // It's not really a parametric function, how can the original // function type be preserved if every function is turned into // a vector-valued function? function.RequestedType = FunctionType.Parametric; } else { vector = new Inner(new Boundary("〈"), new MathList(expressionParts), new Boundary("〉")); } atoms = atoms.Take(idxOfEquals + 1).ToList(); atoms.Add(vector); } else if (atoms[0] is Accent accent) { // Combining Right Arrow Above if (accent.Nucleus == "\u20d7") { // Vector function.RequestedType = FunctionType.VectorField; } // Combining Circumflex Accent else if (accent.Nucleus == "\u0302") { // Transformation function.RequestedType = FunctionType.Transformation; // Convert the transformation into a vector-valued function // for easier parsing // TODO } function.Name = accent.InnerList.DebugString; } // Find the name of the function bool foundOpen = false; int idxOfOpen = 0; while (!foundOpen && idxOfOpen + 1 < atoms.Count) { var atom = atoms[idxOfOpen]; if (atom is Variable) { function.Name += atom.Nucleus; idxOfOpen++; } else if (atom is Open) { foundOpen = true; } else { idxOfOpen++; } } // Find the input variables bool foundClose = false; int idxOfClose = idxOfOpen + 1; while (!foundClose && idxOfClose + 1 < atoms.Count) { var atom = atoms[idxOfClose]; if (atom is Variable var) { function.Inputs.Add(var.Nucleus); } else if (atom is Punctuation) { Guard.IsEqualTo(atom.Nucleus, ",", nameof(atom)); } else { Guard.IsOfType(atom, typeof(Close), nameof(atom)); foundClose = true; } idxOfClose++; } for (int i = idxOfEquals + 1; i < atoms.Count; i++) { var atom = atoms[i]; if (atom is Inner inner) { if (inner.LeftBoundary.Nucleus == "〈" && inner.RightBoundary.Nucleus == "〉") { // Vector var components = inner.InnerList.Split(new Punctuation(",")); function.FunctionBody = new Vector( "<" + String.Join(",", components.Select(c => ConvertToMathString(c))) + ">" ); } } } return(function); }