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

Return-To-The-Roots / s25client / 14558085972

20 Apr 2025 09:19AM UTC coverage: 50.309% (+0.02%) from 50.288%
14558085972

Pull #1760

github

web-flow
Merge 6739ec4e2 into c8cf430f2
Pull Request #1760: [Combination] Fix loading of Lua GameData and CI updates

11 of 26 new or added lines in 14 files covered. (42.31%)

2 existing lines in 1 file now uncovered.

22365 of 44455 relevant lines covered (50.31%)

36183.12 hits per line

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

0.0
/libs/s25main/desktops/dskGameLoader.cpp
1
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
2
//
3
// SPDX-License-Identifier: GPL-2.0-or-later
4

5
#include "dskGameLoader.h"
6
#include "Game.h"
7
#include "Loader.h"
8
#include "WindowManager.h"
9
#include "controls/ctrlText.h"
10
#include "controls/ctrlTimer.h"
11
#include "dskDirectIP.h"
12
#include "dskGameInterface.h"
13
#include "dskLobby.h"
14
#include "dskSinglePlayer.h"
15
#include "files.h"
16
#include "ingameWindows/iwMsgbox.h"
17
#include "network/GameClient.h"
18
#include "ogl/FontStyle.h"
19
#include "liblobby/LobbyClient.h"
20
#include <memory>
21
#include <utility>
22

23
/**
24
 *  Konstruktor von @p dskGameLoader.
25
 *  Startet das Spiel und lädt alles Notwendige.
26
 */
27
dskGameLoader::dskGameLoader(std::shared_ptr<Game> game)
×
28
    : Desktop(LOADER.GetImageN(ResourceId(LOAD_SCREENS[rand() % LOAD_SCREENS.size()]), 0)), position(0),
×
29
      loader_(LOADER, std::move(game))
×
30
{
31
    WINDOWMANAGER.SetCursor(Cursor::None);
×
32

33
    using namespace std::chrono_literals;
34
    AddTimer(1, 50ms);
×
35

36
    AddText(10, DrawPoint(800 / 2, 600 - 50), "", COLOR_YELLOW, FontStyle::CENTER, LargeFont);
×
37

38
    for(unsigned i = 0; i < 8; ++i)
×
39
        AddText(11 + i, DrawPoint(30, 30 + i * 20), "", COLOR_GREEN, FontStyle{}, LargeFont);
×
40

41
    LOBBYCLIENT.AddListener(this);
×
42
    GAMECLIENT.SetInterface(this);
×
43
}
×
44

45
dskGameLoader::~dskGameLoader()
×
46
{
47
    WINDOWMANAGER.SetCursor();
×
48
    LOBBYCLIENT.RemoveListener(this);
×
49
    GAMECLIENT.RemoveInterface(this);
×
50
}
×
51

52
void dskGameLoader::Msg_MsgBoxResult(const unsigned msgbox_id, const MsgboxResult /*mbr*/)
×
53
{
54
    if(msgbox_id == 0) // Verbindung zu Server verloren?
×
55
    {
56
        GAMECLIENT.Stop();
×
57

58
        if(LOBBYCLIENT.IsLoggedIn()) // steht die Lobbyverbindung noch?
×
59
            WINDOWMANAGER.Switch(std::make_unique<dskLobby>());
×
60
        else if(loader_.getGame()->world_.IsSinglePlayer())
×
61
            WINDOWMANAGER.Switch(std::make_unique<dskSinglePlayer>());
×
62
        else
63
            WINDOWMANAGER.Switch(std::make_unique<dskDirectIP>());
×
64
    }
65
}
×
66

67
void dskGameLoader::Msg_Timer(const unsigned /*ctrl_id*/)
×
68
{
69
    auto* timer = GetCtrl<ctrlTimer>(1);
×
70
    auto* text = GetCtrl<ctrlText>(10 + position);
×
71
    using namespace std::chrono_literals;
72
    const auto interval = 50ms;
×
73

74
    timer->Stop();
×
75

76
    switch(position)
×
77
    {
78
        case 0: // Kartename anzeigen
×
79
            text->SetText(GAMECLIENT.GetMapTitle());
×
80
            break;
×
81

82
        case 1: // Karte geladen
×
83
            text->SetText(_("Map was loaded and pinned at the wall..."));
×
84
            break;
×
85

86
        case 2: // Nationen ermitteln
×
87
            loader_.initNations();
×
88

89
            text->SetText(_("Tribal chiefs assembled around the table..."));
×
90
            break;
×
91

92
        case 3: // Objekte laden
×
93
        {
94
            loader_.initTextures();
×
95
            if(!loader_.loadTextures())
×
96
            {
97
                ShowErrorMsg(_("Failed to load game resources"));
×
98
                return; // Don't restart timer!
×
99
            }
100

101
            text->SetText(_("Game crate was picked and spread out..."));
×
102
            break;
×
103
        }
104
        case 4: // Welt erstellen
×
105
            try
106
            {
107
                // Do this here as it will init OGL
108
                gameInterface = std::make_unique<dskGameInterface>(loader_.getGame(), GAMECLIENT.GetNWFInfo(),
×
109
                                                                   GAMECLIENT.GetPlayerId());
×
NEW
110
            } catch(const std::runtime_error& e)
×
111
            {
112
                ShowErrorMsg(std::string(_("Failed to init GUI: ")) + e.what());
×
113
                return;
×
114
            }
115
            // TODO: richtige Messages senden, um das zu laden /*GetMap()->GenerateOpenGL();*/
116

117
            // We are done, wait for others
118
            GAMECLIENT.GameLoaded();
×
119

120
            text->SetText(_("World was put together and glued..."));
×
121
            break;
×
122

123
        case 5: // nochmal text anzeigen
×
124
            text->SetText(_("And let's go!"));
×
125
            text->SetTextColor(COLOR_RED);
×
126
            return;
×
127
    }
128

129
    ++position;
×
130
    timer->Start(interval);
×
131
}
132

133
void dskGameLoader::ShowErrorMsg(const std::string& error)
×
134
{
135
    auto wnd = std::make_unique<iwMsgbox>(_("Error"), error, this, MsgboxButton::Ok, MsgboxIcon::ExclamationRed, 0);
×
136
    if(IsActive())
×
137
        WINDOWMANAGER.Show(std::move(wnd));
×
138
    else
139
        WINDOWMANAGER.ShowAfterSwitch(std::move(wnd));
×
140
    GetCtrl<ctrlTimer>(1)->Stop();
×
141
}
×
142

143
/**
144
 *  (Lobby-)Status: Benutzerdefinierter Fehler (kann auch Conn-Loss o.ä sein)
145
 */
146
void dskGameLoader::LC_Status_Error(const std::string& error)
×
147
{
148
    ShowErrorMsg(error);
×
149
}
×
150

151
void dskGameLoader::CI_GameStarted()
×
152
{
153
    RTTR_Assert(gameInterface);
×
154
    WINDOWMANAGER.Switch(std::move(gameInterface));
×
155
}
×
156

157
void dskGameLoader::CI_Error(const ClientError ce)
×
158
{
159
    ShowErrorMsg(ClientErrorToStr(ce));
×
160
}
×
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