Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ build.ninja
Testing/
compile_commands.json
_deps/
!/cmake/get_cpm.cmake
12 changes: 12 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"configurations": [
{
"name": "Win32",
"includePath": ["${default}"],
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"label": "Build",
"type": "shell",
"detail": "Run and build memory",
"command": "cmake --build . && cd build && ./Memory",
"command": "cd build && cmake --build . && ./Memory",
"windows": {
"command": "cmake --build . && cd build && Memory.exe"
"command": "cd build && cmake --build . && Memory.exe"
},
"group": "build",
"problemMatcher": "$gcc"
Expand Down
39 changes: 23 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
cmake_minimum_required(VERSION 3.11)
cmake_minimum_required(VERSION 3.24)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)

# ---- Project ----

project (
Memory
VERSION 0.1.0
LANGUAGES CXX
)

# ---- Dependencies ----

include(FetchContent)
include(cmake/get_cpm.cmake)
CPMAddPackage("gh:adsgames/asw@0.5.7")

project (Memory)
# ---- Source code ----

# Source code
file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h)

add_executable (${PROJECT_NAME} ${SOURCES} ${HEADERS})
# ---- Executable ----

add_executable (${PROJECT_NAME} ${SOURCES} ${HEADERS})
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic)

FetchContent_Declare(
asw
GIT_REPOSITORY https://github.com/adsgames/asw.git
GIT_TAG v0.5.4
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(asw)
# ---- Libs ----

# Link Libs
if(MINGW)
target_link_libraries(${PROJECT_NAME} -lmingw32)
endif(MINGW)
Expand All @@ -35,7 +39,8 @@ target_link_libraries(
asw
)

# Emscripten support
# ---- Emscripten ----

if(EMSCRIPTEN)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "index")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
Expand All @@ -55,5 +60,7 @@ if(EMSCRIPTEN)
)
endif(EMSCRIPTEN)

file(COPY ${CMAKE_CURRENT_LIST_DIR}/assets/ DESTINATION ${CMAKE_BINARY_DIR}/build/assets/)
# ---- Assets ----

file(COPY ${CMAKE_CURRENT_LIST_DIR}/assets/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets/)

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ Match all the cards on the table in four different difficulties. Compete against

## Setup

### Build
### CMake

```bash
cmake .
make
cmake -B build .
cmake --build ./build
```

### Build Emscripten

```bash
emcmake cmake .
make
emcmake cmake -B build .
cmake --build ./build
```
24 changes: 24 additions & 0 deletions cmake/get_cpm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.40.8)
set(CPM_HASH_SUM "78ba32abdf798bc616bab7c73aac32a17bbd7b06ad9e26a6add69de8f3ae4791")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()

# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)

file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)

include(${CPM_DOWNLOAD_LOCATION})
3 changes: 0 additions & 3 deletions sonar-project.properties

This file was deleted.

2 changes: 1 addition & 1 deletion src/ui/InputBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void InputBox::update() {

for (unsigned int i = 0; i <= text.length(); i++) {
const int textSize = asw::util::getTextSize(font, text.substr(0, i)).x;
const int distance = abs(textSize + x + 6 - asw::input::mouse.x);
const int distance = std::abs(textSize + x + 6 - asw::input::mouse.x);

if (distance < closest) {
textIterator = i;
Expand Down