-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_tic80_python.bat
More file actions
185 lines (163 loc) · 6.54 KB
/
run_tic80_python.bat
File metadata and controls
185 lines (163 loc) · 6.54 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
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
@REM setlocal
@REM set "TIC80_EXE=D:\Projects\tic80\tic80.exe"
@REM set "PROJ_DIR=.\tic80\python"
@REM set "MAIN=main.py"
@REM if not exist "%PROJ_DIR%" mkdir "%PROJ_DIR%"
@REM REM Create a starter cart on first run (optional)
@REM if not exist "%PROJ_DIR%\%MAIN%" (
@REM "%TIC80_EXE%" --fs "%PROJ_DIR%" --cmd "new python & save %MAIN%"
@REM )
@REM REM Auto-load and run the game
@REM "%TIC80_EXE%" --fs "%PROJ_DIR%" --cmd "load %MAIN% & run" --crt
@REM endlocal
@echo off
setlocal
REM --- Root = folder of this .bat (WYRDWAY)
set "ROOT=%~dp0"
set "FS_ROOT=%ROOT%"
if "%FS_ROOT:~-1%"=="\" set "FS_ROOT=%FS_ROOT:~0,-1%"
pushd "%ROOT%" >nul
REM --- Project paths
set "PROJ_DIR=%ROOT%tic80\python"
set "GAME_FILE=tic80\python\game.py"
set "MAIN_FILE=tic80\python\main.py"
set "BUILD_FILE=tic80\python\build.py"
set "MIN_BUILD_FILE=build.min.py"
set "MINIFY_SCRIPT=%ROOT%scripts\minify_tic80_build.py"
set "MINIFY_SCRIPT_REL=scripts\minify_tic80_build.py"
set "POST_BUILD_CMD=python %MINIFY_SCRIPT_REL% {input} {output}"
set "DIST_DIR=%ROOT%dist"
set "OUT_BASE=wyrdway"
REM --- Find tq-bundler.exe (1) root, (2) tools\, (3) PATH
set "TQ_BUNDLER_PATH="
if exist "%ROOT%tq-bundler.exe" set "TQ_BUNDLER_PATH=%ROOT%tq-bundler.exe"
if not defined TQ_BUNDLER_PATH if exist "%ROOT%tools\tq-bundler.exe" set "TQ_BUNDLER_PATH=%ROOT%tools\tq-bundler.exe"
if not defined TQ_BUNDLER_PATH (
for /f "delims=" %%i in ('where tq-bundler.exe 2^>nul') do (
set "TQ_BUNDLER_PATH=%%i"
goto :tq_done
)
)
:tq_done
if not defined TQ_BUNDLER_PATH (
echo [ERROR] tq-bundler.exe not found.
echo Put tq-bundler.exe in the repo root, or in .\tools\, or add it to PATH.
popd >nul
exit /b 1
)
REM --- Find tic80.exe (1) root, (2) tic80\, (3) env var TIC80_EXE, (4) PATH
set "TIC80_EXE_PATH="
if exist "%ROOT%tic80.exe" set "TIC80_EXE_PATH=%ROOT%tic80.exe"
if not defined TIC80_EXE_PATH if exist "%ROOT%tic80\tic80.exe" set "TIC80_EXE_PATH=%ROOT%tic80\tic80.exe"
if not defined TIC80_EXE_PATH if defined TIC80_EXE set "TIC80_EXE_PATH=%TIC80_EXE%"
if not defined TIC80_EXE_PATH (
for /f "delims=" %%i in ('where tic80.exe 2^>nul') do (
set "TIC80_EXE_PATH=%%i"
goto :tic_done
)
)
:tic_done
if not defined TIC80_EXE_PATH (
echo [ERROR] tic80.exe not found.
echo Put tic80.exe in the repo root, or in .\tic80\, or set env var TIC80_EXE, or add it to PATH.
popd >nul
exit /b 1
)
if not exist "%TIC80_EXE_PATH%" (
echo [ERROR] tic80.exe path resolved but file doesn't exist:
echo %TIC80_EXE_PATH%
popd >nul
exit /b 1
)
REM --- Validate project files
if not exist "%PROJ_DIR%\" (
echo [ERROR] Project folder not found: %PROJ_DIR%
popd >nul
exit /b 1
)
if not exist "%GAME_FILE%" (
echo [ERROR] Missing: %GAME_FILE%
popd >nul
exit /b 1
)
if not exist "%MAIN_FILE%" (
echo [ERROR] Missing: %MAIN_FILE%
popd >nul
exit /b 1
)
REM --- Modes:
REM run_tic80_python.bat -> bundle + minify(via tq-bundler post-build) + watch + run
REM run_tic80_python.bat dev -> bundle + minify(via tq-bundler post-build) + watch + run
REM run_tic80_python.bat build -> bundle + minify(via tq-bundler post-build) only
REM run_tic80_python.bat dist -> bundle + minify(via tq-bundler post-build) + export .tic/.exe/html
set "MODE=%~1"
if "%MODE%"=="" set "MODE=run"
if /i not "%MODE%"=="run" if /i not "%MODE%"=="dev" if /i not "%MODE%"=="build" if /i not "%MODE%"=="dist" (
echo [ERROR] Unknown mode: %MODE%
echo Usage: run_tic80_python.bat [run^|dev^|build^|dist]
popd >nul
exit /b 1
)
if not exist "%MINIFY_SCRIPT%" (
echo [ERROR] Missing: %MINIFY_SCRIPT%
popd >nul
exit /b 1
)
if /i "%MODE%"=="dev" goto :run_dev
if /i "%MODE%"=="build" goto :build_only
if /i "%MODE%"=="dist" goto :dist
if /i not "%MODE%"=="run" (
echo [ERROR] Internal mode dispatch failure: %MODE%
popd >nul
exit /b 1
)
echo [INFO] Using tq-bundler: %TQ_BUNDLER_PATH%
echo [INFO] Using tic80: %TIC80_EXE_PATH%
echo [INFO] Bundling + minifying via tq-bundler post-build + launching watcher...
echo "%TQ_BUNDLER_PATH%" run "%GAME_FILE%" "%MAIN_FILE%" --post-output "%MIN_BUILD_FILE%" --post-build "%POST_BUILD_CMD%" --tic "%TIC80_EXE_PATH%"
echo.
"%TQ_BUNDLER_PATH%" run "%GAME_FILE%" "%MAIN_FILE%" --post-output "%MIN_BUILD_FILE%" --post-build "%POST_BUILD_CMD%" --tic "%TIC80_EXE_PATH%"
set "EC=%errorlevel%"
popd >nul
exit /b %EC%
:run_dev
echo [INFO] Using tq-bundler: %TQ_BUNDLER_PATH%
echo [INFO] Using tic80: %TIC80_EXE_PATH%
echo [INFO] Bundling + minifying via tq-bundler post-build + launching watcher (dev)...
echo "%TQ_BUNDLER_PATH%" run "%GAME_FILE%" "%MAIN_FILE%" --post-output "%MIN_BUILD_FILE%" --post-build "%POST_BUILD_CMD%" --tic "%TIC80_EXE_PATH%"
echo.
"%TQ_BUNDLER_PATH%" run "%GAME_FILE%" "%MAIN_FILE%" --post-output "%MIN_BUILD_FILE%" --post-build "%POST_BUILD_CMD%" --tic "%TIC80_EXE_PATH%"
set "EC=%errorlevel%"
popd >nul
exit /b %EC%
:build_only
echo [INFO] Using tq-bundler: %TQ_BUNDLER_PATH%
echo [INFO] Bundling + minifying via tq-bundler post-build (build only)...
echo "%TQ_BUNDLER_PATH%" run "%GAME_FILE%" "%MAIN_FILE%" --post-output "%MIN_BUILD_FILE%" --post-build "%POST_BUILD_CMD%"
echo.
"%TQ_BUNDLER_PATH%" run "%GAME_FILE%" "%MAIN_FILE%" --post-output "%MIN_BUILD_FILE%" --post-build "%POST_BUILD_CMD%"
set "EC=%errorlevel%"
popd >nul
exit /b %EC%
:dist
echo [INFO] Using tq-bundler: %TQ_BUNDLER_PATH%
echo [INFO] Using tic80: %TIC80_EXE_PATH%
echo [INFO] Cleaning dist folder...
if exist "%DIST_DIR%" rmdir /s /q "%DIST_DIR%"
mkdir "%DIST_DIR%"
echo [INFO] Bundling + minifying via tq-bundler post-build...
echo "%TQ_BUNDLER_PATH%" run "%GAME_FILE%" "%MAIN_FILE%" --post-output "%MIN_BUILD_FILE%" --post-build "%POST_BUILD_CMD%"
echo.
"%TQ_BUNDLER_PATH%" run "%GAME_FILE%" "%MAIN_FILE%" --post-output "%MIN_BUILD_FILE%" --post-build "%POST_BUILD_CMD%"
if errorlevel 1 (
set "EC=%errorlevel%"
popd >nul
exit /b %EC%
)
echo [INFO] Exporting .tic/.exe/html/linux/mac to dist...
echo "%TIC80_EXE_PATH%" --cli --crt --fs "%FS_ROOT%" --cmd "load tic80/python/game.py & import code tic80/python/build.min.py & save dist/%OUT_BASE%.tic & export win dist/%OUT_BASE% alone=0 & export linux dist/%OUT_BASE%-linux alone=0 & export mac dist/%OUT_BASE%-mac alone=0 & export html dist/%OUT_BASE% alone=0 & exit"
echo.
"%TIC80_EXE_PATH%" --cli --crt --fs "%FS_ROOT%" --cmd "load tic80/python/game.py & import code tic80/python/build.min.py & save dist/%OUT_BASE%.tic & export win dist/%OUT_BASE% alone=0 & export linux dist/%OUT_BASE%-linux alone=0 & export mac dist/%OUT_BASE%-mac alone=0 & export html dist/%OUT_BASE% alone=0 & exit"
set "EC=%errorlevel%"
popd >nul
exit /b %EC%