python 3 compatibility
authorFrank DeMarco <if.self.end@gmail.com>
Wed, 3 Jul 2019 08:17:51 +0000 (04:17 -0400)
committerFrank DeMarco <if.self.end@gmail.com>
Wed, 3 Jul 2019 08:17:51 +0000 (04:17 -0400)
OPEN-GAME
PictureProcessing.py
config
lib/pgfw
resource/progress
sdl/Makefile [deleted file]
sdl/main.cpp [deleted file]
sdl/resource/Field.png [deleted file]

index 9ebd442..9d6d870 100755 (executable)
--- a/OPEN-GAME
+++ b/OPEN-GAME
@@ -2,7 +2,7 @@
 
 from os import environ, execvp, chdir, getcwd
 from os.path import exists, join, dirname
-from sys import version_info, argv, maxint
+from sys import version_info, argv
 
 def can_import(module_name):
     try:
@@ -29,14 +29,14 @@ def launch_alternative(alternatives):
 def move_to_executable():
     chdir(dirname(argv[0]))
 
-if is_python_3():
-    launch_alternative(["python2", "python2.7", "python2.6"])
+if is_python_3():
+    launch_alternative(["python2", "python2.7", "python2.6"])
 
 # if maxint >> 33:
 #     launch_alternative(["python-32", "python2-32", "python2.7-32", "python2.6-32"])
 
-if not can_import("pygame"):
-    launch_alternative(["python2.7", "python2.6"])
+if not can_import("pygame"):
+    launch_alternative(["python2.7", "python2.6"])
 
 if "--go-to-dir" in argv:
     move_to_executable()
index daaaaf5..abc7f8e 100644 (file)
@@ -8,8 +8,9 @@ from sys import argv
 from pygame import PixelArray, Surface, Color, joystick, version, mixer, draw
 from pygame.event import clear, Event
 from pygame.image import load, save
-from pygame.transform import flip, scale
-from pygame.mixer import Sound, set_num_channels, get_num_channels
+from pygame.transform import flip, scale, smoothscale
+from pygame.mixer import Sound, set_num_channels, get_num_channels, pause, unpause, stop
+from pygame.key import get_mods
 from pygame.locals import *
 
 from lib.pgfw.pgfw.Game import Game
@@ -24,12 +25,13 @@ class PictureProcessing(Game):
 
     SCALE = 3
     CHANNEL_COUNT = 16
-    KEYBOARD, GAMEPAD = xrange(2)
+    KEYBOARD, GAMEPAD = range(2)
 
     def __init__(self):
         Game.__init__(self)
         mixer.init(44100, -16, self.CHANNEL_COUNT, 4096)
         self.get_configuration().type_declarations.add("bool", "mouse", "resets")
+        self.get_configuration().type_declarations.add("bool", "display", "slides-enabled")
         self.sound_effects = SoundEffects(self)
         self.glyphs = Glyphs(self)
         self.editor = Editor(self)
@@ -38,6 +40,7 @@ class PictureProcessing(Game):
         self.title = Title(self)
         self.introduction = Introduction(self)
         self.ending = Ending(self)
+        self.slides = Slides(self)
         self.subscribe(self.respond)
         self.subscribe(self.respond, MOUSEBUTTONDOWN)
         self.reset()
@@ -45,9 +48,13 @@ class PictureProcessing(Game):
         if self.check_command_line("-wallpaper"):
             self.write_wallpaper()
 
+    def are_slides_enabled(self):
+        return self.check_command_line("-slides") or self.get_configuration("display", "slides-enabled")
+
     def write_wallpaper(self):
         index = argv.index("--wallpaper")
-        width, height = map(int, argv[index + 1:index + 3])
+        # width, height = map(int, argv[index + 1:index + 3])
+        width, height = [int(size) for size in argv[index + 1:index + 3]]
         wallpaper = ScrollingBackground(self, size=(width, height))
         surface = wallpaper.get_current_frame()
         if argv[index + 3] == "-":
@@ -56,7 +63,7 @@ class PictureProcessing(Game):
             from os import unlink
             path = mkstemp(".png")[1]
             save(surface, path)
-            print path
+            print path
         else:
             save(surface, argv[index + 3])
         self.delegate.post("quit")
@@ -66,6 +73,13 @@ class PictureProcessing(Game):
            (self.get_configuration("mouse", "resets") and event.type == MOUSEBUTTONDOWN and
             (1 <= event.button <= 3)):
             self.reset()
+        elif self.are_slides_enabled() and self.delegate.compare(event, "slides"):
+            self.slides.toggle()
+            if self.slides.active:
+                if get_mods() & KMOD_LSHIFT:
+                    self.slides.increment_index(-1)
+                elif get_mods() & KMOD_RSHIFT:
+                    self.slides.increment_index(1)
 
     def reset(self):
         self.title.reset()
@@ -74,9 +88,11 @@ class PictureProcessing(Game):
         self.introduction.reset()
         self.ending.reset()
         self.editor.reset()
+        self.slides.reset()
 
     def get_progress(self):
-        return map(int, open(self.get_resource("progress")).read().split())
+        return [int(field) for field in open(self.get_resource("progress")).read().split()]
+        # return map(int, open(self.get_resource("progress")).read().split())
 
     def write_progress(self, level_index, swap_count, update=False):
         if update:
