117 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			117 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			Python
		
	
	
	
import os
 | 
						|
from dataclasses import dataclass
 | 
						|
import json
 | 
						|
 | 
						|
 | 
						|
@dataclass
 | 
						|
class Context:
 | 
						|
    project_original_path: str
 | 
						|
    local_repo_commit: str
 | 
						|
    repo_url: str = ""
 | 
						|
    repo_branch: str = ""
 | 
						|
    repo_commit: str = ""
 | 
						|
    package_name: str = ""
 | 
						|
 | 
						|
    game_type: str = ""
 | 
						|
 | 
						|
    proguard_key = {}
 | 
						|
    app_name: str = ""
 | 
						|
 | 
						|
    original_package: str = "com.drop.meme.merge.game.fsaew.puzzle"
 | 
						|
    project_original_path: str = "project/original"
 | 
						|
 | 
						|
    temp_project_path: str = ""
 | 
						|
    temp_project_config_path: str = ""
 | 
						|
    # 本地的版本号
 | 
						|
    local_repo_branch: str = ""
 | 
						|
    local_repo_commit: str = ""
 | 
						|
 | 
						|
    admob_app_id: str = ""
 | 
						|
    game_services_project_id: str = ""
 | 
						|
    facebook_app_id: str = ""
 | 
						|
    facebook_client_token: str = ""
 | 
						|
 | 
						|
    version_display_name: str = "1"
 | 
						|
    version_code: int = 1
 | 
						|
 | 
						|
    config: any = None
 | 
						|
 | 
						|
    sdk_version: str = ""
 | 
						|
    sdk_prolink_version: str = ""
 | 
						|
 | 
						|
    out_project: str = ""
 | 
						|
    out_debug_apk: str = ""
 | 
						|
    out_release_apk: str = ""
 | 
						|
    out_release_aab: str = ""
 | 
						|
 | 
						|
    proguard_dict = {}
 | 
						|
 | 
						|
    string: dict = None
 | 
						|
 | 
						|
    update_code: bool = True
 | 
						|
    update_config: bool = True
 | 
						|
    update_keystore: bool = True
 | 
						|
    update_res_img: bool = True
 | 
						|
    update_res_icon: bool = True
 | 
						|
    update_res_unity: bool = True
 | 
						|
    config_path: str = ""
 | 
						|
    keystore_path: str = ""
 | 
						|
    res_img_path: str = ""
 | 
						|
    res_icon_path: str = ""
 | 
						|
    res_unity_path: str = ""
 | 
						|
 | 
						|
    config_config_md5: str = ""
 | 
						|
    config_keystore_md5: str = ""
 | 
						|
    config_res_img_md5: str = ""
 | 
						|
    config_res_icon_md5: str = ""
 | 
						|
    config_res_unity_md5: str = ""
 | 
						|
 | 
						|
    @classmethod
 | 
						|
    def from_json(cls, json_str: str):
 | 
						|
        data = json.loads(json_str)
 | 
						|
        return cls(**data)
 | 
						|
 | 
						|
    def get_config(self, key: str, default_value: str = '') -> str:
 | 
						|
        if self.config is None:
 | 
						|
            return default_value
 | 
						|
        return self.config.get(key, default_value).replace(" ", " ")
 | 
						|
 | 
						|
    def get_app_name(self):
 | 
						|
        if self.app_name:
 | 
						|
            return self.app_name
 | 
						|
        return self.get_config("app_name")
 | 
						|
 | 
						|
    def get_cache_config(self) -> dict[str, str]:
 | 
						|
        try:
 | 
						|
            path = os.path.join(self.temp_project_config_path, "config.json")
 | 
						|
            args = json.load(open(path, "r", encoding="utf-8"))
 | 
						|
            return args
 | 
						|
        except:
 | 
						|
            return {}
 | 
						|
 | 
						|
    def get_cache_config_from_key(self, key: str, default: str = "") -> str:
 | 
						|
        try:
 | 
						|
            return self.get_cache_config().get(key, default)
 | 
						|
        except:
 | 
						|
            return default
 | 
						|
 | 
						|
    def save_cache_config(self, key: str, value: str):
 | 
						|
        path = os.path.join(self.temp_project_config_path, "config.json")
 | 
						|
        config = self.get_cache_config()
 | 
						|
        config[key] = value
 | 
						|
        json.dump(config, open(path, "w", encoding="utf-8"), indent=4)
 | 
						|
 | 
						|
    def get_map(self) -> dict[str, str]:
 | 
						|
        try:
 | 
						|
            path = os.path.join(self.temp_project_config_path, "map.json")
 | 
						|
            return json.load(open(path, "r", encoding="utf-8"))
 | 
						|
        except:
 | 
						|
            return {}
 | 
						|
 | 
						|
    def save_map(self, map: dict[str, str]):
 | 
						|
        path = os.path.join(self.temp_project_config_path, "map.json")
 | 
						|
        json.dump(map, open(path, "w", encoding="utf-8"), indent=4)
 | 
						|
 | 
						|
    def get_map_from_key(self, file_name) -> str:
 | 
						|
        return self.get_map().get(file_name, file_name)
 |