linebreaks; hide locations

This commit is contained in:
Frank DeMarco 2014-09-13 14:05:42 +09:00
parent f8b5c68a92
commit fbc93f3aa6
3 changed files with 38 additions and 18 deletions

View File

@ -34,7 +34,7 @@ class Animation(GameChild):
account.set_interval(interval) account.set_interval(interval)
account.play() account.play()
def get_default(self, method): def get_default(self, method=None):
if not method: if not method:
method = self.default_method method = self.default_method
return method return method

View File

@ -18,13 +18,16 @@ class GameChild:
current = current.parent current = current.parent
return current return current
def get_configuration(self, section=None, option=None): def get_configuration(self, section=None, option=None, linebreaks=True):
config = self.game.configuration config = self.game.configuration
if option is None and section is None:
return config
if option and section: if option and section:
return config.get(section, option) rvalue = config.get(section, option)
if section: if not linebreaks and isinstance(rvalue, str):
return config.get_section(section) rvalue = rvalue.replace("\n", " ")
return config return rvalue
return config.get_section(section)
def get_input(self): def get_input(self):
return self.game.input return self.game.input

View File

@ -18,11 +18,11 @@ class Sprite(Animation):
Animation.__init__(self, parent, self.shift_frame, framerate) Animation.__init__(self, parent, self.shift_frame, framerate)
self.frames = [] self.frames = []
self.mirrored = False self.mirrored = False
self.hidden = False
self.alpha = 255 self.alpha = 255
self.locations = [Location(self)] self.locations = []
self.framesets = [Frameset(self, framerate=framerate)] self.framesets = [Frameset(self, framerate=framerate)]
self.set_frameset(0) self.set_frameset(0)
self.locations.append(Location(self))
self.motion_overflow = Vector() self.motion_overflow = Vector()
self.display_surface = self.get_display_surface() self.display_surface = self.get_display_surface()
@ -63,12 +63,12 @@ class Sprite(Animation):
self.register_interval() self.register_interval()
def load_from_path(self, path, transparency=False, ppa=True, key=None, def load_from_path(self, path, transparency=False, ppa=True, key=None,
extension=None, omit=False): query=None, omit=False):
if isfile(path): if isfile(path):
paths = [path] paths = [path]
else: else:
if extension: if query:
paths = sorted(glob(join(path, "*." + extension))) paths = sorted(glob(join(path, query)))
else: else:
paths = [join(path, name) for name in sorted(listdir(path))] paths = [join(path, name) for name in sorted(listdir(path))]
for path in paths: for path in paths:
@ -165,16 +165,23 @@ class Sprite(Animation):
for location in self.locations: for location in self.locations:
location.fader.set_alpha() location.fader.set_alpha()
def add_frameset(self, order, framerate=None, name=None): def add_frameset(self, order=[], framerate=None, name=None, switch=False):
frameset = Frameset(self, order, framerate, name) frameset = Frameset(self, order, framerate, name)
self.framesets.append(frameset) self.framesets.append(frameset)
if switch:
self.set_frameset(len(self.framesets) - 1)
return frameset return frameset
def hide(self): def hide(self):
self.hidden = True for location in self.locations:
location.hide()
def unhide(self): def unhide(self):
self.hidden = False for location in self.locations:
location.unhide()
def is_hidden(self):
return all(location.is_hidden() for location in self.locations)
def remove_locations(self, location=None): def remove_locations(self, location=None):
if location: if location:
@ -205,6 +212,7 @@ class Location(Rect):
Rect.__init__(self, rect) Rect.__init__(self, rect)
self.motion_overflow = Vector() self.motion_overflow = Vector()
self.fader = Fader(self) self.fader = Fader(self)
self.unhide()
def move_ip(self, dx, dy): def move_ip(self, dx, dy):
if isinstance(dx, float) or isinstance(dy, float): if isinstance(dx, float) or isinstance(dy, float):
@ -224,6 +232,15 @@ class Location(Rect):
def reset_motion_overflow(self): def reset_motion_overflow(self):
self.motion_overflow.place_at_origin() self.motion_overflow.place_at_origin()
def hide(self):
self.hidden = True
def unhide(self):
self.hidden = False
def is_hidden(self):
return self.hidden
class Fader(Surface): class Fader(Surface):
@ -238,7 +255,7 @@ class Fader(Surface):
def init_surface(self): def init_surface(self):
Surface.__init__(self, self.location.size) Surface.__init__(self, self.location.size)
if self.location.sprite.frames: if self.location.sprite.get_current_frameset().length():
background = Surface(self.get_size()) background = Surface(self.get_size())
sprite = self.location.sprite sprite = self.location.sprite
key = sprite.get_current_frame().get_colorkey() or (255, 0, 255) key = sprite.get_current_frame().get_colorkey() or (255, 0, 255)
@ -272,12 +289,12 @@ class Fader(Surface):
frame.set_alpha(255) frame.set_alpha(255)
self.blit(frame, (0, 0)) self.blit(frame, (0, 0))
frame.set_alpha(sprite.alpha) frame.set_alpha(sprite.alpha)
if not sprite.hidden: if not self.location.hidden:
self.blit_to_display(self) self.blit_to_display(self)
elif self.fade_remaining is None or self.get_alpha() >= sprite.alpha: elif self.fade_remaining is None or self.get_alpha() >= sprite.alpha:
if self.fade_remaining >= 0: if self.fade_remaining >= 0:
self.update_alpha() self.update_alpha()
if not sprite.hidden: if not self.location.hidden:
self.blit_to_display(sprite.get_current_frame()) self.blit_to_display(sprite.get_current_frame())
def blit_to_display(self, frame): def blit_to_display(self, frame):
@ -301,7 +318,7 @@ class Fader(Surface):
self.blit(self.background, (0, 0)) self.blit(self.background, (0, 0))
class Frameset(): class Frameset:
def __init__(self, sprite, order=[], framerate=None, name=None): def __init__(self, sprite, order=[], framerate=None, name=None):
self.sprite = sprite self.sprite = sprite