@@ -91,14 +107,107 @@ class PictureProcessing(Game):
         return not self.check_command_line("-keyboard") and joystick.get_count()
 
     def update(self):
-        if self.editor.active:
+        if not self.slides.active:
             self.editor.update()
-        else:
             self.introduction.update()
             self.title.update()
             self.levels.update()
             self.interface.update()
             self.ending.update()
+        else:
+            self.slides.update()
+
+
+class Slides(GameChild):
+
+    ROOT = "local/egw-slides"
+    VIDEOBALL_INDEX = 4
+
+    def __init__(self, parent):
+        GameChild.__init__(self, parent)
+        self.loaded = False
+        self.subscribe(self.respond)
+        self.index = 0
+
+    def activate(self):
+        self.active = True
+        if not self.loaded:
+            self.load()
+        pause()
+        if self.index == self.VIDEOBALL_INDEX:
+            self.play_videoball()
+
+    def deactivate(self):
+        self.active = False
+        self.videoball_audio.stop()
+        unpause()
+
+    def toggle(self):
+        if self.active:
+            self.deactivate()
+        else:
+            self.activate()
+
+    def reset(self):
+        self.active = False
+        if self.loaded:
+            self.videoball_audio.stop()
+
+    def load(self):
+        tile = self.get_game().levels.levels[1].tiles[3]
+        self.background = ScrollingBackground(self, [tile], fill=(255, 0, 0))
+        self.slides = []
+        for ii, path in enumerate(sorted(glob(join(self.ROOT, "*")))):
+            dsr = self.get_display_surface().get_rect()
+            if ii == self.VIDEOBALL_INDEX:
+                slide = Sprite(self)
+                for frame_path in sorted(glob("local/videoball-frames/*.png")):
+                    slide.add_frame(load(frame_path).convert())
+                slide.location.center = dsr.center
+                self.slides.append(slide)
+            slide = Sprite(self)
+            original_image = load(path).convert()
+            original_width, original_height = original_image.get_size()
+            if original_width > original_height:
+                size = dsr.w, int(original_height * (float(dsr.w) / original_width))
+            else:
+                size = int(original_width * (float(dsr.h) / original_height)), dsr.h
+            scaled_image = smoothscale(original_image, size)
+            slide.add_frame(scaled_image)
+            slide.location.center = dsr.center
+            self.slides.append(slide)
+        self.videoball_audio = Sound("local/videoball-frames/audio.wav")
+        self.loaded = True
+
+    def respond(self, event):
+        if self.active:
+            delegate = self.get_game().delegate
+            if delegate.compare(event, "right"):
+                self.increment_index(1)
+            elif delegate.compare(event, "left"):
+                self.increment_index(-1)
+
+    def increment_index(self, increment):
+        self.index = (self.index + increment) % len(self.slides)
+        if self.index == self.VIDEOBALL_INDEX:
+            self.play_videoball()
+        else:
+            self.videoball_audio.stop()
+
+    def play_videoball(self):
+        self.slides[self.index].get_current_frameset().reset()
+        self.videoball_audio.stop()
+        self.videoball_audio.play()
+
+    def update(self):
+        if self.active:
+            self.background.update()
+            slide = self.slides[self.index]
+            if self.index == self.VIDEOBALL_INDEX:
+                frameset = slide.get_current_frameset()
+                if frameset.current_index == len(frameset.order) - 1:
+                    self.play_videoball()
+            slide.update()
 
 
 class Editor(GameChild):
@@ -160,8 +269,13 @@ class Editor(GameChild):
         self.subscribe(self.respond)
         self.levels = []
         self.painting = []
-        for _ in xrange(self.TILE_SIZE):
+        for _ in range(self.TILE_SIZE):
             self.painting.append([0] * self.TILE_SIZE)
+        self.loaded = False
+        self.mixer_color = MixableColor()
+        self.added_colors = []
+
+    def reset(self):
         self.at_level_select = True
         self.at_view = False
         self.at_tile_bar = False
@@ -177,14 +291,10 @@ class Editor(GameChild):
         self.palette_index = 0
         self.tile_load_index = 0
         self.mixer_index = 0
-        self.loaded = False
+        self.tile_menu_index = 0
         self.menu_hidden = False
         self.paint_pressed = False
-        self.tile_menu_index = 0
-        self.mixer_color = MixableColor()
-        self.added_colors = []
-
-    def reset(self):
+        self.box = FlashingCursor(self, *([self.get_level_tile_size()] * 2))
         self.deactivate()
 
     def activate(self):
@@ -192,6 +302,7 @@ class Editor(GameChild):
         if not self.loaded:
             self.load()
         self.paint_pressed = False
+        self.set_level_title()
 
     def load(self):
         self.read_levels()
@@ -293,19 +404,17 @@ class Editor(GameChild):
         self.palette_cursor = self.get_cursor()
         self.mixer_cursor = self.get_cursor(300, 100)
         self.mixer_cursor.location.center = dsr.center
-        self.box_cursor = self.get_cursor()
         self.tile_menu_cursor = self.get_label(self.TILE_MENU_CURSOR)
         self.tile_menu_cursor.location.top = self.tile_menu_background.location.top
         new_tile = self.new_tile = Surface([self.TILE_SIZE] * 2)
         new_tile.fill((255, 255, 255))
