AntiMicroX/antimicrox

Refactor class JoyButtonSlot

オープン

#376 opened on 2022/02/12

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)C++ (236 件のフォーク)auto 404
good first issuerefactor

Repository metrics

Stars
 (3,844 個のスター)
PR merge metrics
 (PR metrics pending)

説明

Class JoyButtonSlot should be divided into several smaller classes with common ancestor.

It would help to avoid mess in code.

New classes should describe actions and execution of them.
It would help avoiding things like:


void sendevent(JoyButtonSlot *slot, bool pressed)
{
    JoyButtonSlot::JoySlotInputAction device = slot->getSlotMode();

    if (device == JoyButtonSlot::JoyKeyboard)
    {
        EventHandlerFactory::getInstance()->handler()->sendKeyboardEvent(slot, pressed);
    } else if (device == JoyButtonSlot::JoyMouseButton)
    {
        EventHandlerFactory::getInstance()->handler()->sendMouseButtonEvent(slot, pressed);
    } else if ((device == JoyButtonSlot::JoyTextEntry) && pressed && !slot->getTextData().isEmpty())
    {
        EventHandlerFactory::getInstance()->handler()->sendTextEntryEvent(slot->getTextData());
    } else if ((device == JoyButtonSlot::JoyExecute) && pressed && !slot->getTextData().isEmpty())
    {
        ///....

Or

if ((tempcode == static_cast<int>(JoyButtonSlot::MouseWheelUp)) ||
            (tempcode == static_cast<int>(JoyButtonSlot::MouseWheelDown)))
        {
            slot->getMouseInterval()->restart();
            wheelVerticalTime.restart();
            currentWheelVerticalEvent = slot;
            getActiveSlotsLocal().append(slot);
            wheelEventVertical();
            currentWheelVerticalEvent = nullptr;
        } else if ((tempcode == static_cast<int>(JoyButtonSlot::MouseWheelLeft)) ||
                   (tempcode == static_cast<int>(JoyButtonSlot::MouseWheelRight)))
        {
            slot->getMouseInterval()->restart();
            wheelHorizontalTime.restart();

コントリビューターガイド