Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
L0laapk3 committed Jun 14, 2020
2 parents 174501d + b219e7e commit bd08875
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 23 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
![image](https://user-images.githubusercontent.com/6313423/46447780-0d723880-c784-11e8-8e6f-2b35d24f25b9.png)
This [Factorio](http://www.factorio.com/) mod turns your factory into a timeline! You can view the map locally or upload it to a web server.

Live demo: https://factoriomaps.com/beta/user/L0laapk3/megabase/index.html

Mod portal link: https://mods.factorio.com/mod/L0laapk3_FactorioMaps

# How to Install
Expand Down
26 changes: 14 additions & 12 deletions auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
from pathlib import Path

try:
with Path(__file__, "..", "packages.txt").open("r", encoding="utf-8") as f:
with Path(__file__, "..", "packages.txt").resolve().open("r", encoding="utf-8") as f:
pkg_resources.require(f.read().splitlines())
except (DistributionNotFound, VersionConflict) as ex:
traceback.print_exc()
print("\nDependencies not met. Run `pip install -r packages.txt` to install missing dependencies.")
sys.exit(1)

import glob
import argparse
import configparser
import datetime
Expand Down Expand Up @@ -169,7 +170,7 @@ def checkUpdate(reverseUpdateTest:bool = False):
try:
print("checking for updates")
latestUpdates = json.loads(urllib.request.urlopen('https://cdn.jsdelivr.net/gh/L0laapk3/FactorioMaps@latest/updates.json', timeout=30).read())
with Path(__file__, "..", "updates.json").open("r", encoding="utf-8") as f:
with Path(__file__, "..", "updates.json").resolve().open("r", encoding="utf-8") as f:
currentUpdates = json.load(f)
if reverseUpdateTest:
latestUpdates, currentUpdates = currentUpdates, latestUpdates
Expand Down Expand Up @@ -294,7 +295,7 @@ def buildAutorun(args: Namespace, workFolder: Path, outFolder: Path, isFirstSnap
def lowerBool(value: bool):
return str(value).lower()

with open("autorun.lua", "w", encoding="utf-8") as f:
with Path(__file__, "..", "autorun.lua").resolve().open("w", encoding="utf-8") as f:
surfaceString = '{"' + '", "'.join(args.surface) + '"}' if args.surface else "nil"
autorunString = \
f'''fm.autorun = {{
Expand Down Expand Up @@ -335,6 +336,8 @@ def buildConfig(args: Namespace, tmpDir, basepath):
config["path"] = {}
config["path"]["write-data"] = tmpDir

config["path"]["script-output"] = str(basepath)

if "graphics" not in config:
config["graphics"] = {}
config["graphics"]["screenshots-threads-count"] = str(args.screenshotthreads if args.screenshotthreads else args.maxthreads)
Expand All @@ -344,9 +347,6 @@ def buildConfig(args: Namespace, tmpDir, basepath):
configFile.writelines(("; version=3\n", ))
config.write(configFile, space_around_delimiters=False)

# TODO: change this when https://forums.factorio.com/viewtopic.php?f=28&t=81221 is implemented
linkDir(Path(tmpDir, "script-output"), basepath)

copy(Path(userFolder, 'player-data.json'), tmpDir)

return configPath
Expand Down Expand Up @@ -427,8 +427,9 @@ def kill(pid, onlyStall=False):

saveGames = OrderedSet()
for saveName in saveNames:
globResults = list(saves.glob(saveName))
globResults += list(saves.glob(f"{saveName}.zip"))
saveNameEscaped = glob.escape(saveName).replace("[*]", "*")
globResults = list(saves.glob(saveNameEscaped))
globResults += list(saves.glob(f"{saveNameEscaped}.zip"))

if not globResults:
print(f'Cannot find savefile: "{saveName}"')
Expand Down Expand Up @@ -601,7 +602,7 @@ def kill(pid, onlyStall=False):
time.sleep(0.4)

# empty autorun.lua
open("autorun.lua", 'w', encoding="utf-8").close()
Path(__file__, "..", "autorun.lua").resolve().open('w', encoding="utf-8").close()

latest = []
with datapath.open('r', encoding="utf-8") as f:
Expand Down Expand Up @@ -701,9 +702,10 @@ def refZoom():
for surfaceName, surfaceStuff in mapStuff["surfaces"].items():
if "chunks" in surfaceStuff:
data["maps"][int(mapIndex)]["surfaces"][surfaceName]["chunks"] = surfaceStuff["chunks"]
for linkIndex, link in enumerate(surfaceStuff["links"]):
data["maps"][int(mapIndex)]["surfaces"][surfaceName]["links"][linkIndex]["path"] = link["path"]
data["maps"][int(mapIndex)]["surfaces"][surfaceName]["links"][linkIndex]["zoom"]["min"] = link["zoom"]["min"]
if "links" in surfaceStuff:
for linkIndex, link in enumerate(surfaceStuff["links"]):
data["maps"][int(mapIndex)]["surfaces"][surfaceName]["links"][linkIndex]["path"] = link["path"]
data["maps"][int(mapIndex)]["surfaces"][surfaceName]["links"][linkIndex]["zoom"]["min"] = link["zoom"]["min"]
destf.seek(0)
json.dump(data, destf)
destf.truncate()
Expand Down
9 changes: 8 additions & 1 deletion control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ script.on_event(defines.events.on_tick, function(event)

game.tick_paused = true
game.ticks_to_run = 0
player.character.active = false
if player.character then
player.character.active = false
end

local main = player.gui.center.add{type = "frame", caption = text[1], direction = "vertical"}
local topLine = main.add{type = "flow", direction = "horizontal"}
Expand Down Expand Up @@ -286,3 +288,8 @@ script.on_event(defines.events.on_tick, function(event)

end
end)

function unpause()
game.tick_paused = false
end
script.on_init(unpause)
2 changes: 1 addition & 1 deletion crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def crop(outFolder, timestamp, surface, daytime, basePath=None, args: Namespace

subname = Path(timestamp, surface, daytime)
toppath = Path(
basePath if basePath else Path(__file__, "..", "..", "..", "script-output", "FactorioMaps"),
basePath if basePath else Path(__file__, "..", "..", "..", "script-output", "FactorioMaps").resolve(),
outFolder,
)

Expand Down
4 changes: 4 additions & 0 deletions data.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_, _, mainVersion, majorVersion, minorVersion = string.find(mods["base"], "(%d+)%.(%d+)%.(%d+)")
if tonumber(mainVersion) <= 0 and tonumber(majorVersion) <= 18 and tonumber(minorVersion) < 29 then
error("\nThis version of factorioMaps requires factorio 0.18.29 or higher!")
end
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": "4.0.1",
"version": "4.1.0",
"title": "FactorioMaps",
"author": "L0laapk3",
"contact": "https://github.com/L0laapk3/",
Expand Down
2 changes: 1 addition & 1 deletion ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def ref(

psutil.Process(os.getpid()).nice(psutil.BELOW_NORMAL_PRIORITY_CLASS if os.name == 'nt' else 10)

workFolder = basepath if basepath else Path(__file__, "..", "..", "..", "script-output", "FactorioMaps")
workFolder = basepath if basepath else Path(__file__, "..", "..", "..", "script-output", "FactorioMaps").resolve()
topPath = Path(workFolder, outFolder)
dataPath = Path(topPath, "mapInfo.json")
maxthreads = args.refthreads if args.refthreads else args.maxthreads
Expand Down
2 changes: 1 addition & 1 deletion updateLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

def update(Force=True):

targetPath = Path(__file__, "..", "web", "lib")
targetPath = Path(__file__, "..", "web", "lib").resolve()

if not Force:
try:
Expand Down
8 changes: 7 additions & 1 deletion updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,11 @@
"Day and night snapshots are now completely identical instead of 1 tick apart",
"Added option to set the default snapshot when the page loads"
],
"4.0.1": "!Bugfix with default snapshot index"
"4.0.1": "!Bugfix with default snapshot index",
"4.1.0": [
"Replace symlinks with the new script-output config option, restore linux compatibility",
"Fix for editor/god mode maps",
"Fix for when the CWD is different than the script directory",
"Bugfixes :)"
]
}
6 changes: 3 additions & 3 deletions zoom.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def printErase(arg):

# note that these are all 64 bit libraries since factorio doesnt support 32 bit.
if os.name == "nt":
jpeg = TurboJPEG(Path(__file__, "..", "mozjpeg/turbojpeg.dll").as_posix())
jpeg = TurboJPEG(Path(__file__, "..", "mozjpeg/turbojpeg.dll").resolve().as_posix())
# elif _platform == "darwin": # I'm not actually sure if mac can run linux libraries or not.
# jpeg = TurboJPEG("mozjpeg/libturbojpeg.dylib") # If anyone on mac has problems with the line below please make an issue :)
else:
jpeg = TurboJPEG(Path(__file__, "..", "mozjpeg/libturbojpeg.so").as_posix())
jpeg = TurboJPEG(Path(__file__, "..", "mozjpeg/libturbojpeg.so").resolve().as_posix())


def saveCompress(img, path: Path):
Expand Down Expand Up @@ -270,7 +270,7 @@ def zoom(

psutil.Process(os.getpid()).nice(psutil.BELOW_NORMAL_PRIORITY_CLASS if os.name == "nt" else 10)

workFolder = basepath if basepath else Path(__file__, "..", "..", "..", "script-output", "FactorioMaps")
workFolder = basepath if basepath else Path(__file__, "..", "..", "..", "script-output", "FactorioMaps").resolve()

topPath = Path(workFolder, outFolder)
dataPath = Path(topPath, "mapInfo.json")
Expand Down

0 comments on commit bd08875

Please sign in to comment.