workflow
      this post will cover setting up a development environment/routine for modding
      brogue, specifically on nixos since that's what I'm using.


      step 1: getting the code
      head on over the the brogue website and download the right version based on
      whatever os you're using. the linux version uses a fancy-schmancy archiving format, so here's how to open it:
      
$ bunzip2 brogue-1.7.5-linux-amd64.tbz2 $ tar -xf brogue-1.7.5-linux-amd64.tar $ cd brogue-1.7.5/
step 2: getting the nix files if you're using nixos, you'll want to make your brogue mod into a package. this makes things like dependencies and build steps easier to manage. to read more about building nix packages, read the wiki. now go into the top directory of the brogue code, and create a file called default.nix with the following contents:
{ nixpkgs? , system ? builtins.currentSystem }: let pkgs = import nixpkgs { inherit system; }; callPackage = pkgs.lib.callPackageWith (pkgs // self); self = rec { mbrogue = callPackage ./mbrogue.nix { }; }; in self
this file wraps another file called mbrogue.nix (in the same directory), which has the following contents:
{ stdenv, fetchurl, SDL, ncurses, libtcod, makeDesktopItem }: stdenv.mkDerivation rec { pname = "mbrogue"; version = "1.7.5"; src = ./.; prePatch = '' sed -i Makefile -e 's,LIBTCODDIR=.*,LIBTCODDIR=${libtcod},g' \ -e 's,sdl-config,${SDL.dev}/bin/sdl-config,g' sed -i src/platform/tcod-platform.c -e "s,fonts/font,$out/share/brogue/fonts/font,g" make clean rm -rf src/libtcod* ''; buildInputs = [ SDL ncurses libtcod ]; installPhase = '' install -m 555 -D bin/mbrogue $out/bin/mbrogue mkdir -p $out/share/mbrogue cp -r bin/fonts $out/share/mbrogue/ ''; meta = with stdenv.lib; { description = "A severely hacked-up roguelike game"; license = licenses.agpl3; platforms = [ "x86_64-linux" ]; }; }
this file is essentially a copy of brogue's nix derivation, with a few modifications. I'm no nix expert yet, so if there's something wrong with this then please let me know. and by the way, the package is called "mbrogue" for "modded brogue." change the name to whatever you want. as you can see, the nix package derivation thingy does roughly three things: - provides metadata for the package (version, name, etc) - has steps to patch, build, and install the program - provides the nix package names of dependencies (sdl, ncurses, and libtcod) step 3: enter the nix-shell in the same directory as the default.nix file, run nix-shell, which will drop you into a shell with dependency packages loaded and some new environment variables added. step 4: patching before you build, you need to do some patching (only do this if you're on nixos, by the way). run patchPhase in the nix-shell, which will proceed to clean up unnecessary libraries and tweak the makefile so it can find dependencies correctly. the nix package definition includes a patching step that uses sed to replace some paths, so remember that running patchPhase more than once will end up creating some really broken paths since sed will still operate on patched files. I also found the need to apply a kludge to fix font loading, so either figure out a better solution or do the following: - open src/platform/tcod-platform.c - go to the sprintf call that exists around line 54 - change the path argument so it's absolute in addition to all that, gcc emits tons of warnings when compiling brogue. if you don't want this (trust me, you don't), replace the CFLAGS definition in the Makefile with this line: CFLAGS=-Isrc/brogue -Isrc/platform -w ${DEFINES} as a final optional step, rename "brogue" to "mbrogue" in the Makefile, so that the resulting binary has the correct name. step 5: building and running to build, run buildPhase while inside nix-shell. to run, execute bin/mbrogue. step 6: installing in all honesty, I haven't figured out this part yet. I think you either need to run installPhase as root within the nix-shell, or you have to run nix-build within the nix-shell. it keeps erroring when I try to do it and there's no immediate need for it to be properly installed on my computer while I'm developing it, so ¯\_(ツ)_/¯. step 7: turning on debug mode you'll want to enable debug mode most times you run the game. debug mode gives you an overpowered inventory, the ability to teleport (using < and > to go between levels, and the mouse to go to specific tiles), and the ability to come back to life after death. near line 68 of src/brogue/Rogue.h, change this: #define DEBUGGING 0 to this: #define DEBUGGING 1 as a bonus, you can also customize your starting inventory in debug mode. the code for this is inside a DEBUG block around line 451 of src/brogue/RogueMain.c.