{ config, lib, pkgs, inputs, ... }:

# Launch options: -novid -nojoy -nosteamcontroller -nohltv -particles 1 -precachefontchars -noquicktime -console -windowed -noborder

let cfg = config.sydnix.users.crumb.tf2;
in {
  options.sydnix.users.crumb.tf2 = {
    enable = lib.mkEnableOption "Madeleine's Team Fortress 2 config";
  };

  config = lib.mkIf cfg.enable
    (let
      tf2pkgs = inputs.tf2-nix.legacyPackages.x86_64-linux;
      tgz = x: pkgs.runCommand "source" {} ''
        tarball="${x}"
        tar xzf "$tarball"
        base="$(stripHash "$tarball")"
        mv "''${base%.tar.gz}" $out
      '';
      my-config = tf2pkgs.mergeTf2Configs (with tf2pkgs; [
          mastercomfig.presets.medium-low
          mastercomfig.addons.flat-mouse
          mastercomfig.addons.no-tutorial
          mastercomfig.addons.null-canceling-movement
          # improved-crosshairs
          (tgz ./tf2/improved-crosshairs-0.1.1.tar.gz)
          loadouts-script
          (huds.deerhud.overrideAttrs (final: prev: {
            patches = [ ./tf2/raise-uber-meter.patch ];
          }))
          maps.jump_noskillrequired_b3
          ./tf2/my-config
          (tgz ./tf2/quake-hitsounds.tar.gz)
        ]);
      game-dir = ".local/share/Steam/steamapps/common/Team Fortress 2/tf";
    in {
      home.file.${game-dir} = {
        recursive = true;
        source = my-config;
      };
  });
}
