Compare commits

...

2 Commits

Author SHA1 Message Date
Archon0ne
6ad5e1ddeb Merge branch 'main' of https://dev.sp-tarkov.com/archon0ne/LoadOrderEditorDD 2024-05-07 23:31:03 +02:00
Archon0ne
4b063f28aa Initial commit 2024-05-07 23:29:03 +02:00
4 changed files with 166 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Ignore build and distribution directories
/build
/dist
# Ignore LoadOrderEditoDD.spec file
LoadOrderEditoDD.spec

BIN
LoadOrderEditorDD.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

39
LoadOrderEditorDD.spec Normal file
View File

@ -0,0 +1,39 @@
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['appnew.py'],
pathex=[],
binaries=[],
datas=[('F:\\Software\\Miniconda\\Lib\\site-packages\\qtvscodestyle', 'qtvscodestyle')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='LoadOrderEditorDD',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['LoadOrderEditorDD.ico'],
)

121
appnew.py Normal file
View File

@ -0,0 +1,121 @@
import sys
import os
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QListWidget, QPushButton, QListWidgetItem, QMessageBox
from PyQt5.QtCore import Qt
import json
import qtvscodestyle
import shutil
class DragDropApp(QWidget):
def __init__(self, mod_dir):
super().__init__()
self.setWindowTitle('Drag and Drop JSON Reorder')
self.resize(400, 300)
layout = QVBoxLayout(self)
self.list_widget = QListWidget()
layout.addWidget(self.list_widget)
self.save_button = QPushButton('Save Order')
layout.addWidget(self.save_button)
self.mod_dir = mod_dir
if not self.check_mods_directory():
return
self.load_data(mod_dir)
self.list_widget.setDragDropMode(QListWidget.InternalMove)
self.list_widget.setAlternatingRowColors(True)
self.save_button.clicked.connect(lambda: self.save_order(mod_dir))
def check_mods_directory(self):
mods_dir = os.path.join(self.mod_dir, 'user', 'mods')
if not os.path.exists(mods_dir):
error_message = f"Could not find user/mods. This exe belongs in the base directory of SPT-AKI!\nCurrent Directory: {self.mod_dir}"
QMessageBox.critical(self, "Error", error_message)
sys.exit(1) # Add this line to exit the application
return False
return True
def load_data(self, mod_dir):
print("Loading mod data...")
mod_info = []
order_file_path = os.path.join(mod_dir, 'user', 'mods', 'order.json')
if os.path.exists(order_file_path):
with open(order_file_path, 'r') as order_file:
order_data = json.load(order_file)
ordered_mods = order_data.get("order", []) # Get the ordered list of mods from order.json
for entry in os.scandir(os.path.join(mod_dir, "user", "mods")):
if entry.is_dir():
package_file = os.path.join(entry.path, "package.json")
if os.path.exists(package_file):
print(f"Found package.json in {entry.path}")
with open(package_file, 'r') as file:
data = json.load(file)
folder_name = os.path.basename(entry.path) # Extract folder name
mod_info.append({
"name": data["name"],
"folder_name": folder_name, # Use folder name as mod identifier
"version": data["version"],
"author": data["author"],
"akiVersion": data.get("akiVersion", "")
})
print(f"akiVersion for {folder_name}: {data.get('akiVersion', '')}")
# Reorder mod_info based on order.json
if os.path.exists(order_file_path):
ordered_mod_info = []
for mod_name in ordered_mods:
for mod in mod_info:
if mod["folder_name"] == mod_name:
ordered_mod_info.append(mod)
mod_info.remove(mod) # Remove matched mod from mod_info list
break
ordered_mod_info.extend(mod_info) # Append remaining mods to the ordered list
mod_info = ordered_mod_info
for mod in mod_info:
list_item = QListWidgetItem(mod["folder_name"])
tooltip_text = "\n".join([f"{key}: {value}" for key, value in mod.items()])
list_item.setToolTip(tooltip_text)
self.list_widget.addItem(list_item)
def save_order(self, mod_dir):
print("Saving order...")
print(f"Mod directory: {mod_dir}")
new_order = [item.text() for item in [self.list_widget.item(i) for i in range(self.list_widget.count())]]
print(f"New order: {new_order}")
order_file_path = os.path.join(mod_dir, 'user', 'mods', 'order.json')
backup_file_path = os.path.join(mod_dir, 'user', 'mods', 'order.bkp')
# Backup existing order.json as order.bkp
try:
shutil.copy(order_file_path, backup_file_path)
print('Backup created successfully!')
except Exception as e:
print(f'Error creating backup: {e}')
# Save new order to order.json
with open(order_file_path, 'w') as file:
json.dump({"order": new_order}, file, indent=4)
print('Order saved successfully!')
if __name__ == '__main__':
mod_directory = os.getcwd() # Assume current directory if --sptakidir is not given
if len(sys.argv) >= 3 and sys.argv[1] == "--sptakidir":
mod_directory = sys.argv[2]
app = QApplication(sys.argv)
# Apply VS Code's default theme
stylesheet = qtvscodestyle.load_stylesheet(qtvscodestyle.Theme.DARK_VS)
app.setStyleSheet(stylesheet)
print(f"mod_directory: {mod_directory}")
window = DragDropApp(mod_directory)
window.show()
sys.exit(app.exec_())