forked from misaki-eymard/custom-spine-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspine_export.bat
224 lines (180 loc) · 9.68 KB
/
spine_export.bat
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
@echo off
REM Customization Section
REM Enter the path to the Spine executable.
SET SPINE_EXE="C:\Program Files\Spine\Spine.com"
REM Specify the version of Spine Editor you want to use here.
SET VERSION=4.1.23
REM Specify the default export format here.
REM If "json" or "binary" is specified: JSON or binary export will be performed with default settings.
REM If "json+pack" or "binary+pack" is specified: Texture packing will also be performed with default settings.
REM Alternatively, you can specify the path to a specific export settings JSON to use its content as the default export settings.
SET DEFAULT_FORMAT=binary+pack
REM Decide whether to perform animation cleanup (true/false).
REM Even if set to 'false,' cleanup will be performed if the 'cleanUp' is set to 'true' in the export settings JSON.
SET CLEANUP=false
REM Get the script directory
SET "SCRIPT_DIR=%~dp0"
CD /D "%SCRIPT_DIR%"
REM Check if the Spine editor executable was found
IF NOT EXIST %SPINE_EXE% (
SET SPINE_EXE="C:\Program Files\Spine\Spine.com"
)
IF NOT EXIST %SPINE_EXE% (
SET SPINE_EXE="C:\Program Files\Spine\Spine.com"
)
REM Check if the Spine editor executable was found
IF NOT EXIST %SPINE_EXE% (
echo Error: Spine editor executable was not found.
echo Open the script and modify the path to the executable file that is set to 'SPINE_EXE'.
exit /B 1
)
echo Spine exe: %SPINE_EXE%
IF "%~1"=="" (
SET /P "search_dir=Please enter the path to the directory containing the Spine projects you want to export: "
)
REM Counter for the presence of .spine files
SET spine_file_count=0
REM Save .spine files to a temporary file
SET "tmp_file=%temp%\tempfile.tmp"
REM Search for files with extensions ".spine" and ".json" in bulk
dir /B /S /A-D %search_dir%\*.spine > "%tmp_file%"
REM Check if there are files with extension ".spine" within the specified directory
FOR /F "delims=" %%A IN (%tmp_file%) DO (
SET "file_path=%%A"
FOR /F %%B IN ("%%~xA") DO (
IF /I "%%B"=="spine" (
SET /A spine_file_count+=1
REM Get the filename from file_path
FOR %%C IN ("%%A") DO SET "file_name=%%~nxC"
REM Calculate the relative path from search_dir
SET "relative_path=%%A"
SET "relative_path=!relative_path:%search_dir%\=!"
echo ================================
echo #!spine_file_count! : !relative_path!
REM Extract the path to the directory where .spine files exist
SET "directory_path=%%~dpA"
REM Initialize the json_files array
SET "json_files="
REM Find .export.json files within the specified directory and add them to the json_files array
FOR %%D IN ("!directory_path!\*.export.json") DO (
CALL SET json_files[!json_files_count!]=%%D
SET /A json_files_count+=1
)
REM Check if 'jq' is installed
WHERE jq >NUL 2>NUL
IF %ERRORLEVEL% NEQ 0 (
echo Error: 'jq' is not installed. Please install 'jq' and retry.
exit /B 1
)
REM Check the number of JSON files
IF !json_files_count! GEQ 2 (
echo Multiple '.export.json' files were found:
SET "json_file_count=!json_files_count!"
REM Counter to count export operations
SET export_count=0
REM Inner loop: Process JSON files
FOR /L %%E IN (0, 1, !json_files_count!) DO (
SET "json_file=!json_files[%%E]!"
FOR /F %%F IN ("!json_file!") DO (
FOR /F %%G IN ('jq -e ".class == \"export-json\"" "!json_file!"') DO (
IF %%G==true (
echo ================================
SET /A export_count+=1
REM Calculate the relative path from search_dir
SET "relative_json_path=!json_file:%search_dir%\=!"
echo (!export_count!/!json_file_count!) Exporting using the export settings JSON file: !relative_json_path!
REM Extract the value of the "output" parameter within JSON data using 'jq'
FOR /F %%H IN ('jq -r ".output" "!json_file!"') DO SET "output_path=%%H"
REM Add the appropriate parameters to the 'command_args' array
SET "command_args=-i !file_path!"
REM Add the -m option if CLEANUP is set to "true"
IF "%CLEANUP%"=="true" (
SET "command_args=!command_args! -m"
) ELSE (
REM Even if CLEANUP is set to 'false,' cleanup will be performed if
REM 'cleanUp' is set to 'true' in the export settings JSON file.
FOR /F %%I IN ('jq -r ".cleanUp" "!json_file!"') DO (
IF %%I==true (
SET "command_args=!command_args! -m"
)
)
)
REM Add other options
SET "command_args=!command_args! -o !output_path! -e !json_file!"
!SPINE_EXE! !command_args!
echo Exported to the following directory: !output_path!
) ELSE (
echo The found JSON file does not appear to be an export settings JSON. This file will be skipped.
)
)
)
)
) ELSE IF !json_files_count! EQU 1 (
REM Inner loop: Process JSON files
FOR /L %%J IN (0, 1, 0) DO (
SET "json_file=!json_files[%%J]!"
FOR /F %%K IN ("!json_file!") DO (
FOR /F %%L IN ('jq -e ".class == \"export-json\"" "!json_file!"') DO (
IF %%L==true (
SET "relative_json_path=!json_file:%search_dir%\!"
echo Using the export settings JSON file: !relative_json_path!
FOR /F %%M IN ('jq -r ".output" "!json_file!"') DO SET "output_path=%%M"
REM Add the appropriate parameters to the 'command_args' array
SET "command_args=-i !file_path!"
REM Add the -m option if CLEANUP is set to "true"
IF "%CLEANUP%"=="true" (
SET "command_args=!command_args! -m"
) ELSE (
REM Even if CLEANUP is set to 'false,' cleanup will be performed if
REM 'cleanUp' is set to 'true' in the export settings JSON file.
FOR /F %%N IN ('jq -r ".cleanUp" "!json_file!"') DO (
IF %%N==true (
SET "command_args=!command_args! -m"
)
)
)
REM Add other options
SET "command_args=!command_args! -o !output_path! -e !json_file!"
!SPINE_EXE! !command_args!
echo Exported to the following directory: !output_path!
) ELSE (
echo The found JSON file does not appear to be an export settings JSON. Default settings (!DEFAULT_FORMAT!) will be used for export.
SET "command_args=-i !file_path!"
REM Add the -m option if CLEANUP is set to "true"
IF "%CLEANUP%"=="true" (
SET "command_args=!command_args! -m"
)
REM Add other options
SET "command_args=!command_args! -o !directory_path!\export -e !DEFAULT_FORMAT!"
!SPINE_EXE! !command_args!
echo Exported to the following directory: !directory_path!
)
)
)
)
) ELSE (
echo No '.export.json' files were found in the same directory as the Spine project. Default settings (!DEFAULT_FORMAT!) will be used for export.
SET "command_args=-i !file_path!"
REM Add the -m option if CLEANUP is set to "true"
IF "%CLEANUP%"=="true" (
SET "command_args=!command_args! -m"
)
REM Add other options
SET "command_args=!command_args! -o !directory_path!\export -e !DEFAULT_FORMAT!"
!SPINE_EXE! !command_args!
echo Exported to the following directory: !directory_path!
)
)
)
)
REM Delete the temporary file
DEL "%tmp_file%"
echo ================================
IF %spine_file_count% EQU 0 (
echo Error: No files with the '.spine' extension were found.
echo ================================
exit /B 1
) ELSE (
echo Exporting for all Spine projects found in %search_dir% is completed.
echo ================================
)