Kano Avatar details - KanoComputing/kano-profile GitHub Wiki
Avatar Logic
In its current form the logic to handle the creation of avatars for a kano world profile is located in https://github.com/KanoComputing/kano-profile/blob/create_avatar/kano_avatar/logic.py.
This file contains 4 main classes, namely:
AvatarAccessory
AvatarCharacter
AvatarConfParser
AvatarCreator
Of these, the first two are used internally by the logic and only their public methods should be used. The AvatarConfParser
class should only be used to parse an avatar configuration file.
AvatarCreator
inherits from AvatarConfParser
and is the one to be used to create Avatar images.
An example usage would be:
from kano_avatar.logic import AvatarCreator, get_avatar_conf
configuration = get_avatar_conf()
ac = AvatarCreator(configuration)
ac.char_select('Judoka')
ac.obj_select(['list', 'of', 'object', 'names', 'here'])
ac.create_avatar(save_to='new_avatar.png', circ_assets=True)
Configuration file
The logic for kano-avatar is very flexible in terms of adding new characters, items and item categories. It adheres to the YAML format. An example of the file is displayed below:
categories:
- cat_name: Hats
z_index: 2
disp_icon: hats.png
- cat_name: Shirts
z_index: 1
disp_icon: shirts.png
- cat_name: Face
z_index: 1
disp_icon: face.png
characters:
- display_name: Judoka
img_name: Judoka.png
preview_img: Judoka_prev.png
crop_x: 193
crop_y: 108
objects:
# - display_name:
# img_name:
# preview_img:
# position_x:
# position_y:
# category:
#
- display_name: Blue Hat
img_name: blue_hat.png
preview_img: blue_hat_prev.png
position_x: 185
position_y: 55
category: Hats
- display_name: Black Hat
img_name: black_hat.png
preview_img: black_hat_prev.png
position_x: 160
position_y: 50
category: Hats
- display_name: White Hat
img_name: white_hat.png
preview_img: white_hat_prev.png
position_x: 230
position_y: 20
category: Hats
- display_name: T-Shirt
img_name: t_shirt.png
preview_img: t_shirt_prev.png
position_x: 90
position_y: 250
category: Shirts
- display_name: Sleeveless Shirt
img_name: sleeveless_shirt.png
preview_img: sleeveless_shirt_prev.png
position_x: 150
position_y: 250
category: Shirts
- display_name: Cool Shirt
img_name: cool_shirt.png
preview_img: cool_shirt_prev.png
position_x: 75
position_y: 245
category: Shirts
- display_name: Gentlemans Goatee
img_name: goatee.png
preview_img: goatee_prev.png
position_x: 260
position_y: 210
category: Face
- display_name: Red lips
img_name: red_lips.png
preview_img: red_lips_prev.png
position_x: 260
position_y: 200
category: Face
- display_name: Thick Stache
img_name: thick_stache.png
preview_img: thick_stache_prev.png
position_x: 230
position_y: 210
category: Face
For the items, the position_x
and position_y
specify the offset of the top left corner of the asset when it is pasted on the base image, with regards to the latter.
For the character, the crop_x
and crop_y
specify the offset of the top left corner part of the image that will be used for the circular asset.
The preview_img
should point to an image that will be used in the GUI to represent the character/category/item.
Please note that the category names are case sensitive