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
This commit is contained in:
Tristin Stagg 2024-06-12 05:47:42 -05:00 committed by GitHub
parent bc28f4a917
commit 4ab4c889f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 5 deletions

9
docker/Dockerfile Normal file → Executable file
View File

@ -8,6 +8,14 @@ ARG PUID=845
ARG PGID=845 ARG PGID=845
ARG BOX64_VERSION=v0.2.4 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 # version checksum of the archive to download
ARG VERSION ARG VERSION
ARG SHA256 ARG SHA256
@ -20,6 +28,7 @@ ENV PORT=34197 \
VERSION=${VERSION} \ VERSION=${VERSION} \
SHA256=${SHA256} \ SHA256=${SHA256} \
SAVES=/factorio/saves \ SAVES=/factorio/saves \
PRESET="$PRESET" \
CONFIG=/factorio/config \ CONFIG=/factorio/config \
MODS=/factorio/mods \ MODS=/factorio/mods \
SCENARIOS=/factorio/scenarios \ SCENARIOS=/factorio/scenarios \

View File

@ -20,4 +20,5 @@ services:
# - USERNAME=FactorioUsername # - USERNAME=FactorioUsername
# - TOKEN=FactorioToken # - TOKEN=FactorioToken
# - PORT=34198 # - PORT=34198
# - PRESET=deathworld
# - ADDR=::1 # - ADDR=::1

View File

@ -1,9 +1,9 @@
#!/bin/bash #!/bin/bash
set -eoux pipefail set -eoux pipefail
FACTORIO_VOL=/factorio FACTORIO_VOL=/factorio
LOAD_LATEST_SAVE="${LOAD_LATEST_SAVE:-true}" LOAD_LATEST_SAVE="${LOAD_LATEST_SAVE:-true}"
GENERATE_NEW_SAVE="${GENERATE_NEW_SAVE:-false}" GENERATE_NEW_SAVE="${GENERATE_NEW_SAVE:-false}"
PRESET="${PRESET:-""}"
SAVE_NAME="${SAVE_NAME:-""}" SAVE_NAME="${SAVE_NAME:-""}"
BIND="${BIND:-""}" BIND="${BIND:-""}"
CONSOLE_LOG_LOCATION="${CONSOLE_LOG_LOCATION:-""}" CONSOLE_LOG_LOCATION="${CONSOLE_LOG_LOCATION:-""}"
@ -75,10 +75,18 @@ if [[ $GENERATE_NEW_SAVE == true ]]; then
if [[ -f "$SAVES/$SAVE_NAME.zip" ]]; then if [[ -f "$SAVES/$SAVE_NAME.zip" ]]; then
echo "Map $SAVES/$SAVE_NAME.zip already exists, skipping map generation" echo "Map $SAVES/$SAVE_NAME.zip already exists, skipping map generation"
else else
$EXEC /opt/factorio/bin/x64/factorio \ if [[ ! -z "$PRESET" ]]; then
--create "$SAVES/$SAVE_NAME.zip" \ $EXEC /opt/factorio/bin/x64/factorio \
--map-gen-settings "$CONFIG/map-gen-settings.json" \ --create "$SAVES/$SAVE_NAME.zip" \
--map-settings "$CONFIG/map-settings.json" --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
fi fi

View File

@ -6,6 +6,8 @@ if [[ -z ${1:-} ]]; then
fi fi
SERVER_SCENARIO="$1" SERVER_SCENARIO="$1"
PRESET="${PRESET:-""}"
mkdir -p "$SAVES" mkdir -p "$SAVES"
mkdir -p "$CONFIG" mkdir -p "$CONFIG"
mkdir -p "$MODS" mkdir -p "$MODS"
@ -32,6 +34,7 @@ fi
exec /opt/factorio/bin/x64/factorio \ exec /opt/factorio/bin/x64/factorio \
--port "$PORT" \ --port "$PORT" \
--start-server-load-scenario "$SERVER_SCENARIO" \ --start-server-load-scenario "$SERVER_SCENARIO" \
--preset "$PRESET" \
--map-gen-settings "$CONFIG/map-gen-settings.json" \ --map-gen-settings "$CONFIG/map-gen-settings.json" \
--map-settings "$CONFIG/map-settings.json" \ --map-settings "$CONFIG/map-settings.json" \
--server-settings "$CONFIG/server-settings.json" \ --server-settings "$CONFIG/server-settings.json" \