-        for x in xrange(new_tile.get_width()):
-            for y in xrange(new_tile.get_height()):
+        for x in range(new_tile.get_width()):
+            for y in range(new_tile.get_height()):
                 if 3 <= x <= 4 and y != 0 and y != 7:
                     new_tile.set_at((x, y), (0, 0, 0))
                 elif 3 <= y <= 4 and x != 0 and x != 7:
                     new_tile.set_at((x, y), (0, 0, 0))
         self.build_default_palette()
-        self.box = FlashingCursor(self, *([self.get_level_tile_size()] * 2))
         self.tile_load_background = Sprite(self)
         surface = Surface(dsr.inflate(self.TILE_LOAD_MENU_SHRINK).size)
         surface.fill((0, 0, 0))
@@ -322,9 +431,8 @@ class Editor(GameChild):
         self.loaded = True
         self.current_level_is_default = False
         self.level_index = len(self.levels) - 1
-        self.set_level_title()
-        for level in self.levels:
-            print "path:", level.path
+        # for level in self.levels:
+            # print "path:", level.path
 
     def draw_tile_database(self):
         padding = self.TILE_LOAD_MENU_PADDING
@@ -357,8 +465,8 @@ class Editor(GameChild):
         # preview.update()
 
     def get_tile_load_row_count(self):
-        return (self.tile_load_background.location.w - self.TILE_LOAD_MENU_PADDING * 2) / \
-            (self.get_level_tile_size() + self.TILE_LOAD_MENU_MARGIN)
+        return int((self.tile_load_background.location.w - self.TILE_LOAD_MENU_PADDING * 2) / \
+            (self.get_level_tile_size() + self.TILE_LOAD_MENU_MARGIN))
 
     def get_tile_load_cursor_step(self):
         return self.get_level_tile_size() + self.TILE_LOAD_MENU_MARGIN
@@ -376,8 +484,8 @@ class Editor(GameChild):
 
     def build_default_palette(self):
         self.default_palette = [Color(255, 255, 255), Color(0, 0, 0)]
-        for hue in xrange(0, 360 - 45, 45):
-            for lightness in xrange(25, 100, 25):
+        for hue in range(0, 360 - 45, 45):
+            for lightness in range(25, 100, 25):
                 color = Color(0, 0, 0)
                 color.hsla = hue, 100, lightness, 100
                 self.default_palette.append(color)
@@ -407,8 +515,8 @@ class Editor(GameChild):
             level = Level(self)
             if level.load(Level.LOAD_GRID_FILE, path):
                 levels.append(level)
-            else:
-                print "Failed to load level %s" % path
+            else:
+                print "Failed to load level %s" % path
         self.add_default_level()
 
     def add_default_level(self):
@@ -442,7 +550,7 @@ class Editor(GameChild):
         self.get_game().interface.reset()
 
     def respond(self, event):
-        if self.active:
+        if self.active and not self.get_game().slides.active:
             compare = self.get_delegate().compare
             dx, dy = 0, 0
             if compare(event, "action"):
@@ -539,6 +647,7 @@ class Editor(GameChild):
                     self.at_test = False
                     self.at_view = True
                     self.get_current_level().set_swap_status()
+                    self.get_game().interface.deactivate()
             if compare(event, "right"):
                 if self.at_level_select:
                     self.level_index += 1
@@ -552,7 +661,10 @@ class Editor(GameChild):
                         self.tile_index = 0
                 if self.at_tile_menu:
                     self.tile_menu_index += 1
-                    if self.tile_menu_index > 2 or (self.add_tile_selected() and self.tile_menu_index > 1):
+                    if self.tile_menu_index > 1:
+                        if len(self.get_current_level().tiles) == 1 or self.add_tile_selected():
+                            self.tile_menu_index = 0
+                    if self.tile_menu_index > 2:
                         self.tile_menu_index = 0
                 if self.at_tile_edit or self.at_box:
                     dx = 1
@@ -626,7 +738,7 @@ class Editor(GameChild):
                 if self.at_tile_menu:
                     self.tile_menu_index -= 1
                     if self.tile_menu_index < 0:
-                        if self.add_tile_selected():
+                        if self.add_tile_selected() or len(self.get_current_level().tiles) == 1:
                             self.tile_menu_index = 1
                         else:
                             self.tile_menu_index = 2
@@ -733,8 +845,8 @@ class Editor(GameChild):
         level = self.get_current_level()
         level.tiles.pop(index)
         level.original_tiles.pop(index)
-        for ii in xrange(len(level.grid)):
-            for jj in xrange(len(level.grid[ii])):
+        for ii in range(len(level.grid)):
+            for jj in range(len(level.grid[ii])):
                 if level.grid[ii][jj] == index:
                     level.grid[ii][jj] = 0
                 elif level.grid[ii][jj] > index:
@@ -748,12 +860,12 @@ class Editor(GameChild):
 
     def stamp(self):
         size = self.get_level_tile_size()
-        x = self.box.location.left / size
-        y = self.box.location.top / size
-        w = self.box.location.w / size
-        h = self.box.location.h / size
-        for xi in xrange(x, x + w):
-            for yi in xrange(y, y + h):
+        x = int(self.box.location.left / size)
+        y = int(self.box.location.top / size)
+        w = int(self.box.location.w / size)
+        h = int(self.box.location.h / size)
+        for xi in range(x, x + w):
+            for yi in range(y, y + h):
                 self.get_current_level().grid[xi][yi] = self.tile_index
         self.box.location.topleft = [size * coordinate for coordinate in self.box_corner]
         level = self.get_current_level()
