commit 056f8bae3e22af6475018c00af376ca8810c4850
parent 689cd18e5920f4f8aa1087b1387b2738847a87b3
Author: Erik Letson <hmagellan@hmagellan.com>
Date: Wed, 2 Dec 2020 23:00:58 -0600
Tentative per-pixel alpha functionality
Diffstat:
2 files changed, 84 insertions(+), 53 deletions(-)
diff --git a/data/json/sheets.json b/data/json/sheets.json
@@ -3,192 +3,224 @@
"filename" : "mainmenubg.png",
"dimensions" : [1024, 768],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"mainmenu_buttons_1" : {
"filename" : "mainmenu_buttons_1.png",
"dimensions" : [100, 50],
"total_sprites" : 16,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"still_scene_text_box_1" : {
"filename" : "still_scene_text_box_1.png",
"dimensions" : [1024, 260],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"still_scene_name_box_1" : {
"filename" : "still_scene_name_box_1.png",
"dimensions" : [150, 54],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"continue_prompt_1" : {
"filename" : "continue_prompt_1.png",
"dimensions" : [32, 13],
"total_sprites" : 9,
- "anim_class" : "Continue_Prompt_1"
+ "anim_class" : "Continue_Prompt_1",
+ "alpha" : false
},
"test_scene_bg_1" : {
"filename" : "test_scene_bg_1.png",
"dimensions" : [1024, 768],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"test_scene_char1" : {
"filename" : "test_scene_char1.png",
"dimensions" : [72, 200],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"jisella_1" : {
"filename" : "jisella_1.png",
"dimensions" : [64, 64],
"total_sprites" : 72,
- "anim_class" : "Piece_Unique_1"
+ "anim_class" : "Piece_Unique_1",
+ "alpha" : false
},
"jisella_2" : {
"filename" : "jisella_2.png",
"dimensions" : [64, 64],
"total_sprites" : 72,
- "anim_class" : "Piece_Unique_1"
+ "anim_class" : "Piece_Unique_1",
+ "alpha" : false
},
"jisella_3" : {
"filename" : "jisella_3.png",
"dimensions" : [64, 64],
"total_sprites" : 72,
- "anim_class" : "Piece_Unique_1"
+ "anim_class" : "Piece_Unique_1",
+ "alpha" : false
},
"jisella_4" : {
"filename" : "jisella_4.png",
"dimensions" : [64, 64],
"total_sprites" : 72,
- "anim_class" : "Piece_Unique_1"
+ "anim_class" : "Piece_Unique_1",
+ "alpha" : false
},
"jisella_pictures_1_icons_small" : {
"filename" : "pictures/jisella_1/icons_small.png",
"dimensions" : [24, 24],
"total_sprites" : 2,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"jisella_pictures_2_icons_small" : {
"filename" : "pictures/jisella_2/icons_small.png",
"dimensions" : [24, 24],
"total_sprites" : 2,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"jisella_pictures_3_icons_small" : {
"filename" : "pictures/jisella_3/icons_small.png",
"dimensions" : [24, 24],
"total_sprites" : 2,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"jisella_pictures_4_icons_small" : {
"filename" : "pictures/jisella_4/icons_small.png",
"dimensions" : [24, 24],
"total_sprites" : 2,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"jisella_pictures_1_battle_portrait" : {
"filename" : "pictures/jisella_1/battle_portrait.png",
"dimensions" : [294, 651],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"jisella_pictures_2_battle_portrait" : {
"filename" : "pictures/jisella_2/battle_portrait.png",
"dimensions" : [294, 651],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"jisella_pictures_3_battle_portrait" : {
"filename" : "pictures/jisella_3/battle_portrait.png",
"dimensions" : [294, 651],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"jisella_pictures_4_battle_portrait" : {
"filename" : "pictures/jisella_4/battle_portrait.png",
"dimensions" : [294, 651],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"cursor1" : {
"filename" : "cursor1.png",
"dimensions" : [64, 64],
"total_sprites" : 4,
- "anim_class" : "Board_Cursor_1"
+ "anim_class" : "Board_Cursor_1",
+ "alpha" : false
},
"board_overlays_1" : {
"filename" : "board_overlays_1.png",
"dimensions" : [64, 64],
"total_sprites" : 4,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"turn_order_tray_1" : {
"filename" : "turn_order_tray_1.png",
"dimensions" : [135, 128],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"turn_order_tray_extended_1" : {
"filename" : "turn_order_tray_extended_1.png",
"dimensions" : [135, 320],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"turn_icon_holder_1" : {
"filename" : "turn_icon_holder_1.png",
"dimensions" : [128, 28],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"toggle_more_turn_button_1" : {
"filename" : "toggle_more_turn_button_1.png",
"dimensions" : [135, 14],
"total_sprites" : 2,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"action_buttons_1" : {
"filename" : "action_buttons_1.png",
"dimensions" : [198, 48],
"total_sprites" : 14,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"team_indicator_small_1" : {
"filename" : "team_indicator_small_1.png",
"dimensions" : [12, 12],
"total_sprites" : 2,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"facing_arrows_1" : {
"filename" : "facing_arrows_1.png",
"dimensions" : [64, 64],
"total_sprites" : 4,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"stat_screen_1" : {
"filename" : "stat_screen_1.png",
"dimensions" : [1024, 768],
"total_sprites" : 1,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"affinity_icons_1" : {
"filename" : "affinity_icons_1.png",
"dimensions" : [142, 100],
"total_sprites" : 6,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"affinity_icons_named_1" : {
"filename" : "affinity_icons_named_1.png",
"dimensions" : [142, 100],
"total_sprites" : 6,
- "anim_class" : null
+ "anim_class" : null,
+ "alpha" : false
},
"plumb_bob_1" : {
"filename" : "plumb_bob_1.png",
"dimensions" : [22, 22],
"total_sprites" : 6,
- "anim_class" : "Plumb_Bob_1"
+ "anim_class" : "Plumb_Bob_1",
+ "alpha" : false
}
}
diff --git a/src/images.py b/src/images.py
@@ -7,21 +7,8 @@ from .constants import *
#############
# This file contains:
-# 1. Important environment values and functions for loading images
-# 2. The 'SheetManager' class, which is a Manager object that handles sheets (e.g. loading)
-# 3. The 'Sheet' class, which is used to represent enumerated spritesheets
-
-#####################################################
-# Section 1 - Environment Values and Image Loading #
-#####################################################
-
-def load_image(filename):
- """
- Load an image file as a PyGame image. This is generic
- and can function even outside of the normal sheet
- dynamic that the game uses.
- """
- return pygame.image.load(os.path.join(IMAGE_PATH, filename)).convert()
+# 1. The 'SheetManager' class, which is a Manager object that handles sheets (e.g. loading)
+# 2. The 'Sheet' class, which is used to represent enumerated spritesheets
###################################
# Section 2 - SheetManager Object #
@@ -59,7 +46,7 @@ class SheetManager(manager.Manager):
an = {}
if self.sheets_def[j]["anim_class"] != None:
an = self.animations[self.sheets_def[j]["anim_class"]]
- self.loaded_sheets[j] = Sheet(self, self.sheets_def[j]["filename"], j, tuple(self.sheets_def[j]["dimensions"]), self.sheets_def[j]["total_sprites"], an)
+ self.loaded_sheets[j] = Sheet(self, self.sheets_def[j]["filename"], j, tuple(self.sheets_def[j]["dimensions"]), self.sheets_def[j]["total_sprites"], an, self.sheets_def[j]["alpha"])
def load_animations_from_json(self, anim_json):
"""
@@ -76,6 +63,14 @@ class SheetManager(manager.Manager):
if type(self.anims_def[c][a][i][v]) == list:
self.animations[c][a][i][v] = tuple(self.anims_def[c][a][i][v])
+ def load_image(self, filename):
+ """
+ Load an image file as a PyGame image. This is generic
+ and can function even outside of the normal sheet
+ dynamic that the game uses.
+ """
+ return pygame.image.load(os.path.join(IMAGE_PATH, filename)).convert()
+
def get_sheet(self, name):
"""
Return the sheet matching name if it exists.
@@ -104,7 +99,7 @@ class Sheet(object):
(that is, all sprites are the same dimensions).
"""
- def __init__(self, manager, filename, name, sprite_size, total_sprites, animations):
+ def __init__(self, manager, filename, name, sprite_size, total_sprites, animations, alpha):
# Important values
self.manager = manager
@@ -114,6 +109,7 @@ class Sheet(object):
self.total_sprites = total_sprites
self.sprites = {}
self.animations = animations
+ self.alpha = alpha
# Try and load all sprites on the sheet, or log if we failed
if not self.load_sheet(filename, sprite_size, total_sprites):
@@ -129,7 +125,7 @@ class Sheet(object):
# First, attempt to load the image file. Failing that, create
# a sheet as a NoneType object
try:
- self.sheet = load_image(filename)
+ self.sheet = self.manager.load_image(filename)
except:
self.sheet = None
@@ -147,9 +143,12 @@ class Sheet(object):
# Get a rect that can be used to make a subsurface of the sheet
new_rect = pygame.Rect((x * sprite_size[0], y * sprite_size[1]), sprite_size)
- # Load image, store in our sprites dict, and set colorkey
- self.sprites[(x, y)] = self.sheet.subsurface(new_rect).convert()
- self.sprites[(x, y)].set_colorkey(COLORKEY)
+ # Load image, store in our sprites dict, and set colorkey or alpha
+ if not self.alpha:
+ self.sprites[(x, y)] = self.sheet.subsurface(new_rect).convert()
+ self.sprites[(x, y)].set_colorkey(COLORKEY)
+ else:
+ self.sprites[(x, y)] = self.sheet.subsurface(new_rect).convert_alpha()
# Scoot over to the right
x += 1