changeset 263:3b4a78422201

Shuffled a bunch of stuff into more appropriate places.
author Jeremy Thurgood <firxen@gmail.com>
date Fri, 27 Aug 2010 19:29:37 +0200
parents 5f58da9eeb52
children 3cedc4f95925
files gamelib/scenes/bridge.py gamelib/scenes/crew_quarters.py gamelib/scenes/cryo.py gamelib/scenes/engine.py gamelib/scenes/machine.py gamelib/scenes/map.py gamelib/scenes/mess.py gamelib/scenes/scene_widgets.py gamelib/state.py gamelib/statehelpers.py
diffstat 10 files changed, 161 insertions(+), 154 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/scenes/bridge.py	Fri Aug 27 19:22:47 2010 +0200
+++ b/gamelib/scenes/bridge.py	Fri Aug 27 19:29:37 2010 +0200
@@ -6,11 +6,12 @@
 from albow.resource import get_image
 
 from gamelib.cursor import CursorSprite
-from gamelib.state import Scene, Item, Thing, Result, InteractText, \
-                          InteractNoImage, InteractRectUnion, InteractImage, \
-                          InteractAnimated
-from gamelib.statehelpers import GenericDescThing
-from gamelib.scenes.scene_widgets import Door
+from gamelib.state import Scene, Item, Thing, Result
+
+from gamelib.scenes.scene_widgets import (Door, InteractText, InteractNoImage,
+                                          InteractRectUnion, InteractImage,
+                                          InteractAnimated, GenericDescThing)
+
 
 class Bridge(Scene):
 
--- a/gamelib/scenes/crew_quarters.py	Fri Aug 27 19:22:47 2010 +0200
+++ b/gamelib/scenes/crew_quarters.py	Fri Aug 27 19:29:37 2010 +0200
@@ -1,8 +1,10 @@
 """Crew quarters."""
 
 from gamelib.cursor import CursorSprite
-from gamelib.state import Scene, Item, Thing, Result, InteractText
-from gamelib.scenes.scene_widgets import Door
+from gamelib.state import Scene, Item, Thing, Result
+from gamelib.scenes.scene_widgets import (Door, InteractText, InteractNoImage,
+                                          InteractRectUnion, InteractImage,
+                                          InteractAnimated, GenericDescThing)
 
 class CrewQuarters(Scene):
 
--- a/gamelib/scenes/cryo.py	Fri Aug 27 19:22:47 2010 +0200
+++ b/gamelib/scenes/cryo.py	Fri Aug 27 19:29:37 2010 +0200
@@ -6,13 +6,12 @@
 from gamelib import speech
 from gamelib.sound import get_sound
 from gamelib.cursor import CursorSprite
-from gamelib.state import Scene, Item, CloneableItem, Thing, Result, \
-                          InteractImage, InteractNoImage, InteractRectUnion, \
-                          InteractAnimated
-from gamelib.statehelpers import GenericDescThing
-from gamelib.scenes.scene_widgets import Door
+from gamelib.state import Scene, Item, CloneableItem, Thing, Result
 from gamelib.constants import DEBUG
 from gamelib.scenes.game_constants import PLAYER_ID
+from gamelib.scenes.scene_widgets import (Door, InteractText, InteractNoImage,
+                                          InteractRectUnion, InteractImage,
+                                          InteractAnimated, GenericDescThing)
 
 
 class Cryo(Scene):
--- a/gamelib/scenes/engine.py	Fri Aug 27 19:22:47 2010 +0200
+++ b/gamelib/scenes/engine.py	Fri Aug 27 19:29:37 2010 +0200
@@ -1,7 +1,9 @@
 """Engine room where things need to be repaired."""
 
-from gamelib.state import Scene, Item, Thing, InteractNoImage, Result
-from gamelib.scenes.scene_widgets import Door
+from gamelib.state import Scene, Item, Thing, Result
+from gamelib.scenes.scene_widgets import (Door, InteractText, InteractNoImage,
+                                          InteractRectUnion, InteractImage,
+                                          InteractAnimated, GenericDescThing)
 
 
 class Engine(Scene):
--- a/gamelib/scenes/machine.py	Fri Aug 27 19:22:47 2010 +0200
+++ b/gamelib/scenes/machine.py	Fri Aug 27 19:29:37 2010 +0200
@@ -1,8 +1,10 @@
 """Machine room where tools and machines are found."""
 
-from gamelib.state import Scene, Item, Thing, InteractNoImage, InteractText, Result
+from gamelib.state import Scene, Item, Thing, Result
 from gamelib.cursor import CursorSprite
-from gamelib.scenes.scene_widgets import Door
+from gamelib.scenes.scene_widgets import (Door, InteractText, InteractNoImage,
+                                          InteractRectUnion, InteractImage,
+                                          InteractAnimated, GenericDescThing)
 
 
 class Machine(Scene):
