Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
L0laapk3 committed Oct 15, 2019
2 parents 338662a + 5ba84bd commit e9f5c79
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 60 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ Mod portal link: https://mods.factorio.com/mod/L0laapk3_FactorioMaps
# How to Install
**Note that this program now only runs on 64 bit python version 3.6 or higher.**
1. Download FactorioMaps to `%appdata%\mods\`, either from the [mod portal](https://mods.factorio.com/mod/L0laapk3_FactorioMaps) (The mod does not need to be enabled to work) and then unzipping it, or from [the github releases page](https://github.com/L0laapk3/FactorioMaps/releases).
1. Install the latest version of [**64 bit** python 3.7](https://www.python.org/downloads/). (Do not install python 2.)
1. Recommended: [Add python to your environment variables](https://stackoverflow.com/a/4855685/3185280).
1. Install pip: Download the latest [get-pip.py](https://bootstrap.pypa.io/get-pip.py), and run it (`python get-pip.py` in the command line).
1. Install the following pip packages: `pip install -r packages.txt`.
1. Install the latest version of [**64 bit** python 3](https://www.python.org/downloads/). (Do *not* install python 2.)
Make sure to do a select the "add python to PATH" and "install pip" options.
1. Inside the factoriomaps folder, install the required pip packages: `python -m pip install -r packages.txt`.

# How to Use
1. Make sure you close factorio before starting the process.
Expand All @@ -24,7 +23,8 @@ Mod portal link: https://mods.factorio.com/mod/L0laapk3_FactorioMaps
* `python auto.py outfolder savename` Generate a snapshot of *savename* and store it to folder *outfolder*.
* `python auto.py outfolder savename1 savename2 savename3` Generate timeline snapshots of *savename1*, *savename2*, *savename3* in that order, and store it to folder *outfolder*.
* `python auto.py --factorio=PATH` Same as `python auto.py`, but will use `factorio.exe` from *PATH* instead of attempting to find it in common locations.
* `python auto.py --verbosegame` Display *all* game logs.
* `python auto.py --verbose` Displays factoriomaps related logs.
* `python auto.py --verbosegame` Displays *all* game logs.
* `python auto.py --basepath=PATH` Same as `python auto.py`, but will output to *PATH* instead of `script-output\FactorioMaps`. Not recommended to use.

1. An `index.html` will be created in `%appdata%\Factorio\script-output\FactorioMaps\mapName`. Enjoy!
Expand Down
2 changes: 1 addition & 1 deletion api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ local function resolveSurface(surface, default, errorText)
end

local roundMultiplier = 32
if fm.autorun.HD then
if fm.autorun and fm.autorun.HD then
roundMultiplier = 64
end

Expand Down
88 changes: 41 additions & 47 deletions auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,41 +232,31 @@ def parseArg(arg):



args = list(filter(parseArg, args))
if len(args) > 0:
foldername = args[0]
newArgs = list(filter(parseArg, args))
if kwargs["verbose"]:
print(args)
if len(newArgs) > 0:
foldername = newArgs[0]
else:
foldername = os.path.splitext(os.path.basename(max([os.path.join("../../saves", basename) for basename in os.listdir("../../saves") if basename not in { "_autosave1.zip", "_autosave2.zip", "_autosave3.zip" }], key=os.path.getmtime)))[0]
print("No save name passed. Using most recent save: %s" % foldername)
savenames = args[1:] or [ foldername ]
savenames = newArgs[1:] or [ foldername ]

for saveName in savenames:
savePath = os.path.join("../../saves", saveName)
if not (os.path.isdir(savePath) or os.path.isfile(savePath + ".zip")):
if not (os.path.isdir(savePath) or os.path.isfile(savePath) or os.path.isfile(savePath + ".zip")):
print(f'Cannot find savefile: "{saveName}"')
raise ValueError(f'Cannot find savefile: "{saveName}"')

possiblePaths = [
"C:/Program Files/Factorio/bin/x64/factorio.exe",
"D:/Program Files/Factorio/bin/x64/factorio.exe",
"E:/Program Files/Factorio/bin/x64/factorio.exe",
"F:/Program Files/Factorio/bin/x64/factorio.exe",
"G:/Program Files/Factorio/bin/x64/factorio.exe",
"H:/Program Files/Factorio/bin/x64/factorio.exe",
"C:/Games/Factorio/bin/x64/factorio.exe",
"D:/Games/Factorio/bin/x64/factorio.exe",
"E:/Games/Factorio/bin/x64/factorio.exe",
"F:/Games/Factorio/bin/x64/factorio.exe",
"G:/Games/Factorio/bin/x64/factorio.exe",
"H:/Games/Factorio/bin/x64/factorio.exe",
windowsPaths = [
"Program Files/Factorio/bin/x64/factorio.exe",
"Games/Factorio/bin/x64/factorio.exe",
"Program Files (x86)/Steam/steamapps/common/Factorio/bin/x64/factorio.exe",
"Steam/steamapps/common/Factorio/bin/x64/factorio.exe",
]
possiblePaths = [driveletter + ":/" + path for driveletter in 'CDEFGHIJKL' for path in windowsPaths] + [
"../../bin/x64/factorio.exe",
"../../bin/x64/factorio",
"C:/Program Files (x86)/Steam/steamapps/common/Factorio/bin/x64/factorio.exe",
"D:/Program Files (x86)/Steam/steamapps/common/Factorio/bin/x64/factorio.exe",
"E:/Program Files (x86)/Steam/steamapps/common/Factorio/bin/x64/factorio.exe",
"F:/Program Files (x86)/Steam/steamapps/common/Factorio/bin/x64/factorio.exe",
"G:/Program Files (x86)/Steam/steamapps/common/Factorio/bin/x64/factorio.exe",
"H:/Program Files (x86)/Steam/steamapps/common/Factorio/bin/x64/factorio.exe",
]
try:
factorioPath = next(x for x in map(os.path.abspath, [kwargs["factorio"]] if kwargs["factorio"] else possiblePaths) if os.path.isfile(x))
Expand Down Expand Up @@ -335,9 +325,7 @@ def parseArg(arg):
print(line)
print("")
print("")
print(" Download: https://mods.factorio.com/mod/L0laapk3_FactorioMaps")
print(" OR")
print(" https://github.com/L0laapk3/FactorioMaps")
print(" Download: https://git.io/factoriomaps")
if majorUpdate:
print("")
print("You can dismiss this by using --noupdate (not recommended)")
Expand Down Expand Up @@ -463,24 +451,25 @@ def changeModlist(newState):

with open("autorun.lua", "w") as f:
surfaceString = '{"' + '", "'.join(kwargs["surface"]) + '"}' if len(kwargs["surface"]) > 0 else "nil"
f.write(
f'fm.autorun = {{\n'
f'HD = {str(kwargs["hd"] == True).lower()},\n'
f'day = {str(kwargs["nightonly"] != True).lower()},\n'
f'night = {str(kwargs["dayonly"] != True).lower()},\n'
f'alt_mode = {str(kwargs["no-altmode"] != True).lower()},\n'
f'tags = {str(kwargs["no-tags"] != True).lower()},\n'
f'around_tag_range = {float(kwargs["tag-range"])},\n'
f'around_build_range = {float(kwargs["build-range"])},\n'
f'around_connect_range = {float(kwargs["connect-range"])},\n'
f'connect_types = {{"lamp", "electric-pole", "radar", "straight-rail", "curved-rail", "rail-signal", "rail-chain-signal", "locomotive", "cargo-wagon", "fluid-wagon", "car"}},\n'
f'date = "{datetime.datetime.strptime(kwargs["date"], "%d/%m/%y").strftime("%d/%m/%y")}",\n'
f'surfaces = {surfaceString},\n'
f'name = "{foldername + "/"}",\n'
f'mapInfo = {mapInfoLua},\n'
f'chunkCache = {chunkCache},\n'
f'}}'
)
autorunString = (f'fm.autorun = {{\n'
f'HD = {str(kwargs["hd"] == True).lower()},\n'
f'day = {str(kwargs["nightonly"] != True).lower()},\n'
f'night = {str(kwargs["dayonly"] != True).lower()},\n'
f'alt_mode = {str(kwargs["no-altmode"] != True).lower()},\n'
f'tags = {str(kwargs["no-tags"] != True).lower()},\n'
f'around_tag_range = {float(kwargs["tag-range"])},\n'
f'around_build_range = {float(kwargs["build-range"])},\n'
f'around_connect_range = {float(kwargs["connect-range"])},\n'
f'connect_types = {{"lamp", "electric-pole", "radar", "straight-rail", "curved-rail", "rail-signal", "rail-chain-signal", "locomotive", "cargo-wagon", "fluid-wagon", "car"}},\n'
f'date = "{datetime.datetime.strptime(kwargs["date"], "%d/%m/%y").strftime("%d/%m/%y")}",\n'
f'surfaces = {surfaceString},\n'
f'name = "{foldername + "/"}",\n'
f'mapInfo = {mapInfoLua},\n'
f'chunkCache = {chunkCache},\n'
f'}}')
f.write(autorunString)
if kwargs["verbose"]:
printErase(autorunString)


printErase("building config.ini")
Expand Down Expand Up @@ -514,8 +503,11 @@ def changeModlist(newState):
isSteam = None
pidBlacklist = [p.info["pid"] for p in psutil.process_iter(attrs=['pid', 'name']) if p.info['name'] == "factorio.exe"]

popenArgs = (factorioPath, '--load-game', os.path.abspath(os.path.join("../../saves", savename+".zip")), '--disable-audio', '--config', configPath, "--mod-directory", os.path.abspath(kwargs["modpath"]), "--disable-migration-window")

popenArgs = (factorioPath, '--load-game', os.path.abspath(os.path.join("../../saves", savename)), '--disable-audio', '--config', configPath, "--mod-directory", os.path.abspath(kwargs["modpath"]), "--disable-migration-window")
if kwargs["verbose"]:
printErase(popenArgs)


condition = mp.Condition()


Expand Down Expand Up @@ -552,6 +544,8 @@ def changeModlist(newState):
with open(datapath, 'r') as f:
for line in f:
latest.append(line.rstrip("\n"))
if kwargs["verbose"]:
printErase(latest)


firstOtherInputs = latest[-1].split(" ")
Expand Down
7 changes: 5 additions & 2 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,15 @@ script.on_event(defines.events.on_tick, function(event)
text = {
"Factoriomaps automatic world capture",
"Factoriomaps is now finished capturing your game and will close soon.",
"If you believe the script is stuck or you see this screen in error,\nconsider making an issue on the github page: https://git.io/factoriomaps"
"If you believe the script is stuck or you see this screen in error,\nconsider making an issue on the github page: https://git.io/factoriomaps",
"Do not save! This will result in a bricked gamestate."
}
else
text = {
"Welcome to FactorioMaps!",
"For instructions, check out",
"You can leave the mod disabled while you play.\nThe scripts will automagically enable it when it needs it!"
"You can leave the mod disabled while you play.\nThe scripts will automagically enable it when it needs it!",
"Do not save! This will result in a bricked gamestate."
}
end

Expand All @@ -287,6 +289,7 @@ script.on_event(defines.events.on_tick, function(event)
end
--topLine.add{type = "label", name = "main-end", caption = "."}.style
main.add{type = "label", caption = text[3]}.style.single_line = false
main.add{type = "label", caption = text[4]}.style.font = "default-bold"
main.style.horizontal_align = "right"


Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "L0laapk3_FactorioMaps",
"version": "3.5.0",
"version": "3.5.1",
"title": "FactorioMaps",
"author": "L0laapk3",
"contact": "https://github.com/L0laapk3/",
Expand Down
1 change: 0 additions & 1 deletion packages.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PyTurboJPEG>=1.1.5
opencv_python>=4.1.0.25
psutil>=5.4.8
numpy>=1.16.4
Pillow>=6.1.0
3 changes: 2 additions & 1 deletion updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"3.3.1": "Fixed a bug where some parts of the map could be missing if multiple factions were used",
"3.3.2": "Many bugfixes.",
"3.4.0": ["Separated map tags to surface and snapshot level", "Thumbnail generation of the map"],
"3.5.0": ["!Added API for integration with i.a. Factorissimo", "Better dependency management", "Several bugfixes"]
"3.5.0": ["!Added API for integration with i.a. Factorissimo", "Better dependency management", "Several bugfixes"],
"3.5.1": "Removed dependency on package that isnt being updated anymore."
}
4 changes: 2 additions & 2 deletions zoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import sys
import time
import cv2, numpy
import numpy
from turbojpeg import TurboJPEG
from shutil import get_terminal_size as tsize
from sys import platform as _platform
Expand Down Expand Up @@ -33,7 +33,7 @@ def printErase(arg):
try:
tsiz = tsize()[0]
print("\r{}{}\n".format(arg, " " * (tsiz*math.ceil(len(arg)/tsiz)-len(arg) - 1)), end="", flush=True)
except e:
except:
#raise
pass

Expand Down

0 comments on commit e9f5c79

Please sign in to comment.