Merge pull request #84873 from mnacamura/cdda-mods

cataclysmDDA: add modding interface
This commit is contained in:
worldofpeace 2020-07-22 16:18:32 -04:00 committed by GitHub
commit 8b6e9818a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 466 additions and 186 deletions

View file

@ -1,4 +1,4 @@
MD_TARGETS=$(addsuffix .xml, $(basename $(wildcard ./*.md ./**/*.md))) MD_TARGETS=$(addsuffix .xml, $(basename $(shell find . -type f -regex '.*\.md$$')))
.PHONY: all .PHONY: all
all: validate format out/html/index.html out/epub/manual.epub all: validate format out/html/index.html out/epub/manual.epub

View file

@ -0,0 +1,94 @@
# Cataclysm: Dark Days Ahead
## How to install Cataclysm DDA
To install the latest stable release of Cataclysm DDA to your profile, execute
`nix-env -f "<nixpkgs>" -iA cataclysm-dda`. For the curses build (build
without tiles), install `cataclysmDDA.stable.curses`. Note: `cataclysm-dda` is
an alias to `cataclysmDDA.stable.tiles`.
If you like access to a development build of your favorite git revision,
override `cataclysm-dda-git` (or `cataclysmDDA.git.curses` if you like curses
build):
```nix
cataclysm-dda-git.override {
version = "YYYY-MM-DD";
rev = "YOUR_FAVORITE_REVISION";
sha256 = "CHECKSUM_OF_THE_REVISION";
}
```
The sha256 checksum can be obtained by
```sh
nix-prefetch-url --unpack "https://github.com/CleverRaven/Cataclysm-DDA/archive/${YOUR_FAVORITE_REVISION}.tar.gz"
```
The default configuration directory is `~/.cataclysm-dda`. If you prefer
`$XDG_CONFIG_HOME/cataclysm-dda`, override the derivation:
```nix
cataclysm-dda.override {
useXdgDir = true;
}
```
## Customizing with mods
To install Cataclysm DDA with mods of your choice, you can use `withMods`
attribute:
```nix
cataclysm-dda.withMods (mods: with mods; [
tileset.UndeadPeople
])
```
All mods, soundpacks, and tilesets available in nixpkgs are found in
`cataclysmDDA.pkgs`.
Here is an example to modify existing mods and/or add more mods not available
in nixpkgs:
```nix
let
customMods = self: super: lib.recursiveUpdate super {
# Modify existing mod
tileset.UndeadPeople = super.tileset.UndeadPeople.overrideAttrs (old: {
# If you like to apply a patch to the tileset for example
patches = [ ./path/to/your.patch ];
});
# Add another mod
mod.Awesome = cataclysmDDA.buildMod {
modName = "Awesome";
version = "0.x";
src = fetchFromGitHub {
owner = "Someone";
repo = "AwesomeMod";
rev = "...";
sha256 = "...";
};
# Path to be installed in the unpacked source (default: ".")
modRoot = "contents/under/this/path/will/be/installed";
};
# Add another soundpack
soundpack.Fantastic = cataclysmDDA.buildSoundPack {
# ditto
};
# Add another tileset
tileset.SuperDuper = cataclysmDDA.buildTileSet {
# ditto
};
};
in
cataclysm-dda.withMods (mods: with mods.extend customMods; [
tileset.UndeadPeople
mod.Awesome
soundpack.Fantastic
tileset.SuperDuper
])
```

View file

@ -18,6 +18,7 @@
<xi:include href="opengl.xml" /> <xi:include href="opengl.xml" />
<xi:include href="shell-helpers.xml" /> <xi:include href="shell-helpers.xml" />
<xi:include href="steam.xml" /> <xi:include href="steam.xml" />
<xi:include href="cataclysm-dda.section.xml" />
<xi:include href="urxvt.xml" /> <xi:include href="urxvt.xml" />
<xi:include href="weechat.xml" /> <xi:include href="weechat.xml" />
<xi:include href="xorg.xml" /> <xi:include href="xorg.xml" />

View file

