Ejemplo n.º 1
0
class CreatePlatformJson(object):
    def __init__(self,
                 code_version='3.0',
                 platform_type=2,
                 platform="android",
                 pList=['default']):
        # self.platformList = ['qihoo','m4399','anzhi','baidu','downjoy','mi','nearme.gamecenter','uc']
        # self.talking_channel_list = ['000023','000108','000005','110000','000003','000066','000020','000255']

        # self.platformList = ['tencent','lenovo','huawei','youku','pps','kkk','wdj','mumayi']
        # self.talking_channel_list = ['000550','000016','000054','000466','000442','010001','010002','000008']
        # self.platformList = ['7659']
        # self.talking_channel_list = ['007659']

        # self.platformList = ['am']
        # self.talking_channel_list = ['000084']
        # self.platformList = ['shoumeng',"xunlei"]
        # self.talking_channel_list = ['shoumeng',"xunlei"]

        # yq
        # self.platformList = ['tailand']
        # self.talking_channel_list = ['tailand']
        self.platformList = pList
        self.talking_channel_list = ["%s_android" % n for n in pList]
        print(self.platformList)
        print("-----------------")
        print(self.talking_channel_list)

        # self.platformList = ['coolpad',"haima","m7659","maple","meizu","test","null","vivo"]
        # self.talking_channel_list = ['000078',"001104","007659","maple","000014","test","null","000368"]

        self.code_version = code_version
        self.platform_type = platform_type
        self.copy = Copy()

        if platform == "android":
            self.loginUrl = 'http://and.mx.maple-game.com/gateway.php'
        elif platform == "ios":
            self.loginUrl = ""
        else:
            raise Exception, "你输入的平台有误 只能接受android 和ios"

        self.root = 'frameworks/runtime-src/proj.android/platform/'
        self.storePath = "frameworks/runtime-src/proj.android/platform/%s/platform.json"
        self.template = 'frameworks/runtime-src/proj.android/template/'
        # self.storePath = "%s.json"

    def copyF(self, f, t):
        print "copy   ", f, "  =================>  ", t
        if not os.path.exists(t):

            self.copy.copyFile(f, t)

    def copyD(self, f, t):
        for item in os.walk(f):
            if not item[2]:
                continue
            # print "f = ",f," t = ",t
            for file in item[2]:
                f_ = os.path.join(item[0], file)
                # print 'f_',"   ===   > ",f_  ,"   file  ",file
                t_ = f_.replace(f, t)
                # print 't_',"   ===   > ",t_
                self.copyF(f_, t_)

        # if not os.path.exists(t):
        # 	self.copy.copyFiles(f,t)

    def start(self):
        cnt = len(self.platformList)

        for i in range(cnt):
            platform = self.platformList[i]
            channel_id = self.talking_channel_list[i]
            # self.copy.copyFiles(self.template + 'src',self.root + platform + '/src')

            self.createDirFiles(platform)

            path = self.storePath % platform
            jsonInfo = {}
            jsonInfo["game_loginUrl"] = self.loginUrl
            jsonInfo["platform_name"] = platform
            jsonInfo["platform_version"] = self.code_version
            jsonInfo["platform_type"] = self.platform_type
            jsonInfo["platform_desc"] = platform
            jsonInfo["talkingData_channel"] = channel_id
            jsonInfo["game_code_version"] = '' + self.code_version
            jsonInfo["exit_model"] = 0
            jsonInfo["crashCode"] = "1"
            jsonInfo["use_yaya_sdk"] = 1
            exit_model_desc = "0:  使用游戏内退出方式  1:使用sdk的退出"
            jsonInfo["exit_model_desc"] = exit_model_desc

            f = open(path, 'w')
            f.write(json.dumps(jsonInfo, indent=2, ensure_ascii=False))
            f.close()

            # print "handler ",path,"\nvalue:\n",json.dumps(jsonInfo)

        print "successfull"

    def createDirFiles(self, platform):
        path = self.root + platform
        # self.copy.removeDir(path)
        self.copy.createDir(path)

        self.copy.createDir(path + '/libs')
        self.copy.createDir(path + '/assets')
        self.copy.createDir(path + '/res')
        self.copy.createDir(path + '/src/org/cocos2dx/javascript/platform')
        self.copyF(self.template + 'ForManifest.xml',
                   path + '/ForManifest.xml')
        self.copyD(self.template + 'src', self.root + platform + '/src')
