Auto rename and build with icon (WIP)
Monkey Forums/Monkey Code/Auto rename and build with icon (WIP)
| ||
Hi to all For the last day or two I've been tinkering with trans to get it to do three things automatically. 1) To change the default MonkeyGame file out putted. 2) Change the savestate file name from .monkeystate. 3) To detect a default icon and add it to the executable file. Currently V64 GLFW and STDCPP supported. The code below is still a WORK IN PROGRESS. The way that it currently parses the VS and Xcode project template files need to be improved (a lot). And I don't really know if the VS/Xcode project files will break if they are edited before the icon is added to the build, but changing the name should be safe. Now to use it add at the top of your main monkey project source code: #PROJECT_NAME="My Game" then compile your code you should find in the .build folder that the projects back-end compiler files names have changed and your executable has been renamed. Currently spaces are removed to stop the back-end compilers from complaining. At some point in the future I'll looking it. Opening up the main.cpp file and looking at the LoadState functions, you should see .mygamestate instead of .monkeystate. Inside the xcode/mingw/vc2010 folders is a file called dont_delete.txt this is use to keep track of the name of the last build, so deleting it will break trans and the back-end compiler link. To add a icon on the fly. You can use Import or put the icon in the .data folder but you must add #IMAGE_FILES="*.png|*.jpg|*.ico" 'Windows #IMAGE_FILES="*.png|*.jpg|*.icns" 'OS X and name the icon app_icon.ico or app_icon.icns. The code. Back up and modify src/trans/targets/glfw.monkey At the top of the file under "Import target" add "Import modify" Change the methods MakeMingw, MakeVc2010 and MakeXcode to read.. Method MakeMingw() CreateDir "mingw/"+CASED_CONFIG CreateDataDir "mingw/"+CASED_CONFIG+"/data" Local main$=LoadString( "main.cpp" ) main=ReplaceBlock( main,"TRANSCODE",transCode ) main=ReplaceBlock( main,"CONFIG",Config() ) '#### DAWLANE CHANGE 'Change the projects back-end build files Local project:String = AlterBackEnd.Project() main = AlterBackEnd.Main(main) '##### CHANGE END SaveString main,"main.cpp" If OPT_ACTION >= ACTION_BUILD ChangeDir "mingw" Local ccopts:="" Select ENV_CONFIG Case "release" ccopts="-O3 -DNDEBUG" Case "debug" End '#### DAWLANE CHANGE Execute "mingw32-make CCOPTS=~q" + ccopts + "~q OUT=~q" + CASED_CONFIG + "/" + project + "~q" '##### CHANGE END If OPT_ACTION>=ACTION_RUN ChangeDir CASED_CONFIG '#### DAWLANE CHANGE Execute project '##### CHANGE END Endif Endif End Method MakeVc2010() CreateDir "vc2010/"+CASED_CONFIG CreateDataDir "vc2010/"+CASED_CONFIG+"/data" Local main$=LoadString( "main.cpp" ) main=ReplaceBlock( main,"TRANSCODE",transCode ) main=ReplaceBlock( main,"CONFIG",Config() ) '#### DAWLANE CHANGE 'Change the projects back-end build files Local project:String = AlterBackEnd.Project() main = AlterBackEnd.Main(main) '##### CHANGE END SaveString main,"main.cpp" If OPT_ACTION>=ACTION_BUILD ChangeDir "vc2010" '#### DAWLANE CHANGE Execute MSBUILD_PATH + " /p:Configuration=" + CASED_CONFIG + ";Platform=~qwin32~q ~q" + project + ".sln~q" '##### CHANGE END If OPT_ACTION>=ACTION_RUN ChangeDir CASED_CONFIG Execute project Endif Endif End Method MakeXcode() CreateDataDir "xcode/data" Local main$=LoadString( "main.cpp" ) main=ReplaceBlock( main,"TRANSCODE",transCode ) main=ReplaceBlock( main,"CONFIG",Config() ) '#### DAWLANE CHANGE 'Change the projects back-end build files Local project:String = AlterBackEnd.Project() main = AlterBackEnd.Main(main) '##### CHANGE END SaveString main, "main.cpp" If OPT_ACTION>=ACTION_BUILD ChangeDir "xcode" Execute "xcodebuild -configuration " + CASED_CONFIG '#### DAWLANE CHANGE 'Remove the extra icon from the app bundle AlterBackEnd.RemoveExtras() '##### CHANGE END If OPT_ACTION>=ACTION_RUN ChangeDir "build/" + CASED_CONFIG '#### DAWLANE CHANGE ChangeDir project + ".app/Contents/MacOS" Execute "./" + project '##### CHANGE END Endif Endif End For src/trans/targets/stdcpp.monkey Add Import modify to the top of the file under "Import target" And change Local out$="main_" + HostOSto Local out:String = AlterBackEnd.Project() + "_" + HostOS Now make a new file and name it as modify.monkey and save it in src/trans/targets then copy and paste the code below. With that done open src/trans/trans.monkey and compile it, when that's done copy the file main_winnt or main_macos in src/trans/trans.build/stdcpp folder to monkeys bin folder. Back up the trans executable by renaming it, then rename the main_winnt or main_macos to trans_winnt or trans_macos. |
| ||
Would you like to add this to monkey-ext? If so, make a Google Code clone, update to the development branch, then make your changes and push. I'll check it out and mention any changes you might want to make. http://code.google.com/p/monkey-ext/ |