コード例 #1
0
    static void Main(string[] args)
    {
        Def.Config.DefaultHandlerThrowExceptions = Def.Config.DefaultExceptionBehavior.Never;

        {
            var parser = new Def.Parser();
            parser.AddFile("xml/config.xml");
            parser.Finish();
        }

        var userdb = new UserDb();

        foreach (var file in Directory.GetFiles(Config.Global.dataDir, "*.json", SearchOption.AllDirectories).ProgressBar())
        {
            var post = JsonConvert.DeserializeObject <Post>(File.ReadAllText(file));
            userdb.Add(post);
        }

        var authorized = userdb.AuthorizedUsers().ToArray();

        string result = "";

        result += "~author: [";
        result += string.Join(", ", authorized.OrderBy(user => user));
        result += "]";

        Dbg.Inf(result);

        authorized.Shuffle();

        Dbg.Inf("Random sample of authorized users: " + string.Join(" ", authorized.Take(20).Select(user => $"/u/{user}")));
    }
コード例 #2
0
ファイル: Bootstrap.cs プロジェクト: zorbathut/babytoy
    public override void _Input(InputEvent eve)
    {
        base._Input(eve);

        if (eve is InputEventKey evekey)
        {
            // stoooop
            var key = (Godot.KeyList)evekey.Scancode;

            if (!evekey.Pressed || evekey.Echo)
            {
                return;
            }

            Dbg.Inf($"{key}");

            foreach (var button in buttons)
            {
                if (button.key == key)
                {
                    button.node.FindNode <AudioStreamPlayer>("audio").Play();
                    button.node.FindNode <AnimationPlayer>("player").Play("flash");
                    button.node.FindNode <AnimationPlayer>("player").Seek(0);    // want it to reset
                }
            }
        }
    }
コード例 #3
0
    private static IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam)
    {
        bool blnEat = false;

        Dbg.Inf("LLKPA");

        try
        {
            var o = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));

            Dbg.Inf("LLKP");
            switch (wParam.ToInt64())
            {
            case 256:
            case 257:
            case 260:
            case 261:

                //Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key,
                blnEat = ((o.vkCode == 9) && (o.flags == 32))    // alt+tab
                         | ((o.vkCode == 27) && (o.flags == 32)) // alt+esc
                         | ((o.vkCode == 27) && (o.flags == 0))  // ctrl+esc
                         | ((o.vkCode == 91) && (o.flags == 1))  // left winkey
                         | ((o.vkCode == 92) && (o.flags == 1))
                         | ((o.vkCode == 73) && (o.flags == 0));

                break;
            }
        }
        catch (Exception ex)
        {
            Dbg.Ex(ex);
        }

        Dbg.Inf($"LLKP BIE {blnEat}");

        if (blnEat == true)
        {
            return((IntPtr)1);
        }
        else
        {
            return(CallNextHookEx(hookHandle, nCode, wParam, lParam));
        }
    }
コード例 #4
0
    public static IEnumerable <T> ProgressBar <T>(this IEnumerable <T> input, bool shuffle = true)
    {
        var values = input.ToArray();

        if (shuffle)
        {
            values.Shuffle();
        }

        // in seconds
        float accumulatedTime  = 0;
        float accumulatedItems = 0;

        DateTimeOffset lastShown = DateTimeOffset.Now;

        for (int i = 0; i < values.Length; ++i)
        {
            var startTime = DateTimeOffset.Now;

            yield return(values[i]);

            var deltaTime = (DateTimeOffset.Now - startTime);

            // exponential falloff calculation; 50% every minute
            var falloff = (float)Math.Pow(0.5f, deltaTime.TotalMinutes);

            accumulatedTime  *= falloff;
            accumulatedItems *= falloff;

            accumulatedTime  += (float)deltaTime.TotalSeconds;
            accumulatedItems += 1;

            if (i > 0 && (DateTimeOffset.Now - lastShown).TotalSeconds > 0.2f)
            {
                var remaining = (values.Length - i) * (accumulatedTime / accumulatedItems);

                Dbg.Inf($"{i} / {values.Length} -- ETA {remaining / 60:F2}m");
                lastShown = DateTimeOffset.Now;
            }
        }
    }
コード例 #5
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);
        }
    }
コード例 #6
0
ファイル: Bootstrap.cs プロジェクト: zorbathut/babytoy
    public override void _PhysicsProcess(float delta)
    {
        base._PhysicsProcess(delta);

        if (!processed)
        {
            var samples = new List <AudioInfo>();

            foreach (var fname in Util.GetFilesFromDir("res://").Where(fname => !fname.Contains("/.") && fname.EndsWith(".wav.import")))
            {
                samples.Add(new AudioInfo()
                {
                    stream = ResourceLoader.Load(fname.Substring(0, fname.Length - 7)) as AudioStream, weight = 1
                });
            }

            var buttonresource = ResourceLoader.Load("res://button/button.tscn") as PackedScene;
            var buttonexample  = buttonresource.Instance() as Node2D;
            var buttonsize     = (buttonexample.FindNode("image") as Sprite).Texture.GetSize();

            // Init all the buttons
            foreach (var button in Def.Database <ButtonDef> .List)
            {
                var buttoninstance = buttonresource.Instance() as Node2D;
                GetParent().AddChild(buttoninstance);
                buttoninstance.Position = button.position * buttonsize;

                buttoninstance.FindNode <Sprite>("image").Texture = ResourceLoader.Load($"res://button/{(int)(button.size.y * 100)}.{(int)(button.size.x * 100)}.outline.png") as Texture;
                buttoninstance.FindNode <Sprite>("flash").Texture = ResourceLoader.Load($"res://button/{(int)(button.size.y * 100)}.{(int)(button.size.x * 100)}.solid.png") as Texture;

                var sample = samples.RandomElementByWeight(ai => ai.weight);
                samples.Remove(sample);

                buttoninstance.FindNode <AudioStreamPlayer>("audio").Stream = sample.stream;

                KeyList key = (KeyList)0;
                if (button.linkage != (KeyList)0)
                {
                    key = button.linkage;
                }
                else
                {
                    try
                    {
                        key = (KeyList)Enum.Parse(typeof(KeyList), button.defName);
                    }
                    catch (ArgumentException)
                    {
                        Dbg.Inf($"Failed to parse {button.defName}");
                    }
                }

                if (key != (KeyList)0)
                {
                    buttons.Add(new ButtonInfo()
                    {
                        key = key, def = button, node = buttoninstance
                    });
                }
            }
            processed = true;
        }

        foreach (var button in buttons)
        {
            var image = button.node.FindNode <Sprite>("image");
            image.SelfModulate = new Color(button.r.Evaluate(), button.g.Evaluate(), button.b.Evaluate());
            image.Offset       = new Vector2(button.x.Evaluate(), button.y.Evaluate());
        }
    }