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.play()
def get_default(self, method):
def get_default(self, method=None):
if not method:
method = self.default_method
return method

View File

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

View File

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