# HG changeset patch # User Neil Muller # Date 1282743945 -7200 # Node ID 5cb3fbe61f75d9efa261e7b9c888edf4a5f18e29 # Parent f98bc17f5e67416f9cc38ba9002b7cde776b08d0 Add genric thing with description helper class diff -r f98bc17f5e67 -r 5cb3fbe61f75 gamelib/scenes/cryo.py --- a/gamelib/scenes/cryo.py Wed Aug 25 15:34:52 2010 +0200 +++ b/gamelib/scenes/cryo.py Wed Aug 25 15:45:45 2010 +0200 @@ -2,8 +2,6 @@ import random from albow.music import change_playlist, get_music, PlayList -from pygame.colordict import THECOLORS -from pygame.color import Color from gamelib import speech from gamelib.sound import get_sound @@ -11,6 +9,7 @@ from gamelib.state import Scene, Item, Thing, Result, \ InteractImage, InteractNoImage, InteractRectUnion, \ InteractAnimated +from gamelib.statehelpers import GenericDescThing from gamelib.constants import DEBUG @@ -155,22 +154,12 @@ return "A broken cryo chamber. The corpse inside is missing a leg." -class GenericCryoUnit(Thing): +class GenericCryoUnit(GenericDescThing): "Generic Cryo unit" - INITIAL = 'unit' - def __init__(self, number, description, detailed_description, areas): - super(GenericCryoUnit, self).__init__() - self.description = description + super(GenericCryoUnit, self).__init__('cryo.unit', number, description, areas) self.detailed_description = detailed_description - self.name = 'cryo.unit.%d' % number - self.interacts = { - 'unit' : InteractRectUnion(areas) - } - if DEBUG: - # Individual colors to make debugging easier - self._interact_hilight_color = Color(THECOLORS.keys()[number]) def interact_without(self): return Result(self.detailed_description) diff -r f98bc17f5e67 -r 5cb3fbe61f75 gamelib/statehelpers.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/statehelpers.py Wed Aug 25 15:45:45 2010 +0200 @@ -0,0 +1,30 @@ +"""Set of utility classes for common state things""" + +from pygame.color import Color +from pygame.colordict import THECOLORS + +from gamelib.state import Thing, Result, \ + InteractImage, InteractNoImage, InteractRectUnion, \ + InteractAnimated +from gamelib.constants import DEBUG + + +class GenericDescThing(Thing): + "Thing with an InteractiveUnionRect and a description" + + INITIAL = "description" + + def __init__(self, prefix, number, description, areas): + super(GenericDescThing, self).__init__() + self.description = description + self.name = '%s.%s' % (prefix, number) + self.interacts = { + 'description' : InteractRectUnion(areas) + } + if DEBUG: + # Individual colors to make debugging easier + self._interact_hilight_color = Color(THECOLORS.keys()[number]) + + def get_description(self): + return self.description +