@@ -783,8 +895,8 @@ class Editor(GameChild):
                     break
                 index -= 1
         level_file = open(join(level.path, self.get_configuration("editor", "level-file-name")), "w")
-        for jj in xrange(len(grid[0])):
-            for ii in xrange(len(grid)):
+        for jj in range(len(grid[0])):
+            for ii in range(len(grid)):
                 level_file.write(str(hex(grid[ii][jj]))[-1])
             level_file.write("\n")
         for ii, tile in enumerate(level.original_tiles):
@@ -844,18 +956,18 @@ class Editor(GameChild):
 
     def wrap_palette_index(self):
         count = self.get_palette_cell_count()
-        if count % 2 and self.palette_index == count / 2:
+        if count % 2 and self.palette_index == int(count / 2):
             self.palette_index = count - 1
         else:
             self.palette_index += [-1, 1][self.palette_index_is_at_left()] * \
-                (count / 2 + count % 2)
+                (int(count / 2) + count % 2)
 
     def get_palette_cell_count(self):
         return len(self.get_full_palette()) + 1
 
     def palette_index_is_at_left(self):
         length = self.get_palette_cell_count()
-        return self.palette_index < length / 2 + length % 2
+        return self.palette_index < int(length / 2) + length % 2
 
     def move_brush_position(self, dx, dy):
         self.brush_position.move(dx, dy)
@@ -970,7 +1082,7 @@ class Editor(GameChild):
                     palette_right_rect = Rect(0, 0, self.PALETTE_WIDTH, palette_right_height)
                     palette_right_rect.midleft = rect.right + 30, rect.centery
                     y = palette_left_rect.top
-                    for ii in xrange(length):
+                    for ii in range(length):
                         if ii < length / 2 + length % 2:
                             palette_rect = palette_left_rect
                             h = color_left_height
@@ -980,7 +1092,7 @@ class Editor(GameChild):
                         if ii < length - 1:
                             ds.fill(palette[ii], (palette_rect.left, y, palette_rect.w, h))
                         else:
-                            for x in xrange(palette_rect.w):
+                            for x in range(palette_rect.w):
                                 hue = int(float(x) / palette_rect.w * 360)
                                 color = Color(0, 0, 0)
                                 color.hsla = hue, 100, 50, 100
@@ -1064,8 +1176,8 @@ class Editor(GameChild):
                     self.label_switch_tile.location.top = self.label_back_box.location.bottom + 10
                 surface = Surface(self.box.location.size)
                 tile = self.get_current_level().tiles[self.tile_index]
-                for x in xrange(0, surface.get_width(), self.get_level_tile_size()):
-                    for y in xrange(0, surface.get_height(), self.get_level_tile_size()):
+                for x in range(0, surface.get_width(), self.get_level_tile_size()):
+                    for y in range(0, surface.get_height(), self.get_level_tile_size()):
                         surface.blit(tile, (x, y))
                 surface.set_alpha(self.BOX_PREVIEW_ALPHA)
                 ds.blit(surface, self.box.location.topleft)
@@ -1098,8 +1210,8 @@ class Editor(GameChild):
         colors = []
         if not self.add_tile_selected():
             tile = self.get_current_tile()
-            for x in xrange(0, tile.get_width()):
-                for y in xrange(0, tile.get_height()):
+            for x in range(0, tile.get_width()):
+                for y in range(0, tile.get_height()):
                     color = tile.get_at((x, y))
                     if color not in colors and color not in self.default_palette and color not in self.added_colors:
                         colors.append(color)
@@ -1253,7 +1365,7 @@ class SoundEffect(GameChild, Sound):
         channel = Sound.play(self, loops, maxtime, fade_ms)
         if x is not None:
             position = float(x) / self.display_surface.get_width()
-       if position is not None and channel is not None:
+        if position is not None and channel is not None:
             channel.set_volume(*self.get_panning(position))
         return channel
 
@@ -1274,7 +1386,7 @@ class Glyphs(GameChild):
         sheet.set_colorkey(sheet.get_at((0, 0)))
         original = self.original_tiles = []
         tiles = self.tiles = []
-        for y in xrange(0, sheet.get_height(), self.TILE_SIZE):
+        for y in range(0, sheet.get_height(), self.TILE_SIZE):
             surface = Surface([self.TILE_SIZE] * 2)
             surface.set_colorkey(self.TRANSPARENT_COLOR)
             surface.fill(self.TRANSPARENT_COLOR)
@@ -1294,7 +1406,7 @@ class Glyphs(GameChild):
             surface.fill(key)
         else:
             surface.fill(background)
-        for ii, x in enumerate(xrange(0, surface.get_width(), tw + spacing)):
+        for ii, x in enumerate(range(0, surface.get_width(), tw + spacing)):
             surface.blit(tiles[ii], (x, 0))
         return surface
 
@@ -1429,7 +1541,8 @@ class Level(Animation):
                     self.default_tile_index = int(fields[0])
                 else:
                     for field in fields:
-                        digits = map(int, field.split())
+                        digits = [int(member) for member in field.split()]
+                        # digits = map(int, field.split())
                         if len(digits) == 1:
                             index = digits[0]
                         elif len(digits) == 3:
@@ -1440,8 +1553,8 @@ class Level(Animation):
                         else:
                             if len(digits) == 2:
                                 digits *= 2
