Naive saves (#318)
Some checks failed
Lint and Format / lint (push) Has been cancelled

* remove incorrect destroy logic

* remove old restart logic

* force amd flag

* run with saves

fairly trivial stuff (maybe)
This commit is contained in:
Harshit Sharma
2025-08-22 03:49:01 +05:30
committed by GitHub
parent 4b840b7114
commit 81cd2a794f
2 changed files with 59 additions and 70 deletions

View File

@@ -4,7 +4,9 @@
setup_platform() {
ARCH=$(uname -m)
OS=$(uname -s)
if [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then
if [ "$FORCE_AMD" = true ]; then
export DOCKER_PLATFORM="linux/amd64"
elif [ "$ARCH" = "arm64" ] || [ "$ARCH" = "aarch64" ]; then
export DOCKER_PLATFORM="linux/arm64"
else
export DOCKER_PLATFORM="linux/amd64"
@@ -46,12 +48,40 @@ setup_compose_cmd() {
generate_compose_file() {
NUM_INSTANCES=${1:-1}
SCENARIO=${2:-"default_lab_scenario"}
COMMAND=${3:-"--start-server-load-scenario ${SCENARIO}"}
# Build optional mods volume block based on ATTACH_MOD
MODS_VOLUME=""
if [ "$ATTACH_MOD" = true ]; then
MODS_VOLUME=$(printf " - source: %s\n target: /opt/factorio/mods\n type: bind\n" "$MODS_PATH")
fi
# Build optional save file volume block based on SAVE_ADDED
SAVE_VOLUME=""
if [ "$SAVE_ADDED" = true ]; then
# Check if SAVE_FILE is a .zip file
if [[ "$SAVE_FILE" != *.zip ]]; then
echo "Error: Save file must be a .zip file."
exit 1
fi
# Create saves directory if it doesn't exist
mkdir -p ../../.fle/saves
# Get the save file name (basename)
SAVE_FILE_NAME=$(basename "$SAVE_FILE")
# Copy the save file to the local saves directory
cp "$SAVE_FILE" "../../.fle/saves/$SAVE_FILE_NAME"
# Create variable for the container path
CONTAINER_SAVE_PATH="/opt/factorio/saves/$SAVE_FILE_NAME"
SAVE_VOLUME=" - source: ../../.fle/saves
target: /opt/factorio/saves
type: bind"
COMMAND="--start-server ${SAVE_FILE_NAME}"
fi
# Validate scenario
if [ "$SCENARIO" != "open_world" ] && [ "$SCENARIO" != "default_lab_scenario" ]; then
@@ -86,7 +116,7 @@ EOF
factorio_${i}:
image: factoriotools/factorio:1.1.110
platform: \${DOCKER_PLATFORM:-linux/amd64}
command: /opt/factorio/bin/x64/factorio --start-server-load-scenario ${SCENARIO}
command: /opt/factorio/bin/x64/factorio ${COMMAND}
--port 34197 --server-settings /opt/factorio/config/server-settings.json --map-gen-settings
/opt/factorio/config/map-gen-settings.json --map-settings /opt/factorio/config/map-settings.json
--server-banlist /opt/factorio/config/server-banlist.json --rcon-port 27015
@@ -115,6 +145,7 @@ EOF
- source: ../../.fle/data/_screenshots
target: /opt/factorio/script-output
type: bind
${SAVE_VOLUME}
${MODS_VOLUME}
EOF
done
@@ -164,30 +195,9 @@ restart_cluster() {
exit 1
fi
echo "Extracting current configuration..."
# Extract the number of instances
CURRENT_INSTANCES=$(grep -c "factorio_" docker-compose.yml)
# Extract the scenario from the first instance
CURRENT_SCENARIO=$(grep -A1 "command:" docker-compose.yml | grep "start-server-load-scenario" | head -1 | sed -E 's/.*start-server-load-scenario ([^ ]+).*/\1/')
if [ -z "$CURRENT_SCENARIO" ]; then
CURRENT_SCENARIO="default_lab_scenario"
echo "Warning: Could not determine current scenario, using default: $CURRENT_SCENARIO"
fi
echo "Found cluster with $CURRENT_INSTANCES instances using scenario: $CURRENT_SCENARIO"
# Stop the current cluster
echo "Stopping current cluster..."
$COMPOSE_CMD -f docker-compose.yml down
# Start with the same configuration
echo "Restarting cluster..."
start_cluster "$CURRENT_INSTANCES" "$CURRENT_SCENARIO"
echo "Factorio cluster restarted successfully."
echo "Restarting existing Factorio services without regenerating docker-compose..."
$COMPOSE_CMD -f docker-compose.yml restart
echo "Factorio services restarted."
}
# Show usage information
@@ -203,7 +213,9 @@ show_help() {
echo "Options:"
echo " -n NUMBER Number of Factorio instances to run (1-33, default: 1)"
echo " -s SCENARIO Scenario to run (open_world or default_lab_scenario, default: default_lab_scenario)"
echo " -sv SAVE_FILE, --use_save SAVE_FILE Use a .zip save file from factorio"
echo " -m, --attach_mods Attach mods to the instances"
echo " -f86, --force_amd Force AMD platform"
echo ""
echo "Examples:"
echo " $0 Start 1 instance with default_lab_scenario"
@@ -218,9 +230,12 @@ show_help() {
COMMAND="start"
NUM_INSTANCES=1
SCENARIO="default_lab_scenario"
SAVE_FILE=""
# Boolean: attach mods or not
ATTACH_MOD=false
FORCE_AMD=false
SAVE_ADDED=false
# Parse args (supporting both short and long options)
while [[ $# -gt 0 ]]; do
@@ -259,10 +274,28 @@ while [[ $# -gt 0 ]]; do
esac
shift 2
;;
-sv|--use_save)
if [[ -z "$2" || "$2" == -* ]]; then
echo "Error: -sv|--use_save requires an argument."
show_help
exit 1
fi
if [[ ! -f "$2" ]]; then
echo "Error: Save file '$2' does not exist."
exit 1
fi
SAVE_FILE="$2"
SAVE_ADDED=true
shift 2
;;
-m|--attach_mods)
ATTACH_MOD=true
shift
;;
-f86|--force_amd)
FORCE_AMD=true
shift
;;
-h|--help)
show_help
exit 0

View File

@@ -19,7 +19,6 @@ if global.debug == nil then
}
end
-- Note: The debug_rendering.lua library will be loaded separately by the LuaScriptManager
local player = global.agent_characters[1]
player.surface.always_day=true
@@ -341,49 +340,6 @@ global.utils.avoid_entity = function(player_index, entity, position, direction)
return false
end
---- Define a function to be called every tick
--local function on_tick(event)
-- -- Run the check every 60 ticks (1 second)
-- if event.tick % 60 == 0 then
-- for _, player in pairs(game.connected_players) do
-- if check_player_inventory_empty(player) then
-- -- Perform an action or notify the player when their inventory is empty
-- player.print("Your inventory is empty!")
-- end
-- end
-- end
--end
--
---- Register the on_tick function to the on_tick event
--script.on_event(defines.events.on_tick, on_tick)
--script.on_nth_tick(3600, function(event)
-- game.take_screenshot{
-- surface=game.surfaces[1],
-- position={0,0},
-- resolution={2560, 1600},
-- zoom=0.2,
-- path="timelapse/" .. string.format("%06d", event.tick/event.nth_tick) .. ".jpg",
-- show_entity_info=true,
-- allow_in_replay=true,
-- daytime=1
-- }
--end)
for _, ent in pairs(surface.find_entities_filtered({force="player", position=pp, radius=50})) do
if ent.name ~= "character" then
ent.destroy()
end
end
for key, entity in pairs(surface.find_entities_filtered({force="enemy", radius=250, position=pp })) do
cnt = cnt+1
entity.destroy()
end
global.crafting_queue = {}
script.on_event(defines.events.on_tick, function(event)