From 64a92fe1b6641b281b0bae4d98e166f69e1e7e3a Mon Sep 17 00:00:00 2001 From: Michael Raitza Date: Sun, 9 Oct 2022 17:40:33 +0200 Subject: [PATCH] X-Plane addon: Add X-World Europe --- default.nix | 3 +- x-plane/addon.nix | 6 +- x-plane/simHeaven/x-world-europe.nix | 94 ++++++++++++++++++++++++ x-plane/simHeaven/x-world-vegetation.nix | 13 ++++ 4 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 x-plane/simHeaven/x-world-europe.nix diff --git a/default.nix b/default.nix index e0cd7de..e9d44a6 100644 --- a/default.nix +++ b/default.nix @@ -9,7 +9,7 @@ let xPlaneEnv = callPackage ./x-plane { xplanePathStr = "/home/games/xplane"; addons = [ headshake beautifulRoads samBasic samGlobalTrees flyWithLua vividSky airportEnvHD betterLights extendedNightLights toLissA321 ]; }; xPlane12Env = callPackage ./x-plane { xplanePathStr = "/home/games/xplane12"; name = "x-plane12-env"; - addons = [ x-world-vegetation ]; }; + addons = [ x-world-vegetation x-world-europe ]; }; xPlaneSDK = callPackage ./x-plane/sdk.nix {}; ortho4xp = callPackage ./x-plane/ortho4XPWrapper.nix { orthoPathStr = "/home/games/ortho4xp"; }; @@ -29,6 +29,7 @@ let # X-Plane 12 x-world-vegetation = callPackage ./x-plane/simHeaven/x-world-vegetation.nix {}; + x-world-europe = callPackage ./x-plane/simHeaven/x-world-europe.nix {}; pdfchain = callPackage ./pdfchain { }; prism = callPackage ./prism.nix {}; diff --git a/x-plane/addon.nix b/x-plane/addon.nix index 4933609..7e9d45e 100644 --- a/x-plane/addon.nix +++ b/x-plane/addon.nix @@ -1,9 +1,9 @@ { stdenv, requireFile, unzip, p7zip }: { pname , version -, fname -, sha256 -, forumlink +, fname ? null +, sha256 ? null +, forumlink ? null , passthru ? {} , ... }@args: diff --git a/x-plane/simHeaven/x-world-europe.nix b/x-plane/simHeaven/x-world-europe.nix new file mode 100644 index 0000000..f7676ff --- /dev/null +++ b/x-plane/simHeaven/x-world-europe.nix @@ -0,0 +1,94 @@ +{ stdenv +, lib +, mkXPlaneAddon +, impureSrcPath ? "/home/games/xplane-scenery/simHeaven_X-World_Europe" +# Disable to improve frame rate +, enableDetails ? true +# dito +, enableExtras ? true +# Replace scenery objects with null-objects that are covered by ortho scenery +, useOrtho ? true +# Replace default tiles for regions with poor OSM data quality (e.g. remote forests not showing) +# example: [ "+38+001" "+71-009" ] +, replaceTiles ? [ ] +}: +let + inherit (lib) concatStringsSep optional; + dirName = "simHeaven_X-World_Europe"; + linkDirs = concatStringsSep " " ([ + "${dirName}-0-exclusions" + "${dirName}-1-vfr" + "${dirName}-2-regions" + "${dirName}-5-footprints" + "${dirName}-6-scenery" + "${dirName}-7-forests" + "${dirName}-8-network" ] + ++ optional enableDetails "${dirName}-3-details" + ++ optional enableExtras "${dirName}-4-extras"); + + tiles = concatStringsSep " " replaceTiles; +in mkXPlaneAddon { + pname = "x-world-europe"; + version = "1.1"; + src = ""; + buildCommand = '' + mkdir -p "$out" + touch "$out/installed" + ''; + + passthru = { + build = ""; + prepare = '' + test -d "${impureSrcPath}" + for f in ${linkDirs} ; do + mkdir "$XPLANEPATH/Custom Scenery/$f" + for j in "${impureSrcPath}/$f"/* ; do + ln -s "$j" "$XPLANEPATH/Custom Scenery/$f/$(basename "$j")" + done + done + if [ "${toString useOrtho}" = 1 ]; then + f="$XPLANEPATH/Custom Scenery/${dirName}-6-scenery/library.txt" + rm "$f" + ln -s "${impureSrcPath}/${dirName}-6-scenery/library - orthos.txt" "$f" + fi + # In case we want to replace some tiles, link every tile indivdually + if [ -n "${tiles}" ]; then + rm "$XPLANEPATH/Custom Scenery/${dirName}-7-forests/Earth nav data" + for f in "${impureSrcPath}/${dirName}-7-forests/Earth nav data"/* ; do + mkdir -p "$XPLANEPATH/Custom Scenery/${dirName}-7-forests/Earth nav data/$(basename "$f")" + for k in "$f"/* ; do + ln -s "$k" "$XPLANEPATH/Custom Scenery/${dirName}-7-forests/Earth nav data/$(basename "$f")" + done + done + for f in ${tiles} ; do + # bash-ism, transform +HH+LLL -> +H0+LL0 + d=''${f:0:2}0''${f:3:3}0 + s="${impureSrcPath}/${dirName}-7-forests/Earth nav data - osm+autogen/$d/$f.dsf" + t="$XPLANEPATH/Custom Scenery/${dirName}-7-forests/Earth nav data/$d/$f.dsf" + if [ -e "$s" ]; then + rm "$t" + ln -s "$s" "$t" + else + printf "Warning: Replacement tile not found %s\n" "$f" >&2 + fi + done + fi + # Update scenery_packs.ini + ( + cd "$XPLANEPATH" + k= + sed -i -e '/^SCENERY_PACK Custom Scenery\/${dirName}-.*$/d' 'Custom Scenery/scenery_packs.ini' + sed -i -e "/^SCENERY_PACK Custom Scenery\/simHeaven_X-World_Vegetation_Library/i\ + $(for f in ${linkDirs} ; do + printf "''${k}SCENERY_PACK Custom Scenery/%s/" "$f" + k='\\n' + done)" 'Custom Scenery/scenery_packs.ini' + ) + ''; + revert = '' + for f in ${linkDirs} ; do + rm -r "$XPLANEPATH/Custom Scenery/$f" + done + ''; + }; +} diff --git a/x-plane/simHeaven/x-world-vegetation.nix b/x-plane/simHeaven/x-world-vegetation.nix index 3f532bb..2ac5d4b 100644 --- a/x-plane/simHeaven/x-world-vegetation.nix +++ b/x-plane/simHeaven/x-world-vegetation.nix @@ -28,6 +28,19 @@ mkXPlaneAddon { ln -s "$f" "${addonPath}/$(basename "$f")" done ln -s "$XPLANEPATH/Resources/default scenery/1200 forests" "${addonPath}/1200 forests" + + ( + cd "$XPLANEPATH" + if grep -q -E 'Custom Scenery/yOrtho4XP_Overlays' 'Custom Scenery/scenery_packs.ini' ; then + sed -i -e '/^SCENERY_PACK Custom Scenery\/${dirName}\/$/d' 'Custom Scenery/scenery_packs.ini' + sed -i -e "/^SCENERY_PACK Custom Scenery\/yOrtho4XP_Overlays/i\ + SCENERY_PACK Custom Scenery\/${dirName}/" 'Custom Scenery/scenery_packs.ini' + else + sed -i -e '/^SCENERY_PACK Custom Scenery\/${dirName}\/$/d' 'Custom Scenery/scenery_packs.ini' + sed -i -e '$a\ + SCENERY_PACK Custom Scenery\/${dirName}/' 'Custom Scenery/scenery_packs.ini' + fi + ) ''; revert = '' if [ -d "${addonPath}" ]; then