• cocos3 python脚本建立类文件


    以前看过一本关于精简工作内容的书,要把工作中重复的东西都简化

    今天我就来简化cocos3建立.h文件和.cpp文件

    ClassName="TestSprite"
    Type="Sprite"
    
    #.h file write
    file = open(ClassName+'.h', 'w')
    str='''#pragma once
    #include "cocos2d.h"
    USING_NS_CC;
    
    class ClassName:public Type
    {
    public:
        virtual bool init();
        CREATE_FUNC(ClassName);
    };
    '''
    str=str.replace("ClassName",ClassName)
    str=str.replace("Type",Type)
    file.write(str)
    file.close()
    
    
    #.cpp file write
    file = open(ClassName+'.cpp', 'w')
    str='''#include "ClassName.h"
    
    bool ClassName::init()
    {
        if(!Type::init())
        {
            return false;
        }
    
        
        return true;
    }
    '''
    str=str.replace("ClassName",ClassName)
    str=str.replace("Type",Type)
    file.write(str)
    file.close()

    14年12月20日跟新

    ClassName="Lever3Scene"
    Type="Scene"
    
    #.h file write
    
    if Type=="Scene":
        str='''#pragma once
    #include "cocos2d.h"
    USING_NS_CC;
    
    class ClassName:public Type
    {
    public:
        virtual bool init();
        static Scene* createScene();
        CREATE_FUNC(ClassName);
    };
    '''
    else :
        str='''#pragma once
    #include "cocos2d.h"
    USING_NS_CC;
    
    class ClassName:public Type
    {
    public:
        virtual bool init();
        CREATE_FUNC(ClassName);
    };
    '''
    
    file = open(ClassName+'.h', 'w')
    
    str=str.replace("ClassName",ClassName)
    str=str.replace("Type",Type)
    file.write(str)
    file.close()
    
    
    #.cpp file write
    
    if Type=="Scene":
        str='''#include "ClassName.h"
    
    Scene* ClassName::createScene()
    {
        auto scene = Scene::create();
        auto layer = ClassName::create();
        scene->addChild(layer);
        return scene;
    }
    
    bool ClassName::init()
    {
        if(!Type::init())
        {
            return false;
        }
    
        
        return true;
    }
    '''
    else :
        str='''#include "ClassName.h"
    
    
    bool ClassName::init()
    {
        if(!Type::init())
        {
            return false;
        }
    
        
        return true;
    }
    '''
    
    
    file = open(ClassName+'.cpp', 'w')
    str=str.replace("ClassName",ClassName)
    str=str.replace("Type",Type)
    file.write(str)
    file.close()
  • 相关阅读:
    批量修改数据库表前缀
    form表单reset重置按钮
    thinkphp禁止模版标签解析
    form 转json,将form表单中的数据序列化数组后转换为Json
    MIME对应表
    zend studio 12汉化和破解
    hadoop一键安装伪分布式
    简明shell入门
    java中readLine()方法为什么有的行读不到?
    using 40 logical processors based on SQL Server licensing SqlServer CPU核心数限制问题
  • 原文地址:https://www.cnblogs.com/yufenghou/p/4156596.html
Copyright © 2020-2023  润新知