Created
August 15, 2019 00:31
-
-
Save DrBluefall/3bd8dad129ccc014e3d29b3000803a2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Core Language Imports | |
from PIL import Image | |
from pprint import pprint | |
# Third-Party Imports | |
import pg8000 as pg | |
asset_db = pg.connect(user='prismarine-core', database='assets') | |
ac = asset_db.cursor() | |
ab_query = "SELECT row_to_json(abilities) FROM abilities WHERE id = %s;" | |
unknown = { | |
"image": "../assets/img/skills/Unknown.png", | |
"name": "Unknown" | |
} | |
def get_subs(ab_list): | |
return [ ac.execute(ab_query, (i,)).fetchone() if i != 0 else [unknown] for i in ab_list ] | |
def compile_loadout_dict(loadout: dict): | |
weapon_set = ac.execute(""" | |
SELECT row_to_json(main_weapons), row_to_json(sub_weapons), row_to_json(special_weapons) FROM main_weapons | |
JOIN special_weapons ON main_weapons.special=special_weapons.name | |
JOIN sub_weapons ON main_weapons.sub=sub_weapons.name | |
WHERE site_id = %s AND class = %s; | |
""", (loadout["id"], loadout["set"])).fetchone() | |
head = { | |
"gear": ac.execute(""" | |
SELECT row_to_json(headgear) FROM headgear WHERE id = %s; | |
""", (loadout["head"]["gear_id"],)).fetchone()[0], | |
"main": ac.execute(ab_query, (loadout["head"]["main"],)).fetchone()[0] if loadout["head"]["main"] != 0 else unknown, | |
"subs": [ val for sublist in get_subs(loadout["head"]["subs"]) for val in sublist ] | |
} | |
clothes = { | |
"gear": ac.execute(""" | |
SELECT row_to_json(clothing) FROM clothing WHERE id = %s; | |
""", (loadout["clothes"]["gear_id"],)).fetchone()[0], | |
"main": ac.execute(ab_query, (loadout["clothes"]["main"],)).fetchone()[0] if loadout["clothes"]["main"] != 0 else unknown, | |
"subs": [ val for sublist in get_subs(loadout["clothes"]["subs"]) for val in sublist ] | |
} | |
shoes = { | |
"gear": ac.execute(""" | |
SELECT row_to_json(shoes) FROM shoes WHERE id = %s; | |
""", (loadout["shoes"]["gear_id"],)).fetchone()[0], | |
"main": ac.execute(ab_query, (loadout["shoes"]["main"],)).fetchone()[0] if loadout["shoes"]["main"] != 0 else unknown, | |
"subs": [ val for sublist in get_subs(loadout["shoes"]["subs"]) for val in sublist ] | |
} | |
return { | |
"main": weapon_set[0], | |
"sub": weapon_set[1], | |
"special": weapon_set[2], | |
"head": head, | |
"clothes": clothes, | |
"shoes": shoes | |
} | |
def generate_image(loadout: dict): | |
head_coords = { | |
"gear": (183, 24), | |
"main": (153, 118), | |
"subs": [ | |
(189, 127), | |
(217, 127), | |
(246, 127) | |
] | |
} | |
clothes_coords = { | |
"gear": (183, 24), | |
"main": (298, 118), | |
"subs": [ | |
(334, 127), | |
(363, 127), | |
(391, 127) | |
] | |
} | |
shoe_coords = { | |
"gear": (183, 24), | |
"main": (443, 118), | |
"subs": [ | |
(479, 127), | |
(508, 127), | |
(536, 127) | |
] | |
} | |
coord_map = { | |
"head": head_coords, | |
"clothes": clothes_coords, | |
"shoes": shoe_coords | |
} | |
base = Image.open("../assets/img/loadout_base.png") | |
sub_wep = Image.open(loadout["sub"]["image"]).resize((32,32), Image.ANTIALIAS) | |
base.paste(sub_wep, (27, 116), sub_wep) | |
special_wep = Image.open(loadout["special"]["image"]).resize((32,32), Image.ANTIALIAS) | |
base.paste(special_wep, (78, 116), special_wep) | |
main_wep = Image.open(loadout["main"]["image"]).resize((96,96), Image.ANTIALIAS) | |
base.paste(main_wep, (24, 24), main_wep) | |
# Problematic section: | |
for gear in ["head", "clothes", "shoes"]: | |
gear = Image.open(loadout[gear]["gear"]["image"]).resize((32,32), Image.ANTIALIAS) | |
main = Image.open(loadout[gear]["main"]["image"]).resize((32,32), Image.ANTIALIAS) # main says it's unhashable??? Works if put first, but still breaks on line 104 | |
base.paste(main, coord_map[gear]["main"], main) | |
for index, sub in enumerate(loadout[gear]["subs"]): | |
sub = Image.open(sub["image"]).resize((24,24), Image.ANTIALIAS) | |
base.paste(sub, coord_map[gear]["subs"][index], sub) | |
return base |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment