@@ -37,23 +37,41 @@ def unpack_cmd(*, savegame_file: Optional[Path], fileid: Optional[int]) -> None:
37
37
type = Path ,
38
38
nargs = "?" ,
39
39
)
40
+ @app .argument ("--fileid" , type = int , help = "Workshop file id to unpack." )
40
41
@app .argument ("--binary" , action = "store_true" )
41
- def repack_cmd (* , savegame_file : Optional [Path ], binary : bool ) -> None :
42
+ def repack_cmd (
43
+ * , savegame_file : Optional [Path ], fileid : Optional [int ], binary : bool
44
+ ) -> None :
42
45
from .config import config
43
46
from .repack import repack
44
47
45
- if not savegame_file :
48
+ if fileid and savegame_file :
49
+ raise Exception ("Can't specify both a savegame file and a workshop file id." )
50
+ elif fileid and binary :
51
+ raise Exception ("Can't specify both a workshop file id and '--binary'." )
52
+ elif not savegame_file :
46
53
if binary :
47
54
savegame_file = Path ("build/savegame.bson" )
48
55
else :
49
56
savegame_file = Path ("build/savegame.json" )
50
57
51
- if not savegame_file .parent .exists ():
58
+ if not fileid and not savegame_file .parent .exists ():
52
59
savegame_file .parent .mkdir (parents = True )
53
60
54
61
savegame = repack (config = config )
55
62
56
- if binary :
63
+ if fileid :
64
+ import bson
65
+
66
+ from tts .steam import cli_login , update_file , upload_file
67
+
68
+ client = cli_login ()
69
+ # It appears that tabletop simulator depends on the file being named
70
+ # `WorkshopUpload`.
71
+ upload_file (client , "WorkshopUpload" , bson .dumps (savegame ))
72
+ update_file (client , fileid , "WorkshopUpload" )
73
+
74
+ elif binary :
57
75
import bson
58
76
59
77
savegame_file .write_bytes (bson .dumps (savegame ))
@@ -76,4 +94,28 @@ def download_cmd(*, fileid: int, output: Optional[Path]) -> None:
76
94
output .write_text (format_json (mod ))
77
95
78
96
97
+ @app .command (
98
+ "workshop-upload" ,
99
+ help = "Upload a mod to the steam workshop." ,
100
+ description = "This will currently only update a existing mod." ,
101
+ )
102
+ @app .argument ("fileid" , type = int )
103
+ @app .argument (
104
+ "savegame_file" ,
105
+ metavar = "savegame" ,
106
+ type = Path ,
107
+ )
108
+ def upload_cmd (* , fileid : int , savegame_file : Optional [Path ]) -> None :
109
+ import bson
110
+
111
+ from tts .steam import cli_login , update_file , upload_file
112
+
113
+ savegame = json .loads (savegame_file .read_text ())
114
+ client = cli_login ()
115
+ # It appears that tabletop simulator depends on the file being named
116
+ # `WorkshopUpload`.
117
+ upload_file (client , "WorkshopUpload" , bson .dumps (savegame ))
118
+ update_file (client , fileid , "WorkshopUpload" )
119
+
120
+
79
121
main = app .main
0 commit comments