project-creator cocos2d-x 2.1.4 with python3
先日のcreate_project.py。なんかエラーが出て使えない。
と思ったらpython2で書かれてますね、これ。
って事でpython3で動かすために変更をしてみたので備忘録。
本家のForumで検索かけると “tools\project-creator\create_project_python3.py” のファイル名がヒットする。
恐らくgitから持ってくればpython3対応のファイルが既にあるんだと思う。
以下の方法は VS2012でのBuild以外は あまりテストしていないので面倒でない人はそちらを参照する事を推奨。
実行は Win x64版 python3.3.2でpython.orgから落とせるやつを私は使ってます。
+++ create_project.py.1~ 2013-06-11 12:51:24.000000000 +0900 @@ -24,15 +24,15 @@ import shutil
def dumpUsage():
- print(“Usage: create_project.py -project PROJECT_NAME -package PACKAGE_NAME -language PROGRAMING_LANGUAGE”)
- print(“Options:")
- print(” -project PROJECT_NAME Project name, for example: MyGame”)
- print(” -package PACKAGE_NAME Package name, for example: com.MyCompany.MyAwesomeGame”)
- print(” -language PROGRAMING_LANGUAGE Major programing lanauge you want to used, should be [cpp | lua | javascript]")
- print("")
- print(“Sample 1: ./create_project.py -project MyGame -package com.MyCompany.AwesomeGame”)
- print(“Sample 2: ./create_project.py -project MyGame -package com.MyCompany.AwesomeGame -language javascript”)
- print("")
- print “Usage: create_project.py -project PROJECT_NAME -package PACKAGE_NAME -language PROGRAMING_LANGUAGE”
- print “Options:”
- print " -project PROJECT_NAME Project name, for example: MyGame”
- print " -package PACKAGE_NAME Package name, for example: com.MyCompany.MyAwesomeGame”
- print " -language PROGRAMING_LANGUAGE Major programing lanauge you want to used, should be [cpp | lua | javascript]”
- print "”
- print “Sample 1: ./create_project.py -project MyGame -package com.MyCompany.AwesomeGame”
- print “Sample 2: ./create_project.py -project MyGame -package com.MyCompany.AwesomeGame -language javascript”
- print "”
def checkParams(context): # generate our internal params @@ -60,13 +60,13 @@ # pinrt error log our required paramters are not ready raise_error = False if context[“dst_project_name”] == “undefined”:
-
print("Invalid -project parameter")
-
if context[“dst_package_name”] == “undefined”:print "Invalid -project parameter" raise_error = True
-
print("Invalid -package parameter")
-
if context[“language”] == “undefined”:print "Invalid -package parameter" raise_error = True
-
print("Invalid -language parameter")
-
if raise_error != False: sys.exit() @@ -106,15 +106,13 @@ content = "” f1 = open(filepath, “rb”) for line in f1:print "Invalid -language parameter" raise_error = True
-
# convert bytes to str
-
lineStr = str(line, encoding='utf-8')
-
if src_string in lineStr:
-
content += lineStr.replace(src_string, dst_string)
-
if src_string in line:
-
content += line.replace(src_string, dst_string) else:
-
content += lineStr
-
f1.close() f2 = open(filepath, “wb”)content += line
- f2.write(content.encode(‘utf-8’))
- f2.write(content) f2.close()
end of replaceString
@@ -168,7 +166,7 @@ replaceString(proj_path + dst, context[“src_project_name”], context[“dst_project_name”])
# done!
- print(“proj.%s\t\t: Done!” % platform)
- print “proj.%s\t\t: Done!” % platform
end of processPlatformProjects
@@ -184,8 +182,8 @@
copy “lauguage”(cpp/lua/javascript) platform.proj into cocos2d-x/projects/<project_name>/folder
if (os.path.exists(context[“dst_project_path”]) == True):
- print(“Error:” + context[“dst_project_path”] + " folder is already existing”)
- print(“Please remove the old project or choose a new PROJECT_NAME in -project parameter”)
- print “Error:” + context[“dst_project_path”] + " folder is already existing”
- print “Please remove the old project or choose a new PROJECT_NAME in -project parameter” sys.exit() else: shutil.copytree(context[“src_project_path”], context[“dst_project_path”], True) @@ -196,6 +194,6 @@
exec “import %s.handle_project_files” % (platform)
exec “%s.handle_project_files.handle_project_files(context)” % (platform)
-print(“New project has been created in this path: " + context[“dst_project_path”].replace("/tools/project-creator/../..", “")) -print(“Have Fun!") +print “New project has been created in this path: " + context[“dst_project_path”].replace("/tools/project-creator/../..", “") +print “Have Fun!”
追記:再度、Googleってみたところ本家の変更はこれなのかな?
ちゃんと比べてないけど変更の方法は多分ほぼ同じ。唯一違うのが、私の変更が相変わらずファイルをBinaryオープンしてるのに対して
↑の変更はencodingを指定してTextオープンしている点。
git側の実装だと改行コードがlfだったファイルがcrlfに変更になってしまって好みじゃないんだよなぁ、、、。うーむ。