Exemple #1
0
    public override object FromString(string input, Type type, string inputName, int lineNumber)
    {
        // first check to see if we're a static
        {
            var property = typeof(Godot.Vector2).GetProperty(input, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
            if (property != null)
            {
                return(property.GetValue(null));
            }
        }

        // we're not a static. Try parsing.
        if (input.Length >= 3)
        {
            // Chop off parens
            if (input[0] == '(' && input[input.Length - 1] == ')')
            {
                input = input.Substring(1, input.Length - 2);
            }

            var pieces = input.Split(',').Select(item => item.Trim()).ToArray();
            if (pieces.Length == 2)
            {
                return(new Godot.Vector2(float.Parse(pieces[0]), float.Parse(pieces[1])));
            }
        }

        Dbg.Err($"{inputName}:{lineNumber}: Failed to parse Vector2 \"{input}\".");

        return(null);
    }
Exemple #2
0
        internal override void Record <T>(ref T value, string label, Parameters parameters)
        {
            if (asThis)
            {
                Dbg.Err($"Attempting to write a second field after a RecordAsThis call");
                return;
            }

            if (parameters.asThis)
            {
                if (fields.Count > 0)
                {
                    Dbg.Err($"Attempting to make a RecordAsThis call after writing a field");
                    return;
                }

                asThis = true;

                Serialization.ComposeElement(node, value, typeof(T), parameters.CreateContext());

                return;
            }

            if (fields.Contains(label))
            {
                Dbg.Err($"Field '{label}' written multiple times");
                return;
            }

            fields.Add(label);

            Serialization.ComposeElement(node.CreateChild(label, parameters.CreateContext()), value, typeof(T), parameters.CreateContext());
        }
Exemple #3
0
        public override void Record <T>(ref T value, string label)
        {
            if (fields.Contains(label))
            {
                Dbg.Err($"Field '{label}' written multiple times");
                return;
            }

            fields.Add(label);

            element.Add(Serialization.ComposeElement(value, typeof(T), label, context));
        }
Exemple #4
0
    public static string GetFileAsString(string path)
    {
        var file      = new File();
        var openerror = file.Open(path, File.ModeFlags.Read);

        if (openerror != Error.Ok)
        {
            Dbg.Err($"Failure opening file {path}: {openerror}");
            return("");
        }
        var result = file.GetAsText();

        file.Close();
        return(result);
    }
Exemple #5
0
    public override object FromString(string input, Type type, string inputName, int lineNumber)
    {
        if (input.Length >= 3)
        {
            // Chop off parens
            if (input[0] == '(' && input[input.Length - 1] == ')')
            {
                input = input.Substring(1, input.Length - 2);
            }

            var pieces = input.Split(',').Select(item => item.Trim()).ToArray();
            if (pieces.Length == 2)
            {
                return(new Range(float.Parse(pieces[0]), float.Parse(pieces[1])));
            }
        }

        Dbg.Err($"{inputName}:{lineNumber}: Failed to parse Range \"{input}\".");

        return(null);
    }
Exemple #6
0
    public void Enable(bool enabled)
    {
        if (enabled && hookHandle.ToInt64() == 0)
        {
            using (ProcessModule curModule = Process.GetCurrentProcess().MainModule)
            {
                Dbg.Inf($"Hookening");

                hookHandle = SetWindowsHookExA(WH_KEYBOARD_LL, LowLevelKeyboardProc, GetModuleHandle(curModule.ModuleName), 0);

                if (hookHandle.ToInt64() == 0)
                {
                    Dbg.Err("Failed to hook!");
                }
            }
        }
        else if (!enabled && hookHandle.ToInt64() != 0)
        {
            UnhookWindowsHookEx(hookHandle);
            hookHandle = new IntPtr(0);
        }
    }