Created
March 26, 2023 21:18
-
-
Save samueldr/b8b764e618e7ff74cad7eca96c4abef1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { pkgs ? import <nixpkgs> {} }: | |
| let | |
| candyCrisis = | |
| { stdenv | |
| , writeText | |
| , runtimeShell | |
| , fetchFromGitHub | |
| , cmake | |
| , SDL2 | |
| }: | |
| stdenv.mkDerivation { | |
| pname = "CandyCrisis"; | |
| version = "unstable-2023-02-11"; | |
| src = fetchFromGitHub { | |
| owner = "jorio"; | |
| repo = "CandyCrisis"; | |
| rev = "ae730c8d493b92bcc630806267532f063bad35f4"; # master branch | |
| sha256 = "sha256-a3fxvXzRQM4kBZy3/exRAV31JeYEHaov7JM1JOyllxs="; | |
| }; | |
| patches = [ | |
| (writeText "CandyCrisis.patch" '' | |
| From ef69e50be3d4e32f41fb847f6ec6043d0eac7cf3 Mon Sep 17 00:00:00 2001 | |
| From: Samuel Dionne-Riel <samuel@dionne-riel.com> | |
| Date: Sun, 26 Mar 2023 17:10:07 -0400 | |
| Subject: [PATCH 1/2] Fix SDL2main dep | |
| --- | |
| CMakeLists.txt | 6 ++++-- | |
| 1 file changed, 4 insertions(+), 2 deletions(-) | |
| diff --git a/CMakeLists.txt b/CMakeLists.txt | |
| index bb77465..9b88dc8 100644 | |
| --- a/CMakeLists.txt | |
| +++ b/CMakeLists.txt | |
| @@ -68,8 +68,10 @@ if(NOT BUILD_SDL_FROM_SOURCE) | |
| # 1. Look for an SDL2 package, 2. look for the SDL2 component and 3. fail if none can be found | |
| find_package(SDL2 CONFIG REQUIRED COMPONENTS SDL2) | |
| - # 1. Look for an SDL2 package, 2. Look for the SDL2maincomponent and 3. DO NOT fail when SDL2main is not available | |
| - find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) | |
| + if(WIN32) | |
| + # 1. Look for an SDL2 package, 2. Look for the SDL2maincomponent and 3. DO NOT fail when SDL2main is not available | |
| + find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main) | |
| + endif() | |
| message("Found pre-built SDL: " ''${SDL2_PREFIX}) | |
| else() | |
| -- | |
| 2.39.2 | |
| From 08cc59cdea8ccb6bc5a29013ada19028249f1c94 Mon Sep 17 00:00:00 2001 | |
| From: Samuel Dionne-Riel <samuel@dionne-riel.com> | |
| Date: Sun, 26 Mar 2023 17:10:22 -0400 | |
| Subject: [PATCH 2/2] Fix build with CURSOR_SPRITE | |
| Relying on non-cursor sprites fails under wayland. | |
| --- | |
| src/level.c | 10 ++++++---- | |
| 1 file changed, 6 insertions(+), 4 deletions(-) | |
| diff --git a/src/level.c b/src/level.c | |
| index 0d3667a..05f838d 100644 | |
| --- a/src/level.c | |
| +++ b/src/level.c | |
| @@ -505,11 +505,13 @@ redo: | |
| // Reinsert the cursor into the scene | |
| #if USE_CURSOR_SPRITE | |
| + #define MAX(x, y) (((x) > (y)) ? (x) : (y)) | |
| + #define MIN(x, y) (((x) < (y)) ? (x) : (y)) | |
| InsertCursor( mouse, cursorBackSurface, gameStartDrawSurface ); | |
| - drawRect[kCursor].top = min<short>( drawRect[kCursor].top, mouse.v ); | |
| - drawRect[kCursor].left = min<short>( drawRect[kCursor].left, mouse.h ); | |
| - drawRect[kCursor].bottom = max<short>( drawRect[kCursor].bottom, mouse.v + kCursorHeight ); | |
| - drawRect[kCursor].right = max<short>( drawRect[kCursor].right, mouse.h + kCursorWidth ); | |
| + drawRect[kCursor].top = MIN( drawRect[kCursor].top, mouse.v ); | |
| + drawRect[kCursor].left = MIN( drawRect[kCursor].left, mouse.h ); | |
| + drawRect[kCursor].bottom = MAX( drawRect[kCursor].bottom, mouse.v + kCursorHeight ); | |
| + drawRect[kCursor].right = MAX( drawRect[kCursor].right, mouse.h + kCursorWidth ); | |
| #endif | |
| SDLU_SetSystemCursor( selected < 0 ? SYSTEM_CURSOR_ARROW : SYSTEM_CURSOR_HAND ); | |
| -- | |
| 2.39.2 | |
| '') | |
| ]; | |
| buildInputs = [ | |
| SDL2 | |
| ]; | |
| nativeBuildInputs = [ | |
| cmake | |
| ]; | |
| cmakeFlags = [ | |
| "-DCMAKE_BUILD_TYPE=Release" | |
| ]; | |
| # SDLU_SetSystemCursor ends-up segfaulting at Wayland_ShowCursor | |
| env.NIX_CFLAGS_COMPILE = "-DUSE_CURSOR_SPRITE"; | |
| installPhase = '' | |
| mkdir -p $out/opt | |
| cp -rv -t $out/opt \ | |
| CandyCrisisResources \ | |
| "$pname" \ | |
| ReadMe.txt | |
| mkdir -p $out/bin | |
| # The game only checks PWD for the Data directory. | |
| cat <<EOF > $out/bin/"$pname" | |
| #!${runtimeShell} | |
| cd "$out/opt/" | |
| exec "./$pname" "$@" | |
| EOF | |
| chmod +x $out/bin/"$pname" | |
| ''; | |
| } | |
| ; | |
| in | |
| { | |
| CandyCrisis = pkgs.callPackage candyCrisis {}; | |
| cross = { | |
| aarch64.CandyCrisis = pkgs.pkgsCross.aarch64-multiplatform.callPackage candyCrisis {}; | |
| armv7l.CandyCrisis = pkgs.pkgsCross.armv7l-hf-multiplatform.callPackage candyCrisis {}; | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment