Skip to content

Commit

Permalink
Add Utilities class to add utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordonbc committed Apr 6, 2024
1 parent ea7042c commit ce7de29
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions HarmonyLinkLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ set(COMMON_SOURCES
"src/Version.cpp"
"src/dllmain.cpp"
"src/Platform/WineUtilities.cpp"
"src/Utilities.cpp"
)

# Explicitly list include files
set(COMMON_INCLUDES
"include/Core.h"

"include/Structs/FBattery.h"
"include/Structs/FOSVerInfo.h"
"include/Structs/FDevice.h"
Expand All @@ -53,6 +55,8 @@ set(COMMON_INCLUDES

"src/Platform/IPlatformUtilities.h"
"src/Platform/WineUtilities.h"

"src//Utilities.h"
)

set(WINDOWS_SOURCES
Expand Down
12 changes: 12 additions & 0 deletions HarmonyLinkLib/src/Platform/IPlatformUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include "IPlatformUtilities.h"

#include <format>
#include <set>
#include "Utilities.h"

#include "WineUtilities.h"
#if BUILD_WINDOWS
Expand Down Expand Up @@ -100,35 +102,45 @@ namespace HarmonyLinkLib

uint8_t score = 0;

Utilities::DebugPrint("Detected: ", false);

if (is_charging())
{
Utilities::DebugPrint("Charging, ", false);
score += CHARGING_SCORE;
}

if (get_is_external_monitor_connected())
{
Utilities::DebugPrint("External monitor, ", false);
score += EXTERNAL_MONITOR_SCORE;
}

if (get_is_steam_deck_native_resolution())
{
Utilities::DebugPrint("Non-native resolution, ", false);
score += STEAM_DECK_RESOLUTION_SCORE;
}

if (get_keyboard_detected())
{
Utilities::DebugPrint("keyboard ", false);
score += KEYBOARD_DETECTION_SCORE;
}

if (get_mouse_detected())
{
Utilities::DebugPrint("mouse, ", false);
score += MOUSE_DETECTION_SCORE;
}

if (get_external_controller_detected())
{
Utilities::DebugPrint("external controller, ", false);
score += CONTROLLER_DETECTION_SCORE;
}

Utilities::DebugPrint(std::format("Score: {}/{}", score, FINAL_TARGET_DETECTION_SCORE).c_str());

return score >= FINAL_TARGET_DETECTION_SCORE;
}
Expand Down
53 changes: 53 additions & 0 deletions HarmonyLinkLib/src/Utilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "Utilities.h"

#include <iostream>

#include "FString.h"

void HarmonyLinkLib::Utilities::DebugPrint(const FString& String, bool AddNewline)
{
#ifdef DEBUG_MODE
std::wcout << String.c_str();

if (AddNewline)
{
std::wcout << L"\n";
}
#endif
}

void HarmonyLinkLib::Utilities::DebugPrint(const char* String, bool AddNewline)
{
#ifdef DEBUG_MODE
std::wcout << std::wstring(String, String + std::strlen(String));

if (AddNewline) {
std::wcout << L"\n";
}
#endif
}

void HarmonyLinkLib::Utilities::DebugPrint(const wchar_t* String, bool AddNewline)
{
#ifdef DEBUG_MODE
std::wcout << String;

if (AddNewline) {
std::wcout << L"\n";
}
#endif
}
30 changes: 30 additions & 0 deletions HarmonyLinkLib/src/Utilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2024 Jordon Brooks
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "HarmonyLinkLib.h"

namespace HarmonyLinkLib
{
class FString;

class Utilities
{
public:
static void DebugPrint(const FString& String, bool AddNewline = true);
static void DebugPrint(const char* String, bool AddNewline = true);
static void DebugPrint(const wchar_t* String, bool AddNewline = true);
};
}

0 comments on commit ce7de29

Please sign in to comment.