Ejemplo n.º 2
0
class Plugin:

    _rootPath = ""
    copy = ""

    platform_assets = "platform_assets"
    currentPlatform = ""

    def __init__(self, rootPath):
        self._rootPath = rootPath
        self.copy = Copy()

    """
    将临时资源拷贝到项目中
    """

    def tempAssetsToAndroidProject(self):
        self.copy.copyFiles(self.platform_assets, self.fromDir + "assets")

    def registerGamePlatform(self,
                             fromBaseDir,
                             toBaseDir,
                             platformCode,
                             operationCode,
                             platformname="default"):
        if os.path.exists(self.platform_assets):
            shutil.rmtree(self.platform_assets)

        os.mkdir(self.platform_assets)

        self.fromDir = fromBaseDir
        self.toDir = toBaseDir
        """
        平台的assets
        """
        if operationCode == 1:
            self.copy.copyFiles(fromBaseDir + "assets", self.platform_assets)
        elif operationCode == 2:
            self.copy.copyFiles(fromBaseDir + "assets", toBaseDir + "assets")

        self.copy.copyFiles(toBaseDir + "base/assets", toBaseDir + "assets")
        """ 复制 android res """
        Assets().removeAssetsByFilter(toBaseDir + "res", [])
        self.copy.copyFiles(toBaseDir + "base/res", toBaseDir + "res")
        print "copy ", fromBaseDir, " res"
        self.copy.copyFiles(fromBaseDir + "res", toBaseDir + "res")

        mainJsPath = "main.js"
        #if os.path.exists("frameworks/runtime-src/proj.android/platform/main.jsc"):
        #mainJsPath = "main.jsc"

        #if platformCode == 0:
        #self.copy.copyFile(fromBaseDir + mainJsPath, mainJsPath)
        #else:
        # self.copy.copyFile("frameworks/runtime-src/proj.android/platform/" + mainJsPath, mainJsPath)

        # self.copy.removeFileByFilter(toBaseDir + "libs",[])
        """  复制libs """
        # libsList = ["armeabi","armeabi-v7a","mips","x86"]
        self.copy.removeDir(toBaseDir + "libs")

        self.copy.copyFiles(toBaseDir + "base/libs", toBaseDir + "libs")
        self.copy.copyFiles(fromBaseDir + "libs", toBaseDir + "libs")

        # for name in libsList:
        #     ppath = fromBaseDir + 'libs/' + name
        #     if not os.path.exists(ppath):
        #         print "remove unused"
        #         self.copy.removeDir(toBaseDir + 'libs/' + name)

        appPath = 'src/org/cocos2dx/javascript/MyApplication.java'
        self.copy.copyFile(toBaseDir + 'base/' + appPath, toBaseDir + appPath)

        myActivity = 'src/org/cocos2dx/javascript/AppActivity.java'
        self.copy.copyFile(toBaseDir + 'base/' + myActivity,
                           toBaseDir + myActivity)
        """  复制平台代码 """
        Assets().removeAssetsByFilter(
            toBaseDir + "src/org/cocos2dx/javascript/platform",
            ['base', 'PlatformManager.java'])
        # Assets().removeAssetsByFilter(toBaseDir + "src/com/maple/hope/",[])
        Assets().removeAssetsByFilter(toBaseDir + "src/com/", ["android"])
        # self.copy.removeDir(toBaseDir + "src")
        # self.copy.copyFiles(toBaseDir + "base/src",toBaseDir + "src")
        self.copy.copyFiles(toBaseDir + "base/src", toBaseDir + "src")
        self.copy.copyFiles(fromBaseDir + "src", toBaseDir + "src")

        self.copy.copyFile(fromBaseDir + "AndroidManifest.xml",
                           toBaseDir + "AndroidManifest.xml")
        """ 复制平台配置 """
        platformJson = "platform.json"
        self.copy.copyFile(fromBaseDir + platformJson, platformJson)
        self.copy.copyFile(fromBaseDir + platformJson,
                           toBaseDir + 'assets/' + platformJson)

        # #-------------------------------   clear platform code ---------------------------------------
        # #baidu
        # self.copy.removeFileByFilter(toBaseDir + "src/org/cocos2dx/javascript/platform/baidu",[])
        # #oppo
        # self.copy.removeDir(toBaseDir + "src/com/nearme/gamecenter/open/api")

        # #-------------------------------   clear platform code ---------------------------------------

        # #-------------------------------   add platform code -----------------------------------------
        # # baidu_platform
        # if platformCode == 4:
        #     self.refisterBaidu(fromBaseDir,toBaseDir)
        # elif platformCode == 5:
        #     self.registerOppo(fromBaseDir,toBaseDir)
        #-------------------------------   add platform code ----------------------------------------

    def backFileToPlatfrom(self, f, t, t2=""):
        if os.path.exists(t):
            self.copy.copyFile(f, t)
        elif os.path.exists(t2):
            self.copy.copyFile(f, t2)

    """  将在项目中修改的平台代码保存到平台中去 """

    def backToPlatform(self):
        """  平台相关 src  """
        tailPath = 'src/org/cocos2dx/javascript/platform'
        info = self.copy.getFileData('python/log.txt')
        if info == "":
            return
        recoderList = info.split('_')
        platformname = recoderList[0]

        print "将当前项目中修改数据回退到平台%s" % platformname

        # curPlatJsonPath = "frameworks/runtime-src/proj.android/assets/platform.json"
        # jsonData = json.loads(self.copy.getFileData(curPlatJsonPath))
        # if not jsonData['platform_name'] == platformname:
        #     tkMessageBox.showinfo("通知","平台不当 保存的是%s,而当前是%s"%(platformname,jsonData['platform_name']))
        #     return

        headPath = 'frameworks/runtime-src/proj.android/'
        fromDir = headPath + tailPath
        toDir = headPath + 'platform/' + platformname + '/' + tailPath

        print "fromDir = ", fromDir, "  toDir = ", toDir
        for item in os.walk(fromDir):
            # print 'javascript/platform/base    ',item[0] ,'javascript/platform/base' in item[0]
            if not item[2] or 'javascript/platform/base' in item[0]:
                print "filter file%s" % item[0]
                continue

            filterList = ['.DS_Store', 'PlatformManager.java']
            for file in item[2]:
                if file in filterList:
                    continue
                fromPath = os.path.join(item[0], file)
                toPath = fromPath.replace(fromDir, toDir)
                # print fromPath , " ======> ",toPath
                self.copy.copyFile(fromPath, toPath)
        """ handler MyApplication """

        backFiles = [
            "src/org/cocos2dx/javascript/MyApplication.java",
            "src/org/cocos2dx/javascript/AppActivity.java",
            "src/org/cocos2dx/javascript/LoadingActivity.java"
        ]
        for file in backFiles:
            self.backFileToPlatfrom(
                headPath + file,
                headPath + 'platform/' + platformname + '/' + file,
                headPath + 'base/' + file)
        """      back to push   """
        pushname = recoderList[1]
        pushPath = headPath + 'src/org/cocos2dx/javascript/push'
        self.copy.copyFiles(pushPath, headPath + 'push/' + pushname + '/src')
        """  项目配置 """
        self.copy.copyFile(
            headPath + 'assets/platform.json',
            headPath + 'platform/' + platformname + '/platform.json')
        self.copy.copyFile(headPath + 'assets/main.js', 'main.js')
        """  about com dir"""
        for item in os.walk(headPath + "src/com"):
            if not item[2]:
                continue

            for file in item[2]:
                fromFile = os.path.join(item[0], file)
                toFile = fromFile.replace(
                    headPath + "src/com",
                    headPath + "platform/" + platformname + "/src/com", 1)
                if os.path.exists(toFile):
                    self.copy.copyFile(fromFile, toFile)

    def registerPushPlatform(self, fromBaseDir, toBaseDir, pushCode, p=None):

        javaDir = toBaseDir + "src/org/cocos2dx/javascript/push"
        self.copy.removeDir(javaDir)
        self.copy.copyFiles(fromBaseDir + 'src', javaDir)
        """
             tt平台需要用自己的android-support-v4.jar 而这个版本比push里的高,只能特殊处理下了  
        """
        # if not p == "tencent":
        #     self.copy.copyFiles(fromBaseDir + "assets",toBaseDir + "assets")
        #     if not p =="tt":
        #         self.copy.copyFiles(fromBaseDir + "libs",toBaseDir + "libs")
        #     else:
        #         self.copy.copyFiles(fromBaseDir + "libs",toBaseDir + "libs",filterFiles=['android-support-v4.jar'])
        filterList = ["tt", "yeshen"]
        self.copy.copyFiles(fromBaseDir + "assets", toBaseDir + "assets")
        if not p in filterList:
            self.copy.copyFiles(fromBaseDir + "libs", toBaseDir + "libs")
        else:
            self.copy.copyFiles(fromBaseDir + "libs",
                                toBaseDir + "libs",
                                filterFiles=['android-support-v4.jar'])
        self.currentPlatform = p

    def registerLogPlatform(self, fromBaseDir, toBaseDir):
        self.copy.copyFiles(fromBaseDir + "assets", self.platform_assets)
        self.copy.copyFiles(fromBaseDir + "libs", toBaseDir + "libs")
        self.copy.copyFiles(fromBaseDir + "res", toBaseDir + "res")

