2022-02-08 01:29:02 +00:00
#!/usr/bin/env python3
import argparse
import os
from pathlib import Path
import shutil
import subprocess
import sys
2022-02-17 21:15:00 +00:00
import re
from tools . oot import *
2022-02-08 01:29:02 +00:00
def clean ( ) :
# Clean build environment
print ( " Cleaning build environment " )
# Build list of paths (files and folders) to delete
paths = [ ]
# Assets
2022-02-17 21:15:00 +00:00
paths . append ( Path ( ' assets/ ' ) )
2022-02-08 01:29:02 +00:00
paths . append ( Path ( ' build/ ' ) )
# GlideN64
paths . append ( Path ( ' GLideN64/projects/msvc/build ' ) )
paths . extend ( Path ( ' external/Win32/ ' ) . glob ( ' *GLide* ' ) )
paths . extend ( Path ( ' external/Win32/ ' ) . glob ( ' osal* ' ) )
# ooot
paths . append ( Path ( ' vs/Debug/ ' ) )
# Delete files and folders
for path in paths :
if path . exists ( ) == False :
continue
elif path . is_dir ( ) :
shutil . rmtree ( path )
else :
os . remove ( path )
def build ( ) :
print ( " Starting asset extraction and parsing " )
# sys.executable points to python executable
2022-02-17 21:15:00 +00:00
2022-02-08 01:29:02 +00:00
subprocess . check_call ( [ sys . executable , ' -m ' , ' pip ' , ' install ' , ' tqdm ' ] )
2022-02-18 00:50:02 +00:00
subprocess . check_call ( [ sys . executable , ' -m ' , ' pip ' , ' install ' , ' libyaz0 ' ] )
2022-02-17 21:15:00 +00:00
subprocess . check_call ( [ sys . executable , str ( ' tools/fixbaserom.py ' ) , buildRom ( ) ] )
subprocess . check_call ( [ sys . executable , str ( ' tools/extract_baserom.py ' ) , buildRom ( ) ] )
subprocess . check_call ( [ sys . executable , str ( ' tools/extract_assets.py ' ) , buildRom ( ) ] )
subprocess . check_call ( [ sys . executable , str ( ' tools/extract_z64_variables.py ' ) , buildRom ( ) ] )
subprocess . check_call ( [ sys . executable , str ( ' tools/convert_assets.py ' ) , buildRom ( ) ] )
mkdir ( assetPath ( ' text ' ) )
2022-02-18 00:50:02 +00:00
subprocess . check_call ( [ sys . executable , str ( ' tools/msgenc.py ' ) , str ( romPath ( ' text/charmap.txt ' ) ) , str ( assetPath ( ' text/message_data.h ' ) ) , str ( assetPath ( ' text/message_data.enc.h ' ) ) , buildRom ( ) ] )
subprocess . check_call ( [ sys . executable , str ( ' tools/msgenc.py ' ) , str ( romPath ( ' text/charmap.txt ' ) ) , str ( assetPath ( ' text/message_data_staff.h ' ) ) , str ( assetPath ( ' text/message_data_staff.enc.h ' ) ) , buildRom ( ) ] )
2022-02-17 21:15:00 +00:00
subprocess . check_call ( [ sys . executable , str ( ' tools/extract_missing_assets.py ' ) , buildRom ( ) ] )
subprocess . check_call ( [ sys . executable , str ( ' tools/create_luts.py ' ) , buildRom ( ) ] )
subprocess . check_call ( [ sys . executable , str ( ' tools/fix_mtx.py ' ) , buildRom ( ) ] )
2022-02-09 05:23:19 +00:00
2022-02-08 01:29:02 +00:00
print ( " Finished asset extraction and parsing " )
def main ( ) :
# Command Line Interface
parser = argparse . ArgumentParser ( description = " Setup " )
parser . add_argument ( " -c " , " --clean " , help = " Cleans environment before asset extraction " , action = " store_true " , default = False )
2022-03-28 02:32:21 +00:00
parser . add_argument ( " -p " , " --props-only " , help = " Only sets project properties / options (does not extract assets) " , action = " store_true " , default = False )
2022-02-08 01:29:02 +00:00
parser . add_argument ( " -co " , " --clean-only " , help = " Cleans environment without asset extraction " , action = " store_true " , default = False )
2022-02-17 21:15:00 +00:00
parser . add_argument ( " -b " , " --buildRom " , choices = validBuildOptions ( ) , help = " build rom config ex: EUR_MQD " )
parser . add_argument ( " -f " , " --framerate " , choices = [ ' 20 ' , ' 30 ' , ' 60 ' , ' 120 ' , ' 240 ' ] , help = " game framerate " , default = ' 20 ' )
parser . add_argument ( " -m " , " --enable-mouse " , help = " Enables mouse controls " , action = " store_true " , default = True )
2022-03-23 11:42:48 +00:00
parser . add_argument ( " --disable-frizzle-cam " , help = " Disables R-Stick camera control " , action = " store_true " , default = False )
2022-03-13 07:24:29 +00:00
parser . add_argument ( " --disable-distance-culling " , help = " Disables culling distant objects " , action = " store_true " , default = False )
2022-03-18 03:24:14 +00:00
parser . add_argument ( " --enable-gyro " , help = " Enable gyro controls " , action = " store_true " , default = False )
2022-03-23 11:42:48 +00:00
parser . add_argument ( " --enable-debug-level-select " , help = " Enable debug level select on save 1 " , action = " store_true " , default = False )
2022-03-24 13:56:35 +00:00
parser . add_argument ( " -t " , " --text-speed " , choices = [ ' 1 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' , ' 10 ' , ' 20 ' ] , help = " Text scroll speed scaler " , default = ' 1 ' )
2022-03-28 02:32:21 +00:00
parser . add_argument ( " --pause-exit-input-clear-frames " , choices = [ ' 0 ' , ' 2 ' , ' 3 ' , ' 4 ' , ' 5 ' ] , help = " Number of frames to clear input state after pause menu exits (For speed-running, 0 disables) " , default = ' 2 ' )
2022-02-08 01:29:02 +00:00
args = parser . parse_args ( )
2022-02-17 21:15:00 +00:00
if args . buildRom :
setBuildRom ( args . buildRom )
else :
setBuildRom ( findBuildRom ( ) )
2022-02-18 00:50:02 +00:00
with open ( ' vs/oot.props.src ' , ' r ' ) as f :
2022-02-17 21:15:00 +00:00
buffer = f . read ( )
2022-02-18 14:41:37 +00:00
buffer = buffer . replace ( ' #BUILD_ROM# ' , buildRom ( ) )
2022-02-17 21:15:00 +00:00
defines = [ ]
defines . append ( ' ENABLE_ %s FPS ' % args . framerate )
2022-03-24 13:56:35 +00:00
defines . append ( ' TEXT_SPEED_SCALER= %s ' % args . text_speed )
2022-02-17 21:15:00 +00:00
if args . enable_mouse :
defines . append ( ' ENABLE_MOUSE ' )
2022-03-23 11:42:48 +00:00
if not args . disable_frizzle_cam :
2022-03-13 06:54:28 +00:00
defines . append ( ' FIZZLE_CAM ' )
2022-03-18 03:24:14 +00:00
2022-03-13 06:57:47 +00:00
if args . disable_distance_culling :
defines . append ( ' NO_CULLING ' )
2022-03-13 06:54:28 +00:00
2022-03-18 03:24:14 +00:00
if args . enable_gyro :
defines . append ( ' ENABLE_GYRO ' )
2022-03-23 11:42:48 +00:00
if args . enable_debug_level_select :
defines . append ( ' ENABLE_DEBUG_LEVEL_SELECT ' )
2022-03-28 02:32:21 +00:00
if args . pause_exit_input_clear_frames :
defines . append ( ' PAUSE_EXIT_INPUT_CLEAR_FRAMES= %s ' % args . pause_exit_input_clear_frames )
2022-03-23 11:42:48 +00:00
2022-02-17 21:15:00 +00:00
if buildRom ( ) . lower ( ) [ - 1 ] != ' d ' :
defines . append ( ' RETAIL ' )
defines . append ( re . sub ( r ' [^A-Z0-9_]+ ' , ' ' , buildRom ( ) ) )
defines . append ( ' NATIVE ' )
2022-02-18 14:41:37 +00:00
#buffer = re.sub(r'<PreprocessorDefinitions>.*</PreprocessorDefinitions>', r'<PreprocessorDefinitions>%s</PreprocessorDefinitions>' % ';'.join(defines), buffer)
buffer = buffer . replace ( ' #DEFINES# ' , ' ; ' . join ( defines ) )
2022-02-17 21:15:00 +00:00
2022-02-18 00:50:02 +00:00
with open ( ' vs/oot.props ' , ' w ' ) as f :
2022-02-17 21:15:00 +00:00
f . write ( buffer )
2022-03-28 02:32:21 +00:00
if not args . props_only :
if args . clean == True :
clean ( )
build ( )
elif args . clean_only == True :
clean ( )
else :
build ( )
2022-02-08 01:29:02 +00:00
if __name__ == " __main__ " :
main ( )
2022-02-11 06:34:52 +00:00