Skip to content

Commit

Permalink
feat: remove useless lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
AmanMenda committed May 2, 2024
1 parent df5e307 commit 68f121d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Libraries/include/Logic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Stuckfish
{
public:
// method to check if username exists on Chess.com
bool IsChessComUser(const std::string& username);
bool IsChessDotComUser(const std::string& username);
// method to fetch all the games played by the "specified" user in the month.
void GamesPlayedWithinPeriod(const std::string& username, const std::string& year, const std::string& month);
private:
Expand Down
23 changes: 2 additions & 21 deletions Libraries/include/Page.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,34 +76,15 @@ namespace Stuckfish
class Page
{
public:
//static Page& GetInstance(Core& app, Logic& logic);


virtual ~Page() = default; // virtual destructor as the class will be inherited.
virtual void OnUpdate() {};
virtual void OnUIRender() {};
virtual void OnAttach() {};
virtual void OnDetach() {};

/*Page(const Page&) = delete;
void operator=(const Page&) = delete;
Page(Page&&) noexcept = default;
Page& operator=(Page&&) noexcept = default;
std::string& GetUsername(void)
{
return _username;
}*/

public:
bool _errorOccured = false;
std::string _errorMessage = "";

protected:
//Page(Core& app, Logic& logic);
//Core& _app;
//Logic& _logic;

//std::string _username = "";
std::string _errorMessage = "";
};
}
8 changes: 3 additions & 5 deletions Libraries/include/Stuckfish.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ namespace Stuckfish
_pageStack.emplace_back(std::make_shared<T>(std::forward<Args>(args)...));
}

template<typename T>
/*template<typename T>
T& GetLayer() {
return dynamic_cast<T&>(*(_pageStack.front()));
}
}*/

std::vector<std::shared_ptr<Page>>& GetPageStack(void)
{
Expand All @@ -68,8 +68,6 @@ namespace Stuckfish
void RemoveErrorPopup(void);

public:
bool _isRunning = true;

ImFont* _robotoFontHeader = nullptr;
ImFont* _robotoFontBody = nullptr;
ImFont* _robotoFontBodyMedium = nullptr;
Expand All @@ -87,5 +85,5 @@ namespace Stuckfish
std::vector<std::shared_ptr<Page>> _pageStack;
};

std::unique_ptr<Core> CreateApplication(int argc, char* argv[]);
std::unique_ptr<Core> CreateApplication(void);
};
2 changes: 1 addition & 1 deletion Sources/App/Logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static std::string to_lower(std::string s) {

namespace Stuckfish
{
bool Logic::IsChessComUser(const std::string& username)
bool Logic::IsChessDotComUser(const std::string& username)
{
std::string url = "https://api.chess.com/pub/player/" + to_lower(username);
cpr::Response res = cpr::Get(cpr::Url{ url });
Expand Down
54 changes: 25 additions & 29 deletions Sources/App/Stuckfish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,36 @@ namespace Stuckfish
ImGuiIO& io = ImGui::GetIO(); (void)io;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);

#ifdef __EMSCRIPTEN__
io.IniFilename = nullptr;
EMSCRIPTEN_MAINLOOP_BEGIN
#else
while (!glfwWindowShouldClose(_window))
#endif
{
glfwPollEvents();
while (!glfwWindowShouldClose(_window))
{
glfwPollEvents();

// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();

{
{

_pageStack.front()->OnUIRender();
if (_pageStack.front()->_errorOccured)
DisplayErrorPopup(_pageStack.front()->_errorMessage.c_str());
}

ImGui::Render();

glViewport(0, 0, _specs.width, _specs.height);
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(_window);
_pageStack.front()->OnUIRender();
if (_pageStack.front()->_errorOccured)
DisplayErrorPopup(_pageStack.front()->_errorMessage.c_str());
}

ImGui::Render();

glViewport(0, 0, _specs.width, _specs.height);
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(_window);
}
}

void Core::Quit(void)
{
//for (auto& page : _pageStack)
//page.reset();
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
Expand All @@ -126,16 +123,15 @@ namespace Stuckfish
return *current_instance;
}

std::unique_ptr<Core> CreateApplication(int argc, char* argv[])
std::unique_ptr<Core> CreateApplication(void)
{
WindowSpecs specs;

std::unique_ptr<Core> app = std::make_unique<Core>(specs);
//Page& page = Page::GetInstance(Core::Get(), appLogic);

app->PushLayer<UserInfosPage>(Core::Get(), app->_appLogic, app->_userData);
app->PushLayer<UserInfosPage>(Core::Get(), app->_appLogic, app-> _userData);
app->PushLayer<GamesPlayedPage>(Core::Get(), app->_appLogic, app->_userData);

return app;
}

Expand Down
8 changes: 3 additions & 5 deletions Sources/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

int main(int argc, char* argv[])
{
std::unique_ptr<Stuckfish::Core> app = Stuckfish::CreateApplication(argc, argv);
std::unique_ptr<Stuckfish::Core> app = Stuckfish::CreateApplication();

while (app->_isRunning)
{
app->Run();
}
app->Run();
app.release();

return 0;
}
15 changes: 0 additions & 15 deletions Sources/UI/Page.cpp

This file was deleted.

10 changes: 6 additions & 4 deletions Sources/UI/UserInfosPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ namespace Stuckfish

ImGui::SetNextWindowPos(windowPos, ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(static_cast<float>(_app._specs.width) / 2, static_cast<float>(_app._specs.height) / 2), ImGuiCond_Always);
ImGui::Begin(WindowTitlesToString(WindowTitle::USERINFO_PAGE), NULL, ImGuiWindowFlags_NoTitleBar |
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBackground |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBringToFrontOnFocus);

ImGui::Begin(WindowTitlesToString(WindowTitle::USERINFO_PAGE), NULL, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoBringToFrontOnFocus);
ImVec2 contentRegion = ImGui::GetContentRegionAvail();
ImVec2 windowMiddlePos = ImVec2(contentRegion.x / 2.0f, contentRegion.y / 2.0f);

Expand Down Expand Up @@ -44,15 +47,14 @@ namespace Stuckfish
void UserInfosPage::OnUpdate()
{
//std::string& username = _activeSession.GetUsername();

if (_userdata.username.empty())
{
_errorOccured = true;
_errorMessage = ErrorsToString(Errors::EMPTY_USERNAME);
return;
}

bool user_exists = _logic.IsChessComUser(_userdata.username);
bool user_exists = _logic.IsChessDotComUser(_userdata.username);

if (!user_exists)
{
Expand All @@ -61,7 +63,7 @@ namespace Stuckfish
return;
}

_app.GetLayer<UserInfosPage>().OnDetach();
OnDetach();
return;
}

Expand Down
1 change: 0 additions & 1 deletion Stuckfish.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
<ClCompile Include="Sources\Main.cpp" />
<ClCompile Include="Sources\UI\fonts.cpp" />
<ClCompile Include="Sources\UI\GamesPlayedPage.cpp" />
<ClCompile Include="Sources\UI\Page.cpp" />
<ClCompile Include="Sources\UI\UserInfosPage.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 68f121d

Please sign in to comment.