#---------------------------------------- platform --------------------------------------------------------------------

    def refisterBaidu(self, fromBaseDir, toBaseDir):
        self.copy.copyFiles(fromBaseDir + "src",
                            toBaseDir + "src/org/cocos2dx/javascript/platform")

    def registerOppo(self, fromBaseDir, toBaseDir):
        dirPath = "src/com/nearme/gamecenter/open/api"
        self.copy.copyFiles(fromBaseDir + dirPath, toBaseDir + dirPath)

#---------------------------------------- push -------------------------------------------------------------------------

    def registerXgPush(self, fromBaseDir, toBaseDir):
        javaPath = toBaseDir + "src/com/qq/xgdemo/receiver/MessageReceiver.java"
        #self.copy.removeFile(javaPath)
        self.copy.copyFile(fromBaseDir + "MessageReceiver.java", javaPath)

        javaPath = toBaseDir + "src/com/qq/xgdemo/receiver/XGNotification.java"
        #self.copy.removeFile(javaPath)
        self.copy.copyFile(fromBaseDir + "XGNotification.java", javaPath)

        javaPath = toBaseDir + "src/com/qq/xgdemo/receiver/NotificationService.java"
        #self.copy.removeFile(javaPath)
        self.copy.copyFile(fromBaseDir + "NotificationService.java", javaPath)

        javaPath = toBaseDir + "src/com/qq/xgdemo/receiver/DBOpenHelper.java"
        #self.copy.removeFile(javaPath)
        self.copy.copyFile(fromBaseDir + "DBOpenHelper.java", javaPath)

#------------------------- unit function -------------------------------

    def copyFile(self, fromPath, toPath):
        self.copyFile(fromPath, toPath)