-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.py
More file actions
86 lines (70 loc) · 2.89 KB
/
build.py
File metadata and controls
86 lines (70 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Example build script for mods. Feel free to modify the calls at the end of the file to fit your needs
# Intended use: copy this script into your_mod_project/scripts/
import os
import shutil
import subprocess
import time
import xml.etree.ElementTree as ET
from pathlib import Path
import psutil
# script configuration: edit these options to fit your setup
# these paths are relative to your project root. absolute paths also work
GAME_ROOT = Path("C:/Program Files (x86)/Steam/steamapps/common/Stacklands").resolve()
SYNC_FOLDERS = ["Blueprints", "Boosterpacks", "Cards", "Images", "Sounds"]
# you probably dont need to touch these
STACKLANDS_EXE = GAME_ROOT / "Stacklands"
MOD_BIN = Path("bin/Debug/netstandard2.0")
def build_mod():
start_time = time.time()
p = subprocess.Popen("dotnet build", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, stderr = p.communicate()
if p.returncode != 0:
print(stdout.decode())
exit(p.returncode)
print(f"built in {time.time() - start_time:.2f}s")
def launch_stacklands():
subprocess.Popen(STACKLANDS_EXE)
def kill_stacklands():
for proc in psutil.process_iter(["name", "pid"]):
if proc.name() == "Stacklands.exe":
proc.kill()
proc.wait()
def sync_folder(src: Path, dst: Path):
for file in dst.glob("**/*"):
file_in_src = src / file.relative_to(dst)
if file.is_dir() and not file_in_src.exists():
shutil.rmtree(file)
elif file.is_file() and (not file_in_src.exists() or file.stat().st_mtime < file_in_src.stat().st_mtime):
os.remove(file)
for file in src.glob("**/*"):
file_in_dst = dst / file.relative_to(src)
if not file_in_dst.exists():
file_in_dst.parent.mkdir(parents=True, exist_ok=True)
if file.is_file():
shutil.copy(file, file_in_dst)
elif file.is_dir():
shutil.copytree(file, file_in_dst)
def copy_files():
MOD_GAME_PATH.mkdir(exist_ok=True)
shutil.copyfile(MOD_DLL, MOD_GAME_PATH / MOD_DLL.name)
print("syncing folders..")
for folder in SYNC_FOLDERS:
sync_folder(Path(folder), MOD_GAME_PATH / folder)
if __name__ == "__main__":
# this little hack makes the script callable from anywhere
old_path = Path.cwd()
try:
os.chdir(Path(__file__).parent.parent)
found_csprojs = list(Path(".").glob("*.csproj"))
if len(found_csprojs) != 1:
raise RuntimeError("Can't find .csproj file")
with open(found_csprojs[0], encoding="utf-8") as f:
root = ET.parse(f).getroot()
MOD_DLL = MOD_BIN / f"{root.find('./PropertyGroup/AssemblyName').text}.dll"
MOD_GAME_PATH = GAME_ROOT / f"BepInEx/plugins/{found_csprojs[0].stem}"
build_mod()
kill_stacklands()
copy_files()
launch_stacklands()
finally:
os.chdir(old_path)