diff --git a/bin/strings.json b/bin/strings.json index cb89f1bd..5f134a50 100644 --- a/bin/strings.json +++ b/bin/strings.json @@ -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.", @@ -88,6 +89,7 @@ "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'.", @@ -95,6 +97,7 @@ "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.", @@ -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++ 代码与各平台工程。", @@ -426,6 +430,7 @@ "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 的路径。", @@ -433,6 +438,7 @@ "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 文件路径,支持指定多个路径。", @@ -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++ 代碼與各平臺工程。", @@ -763,6 +770,7 @@ "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 的路徑。", @@ -770,6 +778,7 @@ "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 檔案路徑,支持指定多個路徑。", diff --git a/plugins/plugin_generate/bin-templates/cpp-template-default/cocos-project-template.json b/plugins/plugin_generate/bin-templates/cpp-template-default/cocos-project-template.json index ee654741..e22cdf9f 100755 --- a/plugins/plugin_generate/bin-templates/cpp-template-default/cocos-project-template.json +++ b/plugins/plugin_generate/bin-templates/cpp-template-default/cocos-project-template.json @@ -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": { diff --git a/plugins/plugin_generate/bin-templates/js-template-runtime/cocos-project-template.json b/plugins/plugin_generate/bin-templates/js-template-runtime/cocos-project-template.json index 24f391b9..b63453cb 100755 --- a/plugins/plugin_generate/bin-templates/js-template-runtime/cocos-project-template.json +++ b/plugins/plugin_generate/bin-templates/js-template-runtime/cocos-project-template.json @@ -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": { diff --git a/plugins/plugin_generate/bin-templates/lua-template-runtime/cocos-project-template.json b/plugins/plugin_generate/bin-templates/lua-template-runtime/cocos-project-template.json index 9afbe4c6..a1eca1a8 100755 --- a/plugins/plugin_generate/bin-templates/lua-template-runtime/cocos-project-template.json +++ b/plugins/plugin_generate/bin-templates/lua-template-runtime/cocos-project-template.json @@ -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": { diff --git a/plugins/plugin_new/project_new.py b/plugins/plugin_new/project_new.py index 5af84501..17615aad 100644 --- a/plugins/plugin_new/project_new.py +++ b/plugins/plugin_new/project_new.py @@ -25,6 +25,7 @@ import re import utils from collections import OrderedDict +from os.path import relpath # @@ -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() @@ -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", @@ -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() @@ -340,7 +354,7 @@ 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 @@ -348,6 +362,7 @@ def __init__(self, lang, cocos_root, project_name, project_dir, tp_name, tp_dir, 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 @@ -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']) @@ -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 :