import json class Project: def __init__(self): self.chars={} self.char_res=(0,0) self.path=None self.loaded=False self.modified=False def load(self,path): with open(path, "r") as f: project_data = json.load(f) if not "char_width" in project_data or not "char_height" in project_data: raise AttributeError("Character metrics information not found") if not isinstance(project_data["char_width"],int) or not isinstance(project_data["char_height"],int): raise AttributeError("Invalid character metrics type, expected int") if not "chars" in project_data: raise AttributeError("Character data not found") if not isinstance(project_data["chars"],dict): raise AttributeError("Invalid character data type, expected object") self.chars=project_data["chars"] self.char_res=(project_data["char_width"],project_data["char_height"]) self.path=path self.loaded=True def save(self,path): # save project data to file with open(path, "w") as f: json.dump({ "char_width": self.char_res[0], "char_height": self.char_res[1], "chars": self.chars }, f, indent=4) self.path=path self.loaded=True def does_char_exist(self,c): return chr(c) in self.chars