My Pygame Game Engine
at main 977 B view raw
1## Imports 2 3import json, os 4from colormap import hex2rgb 5 6## Class 7 8class Color_Handler: 9 def __init__(self, game): 10 self.game = game 11 12 ## Returns the hex value of the given link from the current assetpack 13 14 def get_hex(self, color_link): 15 with open(os.path.join("src", "resources", self.game.current_assetpack, "assets", "colors.json"), "r") as color_file: 16 color_json = json.load(color_file) 17 if color_link in color_json: 18 return color_json[color_link] 19 else: 20 return "#00000" 21 22 ## Returns the rgb value of the given link from the current assetpack 23 24 def get_rgb(self, color_link): 25 with open(os.path.join("src", "resources", self.game.current_assetpack, "assets", "colors.json"), "r") as color_file: 26 color_json = json.load(color_file) 27 if color_link in color_json: 28 return hex2rgb(color_json[color_link]) 29 else: 30 return (0, 0, 0) 31