@ -0,0 +1,49 @@
{ stdenvNoCC, lib, type }:
assert lib.elem type [
"mod"
"soundpack"
"tileset"
];
{ modName, version, src, ... } @ args:
stdenvNoCC.mkDerivation (args // rec {
pname = args.pname or "cataclysm-dda-${type}-${modName}";
modRoot = args.modRoot or ".";
configurePhase = args.configurePhase or ''
runHook preConfigure
runHook postConfigure
'';
buildPhase = args.buildPhase or ''
runHook preBuild
runHook postBuild
'';
checkPhase = args.checkPhase or ''
runHook preCheck
runHook postCheck
'';
installPhase = let
baseDir = {
mod = "mods";
soundpack = "sound";
tileset = "gfx";
}.${type};
in args.installPhase or ''
runHook preInstall
destdir="$out/share/cataclysm-dda/${baseDir}"
mkdir -p "$destdir"
cp -R "${modRoot}" "$destdir/${modName}"
runHook postInstall
'';
passthru = {
forTiles = true;
forCurses = type == "mod";
};
})

View file

@ -1,6 +1,7 @@
{ stdenv, fetchFromGitHub, pkgconfig, gettext, ncurses, CoreFoundation { stdenv, runtimeShell, pkgconfig, gettext, ncurses, CoreFoundation
, tiles, SDL2, SDL2_image, SDL2_mixer, SDL2_ttf, freetype, Cocoa , tiles, SDL2, SDL2_image, SDL2_mixer, SDL2_ttf, freetype, Cocoa
, debug, runtimeShell , debug
, useXdgDir
}: }:
let let
@ -12,17 +13,46 @@ let
tilesDeps = [ SDL2 SDL2_image SDL2_mixer SDL2_ttf freetype ] tilesDeps = [ SDL2 SDL2_image SDL2_mixer SDL2_ttf freetype ]
++ optionals stdenv.isDarwin [ Cocoa ]; ++ optionals stdenv.isDarwin [ Cocoa ];
common = { installXDGAppLauncher = ''
launcher="$out/share/applications/cataclysm-dda.desktop"
install -D -m 444 data/xdg/*cataclysm-dda.desktop -T "$launcher"
sed -i "$launcher" -e "s,\(Exec=\)\(cataclysm-tiles\),\1$out/bin/\2,"
install -D -m 444 data/xdg/cataclysm-dda.svg -t $out/share/icons/hicolor/scalable/apps
'';
installMacOSAppLauncher = ''
app=$out/Applications/Cataclysm.app
install -D -m 444 data/osx/Info.plist -t $app/Contents
install -D -m 444 data/osx/AppIcon.icns -t $app/Contents/Resources
mkdir $app/Contents/MacOS
launcher=$app/Contents/MacOS/Cataclysm.sh
cat << EOF > $launcher
#!${runtimeShell}
$out/bin/cataclysm-tiles
EOF
chmod 555 $launcher
'';
in
stdenv.mkDerivation {
pname = "cataclysm-dda";
nativeBuildInputs = [ pkgconfig ]; nativeBuildInputs = [ pkgconfig ];
buildInputs = cursesDeps ++ optionals tiles tilesDeps; buildInputs = cursesDeps ++ optionals tiles tilesDeps;
postPatch = '' postPatch = ''
patchShebangs . patchShebangs .
# Locale patch required for Darwin builds, see:
# https://github.com/NixOS/nixpkgs/pull/74064#issuecomment-560083970
sed -i src/translations.cpp \
-e 's@#elif (defined(__linux__) || (defined(MACOSX) && !defined(TILES)))@#elif 1@'
''; '';
makeFlags = [ makeFlags = [
"PREFIX=$(out)" "USE_HOME_DIR=1" "LANGUAGES=all" "PREFIX=$(out)" "LANGUAGES=all"
(if useXdgDir then "USE_XDG_DIR=1" else "USE_HOME_DIR=1")
] ++ optionals (!debug) [ ] ++ optionals (!debug) [
"RELEASE=1" "RELEASE=1"
] ++ optionals tiles [ ] ++ optionals tiles [
@ -33,8 +63,8 @@ let
postInstall = optionalString tiles postInstall = optionalString tiles
( if !stdenv.isDarwin ( if !stdenv.isDarwin
then utils.installXDGAppLauncher then installXDGAppLauncher
else utils.installMacOSAppLauncher else installMacOSAppLauncher
); );
dontStrip = debug; dontStrip = debug;
@ -44,6 +74,11 @@ let
# make: *** [Makefile:687: obj/tiles/weather_data.o] Error 1 # make: *** [Makefile:687: obj/tiles/weather_data.o] Error 1
enableParallelBuilding = false; enableParallelBuilding = false;
passthru = {
isTiles = tiles;
isCurses = !tiles;
};
meta = with stdenv.lib; { meta = with stdenv.lib; {
description = "A free, post apocalyptic, zombie infested rogue-like"; description = "A free, post apocalyptic, zombie infested rogue-like";
longDescription = '' longDescription = ''
@ -74,36 +109,4 @@ let
maintainers = with maintainers; [ mnacamura ]; maintainers = with maintainers; [ mnacamura ];
platforms = platforms.unix; platforms = platforms.unix;
}; };
}; }
utils = {
fetchFromCleverRaven = { rev, sha256 }:
fetchFromGitHub {
owner = "CleverRaven";
repo = "Cataclysm-DDA";
inherit rev sha256;
};
installXDGAppLauncher = ''
launcher="$out/share/applications/cataclysm-dda.desktop"
install -D -m 444 data/xdg/*cataclysm-dda.desktop -T "$launcher"
sed -i "$launcher" -e "s,\(Exec=\)\(cataclysm-tiles\),\1$out/bin/\2,"
install -D -m 444 data/xdg/cataclysm-dda.svg -t $out/share/icons/hicolor/scalable/apps
'';
installMacOSAppLauncher = ''
app=$out/Applications/Cataclysm.app
install -D -m 444 data/osx/Info.plist -t $app/Contents
install -D -m 444 data/osx/AppIcon.icns -t $app/Contents/Resources
mkdir $app/Contents/MacOS
launcher=$app/Contents/MacOS/Cataclysm.sh
cat << EOF > $launcher
#!${runtimeShell}
$out/bin/cataclysm-tiles
EOF
chmod 555 $launcher
'';
};
in
{ inherit common utils; }

View file

@ -1,25 +1,42 @@
{ stdenv, callPackage, CoreFoundation { newScope, darwin }:
, tiles ? true, Cocoa
, debug ? false
}:
let let
inherit (callPackage ./common.nix { inherit tiles CoreFoundation Cocoa debug; }) common utils; callPackage = newScope self;
inherit (utils) fetchFromCleverRaven;
stable = rec {
tiles = callPackage ./stable.nix {
inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa;
};
curses = tiles.override { tiles = false; };
};
git = rec {
tiles = callPackage ./git.nix {
inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa;
};
curses = tiles.override { tiles = false; };
};
lib = callPackage ./lib.nix {};
pkgs = callPackage ./pkgs {};
self = {
inherit
callPackage
stable
git;
inherit (lib)
buildMod
buildSoundPack
buildTileSet
wrapCDDA;
inherit pkgs;
};
in in
stdenv.mkDerivation (common // rec { self
version = "0.E-2";
name = "cataclysm-dda-${version}";
src = fetchFromCleverRaven {
rev = version;
sha256 = "15l6w6lxays7qmsv0ci2ry53asb9an9dh7l7fc13256k085qcg68";
};
patches = [ ./patches/fix_locale_dir.patch ];
meta = with stdenv.lib.maintainers; common.meta // {
maintainers = common.meta.maintainers ++ [ skeidel ];
};
})

View file

@ -1,33 +1,41 @@
{ stdenv, callPackage, CoreFoundation { lib, callPackage, CoreFoundation, fetchFromGitHub, pkgs, wrapCDDA
, tiles ? true, Cocoa , tiles ? true, Cocoa
, debug ? false , debug ? false
, useXdgDir ? false
, version ? "2019-11-22"
, rev ? "a6c8ece992bffeae3788425dd4b3b5871e66a9cd"
, sha256 ? "0ww2q5gykxm802z1kffmnrfahjlx123j1gfszklpsv0b1fccm1ab"
}: }:
let let
inherit (stdenv.lib) substring; common = callPackage ./common.nix {
inherit (callPackage ./common.nix { inherit tiles CoreFoundation Cocoa debug; }) common utils; inherit CoreFoundation tiles Cocoa debug useXdgDir;
inherit (utils) fetchFromCleverRaven;
in
stdenv.mkDerivation (common // rec {
version = "2019-11-22";
name = "cataclysm-dda-git-${version}";
src = fetchFromCleverRaven {
rev = "a6c8ece992bffeae3788425dd4b3b5871e66a9cd";
sha256 = "0ww2q5gykxm802z1kffmnrfahjlx123j1gfszklpsv0b1fccm1ab";
}; };
patches = [ self = common.overrideAttrs (common: rec {
# Locale patch required for Darwin builds, see: https://github.com/NixOS/nixpkgs/pull/74064#issuecomment-560083970 pname = common.pname + "-git";
./patches/fix_locale_dir_git.patch inherit version;
];
src = fetchFromGitHub {
owner = "CleverRaven";
repo = "Cataclysm-DDA";
inherit rev sha256;
};
makeFlags = common.makeFlags ++ [ makeFlags = common.makeFlags ++ [
"VERSION=git-${version}-${substring 0 8 src.rev}" "VERSION=git-${version}-${lib.substring 0 8 src.rev}"
]; ];
meta = with stdenv.lib.maintainers; common.meta // { passthru = common.passthru // {
maintainers = common.meta.maintainers ++ [ rardiol ]; pkgs = pkgs.override { build = self; };
withMods = wrapCDDA self;
}; };
})
meta = common.meta // {
maintainers = with lib.maintainers;
common.meta.maintainers ++ [ rardiol ];
};
});
in
self

View file

@ -0,0 +1,17 @@
{ callPackage }:
{
buildMod = callPackage ./builder.nix {
type = "mod";
};
buildSoundPack = callPackage ./builder.nix {
type = "soundpack";
};
buildTileSet = callPackage ./builder.nix {
type = "tileset";
};
wrapCDDA = callPackage ./wrapper.nix {};
}

View file

@ -1,18 +0,0 @@
--- a/src/translations.cpp
+++ b/src/translations.cpp
@@ -212,14 +212,12 @@ void set_language()
auto env = getenv( "LANGUAGE" );
locale_dir = std::string( PATH_INFO::base_path() + "lang/mo/" + ( env ? env : "none" ) +
"/LC_MESSAGES/cataclysm-dda.mo" );
-#elif (defined(__linux__) || (defined(MACOSX) && !defined(TILES)))
+#else
if( !PATH_INFO::base_path().empty() ) {
locale_dir = PATH_INFO::base_path() + "share/locale";
} else {
locale_dir = "lang/mo";
}
-#else
- locale_dir = "lang/mo";
#endif
const char *locale_dir_char = locale_dir.c_str();

View file

@ -1,20 +0,0 @@
diff --git a/src/translations.cpp b/src/translations.cpp
index 067e2cd77d..5660d18b3d 100644
--- a/src/translations.cpp
+++ b/src/translations.cpp
@@ -211,14 +211,12 @@ void set_language()
auto env = getenv( "LANGUAGE" );
locale_dir = std::string( FILENAMES["base_path"] + "lang/mo/" + ( env ? env : "none" ) +
"/LC_MESSAGES/cataclysm-dda.mo" );
-#elif (defined(__linux__) || (defined(MACOSX) && !defined(TILES)))
+#else
if( !FILENAMES["base_path"].empty() ) {
locale_dir = FILENAMES["base_path"] + "share/locale";
} else {
locale_dir = "lang/mo";
}
-#else
- locale_dir = "lang/mo";
#endif
const char *locale_dir_char = locale_dir.c_str();

View file

@ -0,0 +1,27 @@
{ lib, callPackage, build ? null }:
let
pkgs = {
mod = {
};
soundpack = {
};
tileset = {
UndeadPeople = callPackage ./tilesets/UndeadPeople {};
};
};
pkgs' = lib.mapAttrs (_: mod: lib.filterAttrs availableForBuild mod) pkgs;
availableForBuild = _: mod:
if isNull build then
true
else if build.isTiles then
mod.forTiles
else
mod.forCurses;
in
lib.makeExtensible (_: pkgs')

View file

@ -0,0 +1,23 @@
{ lib, buildTileSet, fetchFromGitHub }:
buildTileSet {
modName = "UndeadPeople";
version = "2020-07-08";
src = fetchFromGitHub {
owner = "SomeDeadGuy";
repo = "UndeadPeopleTileset";
rev = "f7f13b850fafe2261deee051f45d9c611a661534";
sha256 = "0r06srjr7rq51jk9yfyxz80nfgb98mkn86cbcjfxpibgbqvcp0zm";
};
modRoot = "MSX++UnDeadPeopleEdition";
meta = with lib; {
description = "Cataclysm DDA tileset based on MSX++ tileset";
homepage = "https://github.com/SomeDeadGuy/UndeadPeopleTileset";
license = licenses.unfree;
maintainers = with maintainers; [ mnacamura ];
platforms = platforms.all;
};
}

View file

@ -0,0 +1,34 @@
{ lib, callPackage, CoreFoundation, fetchFromGitHub, pkgs, wrapCDDA
, tiles ? true, Cocoa
, debug ? false
, useXdgDir ? false
}:
let
common = callPackage ./common.nix {
inherit CoreFoundation tiles Cocoa debug useXdgDir;
};
self = common.overrideAttrs (common: rec {
version = "0.E-2";
src = fetchFromGitHub {
owner = "CleverRaven";
repo = "Cataclysm-DDA";
rev = version;
sha256 = "15l6w6lxays7qmsv0ci2ry53asb9an9dh7l7fc13256k085qcg68";
};
passthru = common.passthru // {
pkgs = pkgs.override { build = self; };
withMods = wrapCDDA self;
};
meta = common.meta // {
maintainers = with lib.maintainers;
common.meta.maintainers ++ [ skeidel ];
};
});
in
self

View file

@ -0,0 +1,47 @@
{ lib, symlinkJoin, makeWrapper }:
unwrapped:
pkgsSpec:
let
mods = if lib.isFunction pkgsSpec
then pkgsSpec unwrapped.pkgs
else pkgsSpec;
in
if builtins.length mods == 0
then unwrapped
else symlinkJoin {
name = unwrapped.name + "-with-mods";
paths = [ unwrapped ] ++ mods;
nativeBuildInputs = [ makeWrapper ];
postBuild = ''
if [ -x $out/bin/cataclysm ]; then
wrapProgram $out/bin/cataclysm \
--add-flags "--datadir $out/share/cataclysm-dda/"
fi
if [ -x $out/bin/cataclysm-tiles ]; then
wrapProgram $out/bin/cataclysm-tiles \
--add-flags "--datadir $out/share/cataclysm-dda/"
fi
# Launch the wrapped program
replaceProgram() {
cp "$1" "''${1}.bk"
unlink "$1"
mv "''${1}.bk" "$1"
sed -i "$1" -e "s,/nix/store/.\+\(/bin/cataclysm-tiles\),$out\1,"
}
for script in "$out/share/applications/cataclysm-dda.desktop" \
"$out/Applications/Cataclysm.app/Contents/MacOS/Cataclysm.sh"
do
if [ -e "$script" ]; then
replaceProgram "$script"
fi
done
'';
}

View file

@ -23924,13 +23924,11 @@ in
inherit (darwin.apple_sdk.frameworks) Carbon CoreServices; inherit (darwin.apple_sdk.frameworks) Carbon CoreServices;
}; };
cataclysm-dda = callPackage ../games/cataclysm-dda { cataclysmDDA = callPackage ../games/cataclysm-dda { };
inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa;
};
cataclysm-dda-git = callPackage ../games/cataclysm-dda/git.nix { cataclysm-dda = cataclysmDDA.stable.tiles;
inherit (darwin.apple_sdk.frameworks) CoreFoundation Cocoa;
}; cataclysm-dda-git = cataclysmDDA.git.tiles;
chessdb = callPackage ../games/chessdb { }; chessdb = callPackage ../games/chessdb { };