Last active
April 28, 2022 09:02
-
-
Save Gesugao-san/cbbb6f8bb0dbd2e72d8353f6d5a4857f to your computer and use it in GitHub Desktop.
List mods for Factorio v1.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, json, random, string | |
generateFormFromOSName = bool(1) | |
printMods = bool(0) | |
# + thumbnail.png | |
modpackInfo = { | |
"name": "example-modpack", # aka ID, no spaces | |
"title": "Example Modpack", | |
"author": "Me", | |
"homepage": "", | |
"contact": "", | |
"version": "0.0.1", | |
"factorio_version": "1.1", | |
"description": "", | |
"dependencies": [] | |
} | |
def populateModpackData(): | |
global modpackInfo, generateFormFromOSName | |
if generateFormFromOSName: | |
rnd = str(''.join(random.choice(string.ascii_letters + string.digits) for _ in range(10))) | |
modpackInfo["name"] = os.getlogin().lower() + "-modpack-" + rnd.lower() | |
modpackInfo["title"] = os.getlogin() + " Modpack (" + rnd + ")" | |
modpackInfo["author"] = os.getlogin() | |
def getMods(): | |
modFile = open(os.getenv('APPDATA') + "\\Factorio\\mods\\mod-list.json") | |
data = json.load(modFile) | |
mods = {"All": [], "Enabled": [], "Disabled": [],} | |
for mod in data["mods"]: | |
if mod["name"] == "base": | |
mod["name"] = mod["name"] + " >= 1.1" | |
if mod["enabled"]: | |
mods["Enabled"].append(mod["name"]) | |
else: | |
mods["Disabled"].append(mod["name"]) | |
mods["All"].append(mod["name"]) | |
return mods | |
def writeJson(data): | |
global modpackInfo | |
#modpackInfo["dependencies"] = json.dumps(mods["Enabled"], separators=(', '), escape_forward_slashes=False) | |
modpackInfo["dependencies"] = mods["Enabled"] | |
#modpackInfo["dependencies"] = "[" + '", "'.join(str(modName) for modName in mods["Enabled"]) + "]" | |
InfoFileWrite = open(".\\info.json", "wt") | |
#InfoFileRead = open(".\\info.json") | |
with open('.\\info.json', 'w') as InfoFile: | |
json.dump(modpackInfo, InfoFileWrite, indent="\t") | |
print("New json file is created from info.json file") | |
# with open(".\\info.json") as r: | |
# text = "" | |
# s = r.read() | |
# for each in s: | |
# text = each.replace('\"', '"') | |
# with open(".\\info.json", "w") as w: | |
# w.write(text) | |
# with open('.\\info.json', 'r') as InfoFile: | |
# list = InfoFile.readlines() | |
# print(f'before removal {list}') | |
# json.dump(modpackInfo, InfoFileWrite, indent="\t") | |
# InfoFile.replace('\"', '"') | |
# print("New json file is created from info.json file") | |
# for line in InfoFileRead: | |
# line = line.rstrip() | |
# if '"dependencies": []' in line: | |
# new_line = line.replace("\t\"dependencies\": []", mods["Enabled"]) | |
# print(new_line, end='') | |
# InfoFileWrite.write( line.replace('\t\"dependencies\": [],', '\t\"dependencies\": [' + ", ".join(str(modName) for modName in mods["Enabled"]) + '],') ) | |
if __name__ == "__main__": | |
populateModpackData() | |
mods = getMods() | |
if printMods: | |
print("All mods (" + str(len(mods["All"])) + "): [" + ", ".join(str(modName) for modName in mods["All"]) + "]\n") | |
print("Enabled mods (" + str(len(mods["Enabled"])) + "\\" + str(len(mods["All"])) + "): [" + ", ".join(str(x) for x in mods["Enabled"])+ "]\n") | |
print("Disabled mods (" + str(len(mods["Disabled"])) + "\\" + str(len(mods["All"])) + "): [" + ", ".join(str(x) for x in mods["Disabled"])+ "]\n") | |
writeJson(mods) | |
exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment