about summary refs log tree commit diff
path: root/pkgs/games
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-09-10 18:26:39 +0200
committeraszlig <aszlig@nix.build>2018-09-10 18:27:14 +0200
commit66ddae3556371045332884440d7a1a0ad0a70c9c (patch)
tree08b05e384d67fe98186569746a862eb75b50e350 /pkgs/games
parente5ab073e1b4a53fe68755a4a073d5b8d5b6b19fc (diff)
games/humblebundle: Add Trine 2
Had this lying around for a while already, so just adding for
completeness.

I've tested whether the game still works.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/games')
-rw-r--r--pkgs/games/humblebundle/default.nix1
-rw-r--r--pkgs/games/humblebundle/trine2.nix97
2 files changed, 98 insertions, 0 deletions
diff --git a/pkgs/games/humblebundle/default.nix b/pkgs/games/humblebundle/default.nix
index 4a0792c4..77069bb7 100644
--- a/pkgs/games/humblebundle/default.nix
+++ b/pkgs/games/humblebundle/default.nix
@@ -31,6 +31,7 @@ let
     spaz = callPackage ./spaz.nix {};
     starbound = callPackage ./starbound.nix {};
     swordsandsoldiers = callPackage ./swordsandsoldiers.nix {};
+    trine2 = callPackage_i686 ./trine2.nix {};
     unepic = callPackage ./unepic.nix {};
   };
 in with lib; {
diff --git a/pkgs/games/humblebundle/trine2.nix b/pkgs/games/humblebundle/trine2.nix
new file mode 100644
index 00000000..a6cef22d
--- /dev/null
+++ b/pkgs/games/humblebundle/trine2.nix
@@ -0,0 +1,97 @@
+{ buildGame, fetchHumbleBundle, makeWrapper, runCommandCC, writeText
+, coreutils, openal, libvorbis, libGLU, SDL2, freetype, alsaLib
+}:
+
+buildGame rec {
+  name = "trine2-${version}";
+  version = "2.01";
+
+  src = fetchHumbleBundle {
+    machineName = "trine2complete_linux";
+    suffix = "zip";
+    md5 = "82049b65c1bce6841335935bc05139c8";
+  };
+
+  nativeBuildInputs = [ makeWrapper ];
+  buildInputs = [ openal libvorbis libGLU freetype alsaLib ];
+
+  patchPhase = ''
+    patchelf --replace-needed libSDL-1.3.so.0 libSDL.so \
+      bin/trine2_linux_32bit
+    patchelf --replace-needed libPhysXLoader.so.1 libPhysXLoader.so \
+      bin/trine2_linux_32bit
+  '';
+
+  getResolutionArgs = runCommandCC "get-resolution-args" {
+    buildInputs = [ SDL2 ];
+    src = writeText "get-resolution-args.c" ''
+      #include <SDL.h>
+
+      int main(void)
+      {
+        int width = 0, height = 0;
+        SDL_DisplayMode current;
+
+        SDL_Init(SDL_INIT_VIDEO);
+
+        int displays = SDL_GetNumVideoDisplays();
+
+        for (int i = 0; i < displays; ++i) {
+          if (SDL_GetCurrentDisplayMode(i, &current) != 0)
+            goto err;
+
+          if (current.w * current.h > width * height) {
+            width = current.w;
+            height = current.h;
+          }
+        }
+
+        if (width == 0 && height == 0)
+          goto err;
+
+        SDL_Quit();
+        printf("-RenderingModule:DetectedFullscreenWidth=%d\n", width);
+        printf("-RenderingModule:DetectedFullscreenHeight=%d\n", height);
+        return EXIT_SUCCESS;
+
+      err:
+        fputs("Unable to get current display mode.\n", stderr);
+        SDL_Quit();
+        return EXIT_FAILURE;
+      }
+    '';
+  } "gcc -Wall $(sdl2-config --cflags --libs) -o \"$out\" \"$src\"";
+
+  installPhase = ''
+    for name in Cg CgGL PhysXCooking PhysXCore PhysXLoader; do
+      install -vD "lib/lib32/lib$name.so" "$out/libexec/trine2/lib$name.so"
+    done
+
+    install -vD lib/lib32/libSDL-1.3.so.0 "$out/libexec/trine2/libSDL.so"
+
+    mkdir -p "$out/share/trine2"
+    cp -rvt "$out/share/trine2" *.fbq trine2.png data
+
+    install -vD bin/trine2_linux_32bit "$out/libexec/trine2/trine2"
+
+    rtDataPath="\''${XDG_DATA_HOME:-\$HOME/.local/share}"
+    makeWrapper "$out/libexec/trine2/trine2" "$out/bin/trine2" \
+      --run "cd '$out/share/trine2'" \
+      --run '${coreutils}/bin/ln -s "'"$rtDataPath"'" "$HOME/.frozenbyte"' \
+      --prefix LD_LIBRARY_PATH : "$out/libexec/trine2" \
+      --add-flags "\$($getResolutionArgs)"
+
+    mkdir -p "$out/share/applications"
+    cat > "$out/share/applications/trine2.desktop" <<EOF
+    [Desktop Entry]
+    Name=Trine 2
+    Type=Application
+    Version=1.1
+    Exec=$out/bin/trine2
+    Icon=$out/share/trine2/trine2.png
+    Categories=Game
+    EOF
+  '';
+
+  sandbox.paths.required = [ "$XDG_DATA_HOME/Trine2" ];
+}