• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Return-To-The-Roots / s25client / 12326088439

14 Dec 2024 02:32AM UTC coverage: 50.208% (+0.04%) from 50.166%
12326088439

Pull #1688

github

web-flow
Merge 9e790e304 into 77372c5a4
Pull Request #1688: Refactoring of existing cheats (see #1679)

32 of 46 new or added lines in 4 files covered. (69.57%)

5 existing lines in 2 files now uncovered.

22296 of 44407 relevant lines covered (50.21%)

34821.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/libs/s25main/CheatCommandTracker.cpp
1
// Copyright (C) 2024 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "CheatCommandTracker.h"
6
#include "Cheats.h"
7
#include "driver/KeyEvent.h"
8

9
namespace {
10
auto makeCircularBuffer(const std::string& str)
9✔
11
{
12
    return boost::circular_buffer<char>{cbegin(str), cend(str)};
9✔
13
}
14
const auto enableCheatsStr = makeCircularBuffer("winter");
15
} // namespace
16

17
CheatCommandTracker::CheatCommandTracker(Cheats& cheats) : cheats_(cheats), lastChars_(enableCheatsStr.size()) {}
18✔
18

19
void CheatCommandTracker::onKeyEvent(const KeyEvent& ke)
117✔
20
{
21
    if(!cheats_.areCheatsAllowed())
117✔
22
        return;
6✔
23

24
    if(checkSpecialKeyEvent(ke))
111✔
25
        lastChars_.clear();
1✔
26
    else
27
        onCharKeyEvent(ke);
110✔
28
}
29

NEW
30
void CheatCommandTracker::onChatCommand(const std::string& cmd)
×
31
{
NEW
32
    if(!cheats_.areCheatsAllowed())
×
NEW
33
        return;
×
34

NEW
35
    if(cmd == "apocalypsis")
×
NEW
36
        cheats_.armageddon();
×
37
}
38

39
bool CheatCommandTracker::checkSpecialKeyEvent(const KeyEvent& ke)
111✔
40
{
41
    if(ke.kt == KeyType::Char)
111✔
42
        return false;
110✔
43

44
    switch(ke.kt)
1✔
45
    {
46
        case KeyType::F10: cheats_.toggleHumanAIPlayer(); break;
1✔
NEW
47
        default: break;
×
48
    }
49

50
    return true;
1✔
51
}
52

53
void CheatCommandTracker::onCharKeyEvent(const KeyEvent& ke)
110✔
54
{
55
    lastChars_.push_back(ke.c);
110✔
56

57
    if(lastChars_ == enableCheatsStr)
110✔
58
        cheats_.toggleCheatMode();
9✔
59
}
110✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc