Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding functionality so that cocos can use one source directory for t… #306

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"NEW_ARG_IOS_BUNDLEID" : "Set a bundle id for iOS project.",
"NEW_ARG_MAC_BUNDLEID" : "Set a bundle id for Mac project.",
"NEW_ARG_ENGINE_PATH" : "Set the path of engine.",
"NEW_ARG_NOCOPY_ENGINE" : "Don't copy engine source and use root cocos directory",
"NEW_ARG_PORTRAIT" : "Set the project be portrait.",
"NEW_ARG_GROUP_SCRIPT" : "lua/js project arguments",
"NEW_ARG_NO_NATIVE" : "Create the project without native support.",
Expand All @@ -88,13 +89,15 @@
"NEW_INFO_STEP_IOS_BUNDLEID_FMT" : "> Replace the iOS bundle id from '%s' to '%s'",
"NEW_INFO_STEP_MAC_BUNDLEID_FMT" : "> Replace the Mac bundle id from '%s' to '%s'",
"NEW_INFO_STEP_MODIFY_FILE" : "> Modify files by re.sub()",
"NEW_INFO_STEP_RELATIVE_PATH" : "> Replacing cocos2d path with relative path",
"NEW_WARNING_NOT_A_FILE_FMT" : "%s is not a file.",
"NEW_ERROR_FOLDER_EXISTED_FMT" : "Fatal: %s folder is already exist.",
"NEW_ERROR_ENGINE_TIP_FMT" : "You can specify the path of %s by argument '-e'.",
"NEW_ERROR_TEMPLATE_NOT_FOUND_FMT" : "Fatal: can't find any template for <%s> language.\n%s",
"NEW_ERROR_DEFAILT_CFG_NOT_FOUND_FMT" : "Fatal: the '%s' dosen't has 'do_default' creating step.",
"NEW_ERROR_CMD_NOT_FOUND_FMT" : "Method '%s' is not found.",
"NEW_ERROR_PKG_NAME_NOT_SPECIFIED" : "Package name not specified.",
"NEW_WARNING_ENGINE_PATH_NOT_RELATIVE" : "The cocos2d engine source directory %s is not relative to project %s, defaulting to copying engine source.",
"LUACOMPILE_BRIEF" : "Encrypt and/or compile lua files.",
"LUACOMPILE_ARG_VERBOSE" : "Verbose output.",
"LUACOMPILE_ARG_SRC" : "Source directory of lua files needed to be compiled, supports mutiple source directories.",
Expand Down Expand Up @@ -405,6 +408,7 @@
"NEW_ARG_IOS_BUNDLEID" : "设置工程的 iOS Bundle ID。",
"NEW_ARG_MAC_BUNDLEID" : "设置工程的 Mac Bundle ID。",
"NEW_ARG_ENGINE_PATH" : "设置引擎路径。",
"NEW_ARG_NOCOPY_ENGINE" : "不要复制引擎源代码,并使用root科科斯目录",
"NEW_ARG_PORTRAIT" : "设置工程为竖屏。",
"NEW_ARG_GROUP_SCRIPT" : "lua/js 工程可用参数",
"NEW_ARG_NO_NATIVE" : "设置新建的工程不包含 C++ 代码与各平台工程。",
Expand All @@ -426,13 +430,15 @@
"NEW_INFO_STEP_IOS_BUNDLEID_FMT" : "> 替换 iOS 工程的 Bundle ID,'%s' 替换为 '%s'。",
"NEW_INFO_STEP_MAC_BUNDLEID_FMT" : "> 替换 Mac 工程的 Bundle ID,'%s' 替换为 '%s'。",
"NEW_INFO_STEP_MODIFY_FILE" : "> 使用 re.sub() 修改文件内容。",
"NEW_INFO_STEP_RELATIVE_PATH" : ">更换cocos2d的路径使用相对路径",
"NEW_WARNING_NOT_A_FILE_FMT" : "%s 不是有效的文件。",
"NEW_ERROR_FOLDER_EXISTED_FMT" : "错误:文件夹 %s 已经存在",
"NEW_ERROR_ENGINE_TIP_FMT" : "可以使用 -e 参数指定 %s 的路径。",
"NEW_ERROR_TEMPLATE_NOT_FOUND_FMT" : "错误:找不到 <%s> 模板。\n%s",
"NEW_ERROR_DEFAILT_CFG_NOT_FOUND_FMT" : "错误:'%s' 没有配置 'do_default' 数据。",
"NEW_ERROR_CMD_NOT_FOUND_FMT" : "未找到 '%s' 函数。",
"NEW_ERROR_PKG_NAME_NOT_SPECIFIED" : "未指定包名。",
"NEW_WARNING_ENGINE_PATH_NOT_RELATIVE" : "该发动机的cocos2d的源代码目录%s不是相对于项目%s,默认为复制引擎源。",
"LUACOMPILE_BRIEF" : "对 lua 文件进行加密和编译为字节码的处理。",
"LUACOMPILE_ARG_VERBOSE" : "更多输出信息。",
"LUACOMPILE_ARG_SRC" : "指定需要编译的 lua 文件路径,支持指定多个路径。",
Expand Down Expand Up @@ -742,6 +748,7 @@
"NEW_ARG_IOS_BUNDLEID" : "設置工程的 iOS Bundle ID。",
"NEW_ARG_MAC_BUNDLEID" : "設置工程的 Mac Bundle ID。",
"NEW_ARG_ENGINE_PATH" : "設置引擎路徑。",
"NEW_ARG_NOCOPY_ENGINE" : "不要复制引擎源代码,并使用root科科斯目录",
"NEW_ARG_PORTRAIT" : "設置工程為豎屏。",
"NEW_ARG_GROUP_SCRIPT" : "lua/js 工程可用參數",
"NEW_ARG_NO_NATIVE" : "設置新建的工程不包含 C++ 代碼與各平臺工程。",
Expand All @@ -763,13 +770,15 @@
"NEW_INFO_STEP_IOS_BUNDLEID_FMT" : "> 替換 iOS 工程的 Bundle ID,'%s' 替換為 '%s'。",
"NEW_INFO_STEP_MAC_BUNDLEID_FMT" : "> 替換 Mac 工程的 Bundle ID,'%s' 替換為 '%s'。",
"NEW_INFO_STEP_MODIFY_FILE" : "> 使用 re.sub() 修改檔案內容。",
"NEW_INFO_STEP_RELATIVE_PATH" : ">更换cocos2d的路径使用相对路径",
"NEW_WARNING_NOT_A_FILE_FMT" : "%s 不是有效的檔案。",
"NEW_ERROR_FOLDER_EXISTED_FMT" : "錯誤:檔案夾 %s 已經存在",
"NEW_ERROR_ENGINE_TIP_FMT" : "可以使用 -e 參數指定 %s 的路徑。",
"NEW_ERROR_TEMPLATE_NOT_FOUND_FMT" : "錯誤:找不到 <%s> 範本。\n%s",
"NEW_ERROR_DEFAILT_CFG_NOT_FOUND_FMT" : "錯誤:'%s' 沒有配置 'do_default' 數據。",
"NEW_ERROR_CMD_NOT_FOUND_FMT" : "未找到 '%s' 函數。",
"NEW_ERROR_PKG_NAME_NOT_SPECIFIED" : "未指定包名。",
"NEW_WARNING_ENGINE_PATH_NOT_RELATIVE" : "该发动机的cocos2d的源代码目录%s不是相对于项目%s,默认为复制引擎源。",
"LUACOMPILE_BRIEF" : "對 lua 檔案進行加密和編譯為位元組碼的處理。",
"LUACOMPILE_ARG_VERBOSE" : "更多輸出資訊。",
"LUACOMPILE_ARG_SRC" : "指定需要編譯的 lua 檔案路徑,支持指定多個路徑。",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
"files": [
"proj.ios_mac/ios/Info.plist"
]
},
"project_replace_relative_path": {
"src_relative_path":"../cocos2d",
"src_relative_prefix":"../",
"files": [
"proj.win32/PROJECT_NAME.vcxproj",
"proj.ios_mac/PROJECT_NAME.xcodeproj/project.pbxproj",
"proj.android/build_native.py"
]
}
},
"change_orientation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
"files":[
"frameworks/runtime-src/proj.ios_mac/ios/Info.plist"
]
},
"project_replace_relative_path": {
"src_relative_path":"$(SRCROOT)/../../cocos2d-x",
"src_relative_prefix":"$(SRCROOT)/../../",
"files": [
"frameworks/runtime-src/proj.win32/PROJECT_NAME.vcxproj",
"frameworks/runtime-src/proj.ios_mac/PROJECT_NAME.xcodeproj/project.pbxproj"
]
}
},
"change_orientation": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@
"files": [
"frameworks/runtime-src/proj.ios_mac/ios/Info.plist"
]
}
},
"project_replace_relative_path": {
"src_relative_path":"$(SRCROOT)/../../cocos2d-x",
"src_relative_prefix":"$(SRCROOT)/../../",
"files": [
"frameworks/runtime-src/proj.win32/PROJECT_NAME.vcxproj",
"frameworks/runtime-src/proj.ios_mac/PROJECT_NAME.xcodeproj/project.pbxproj"
]
}

},
"change_orientation": {
"append_from_template": {
Expand Down
48 changes: 45 additions & 3 deletions plugins/plugin_new/project_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import re
import utils
from collections import OrderedDict
from os.path import relpath


#
Expand Down Expand Up @@ -66,6 +67,15 @@ def init(self, args):
if os.path.isdir(tp_path):
self._templates_paths.append(tp_path)

# make relative path if we don't want to copy the engine source to the project directory
self._relative_path = None
if args.nocopy_engine is not None:
self._relative_path = os.path.relpath(self._cocosroot, self._projdir)
if self._relative_path[:2] != ".." :
cocos.Logging.warning(MultiLanguage.get_string('NEW_WARNING_ENGINE_PATH_NOT_RELATIVE',
(self._projdir, self._cocosroot)))
self._relative_path = None

# remove duplicates keeping order
o = OrderedDict.fromkeys(self._templates_paths)
self._templates_paths = o.keys()
Expand Down Expand Up @@ -110,6 +120,9 @@ def parse_args(self, argv):
parser.add_argument("--portrait", action="store_true", dest="portrait",
help=MultiLanguage.get_string('NEW_ARG_PORTRAIT'))

parser.add_argument("-n", "--nocopy-engine", action="store_true", dest="nocopy_engine",
help=MultiLanguage.get_string('NEW_ARG_NOCOPY_ENGINE'))

group = parser.add_argument_group(MultiLanguage.get_string('NEW_ARG_GROUP_SCRIPT'))
group.add_argument(
"--no-native", action="store_true", dest="no_native",
Expand Down Expand Up @@ -192,8 +205,9 @@ def _create_from_cmd(self):

tp_dir = self._templates.template_path()

creator = TPCreator(self._lang, self._cocosroot, self._projname, self._projdir,
self._tpname, tp_dir, self._package, self._mac_bundleid, self._ios_bundleid)
creator = TPCreator(self._lang, self._cocosroot, self._projname, self._projdir, self._tpname,
tp_dir, self._package, self._mac_bundleid, self._ios_bundleid, self._relative_path)

# do the default creating step
creator.do_default_step()

Expand Down Expand Up @@ -340,14 +354,15 @@ def select_one(self):

class TPCreator(object):

def __init__(self, lang, cocos_root, project_name, project_dir, tp_name, tp_dir, project_package, mac_id, ios_id):
def __init__(self, lang, cocos_root, project_name, project_dir, tp_name, tp_dir, project_package, mac_id, ios_id, cocos_relative_path):
self.lang = lang
self.cocos_root = cocos_root
self.project_dir = project_dir
self.project_name = project_name
self.package_name = project_package
self.mac_bundleid = mac_id
self.ios_bundleid = ios_id
self.cocos_relative_path = cocos_relative_path

self.tp_name = tp_name
self.tp_dir = tp_dir
Expand Down Expand Up @@ -481,6 +496,10 @@ def append_x_engine(self, v):
if cocos.CCPlugin.get_cocos2d_mode() == 'distro':
return

# don't copy source files, link to relative directory
if self.cocos_relative_path is not None:
return

src = os.path.join(self.cocos_root, v['from'])
dst = os.path.join(self.project_dir, v['to'])

Expand Down Expand Up @@ -674,6 +693,29 @@ def project_replace_ios_bundleid(self, v):
cocos.Logging.warning(MultiLanguage.get_string('NEW_WARNING_FILE_NOT_FOUND_FMT',
os.path.join(dst_project_dir, dst)))

def project_replace_relative_path(self, v):
""" will modify the content of a file to replace path with relative path
"""

if self.cocos_relative_path is None:
return

dst_project_dir = self.project_dir
dst_project_name = self.project_name
dst_relative_path = v['src_relative_prefix'] + self.cocos_relative_path
cocos.Logging.info(MultiLanguage.get_string('NEW_INFO_STEP_RELATIVE_PATH'))

files = v['files']
for f in files:
dst = f.replace("PROJECT_NAME", dst_project_name)
if os.path.exists(os.path.join(dst_project_dir, dst)):
replace_string(
os.path.join(dst_project_dir, dst), v['src_relative_path'], dst_relative_path)
else:
cocos.Logging.warning(MultiLanguage.get_string('NEW_WARNING_FILE_NOT_FOUND_FMT',
os.path.join(dst_project_dir, dst)))


def modify_files(self, v):
""" will modify the content of the file
format of v is :
Expand Down