CocosBuilderで作ったLayerのLoaderのヘッダファイルを作ってくれる。 【使い方】
python LoaderCreater.py 元となるレイヤークラス名
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# coding: UTF-8 | |
import re | |
import sys # モジュール属性 argv を取得するため | |
argvs = sys.argv # コマンドライン引数を格納したリストの取得 | |
argc = len(argvs) # 引数の個数 | |
if (argc != 2): | |
print ('Usage: # python %s ClassName' % argvs[0]) | |
quit() | |
_underscorer1 = re.compile(r'(.)([A-Z][a-z]+)') | |
_underscorer2 = re.compile('([a-z0-9])([A-Z])') | |
def camelToSnake(s): | |
subbed = _underscorer1.sub(r'\1_\2', s) | |
return _underscorer2.sub(r'\1_\2', subbed).upper() | |
class_name = argvs[1] | |
snaked_name = camelToSnake(class_name) | |
# 書き込む文字列 | |
str = """#ifndef __%s_LOADER__ | |
#define __%s_LOADER__ | |
#include "%s.h" | |
class %sLoader : public cocos2d::extension::CCLayerLoader | |
{ | |
public: | |
CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(%sLoader, loader); | |
protected: | |
CCB_VIRTUAL_NEW_AUTORELEASE_CREATECCNODE_METHOD(%s); | |
}; | |
#endif /* __%s_LOADER__ */ | |
""" % (snaked_name, snaked_name, class_name, class_name, class_name, class_name, snaked_name) | |
header_file = '%s.h' % class_name | |
f = open(header_file, 'w') # 書き込みモードで開く | |
f.write(str) # 引数の文字列をファイルに書き込む | |
f.close() # ファイルを閉じる | |
print ('Created %s File.' % header_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment