think of the poor windows users
authoradrianna <adrianna.pinska@gmail.com>
Sat, 5 Mar 2016 19:38:19 +0000 (21:38 +0200)
committeradrianna <adrianna.pinska@gmail.com>
Sat, 5 Mar 2016 19:38:27 +0000 (21:38 +0200)
koperkapel/roaches.py
koperkapel/scenes/roach_management.py
koperkapel/scenes/viewlevel.py
koperkapel/serums.py
koperkapel/util.py [new file with mode: 0644]
koperkapel/vehicles/base.py
koperkapel/weapons.py

index b708a88b9b0219f65bee7656b924362113cca6a8..680d2a69b24b0183a70700cde72e68cfcaea458a 100644 (file)
@@ -4,6 +4,7 @@ from pgzero.loaders import images
 from pygame.constants import BLEND_RGBA_MULT
 from .actors.animsurf import AnimatedSurfActor
 from .serums import roach_serum_color
+from .util import safepath
 
 NAMES = [
     "roupert",
@@ -75,8 +76,8 @@ class RoachFactory:
         self.frames = 4
 
     def assemble_frame(self, i, color, roach_data, weapon=None):
-        roach = images.load("roach%s/roach_%d" % (self.suffix, i + 1))
-        eyes = images.load("roach%s/eyes_%d" % (self.suffix, i + 1))
+        roach = images.load(safepath("roach%s/roach_%d") % (self.suffix, i + 1))
+        eyes = images.load(safepath("roach%s/eyes_%d") % (self.suffix, i + 1))
         if weapon is None:
             frame = roach.copy()
             frame.fill(color, None, BLEND_RGBA_MULT)
index 4e41b9c538608d0dd7df2097335a772556d1331a..dd05e755404334f6b37394a044a02b30f1ec6f78 100644 (file)
@@ -11,6 +11,7 @@ from ..roaches import big_roaches, roach_by_name
 from ..serums import big_serums, roach_is_serumless, SERUMS
 from ..vehicles.base import Vehicle
 from .base import Scene, ChangeSceneEvent, defer_to_update
+from ..util import safepath
 
 
 TOOLBAR_LEFT_X = WIDTH * 3 // 4
@@ -135,10 +136,10 @@ class RoachesScene(Scene):
 
     def _init_pads(self):
         self._roach_pad = self._pad_layer.add(
-            Actor("roach_management/roach_pad", anchor=("left", "bottom")))
+            Actor(safepath("roach_management/roach_pad"), anchor=("left", "bottom")))
         self._roach_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y)
         self._inventory_pad = self._pad_layer.add(
-            Actor("roach_management/inventory_pad", anchor=("left", "top")))
+            Actor(safepath("roach_management/inventory_pad"), anchor=("left", "top")))
         self._inventory_pad.pos = (TOOLBAR_LEFT_X, TOOLBAR_MID_Y)
 
     def _add_button(self, name, anchor, inset, pos, action):
@@ -150,23 +151,23 @@ class RoachesScene(Scene):
     def _init_buttons(self):
         self._button_layer.clear()
         self._add_button(
-            "roach_management/left_button", ("left", "bottom"), (1, -1),
+            safepath("roach_management/left_button"), ("left", "bottom"), (1, -1),
             self._roach_pad.bottomleft, self._roach_left)
 
         self._add_button(
-            "roach_management/right_button", ("right", "bottom"), (-1, -1),
+            safepath("roach_management/right_button"), ("right", "bottom"), (-1, -1),
             self._roach_pad.bottomright, self._roach_right)
 
         self._add_button(
-            "roach_management/left_button", ("left", "bottom"), (1, -1),
+            safepath("roach_management/left_button"), ("left", "bottom"), (1, -1),
             self._inventory_pad.bottomleft, self._inventory_left)
 
         self._add_button(
-            "roach_management/right_button", ("right", "bottom"), (-1, -1),
+            safepath("roach_management/right_button"), ("right", "bottom"), (-1, -1),
             self._inventory_pad.bottomright, self._inventory_right)
 
         self._add_button(
-            "roach_management/eject_button", ("right", "top"), (-1, 1),
+            safepath("roach_management/eject_button"), ("right", "top"), (-1, 1),
             (TOOLBAR_LEFT_X, TOOLBAR_TOP_Y), self._eject_roach)
 
     def _roach_left(self):
index f6c56b66861b140ce95c86c8164d6e76da41e16e..28e4026ce82a154b2ccad7afdb517c2f5a34e70e 100644 (file)
@@ -1,13 +1,12 @@
 """Render a level and allow moving the scene"""
 
-import os
-
 from pygame.constants import BLEND_RGBA_MULT
 from pgzero.constants import keys
 from pgzero.loaders import images
 from .level import BaseLevelScene
 from .base import MoveViewportEvent
 from ..constants import TILE_SIZE
