From: adrianna Date: Sat, 5 Mar 2016 19:38:19 +0000 (+0200) Subject: think of the poor windows users X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=ed7b7dbe49f3962132f0db806552a5873d6fc113;p=koperkapel.git think of the poor windows users --- diff --git a/koperkapel/roaches.py b/koperkapel/roaches.py index b708a88..680d2a6 100644 --- a/koperkapel/roaches.py +++ b/koperkapel/roaches.py @@ -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) diff --git a/koperkapel/scenes/roach_management.py b/koperkapel/scenes/roach_management.py index 4e41b9c..dd05e75 100644 --- a/koperkapel/scenes/roach_management.py +++ b/koperkapel/scenes/roach_management.py @@ -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): diff --git a/koperkapel/scenes/viewlevel.py b/koperkapel/scenes/viewlevel.py index f6c56b6..28e4026 100644 --- a/koperkapel/scenes/viewlevel.py +++ b/koperkapel/scenes/viewlevel.py @@ -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 diff --git a/koperkapel/serums.py b/koperkapel/serums.py index 38794fd..2239114 100644 --- a/koperkapel/serums.py +++ b/koperkapel/serums.py @@ -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 index 0000000..246fb57 --- /dev/null +++ b/koperkapel/util.py @@ -0,0 +1,6 @@ +"""Utility functions""" + +import os + +def safepath(path): + return os.path.join(*path.split("/")) diff --git a/koperkapel/vehicles/base.py b/koperkapel/vehicles/base.py index 27e1b24..3d7765c 100644 --- a/koperkapel/vehicles/base.py +++ b/koperkapel/vehicles/base.py @@ -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) diff --git a/koperkapel/weapons.py b/koperkapel/weapons.py index da8c4c3..890743d 100644 --- a/koperkapel/weapons.py +++ b/koperkapel/weapons.py @@ -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