-                            for x in xrange(digits[0], digits[2] + 1):
-                                for y in xrange(digits[1], digits[3] + 1):
+                            for x in range(digits[0], digits[2] + 1):
+                                for y in range(digits[1], digits[3] + 1):
                                     self.grid[x][y] = index
         for x, row in enumerate(self.grid):
             for y, value in enumerate(row):
@@ -1461,7 +1574,7 @@ class Level(Animation):
         dsr = ds.get_rect()
         scene_plate.location.center = dsr.centerx, dsr.centery - self.TITLE_OFFSET
         border_tiles = self.border_tiles = []
-        for ii in xrange(self.TITLE_BORDER_SIZE[0] * 2 + self.TITLE_BORDER_SIZE[1] * 2 - 4):
+        for ii in range(self.TITLE_BORDER_SIZE[0] * 2 + self.TITLE_BORDER_SIZE[1] * 2 - 4):
             border_tiles.append(self.tiles[ii % len(self.tiles)])
         path = glob(join(self.get_resource("aud/level"), basename(directory) + "*"))[0]
         self.full_audio = Sound(path)
@@ -1493,9 +1606,9 @@ class Level(Animation):
     def set_entire_grid(self, index=None):
         self.grid = []
         ds = self.get_display_surface()
-        for x in xrange(ds.get_width() / self.tiles[0].get_width()):
+        for x in range(int(ds.get_width() / self.tiles[0].get_width())):
             self.grid.append([index] *
-                             (ds.get_height() / self.tiles[0].get_height()))
+                             (int(ds.get_height() / self.tiles[0].get_height())))
 
     def load_grid_file(self, directory):
         for path in sorted(glob(join(directory, "*.png"))):
@@ -1524,8 +1637,8 @@ class Level(Animation):
         else:
             default = Surface([Editor.TILE_SIZE] * 2)
             default.fill((255, 255, 255))
-            for y in xrange(default.get_height()):
-                for x in xrange([1, 2, 2, 2, 2, 2, 7, 8][y]):
+            for y in range(default.get_height()):
+                for x in range([1, 2, 2, 2, 2, 2, 7, 8][y]):
                     default.set_at((x, y), (200, 200, 200))
         self.add_tile(default)
         self.set_entire_grid(0)
@@ -1537,9 +1650,9 @@ class Level(Animation):
         preview = self.preview = Surface(
             (tw * len(self.grid) * self.PREVIEW_SCALE,
              th * len(self.grid[0]) * self.PREVIEW_SCALE))
