From 4ab4c889f4b5f53ea160b1b9b21ba1cae9eabc45 Mon Sep 17 00:00:00 2001 From: Tristin Stagg Date: Wed, 12 Jun 2024 05:47:42 -0500 Subject: [PATCH] Add support for --preset options provided by vanilla and popular mods (#482) * Add support for --preset options provided by vanilla and popular mods * Add support for --preset in scenario.sh * Replace SU_EXEC with EXEC --- docker/Dockerfile | 9 +++++++++ docker/docker-compose.yml | 1 + docker/files/docker-entrypoint.sh | 18 +++++++++++++----- docker/files/scenario.sh | 3 +++ 4 files changed, 26 insertions(+), 5 deletions(-) mode change 100644 => 100755 docker/Dockerfile diff --git a/docker/Dockerfile b/docker/Dockerfile old mode 100644 new mode 100755 index af4382ff..f2299bad --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,6 +8,14 @@ ARG PUID=845 ARG PGID=845 ARG BOX64_VERSION=v0.2.4 +# optionally utilize a built-in map-gen-preset (see data/base/prototypes/map-gen-presets +# if this is used, the preset will be used over any .json files supplied +# vanilla factorio provides the following presets: +# rich-resources, marathon, death-world, death-world-marathon, rail-world, ribbon-world, island +# a modded factorio example for using this: +# space-exploration +ARG PRESET + # version checksum of the archive to download ARG VERSION ARG SHA256 @@ -20,6 +28,7 @@ ENV PORT=34197 \ VERSION=${VERSION} \ SHA256=${SHA256} \ SAVES=/factorio/saves \ + PRESET="$PRESET" \ CONFIG=/factorio/config \ MODS=/factorio/mods \ SCENARIOS=/factorio/scenarios \ diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 35d1778c..eb59fdb3 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -20,4 +20,5 @@ services: # - USERNAME=FactorioUsername # - TOKEN=FactorioToken # - PORT=34198 +# - PRESET=deathworld # - ADDR=::1 diff --git a/docker/files/docker-entrypoint.sh b/docker/files/docker-entrypoint.sh index bf18fb83..420bedd3 100755 --- a/docker/files/docker-entrypoint.sh +++ b/docker/files/docker-entrypoint.sh @@ -1,9 +1,9 @@ #!/bin/bash set -eoux pipefail - FACTORIO_VOL=/factorio LOAD_LATEST_SAVE="${LOAD_LATEST_SAVE:-true}" GENERATE_NEW_SAVE="${GENERATE_NEW_SAVE:-false}" +PRESET="${PRESET:-""}" SAVE_NAME="${SAVE_NAME:-""}" BIND="${BIND:-""}" CONSOLE_LOG_LOCATION="${CONSOLE_LOG_LOCATION:-""}" @@ -75,10 +75,18 @@ if [[ $GENERATE_NEW_SAVE == true ]]; then if [[ -f "$SAVES/$SAVE_NAME.zip" ]]; then echo "Map $SAVES/$SAVE_NAME.zip already exists, skipping map generation" else - $EXEC /opt/factorio/bin/x64/factorio \ - --create "$SAVES/$SAVE_NAME.zip" \ - --map-gen-settings "$CONFIG/map-gen-settings.json" \ - --map-settings "$CONFIG/map-settings.json" + if [[ ! -z "$PRESET" ]]; then + $EXEC /opt/factorio/bin/x64/factorio \ + --create "$SAVES/$SAVE_NAME.zip" \ + --preset "$PRESET" \ + --map-gen-settings "$CONFIG/map-gen-settings.json" \ + --map-settings "$CONFIG/map-settings.json" + else + $EXEC /opt/factorio/bin/x64/factorio \ + --create "$SAVES/$SAVE_NAME.zip" \ + --map-gen-settings "$CONFIG/map-gen-settings.json" \ + --map-settings "$CONFIG/map-settings.json" + fi fi fi diff --git a/docker/files/scenario.sh b/docker/files/scenario.sh index bafac0b7..f108ca63 100755 --- a/docker/files/scenario.sh +++ b/docker/files/scenario.sh @@ -6,6 +6,8 @@ if [[ -z ${1:-} ]]; then fi SERVER_SCENARIO="$1" +PRESET="${PRESET:-""}" + mkdir -p "$SAVES" mkdir -p "$CONFIG" mkdir -p "$MODS" @@ -32,6 +34,7 @@ fi exec /opt/factorio/bin/x64/factorio \ --port "$PORT" \ --start-server-load-scenario "$SERVER_SCENARIO" \ + --preset "$PRESET" \ --map-gen-settings "$CONFIG/map-gen-settings.json" \ --map-settings "$CONFIG/map-settings.json" \ --server-settings "$CONFIG/server-settings.json" \