Python 批量修改CocosCreator打包文件为全屏

Python 批量修改CocosCreator打包文件为全屏

前言

使用CocosCreator打包了好多项目,但是一个一个改为全屏显示太慢,干脆自动化修改了。

源码

import os

# 所有打包后的文件路径
changeparent_filepath=r"C:\Users\Administrator\Desktop\all"


def bianliwaiceng(waicengPath):
    filepaths=[]
    dirs=os.listdir(waicengPath)
    for file in dirs:
        # file_name=file[:-4] # 去除文件后缀
        print("遍历到"+file)
        filepath=changeparent_filepath+"\\"+file
        if os.path.isdir(filepath):
            # print("是文件夹就进来"+file)
            filepaths.append(filepath)         
    return filepaths

# 从文件夹中找到所有index.html的路径
def zhaodaoIndex(wenjianliebiaoList,mingzi):
    indexFilePath=[]
    for path in wenjianliebiaoList:
        # print(path)
        dirs=os.listdir(path)
        for file in dirs:
            # print(file)
            if file == mingzi:
                indexFilePath.append(path+"\\"+file)
    return indexFilePath

def chuliIndex(allindexList):
    for path in allindexList:
        print("需要处理:"+path)

        # 打开一个文件
        fo = open(path, "r")
        # print(fo.tell())
        lines = fo.readlines()
        # count = len(lines) #文件的总行数
        # print(count)
        # print(lines[22])
        lines[22]='<!-- <h1 class="header">hello_world</h1> -->\n'

        lines[24]='<div id="GameDiv" style="width:100%; height: 100%;">\n'
        lines[25]='  <canvas id="GameCanvas" width="100%" height="100%"></canvas>\n'
        lines[26]='  <div id="splash">\n'
        lines[27]='    <div class="progress-bar stripes">\n'
        lines[28]='      <span style="width: 0%"></span>\n'
        lines[29]='    </div>\n'
        lines[30]='  </div>\n'
        lines[31]='</div>\n'

        lines[33]='<!-- <p class="footer">Made with <a href="https://www.cocos.com/products#CocosCreator" title="cocos creator">Cocos Creator</a></p> -->\n'
        
        # 关闭打开的文件
        fo.close()
        fo = open(path, "w")
        for line in lines:
            fo.writelines(line)
        fo.close()

def chuliCss(allindexList):
    for path in allindexList:
        print("需要处理:"+path)

        # 打开一个文件
        fo = open(path, "r")
        # print(fo.tell())
        lines = fo.readlines()
        # count = len(lines) #文件的总行数
        # print(count)
        lines[106]='/* '+lines[106]
        lines[115]=lines[115]+' */'
        lines.insert(0,'html,body{width: 100%;height: 100%;overflow: hidden;}\n')

        # 关闭打开的文件
        fo.close()
        fo = open(path, "w")
        for line in lines:
            fo.writelines(line)
        fo.close()


pathList = bianliwaiceng(changeparent_filepath)
allIndexPath=zhaodaoIndex(pathList,"index.html")
chuliIndex(allIndexPath)


allCssPath=zhaodaoIndex(pathList,"style-desktop.css")
chuliCss(allCssPath)


參考了一下NeHe 的教程, 在 cocos2d-x 2.0 上可以做點小手腳在 Windows 上全屏顯示! 參考了一下NeHe 的教程, 在 cocos2d-x 2.0 上可以做點小手腳在 Windows 上全屏顯示! 主要修改兩個檔案: CCEGLView.h CCEGLView.cpp 它們在工程里的位置是 libcocos2d->platform->win32 先打開 CCEGLView.h 在 public: 底下加上一個新功能: void setFullScreen(bool flag); 另外在 private: 里加上一個新變數: bool m_bFullScreen; 接下來是 CCEGLView.cpp: 在 Constructor 加上 m_bFullScreen 的初始值: CCEGLView::CCEGLView() : m_bCaptured(false) , m_hWnd(NULL) , m_hDC(NULL) , m_hRC(NULL) , m_lpfnAccelerometerKeyHook(NULL) , m_bFullScreen(false) 再加上我們的 setFullScreen(): void CCEGLView::setFullScreen(bool flag) { m_bFullScreen = flag; } 然後在 Create() 里, 把CreateWindowEx() 那段改成下邊這樣: /////////////// FULLSCREEN HACK - BEGIN DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style DWORD dwStyle = WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX; // Window Style if (m_bFullScreen) { DEVMODE dmScreenSettings; // Device Mode memset(&dmScreenSettings;,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure dmScreenSettings.dmPelsWidth = w; // Selected Screen Width dmScreenSettings.dmPelsHeight = h; // Selected Screen Height dmScreenSettings.dmBitsPerPel = 32; // Selected Bits Per Pixel dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar. if (ChangeDisplaySettings(&dmScreenSettings;,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { // If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode. if (MessageBox(NULL, L"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?",L"cocos2d-x",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { setFullScreen(false); // back to windowed mode } else { // Pop Up A Message Box Letting User Know The Program Is Closing. MessageBox(NULL,L"Program Will Now Close.",L"ERROR",MB_OK|MB_ICONSTOP); return FALSE; // Return FALSE } } else // yeah! we are in fullscreen { dwExStyle = WS_EX_APPWINDOW; dwStyle=WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; //ShowCursor(FALSE); RECT rect; rect.left=(long)0; // Set Left Value To 0 rect.right=(long)w; // Set Right Value To Requested Width rect.top=(long)0; // Set Top Value To 0 rect.bottom=(long)h; // Set Bottom Value To Requested Height AdjustWindowRectEx(&rect;, dwStyle, FALSE, dwExStyle); // Adjust To True Requested Size } } /////////////// FULLSCREEN HACK - END // create window m_hWnd = CreateWindowEx( dwExStyle, // Extended Style For The Window kWindowClassName, // Class Name wszBuf, // Window Title dwStyle, // Defined Window Style 0, 0, // Window Position 0, // Window Width 0, // Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance NULL ); CC_BREAK_IF(! m_hWnd); 基本上這樣已搞定. 最後在我們自己項目的 main.cpp 里選擇全屏即可: AppDelegate app; CCEGLView& eglView = CCEGLView::sharedOpenGLView(); eglView.setFullScreen(true); eglView.setViewName("Hello Tests"); eglView.setFrameSize(1920, 1080); 要注意事項: - eglView.setFullScreen(true) 一定要在 eglView.setViewName("xxx") 前面. - eglView.setFrameSize(1920, 1080) 設定的大小, 一定要是顯卡可以支持的. - 不能再用CCDirector::sharedDirector()->enableRetinaDisplay(true)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值