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

Return-To-The-Roots / s25client / 12453286720

22 Dec 2024 10:04AM UTC coverage: 50.282% (+0.06%) from 50.225%
12453286720

Pull #1723

github

web-flow
Merge e36a78ef6 into 17844c810
Pull Request #1723: Add cheat to enable all buildings

18 of 22 new or added lines in 4 files covered. (81.82%)

6 existing lines in 3 files now uncovered.

22346 of 44441 relevant lines covered (50.28%)

36672.67 hits per line

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

68.97
/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()) {}
14✔
18

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

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

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

35
    if(cmd == "apocalypsis")
×
36
        cheats_.armageddon();
×
NEW
37
    else if(cmd == "impulse9")
×
NEW
38
        cheats_.toggleAllBuildingsEnabled();
×
39
}
40

41
bool CheatCommandTracker::checkSpecialKeyEvent(const KeyEvent& ke)
87✔
42
{
43
    if(ke.kt == KeyType::Char)
87✔
44
        return false;
86✔
45

46
    switch(ke.kt)
1✔
47
    {
48
        case KeyType::F7: cheats_.toggleAllVisible(); break;
×
49
        case KeyType::F10: cheats_.toggleHumanAIPlayer(); break;
1✔
50
        default: break;
×
51
    }
52

53
    return true;
1✔
54
}
55

56
void CheatCommandTracker::onCharKeyEvent(const KeyEvent& ke)
86✔
57
{
58
    lastChars_.push_back(ke.c);
86✔
59

60
    if(lastChars_ == enableCheatsStr)
86✔
61
        cheats_.toggleCheatMode();
6✔
62
}
86✔
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