The cocos2d-x3.0 uses scripts to create classes in classes

Source: Internet
Author: User

Generally, you need to put the new class in the classes folder. This is better for porting. However, the folder cannot be directly specified when VS is directly created, so it took some time to create a script in the afternoon. First, use python to write the file creation function. The interface is simple: Project name and new class name. Because you want to create it in the cocos2d-x/projects folder ., The py file and the subsequent bat file should be placed under the cocos2d-x root directory: py code:

import sys,os    def createFileInClass(projectName,newClassName):      projectDir = "projects\\"+projectName+"\\Classes";      os.chdir(projectDir);      headName=newClassName+".h";      sourceName=newClassName+".cpp"            headFile=open(headName,"a");      tempFileName = "_"+newClassName.upper()+"_H_";            headFile.write("#ifndef "+ tempFileName +"\n#define  "+tempFileName+"\n\n")      headFile.write("#include \"cocos2d.h\""+"\n\n");      headFile.write("using namespace cocos2d;\n\n");      headFile.write("class "+newClassName+"\n"+"{"+"\n"+"};"+"\n\n"+"#endif");      headFile.close();            sourceFile = open(sourceName,"a");      sourceFile.write("#include "+"\""+headName+"\"");      sourceFile.close()        from optparse import OptionParser  parser = OptionParser()  parser.add_option("-p", "--dir", dest="projectName",help="the project name",)  parser.add_option("-n", "--new", dest="newClassName", help="new class")  (options, args) = parser.parse_args()    createFileInClass(options.projectName,options.newClassName) 

 

It is easy to save it as CreateClassInProject. py, but it still takes some time because I have not written python code before. Then bat:
@echo off  echo CreateClassInProject:  set /p projectName=Please Input Project Name:   set /p className=Please Input Class Name:     echo Creating...    E:\cocos2d-x-3.0\CreateClassInProject.py -p %projectName% -n %className%    echo Create successfully,Please add it in Classes. 
Save pause as CreateClassInProject. bat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.