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)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值