+from ..util import safepath
 
 
 class ViewLevelScene(BaseLevelScene):
@@ -16,7 +15,7 @@ class ViewLevelScene(BaseLevelScene):
     def enter(self, world):
         super().enter(world)
         # Mark starting position
-        self._roach = images.load(os.path.join("roach/roach_1")).copy()
+        self._roach = images.load(safepath("roach/roach_1")).copy()
         self._roach.fill((255, 0, 0, 255), None, BLEND_RGBA_MULT)
         x = self._level.start_pos[0] * TILE_SIZE
         y = self._level.start_pos[1] * TILE_SIZE
index 38794fd4926834bba5129b650f836e944c534490..22391145f2b23843f75bccad381cae6f33fc4d7f 100644 (file)
@@ -5,6 +5,7 @@ from pgzero.loaders import images
 from pygame.constants import BLEND_RGBA_MULT
 from pygame.transform import rotate
 from .actors.surf import SurfActor
+from .util import safepath
 
 SERUMS = ["smart", "fast", "strong"]
 
@@ -42,9 +43,9 @@ class SerumFactory:
 
     def assemble(self, name):
         assert name in SERUMS
-        puddle = images.load("serum%s/serum" % (self.suffix,))
+        puddle = images.load(safepath("serum%s/serum") % (self.suffix,))
         puddle = rotate(puddle, 90 * random.randint(0, 3))
-        serum_icon = images.load("serum%s/%s" % (
+        serum_icon = images.load(safepath("serum%s/%s") % (
             self.suffix, SERUM_TILENAME_MAP[name],))
         frame = puddle.copy()
         frame.fill(SERUM_OVERLAY_COLORS[name], None, BLEND_RGBA_MULT)
diff --git a/koperkapel/util.py b/koperkapel/util.py
new file mode 100644 (file)
index 0000000..246fb57
--- /dev/null
@@ -0,0 +1,6 @@
+"""Utility functions"""
+
+import os
+
+def safepath(path):
+    return os.path.join(*path.split("/"))
index 27e1b24d4f0633575ac9519260de5c05d8c1a002..3d7765c11f53094273bfc310b1f6816d118e956a 100644 (file)
@@ -8,6 +8,7 @@ from pgzero.loaders import images
 from ..actors.orientatedsurf import OrientatedSurfActor
 from ..actors.animsurf import AnimatedSurfActor
 from ..weapons import default_weapons
+from ..util import safepath
 
 
 class Vehicle:
@@ -24,12 +25,12 @@ class Vehicle:
         self.game_pos = (0, 0)
 
     def roach_management_overlay(self):
-        return images.load("vehicles/walking/background")
+        return images.load(safepath("vehicles/walking/background"))
 
     def roach_management_frame(self):
         if self.overlay_frame_no is None:
             return None
-        return images.load("vehicle_big/%s_%d" % (
+        return images.load(safepath("vehicle_big/%s_%d") % (
             self.vehicle_type, self.overlay_frame_no))
 
     def init_seats(self):
@@ -92,7 +93,7 @@ class Vehicle:
         cls.register(Roomba)
 
     def _avatar_frame(self, i, weapon, suffix="_tiles"):
-        vehicle = images.load("vehicle%s/%s_%d" % (
+        vehicle = images.load(safepath("vehicle%s/%s_%d") % (
             suffix, self.vehicle_type, i + 1))
         frame = vehicle.copy()
         frame.blit(weapon.surf, (0, 0))
@@ -125,7 +126,7 @@ class Seat:
         self.vehicle_pos = (pos[0] * vrad, pos[1] * vrad)
 
     def actor(self):
-        seat = images.load("vehicles/walking/seat")
+        seat = images.load(safepath("vehicles/walking/seat"))
         selected_seat = seat.copy()
         selected_seat.fill(
             self.vehicle.selected_seat_overlay_color, None, BLEND_RGBA_MULT)
index da8c4c3712b6ccafeca80fed1c17bb929c9384ea..890743dbe5ccb5fb1338006a762f7874aae2a3d6 100644 (file)
@@ -2,6 +2,7 @@
 
 from pgzero.loaders import images
 from .actors.animsurf import AnimatedSurfActor
+from .util import safepath
 
 
 class Weapon:
@@ -35,10 +36,11 @@ class WeaponActor(AnimatedSurfActor):
 class WeaponFactory:
 
     def assemble_frame(self, suffix, weapon, tape):
-        surf = images.load("weapons/%s%s" % (weapon.image_name, suffix))
+        surf = images.load(safepath("weapons/%s%s")
+                            % (weapon.image_name, suffix))
         frame = surf.copy()
         if tape:
-            tape_surf = images.load("weapons/tape")
+            tape_surf = images.load(safepath("weapons/tape"))
             frame.blit(tape_surf, (0, 0))
         return frame