--- a/gamelib/scenes/map.py	Fri Aug 27 19:22:47 2010 +0200
+++ b/gamelib/scenes/map.py	Fri Aug 27 19:29:37 2010 +0200
@@ -7,8 +7,11 @@
    Many parts of the ship are derelict and inaccessible.
    """
 
-from gamelib.state import Scene, Item, Thing, InteractText, Result
+from gamelib.state import Scene, Item, Thing, Result
 from gamelib.scenes.game_constants import PLAYER_ID
+from gamelib.scenes.scene_widgets import (Door, InteractText, InteractNoImage,
+                                          InteractRectUnion, InteractImage,
+                                          InteractAnimated, GenericDescThing)
 
 
 class Map(Scene):
--- a/gamelib/scenes/mess.py	Fri Aug 27 19:22:47 2010 +0200
+++ b/gamelib/scenes/mess.py	Fri Aug 27 19:29:37 2010 +0200
@@ -2,10 +2,11 @@
 
 from random import choice
 
-from gamelib.state import Scene, Item, CloneableItem, Thing, InteractImage, InteractNoImage, Result
-from gamelib.statehelpers import GenericDescThing
+from gamelib.state import Scene, Item, CloneableItem, Thing, Result
 from gamelib.cursor import CursorSprite
-from gamelib.scenes.scene_widgets import Door
+from gamelib.scenes.scene_widgets import (Door, InteractText, InteractNoImage,
+                                          InteractRectUnion, InteractImage,
+                                          InteractAnimated, GenericDescThing)
 
 
 class Mess(Scene):
--- a/gamelib/scenes/scene_widgets.py	Fri Aug 27 19:22:47 2010 +0200
+++ b/gamelib/scenes/scene_widgets.py	Fri Aug 27 19:29:37 2010 +0200
@@ -2,7 +2,138 @@
 
 import random
 
+from pygame import Rect
+from pygame.color import Color
+from pygame.colordict import THECOLORS
+from pygame.surface import Surface
+from albow.resource import get_image
+
 from gamelib.state import Thing, Result
+from gamelib.constants import DEBUG
+from gamelib.widgets import BoomLabel
+
+
+class Interact(object):
+
+    def __init__(self, image, rect, interact_rect):
+        self.image = image
+        self.rect = rect
+        self.interact_rect = interact_rect
+
+    def set_thing(self, thing):
+        pass
+
+    def draw(self, surface):
+        if self.image is not None:
+            surface.blit(self.image, self.rect, None)
+
+    def animate(self):
+        return False
+
+
+class InteractNoImage(Interact):
+
+    def __init__(self, x, y, w, h):
+        super(InteractNoImage, self).__init__(None, None, Rect(x, y, w, h))
+
+
+class InteractText(Interact):
+    """Display box with text to interact with -- mostly for debugging."""
+
+    def __init__(self, x, y, text, bg_color=None):
+        if bg_color is None:
+            bg_color = (127, 127, 127)
+        label = BoomLabel(text)
+        label.set_margin(5)
+        label.border_width = 1
+        label.border_color = (0, 0, 0)
+        label.bg_color = bg_color
+        label.fg_color = (0, 0, 0)
+        image = Surface(label.size)
+        rect = Rect((x, y), label.size)
+        label.draw_all(image)
+        super(InteractText, self).__init__(image, rect, rect)
+
+
+class InteractRectUnion(Interact):
+
+    def __init__(self, rect_list):
+        # pygame.rect.Rect.unionall should do this, but is broken
+        # in some pygame versions (including 1.8, it appears)
+        rect_list = [Rect(x) for x in rect_list]
+        union_rect = rect_list[0]
+        for rect in rect_list[1:]:
+            union_rect = union_rect.union(rect)
+        super(InteractRectUnion, self).__init__(None, None, union_rect)
+        self.interact_rect = rect_list
+
+
+class InteractImage(Interact):
+
+    def __init__(self, x, y, image_name):
+        super(InteractImage, self).__init__(None, None, None)
+        self._pos = (x, y)
+        self._image_name = image_name
+
+    def set_thing(self, thing):
+        self.image = get_image(thing.folder, self._image_name)
+        self.rect = Rect(self._pos, self.image.get_size())
+        self.interact_rect = self.rect
+
+
+class InteractAnimated(Interact):
+    """Interactive with an animation rather than an image"""
+
+    # FIXME: Assumes all images are the same size
+    # anim_seq - sequence of image names
+    # delay - number of frames to wait between changing images
+
+    def __init__(self, x, y, anim_seq, delay):
+        self._pos = (x, y)
+        self._anim_pos = 0
+        self._names = anim_seq
+        self._frame_count = 0
+        self._anim_seq = None
+        self._delay = delay
+
+    def set_thing(self, thing):
+        self._anim_seq = [get_image(thing.folder, x) for x in self._names]
+        self.image = self._anim_seq[0]
+        self.rect = Rect(self._pos, self.image.get_size())
+        self.interact_rect = self.rect
+
+    def animate(self):
+        if self._anim_seq:
+            self._frame_count += 1
+            if self._frame_count > self._delay:
+                self._frame_count = 0
+                self._anim_pos += 1
+                if self._anim_pos >= len(self._anim_seq):
+                    self._anim_pos = 0
+                self.image = self._anim_seq[self._anim_pos]
+                # queue redraw
+                return True
+        return False
+
+
+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
 
 
 class Door(Thing):
--- a/gamelib/state.py	Fri Aug 27 19:22:47 2010 +0200
+++ b/gamelib/state.py	Fri Aug 27 19:29:37 2010 +0200
@@ -5,7 +5,6 @@
 from widgets import BoomLabel
 from pygame.locals import BLEND_ADD
 from pygame.rect import Rect
-from pygame.surface import Surface
 from pygame.color import Color
 
 import constants
@@ -345,109 +344,6 @@
         return self._background.get_size()
 
 
-class Interact(object):
-
-    def __init__(self, image, rect, interact_rect):
-        self.image = image
-        self.rect = rect
-        self.interact_rect = interact_rect
-
-    def set_thing(self, thing):
-        pass
-
-    def draw(self, surface):
-        if self.image is not None:
-            surface.blit(self.image, self.rect, None)
-
-    def animate(self):
-        return False
-
-
-class InteractNoImage(Interact):
-
-    def __init__(self, x, y, w, h):
-        super(InteractNoImage, self).__init__(None, None, Rect(x, y, w, h))
-
-
-class InteractText(Interact):
-    """Display box with text to interact with -- mostly for debugging."""
-
-    def __init__(self, x, y, text, bg_color=None):
-        if bg_color is None:
-            bg_color = (127, 127, 127)
-        label = BoomLabel(text)
-        label.set_margin(5)
-        label.border_width = 1
-        label.border_color = (0, 0, 0)
-        label.bg_color = bg_color
-        label.fg_color = (0, 0, 0)
-        image = Surface(label.size)
-        rect = Rect((x, y), label.size)
-        label.draw_all(image)
-        super(InteractText, self).__init__(image, rect, rect)
-
-
-class InteractRectUnion(Interact):
-
-    def __init__(self, rect_list):
-        # pygame.rect.Rect.unionall should do this, but is broken
-        # in some pygame versions (including 1.8, it appears)
-        rect_list = [Rect(x) for x in rect_list]
-        union_rect = rect_list[0]
-        for rect in rect_list[1:]:
-            union_rect = union_rect.union(rect)
-        super(InteractRectUnion, self).__init__(None, None, union_rect)
-        self.interact_rect = rect_list
-
-
-class InteractImage(Interact):
-
-    def __init__(self, x, y, image_name):
-        super(InteractImage, self).__init__(None, None, None)
-        self._pos = (x, y)
-        self._image_name = image_name
-
-    def set_thing(self, thing):
-        self.image = get_image(thing.folder, self._image_name)
-        self.rect = Rect(self._pos, self.image.get_size())
-        self.interact_rect = self.rect
-
-
-class InteractAnimated(Interact):
-    """Interactive with an animation rather than an image"""
-
-    # FIXME: Assumes all images are the same size
-    # anim_seq - sequence of image names
-    # delay - number of frames to wait between changing images
-
-    def __init__(self, x, y, anim_seq, delay):
-        self._pos = (x, y)
-        self._anim_pos = 0
-        self._names = anim_seq
-        self._frame_count = 0
-        self._anim_seq = None
-        self._delay = delay
-
-    def set_thing(self, thing):
-        self._anim_seq = [get_image(thing.folder, x) for x in self._names]
-        self.image = self._anim_seq[0]
-        self.rect = Rect(self._pos, self.image.get_size())
-        self.interact_rect = self.rect
-
-    def animate(self):
-        if self._anim_seq:
-            self._frame_count += 1
-            if self._frame_count > self._delay:
-                self._frame_count = 0
-                self._anim_pos += 1
-                if self._anim_pos >= len(self._anim_seq):
-                    self._anim_pos = 0
-                self.image = self._anim_seq[self._anim_pos]
-                # queue redraw
-                return True
-        return False
-
-
 class Thing(StatefulGizmo):
     """Base class for things in a scene that you can interact with."""
 
--- a/gamelib/statehelpers.py	Fri Aug 27 19:22:47 2010 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-"""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
-