-        for grid_x, surface_x in enumerate(xrange(0, preview.get_width(),
+        for grid_x, surface_x in enumerate(range(0, preview.get_width(),
                                                   tw * self.PREVIEW_SCALE)):
-            for grid_y, surface_y in enumerate(xrange(0, preview.get_height(),
+            for grid_y, surface_y in enumerate(range(0, preview.get_height(),
                                                       th * self.PREVIEW_SCALE)):
                 scaled = scale(self.original_tiles[self.grid[grid_x][grid_y]],
                                [tw * self.PREVIEW_SCALE] * 2)
@@ -1550,7 +1663,7 @@ class Level(Animation):
 
     def respond(self, event):
         if self.parent.active and self.parent.current_level == self and self.at_title and \
-           self.get_game().delegate.compare(event, "advance") and not self.get_game().editor.active:
+           self.get_game().delegate.compare(event, "advance") and not self.get_game().slides.active:
             self.close_title()
 
     def close_title(self):
@@ -1624,11 +1737,11 @@ class Level(Animation):
             self.full_audio.stop()
 
     def is_solved(self):
-        return all(index == position for index, position in self.swap_status.iteritems())
+        return all(index == position for index, position in self.swap_status.items())
 
     def get_remaining_swap_count(self):
         off = 0
-        for index, position in self.swap_status.iteritems():
+        for index, position in self.swap_status.items():
             off += index != position
         return off / 2 + (off % 2)
 
@@ -1643,16 +1756,16 @@ class Level(Animation):
             br.center = ds.get_rect().center
             index = self.title_border_offset % len(self.border_tiles)
             y = br.top
-            for x in xrange(br.left, br.right, tr.w):
+            for x in range(br.left, br.right, tr.w):
                 ds.blit(self.border_tiles[index % len(self.border_tiles)], (x, y))
                 index += 1
-            for y in xrange(br.top + tr.h, br.bottom, tr.h):
+            for y in range(br.top + tr.h, br.bottom, tr.h):
                 ds.blit(self.border_tiles[index % len(self.border_tiles)], (x, y))
                 index += 1
-            for x in xrange(br.right - tr.w * 2, br.left - tr.w, -tr.w):
+            for x in range(br.right - tr.w * 2, br.left - tr.w, -tr.w):
                 ds.blit(self.border_tiles[index % len(self.border_tiles)], (x, y))
                 index += 1
-            for y in xrange(br.bottom - tr.h * 2, br.top, -tr.h):
+            for y in range(br.bottom - tr.h * 2, br.top, -tr.h):
                 ds.blit(self.border_tiles[index % len(self.border_tiles)], (x, y))
                 index += 1
             self.scene_plate.update()
@@ -1661,9 +1774,9 @@ class Level(Animation):
             if self.title_elapsed >= self.TITLE_LENGTH:
                 self.close_title()
         else:
-            for grid_x, screen_x in enumerate(xrange(0, ds.get_width(),
+            for grid_x, screen_x in enumerate(range(0, ds.get_width(),
                                           self.tiles[0].get_width())):
-                for grid_y, screen_y in enumerate(xrange(0, ds.get_height(),
+                for grid_y, screen_y in enumerate(range(0, ds.get_height(),
                                               self.tiles[0].get_height())):
                     tile_index = self.grid[grid_x][grid_y]
                     swap_index = self.swap_status[tile_index]
@@ -1714,7 +1827,7 @@ class Interface(Animation):
                                         self.OPEN_TEXT_OFFSET
         self.cell_frames = cell_frames = []
         tile_size = glyphs.get_tile(0).get_width()
-        for ii in xrange(self.MAX_TILE_COUNT):
+        for ii in range(self.MAX_TILE_COUNT):
             title = ("%02x%s" % (ii, self.NAME_CHARACTER)).upper()
             title_surface = glyphs.get_surface_from_text(title, self.TEXT_COLOR)
             frame = Surface((self.CELL_INDENT * 2 + title_surface.get_width() + \
@@ -1799,8 +1912,7 @@ class Interface(Animation):
         return 0 < self.get_level().get_remaining_swap_count() <= self.COUNTDOWN_THRESHOLD
 
     def respond(self, event, suppress_sound=False):
-        if self.active and not self.suppressing_commands and \
-           (not self.get_game().editor.active or self.get_game().editor.at_test):
+        if self.active and not self.suppressing_commands and not self.get_game().slides.active:
             delegate = self.get_game().delegate
             effects = self.get_game().sound_effects
             is_pad_mode = self.get_game().is_gamepad_mode()
@@ -1871,7 +1983,7 @@ class Interface(Animation):
                     if not suppress_sound:
                         effects.play("menu-move")
                     cell_count = self.get_cell_count()
-                    bp = (cell_count - 1) / 2
+                    bp = int((cell_count - 1) / 2)
                     if delegate.compare(event, "up"):
                         self.cell_index -= 1
                         if self.cell_index == -1:
@@ -1947,17 +2059,17 @@ class Interface(Animation):
         self.activate()
         self.close()
         cell_count = self.get_cell_count()
-        left_count = cell_count / 2 + cell_count % 2
-        right_count = cell_count / 2
+        left_count = int(cell_count / 2 + cell_count % 2)
+        right_count = int(cell_count / 2)
         sw, sh = self.display_surface.get_size()
-        step = sh / (left_count + 1)
+        step = int(sh / (left_count + 1))
         frames = self.cell_frames
         index = 0
-        for y in xrange(step, step * (left_count + 1), step):
+        for y in range(step, step * (left_count + 1), step):
             frames[index].location.midleft = 0, y
             index += 1
-        step = sh / (right_count + 1)
-        for y in xrange(step, step * (right_count + 1), step):
+        step = int(sh / (right_count + 1))
+        for y in range(step, step * (right_count + 1), step):
             frames[index].location.midright = sw, y
             index += 1
         self.cell_index = 0
@@ -2133,7 +2245,7 @@ class Title(Animation):
         self.option_texts = option_texts
 
     def respond(self, event):
-        if self.active and not self.get_game().editor.active:
+        if self.active and not self.get_game().slides.active:
             delegate = self.get_game().delegate
             if not self.advance_pressed:
                 if delegate.compare(event, "advance") or not self.get_game().is_gamepad_mode() and \
@@ -2196,7 +2308,7 @@ class Title(Animation):
                 self.indicator.update()
             if random() < self.CHUNK_PROBABILITY and \
                get_busy_channel_count() < get_num_channels() - 5:
-                for _ in xrange(randint(1, 4)):
+                for _ in range(randint(1, 4)):
                     chunk = choice(self.audio_chunks)
                     channel = chunk.play()
                     if channel is not None and not isinstance(channel, tuple):
@@ -2214,7 +2326,7 @@ class ScrollingBackground(Sprite):
                  count=1, framerate=None):
         Sprite.__init__(self, parent, framerate)
         frames = []
-        for _ in xrange(count):
+        for _ in range(count):
             frames.append(Surface((size[0], size[1])))
             frames[-1].fill(fill)
         if tiles is None:
@@ -2223,8 +2335,8 @@ class ScrollingBackground(Sprite):
         fw, fh = frames[0].get_size()
         ox = -(tw - (fw % tw)) / 2 if fw % tw else 0
         oy = -(tw - (fh % tw)) / 2 if fh % tw else 0
-        for x in xrange(ox, fw - ox, tw):
-            for y in xrange(oy, fh - oy, tw):
+        for x in range(ox, fw - ox, tw):
+            for y in range(oy, fh - oy, tw):
                 for frame in frames:
                     tile = choice(tiles)
                     if random() >= .5:
@@ -2315,7 +2427,7 @@ class Introduction(Animation):
         self.play(self.blink)
 
     def respond(self, event):
-        if self.active and not self.get_game().editor.active:
+        if self.active and not self.get_game().slides.active:
             if self.get_game().delegate.compare(event, "action"):
                 self.block_index += 1
                 self.current_panel_index += 1
@@ -2390,7 +2502,7 @@ class Ending(Animation):
         self.register(self.unsuppress_advance)
 
     def respond(self, event):
-        if self.active and not self.suppress_commands and not self.get_game().editor.active and \
+        if self.active and not self.suppress_commands and not self.get_game().slides.active and \
            ((self.get_game().is_gamepad_mode() and self.get_game().delegate.compare(event, "advance")) or \
             (not self.get_game().is_gamepad_mode() and self.get_game().delegate.compare(event, "action"))):
             self.deactivate()
@@ -2440,8 +2552,8 @@ class Ending(Animation):
         tw = glyphs.get_tile(0).get_width()
         ds = self.get_display_surface()
         frame = Surface(ds.get_size())
-        for xi, x in enumerate(xrange(0, ds.get_width(), tw)):
-            for yi, y in enumerate(xrange(0, ds.get_height(), tw)):
+        for xi, x in enumerate(range(0, ds.get_width(), tw)):
+            for yi, y in enumerate(range(0, ds.get_height(), tw)):
                 background_color = Color(0, 0, 0)
                 background_color.hsla = randrange(0, 360), 100, 50, 100
                 foreground_color = Color(0, 0, 0)
diff --git a/config b/config
index 8f8c44c..bd5e752 100644 (file)
--- a/config
+++ b/config
@@ -12,14 +12,15 @@ dimensions = 768, 720
 caption = Picture Processing
 fullscreen = no
 show-framerate = no
+slides-enabled = yes
 
 [keys]
 cancel = K_ESCAPE
 action = K_RETURN
 toggle = K_TAB
-context = K_F3
 paint = K_z
 select = K_LSHIFT
+slides = K_F4
 
 [joy]
 advance = 9
index 717b2eb..db87368 160000 (submodule)
--- a/lib/pgfw
+++ b/lib/pgfw
@@ -1 +1 @@
-Subproject commit 717b2eb6860cc1a4804bc258a0b07c5013caf3d5
+Subproject commit db873683d3facee7659a0c98c2645a96f8433552
index 9dd2f00..b748e2d 100644 (file)
@@ -1 +1 @@
-2 37
+0 0
diff --git a/sdl/Makefile b/sdl/Makefile
deleted file mode 100644 (file)
index d3c8d2b..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-SDLCONFIG = /home/frank/local/sdl/bin/sdl2-config
-CFLAGS = $(shell $(SDLCONFIG) --cflags) -Wall -O2
-LFLAGS = $(shell $(SDLCONFIG) --libs) -lSDL2_image
-export ANDROID_HOME = /home/frank/ext/software/android-sdk
-export ANDROID_NDK_HOME = /home/frank/ext/software/android-ndk-r8d
-BUILDDIR = build
-ANDROIDPROJECT = com.tarecontrol.demo
-SDLHOME = /home/frank/ext/software/SDL2-2.0.8
-PROJECTHOME = /home/frank/projects/public/games/pp/sdl
-EMSCRIPTENHOME = /home/frank/ext/software/emsdk/emscripten/tag-1.38.12
-SDLEMLIBSHOME = $(SDLHOME)/build/em/build/.libs
-EMBUILDDIR = em
-WINBUILDDIR = win
-SDLMINGWHOME = $(SDLHOME)/i686-w64-mingw32
-APPDIR = Main.app/Contents
-SYSFWPATH = /Library/Frameworks
-PICC = /home/frank/ext/software/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
-# PICC = /home/frank/ext/software/rpi-tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-g++
-PIMOUNT = /mnt
-PIBUILDDIR = $(PIMOUNT)/home/pi
-
-linux :
-       g++ -c $(CFLAGS) -D__LINUX__ main.cpp
-       g++ -o main $(LFLAGS) main.o -lGL
-
-android :
-       if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi;
-       cd $(SDLHOME)/build-scripts/ && \
-       ./androidbuild.sh $(ANDROIDPROJECT) $(PROJECTHOME)/main.cpp
-       cp -r $(SDLHOME)/build/$(ANDROIDPROJECT) $(BUILDDIR)
-       sed -i s/2\.3\.3/2\.2\.3/g $(BUILDDIR)/$(ANDROIDPROJECT)/build.gradle
-       sed -i s/26\.0\.1/23\.0\.1/g $(BUILDDIR)/$(ANDROIDPROJECT)/app/build.gradle
-       cd $(BUILDDIR)/$(ANDROIDPROJECT) && ./gradlew assembleDebug
-
-emscripten :
-       if [ ! -d $(BUILDDIR)/$(EMBUILDDIR) ]; then mkdir -p $(BUILDDIR)/$(EMBUILDDIR); fi;
-       cd $(BUILDDIR)/$(EMBUILDDIR) && \
-       $(EMSCRIPTENHOME)/em++ -O2 $(PROJECTHOME)/main.cpp -I$(SDLHOME)/include \
-       -Wall -s USE_SDL=2 -o main.html
-
-mingw :
-       if [ ! -d $(BUILDDIR)/$(WINBUILDDIR) ]; then mkdir -p $(BUILDDIR)/$(WINBUILDDIR); fi;
-       cd $(BUILDDIR)/$(WINBUILDDIR) && \
-       i686-w64-mingw32-g++ $(PROJECTHOME)/main.cpp -I$(SDLMINGWHOME)/include/SDL2 -L$(SDLMINGWHOME)/lib \
-       -Wl,-rpath,$(SDLMINGWHOME)/lib -lmingw32 -lSDL2main -lSDL2 -lopengl32 -Wall -O2 -o main.exe && \
-       cp $(SDLMINGWHOME)/bin/SDL2.dll .
-
-osx :
-       if [ ! -d "$(APPDIR)" ]; then mkdir -p $(APPDIR); fi;
-       if [ ! -d "$(APPDIR)" ]; then mkdir $(APPDIR); fi;
-       if [ ! -d "$(APPDIR)/MacOS" ]; then mkdir $(APPDIR)/MacOS; fi;
-       if [ ! -d "$(APPDIR)/Frameworks" ]; then mkdir $(APPDIR)/Frameworks; fi;
-       if [ ! -d "$(APPDIR)/Resources" ]; then mkdir $(APPDIR)/Resources; fi;
-       touch $(APPDIR)/Info.plist
-       cp -r $(SYSFWPATH)/SDL2.framework $(APPDIR)/Frameworks
-       g++ -I $(SYSFWPATH)/SDL2.framework/Headers \
-       -Wl,-rpath,@executable_path/../Frameworks -Wl,-rpath,$(SYSFWPATH) \
-       -framework SDL2 -framework OpenGL main.cpp -o $(APPDIR)/MacOS/main
-
-pi :
-       $(PICC) --sysroot=$(PIMOUNT) main.cpp -I$(PIMOUNT)/opt/vc/include \
-       -I$(PIMOUNT)/opt/vc/include/interface/vcos/pthreads \
-       -I$(PIMOUNT)/opt/vc/include/interface/vmcs_host/linux \
-       -I$(PIMOUNT)/usr/local/include/SDL2 -D_REENTRANT -Wall -O2 -L$(PIMOUNT)/opt/vc/lib \
-       -Wl,-rpath,$(PIMOUNT)/opt/vc/lib -L$(PIMOUNT)/usr/local/lib -Wl,-rpath,$(PIMOUNT)/usr/local/lib \
-       -Wl,--enable-new-dtags -lSDL2 -lGLESv2 -o $(PIBUILDDIR)/main
-
-pi-local :
-       g++ main.cpp $(shell sdl2-config --cflags) -Wall -O2 \
-       -L/opt/vc/lib -Wl,-rpath,/opt/vc/lib $(shell sdl2-config --libs) \
-       -lGLESv2 -o main
-
-cross : linux android emscripten mingw
-
-# main : main.o
-#      g++ -o main $(LFLAGS) -lGL main.o
-
-# main.o : main.cpp
-#      g++ -c $(CFLAGS) -DLINUX main.cpp
diff --git a/sdl/main.cpp b/sdl/main.cpp
deleted file mode 100644 (file)
index 9ceba76..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <stdio.h>
-#include <SDL.h>
-#include <SDL_image.h>
-
-#if defined(__EMSCRIPTEN__) || defined(__arm__)
-#include <GLES2/gl2.h>
-#elif defined(__LINUX__) || defined(__MINGW32__)
-#include <GL/gl.h>
-#elif defined(__ANDROID__)
-#include <GLES/gl.h>
-#endif
-
-int main(int argc, char *argv[])
-{
-    SDL_version version;
-    SDL_GetVersion(&version);
-    printf("SDL %d.%d.%d\n", version.major, version.minor, version.patch);
-    SDL_SetMainReady();
-    if (SDL_Init(SDL_INIT_VIDEO) < 0)
-    {
-        fprintf(stderr, "SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
-    }
-    else
-    {
-        SDL_Window *window = SDL_CreateWindow(
-            "TARE control",
-            SDL_WINDOWPOS_UNDEFINED,
-            SDL_WINDOWPOS_UNDEFINED,
-            640,
-            480,
-            SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
-        if (window == NULL)
-        {
-            fprintf(stderr, "Could not create window! SDL_Error: %s\n", SDL_GetError());
-        }
-        else
-        {
-            SDL_ShowCursor(0);
-            SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
-            if (renderer == NULL)
-            {
-                fprintf(stderr, "Could not create renderer! SDL_Error: %s\n", SDL_GetError());
-            }
-            else
-            {
-                SDL_Texture *texture = IMG_LoadTexture(renderer, "resource/Field.png");
-                if (!texture)
-                {
-                    fprintf(stderr, "Could not load image! SDL_Error: %s\n", SDL_GetError());
-                }
-                else
-                {
-                    SDL_GL_CreateContext(window);
-                    SDL_Event event;
-                    int done = 0;
-                    while (!done)
-                    {
-                        while (SDL_PollEvent(&event))
-                        {
-                            if (event.type == SDL_QUIT)
-                            {
-                                done = 1;
-                            }
-                        }
-                        // SDL_GLContext glcontext = SDL_GL_CreateContext(window);
-                        glClearColor(255, 0, 0, 1);
-                        glClear(GL_COLOR_BUFFER_BIT);
-                        SDL_Rect rect = {0, 0, 240, 160};
-                        SDL_RenderCopy(renderer, texture, NULL, &rect);
-                        SDL_RenderPresent(renderer);
-                        SDL_GL_SwapWindow(window);
-                        // SDL_GL_DeleteContext(glcontext);
-                    }
-                    SDL_DestroyTexture(texture);
-                }
-                SDL_DestroyRenderer(renderer);
-            }
-            SDL_DestroyWindow(window);
-        }
-    }
-    SDL_Quit();
-    return 0;
-}
diff --git a/sdl/resource/Field.png b/sdl/resource/Field.png
deleted file mode 100644 (file)
index d5e74b2..0000000
Binary files a/sdl/resource/Field.png and /dev/null differ