python 3 compatibility
This commit is contained in:
parent
717b2eb686
commit
db873683d3
|
@ -1,4 +1,4 @@
|
|||
from GameChild import GameChild
|
||||
from .GameChild import GameChild
|
||||
|
||||
class Animation(GameChild):
|
||||
|
||||
|
@ -15,7 +15,7 @@ class Animation(GameChild):
|
|||
|
||||
def register(self, *args, **kwargs):
|
||||
interval = None
|
||||
if kwargs.has_key("interval"):
|
||||
if "interval" in kwargs:
|
||||
interval = kwargs["interval"]
|
||||
for method in args:
|
||||
if method not in self.accounts:
|
||||
|
@ -43,13 +43,13 @@ class Animation(GameChild):
|
|||
for account in self.accounts.values():
|
||||
account.halt()
|
||||
else:
|
||||
if self.accounts.has_key(method):
|
||||
if method in self.accounts:
|
||||
self.accounts[method].halt()
|
||||
|
||||
def is_playing(self, method=None, check_all=False, include_delay=False):
|
||||
if check_all:
|
||||
return any(self.is_account_playing(account, include_delay) for \
|
||||
method, account in self.accounts.iteritems())
|
||||
method, account in self.accounts.items())
|
||||
return self.is_account_playing(self.accounts[self.get_default(method)],
|
||||
include_delay)
|
||||
|
||||
|
@ -64,7 +64,7 @@ class Animation(GameChild):
|
|||
self.accounts[method].reset_timer()
|
||||
|
||||
def update(self):
|
||||
for method, account in self.accounts.iteritems():
|
||||
for method, account in self.accounts.items():
|
||||
if account.update():
|
||||
method(**account.args)
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ from os.path import join
|
|||
|
||||
from pygame.mixer import Channel, Sound, music, find_channel, get_num_channels
|
||||
|
||||
from GameChild import *
|
||||
from Input import *
|
||||
from .GameChild import *
|
||||
from .Input import *
|
||||
|
||||
class Audio(GameChild):
|
||||
|
||||
|
@ -41,7 +41,7 @@ class Audio(GameChild):
|
|||
self.set_volume(increment=self.DOWN)
|
||||
|
||||
def update(self):
|
||||
for ii in xrange(get_num_channels()):
|
||||
for ii in range(get_num_channels()):
|
||||
channel = Channel(ii)
|
||||
sound = channel.get_sound()
|
||||
if sound is not None:
|
||||
|
@ -65,7 +65,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
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from sys import argv
|
|||
from re import match
|
||||
from pprint import pformat
|
||||
|
||||
from ConfigParser import RawConfigParser
|
||||
from configparser import RawConfigParser
|
||||
|
||||
class Configuration(RawConfigParser):
|
||||
|
||||
|
@ -65,7 +65,7 @@ class Configuration(RawConfigParser):
|
|||
set_option(section, "windows-dist-path", "dist/win/", False)
|
||||
set_option(section, "windows-icon-path", "", False)
|
||||
set_option(section, "lowercase-boolean-true", "yes", False)
|
||||
set_option(section, "osx-includes", "", False)
|
||||
set_option(section, "osx-includes", "", False)
|
||||
section = "display"
|
||||
add_section(section)
|
||||
set_option(section, "dimensions", "480, 360", False)
|
||||
|
@ -198,7 +198,7 @@ class Configuration(RawConfigParser):
|
|||
|
||||
def set_order(self, fp):
|
||||
self.order = order = []
|
||||
for line in file(self.locate_project_config_file()):
|
||||
for line in open(self.locate_project_config_file()):
|
||||
result = match("^\s*\[(.*)\]\s*$", line)
|
||||
if result:
|
||||
order.append(result.group(1))
|
||||
|
@ -219,7 +219,7 @@ class Configuration(RawConfigParser):
|
|||
|
||||
def print_debug(self, statement):
|
||||
if self.is_debug_mode():
|
||||
print statement
|
||||
print(statement)
|
||||
|
||||
def is_debug_mode(self):
|
||||
return "-d" in argv
|
||||
|
@ -260,6 +260,7 @@ class Configuration(RawConfigParser):
|
|||
def cast_value(self, section, option, value):
|
||||
pair = section, option
|
||||
types = self.type_declarations
|
||||
# if type(value) == str or type(value) == unicode:
|
||||
if type(value) == str:
|
||||
if pair in types["bool"]:
|
||||
if value.lower() == self.get("setup", "lowercase-boolean-true"):
|
||||
|
@ -275,11 +276,11 @@ class Configuration(RawConfigParser):
|
|||
if value == "":
|
||||
return []
|
||||
else:
|
||||
return map(str.strip, value.split(types.list_member_sep))
|
||||
return [member.strip() for member in value.split(types.list_member_sep)]
|
||||
elif pair in types["int-list"]:
|
||||
return map(int, value.split(types.list_member_sep))
|
||||
return [int(member) for member in value.split(types.list_member_sep)]
|
||||
elif pair in types["float-list"]:
|
||||
return map(float, value.split(types.list_member_sep))
|
||||
return [float(member) for member in value.split(types.list_member_sep)]
|
||||
return value
|
||||
|
||||
def set_screen_captures_path(self):
|
||||
|
@ -454,8 +455,8 @@ class TypeDeclarations(dict):
|
|||
self[cast].append((section, option))
|
||||
|
||||
def add_chart(self, chart):
|
||||
for section, declarations in chart.iteritems():
|
||||
for cast, options in declarations.iteritems():
|
||||
for section, declarations in chart.items():
|
||||
for cast, options in declarations.items():
|
||||
if type(options) != list:
|
||||
options = [options]
|
||||
for option in options:
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from pygame.event import get, pump, Event, post
|
||||
from pygame.locals import *
|
||||
|
||||
from GameChild import GameChild
|
||||
from Input import Input
|
||||
from .GameChild import GameChild
|
||||
from .Input import Input
|
||||
|
||||
class Delegate(GameChild):
|
||||
|
||||
|
@ -70,7 +70,7 @@ class Delegate(GameChild):
|
|||
if not self.command_in_list(evt, commands):
|
||||
return False
|
||||
return all(key in evt.dict and evt.dict[key] == value for \
|
||||
key, value in attributes.iteritems())
|
||||
key, value in attributes.items())
|
||||
|
||||
def add_cancel_flag_to_attributes(self, attributes, cancel):
|
||||
attributes[self.cancel_flag_key] = cancel
|
||||
|
@ -79,7 +79,7 @@ class Delegate(GameChild):
|
|||
return self.get_command_attribute(evt) in commands
|
||||
|
||||
def get_command_attribute(self, evt):
|
||||
return evt.dict.has_key(self.command_key) and evt.dict[self.command_key]
|
||||
return (self.command_key in evt.dict) and evt.dict[self.command_key]
|
||||
|
||||
def post(self, command=None, cancel=False, **attributes):
|
||||
attributes[self.command_key] = command
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
from os import environ
|
||||
from sys import maxint
|
||||
from sys import maxsize
|
||||
|
||||
from pygame import display, image, mouse
|
||||
from pygame.locals import *
|
||||
|
||||
from GameChild import *
|
||||
from .GameChild import *
|
||||
|
||||
class Display(GameChild):
|
||||
|
||||
|
@ -85,7 +85,7 @@ class Display(GameChild):
|
|||
flags = self.screen.get_flags()
|
||||
if flags & 0x80000000:
|
||||
full = False
|
||||
if maxint >> 33:
|
||||
if maxsize >> 33:
|
||||
flags ^= 0x80000000
|
||||
else:
|
||||
flags ^= -0x80000000
|
||||
|
|
24
pgfw/Game.py
24
pgfw/Game.py
|
@ -1,18 +1,18 @@
|
|||
import pygame
|
||||
from pygame.locals import *
|
||||
|
||||
from GameChild import GameChild
|
||||
from Mainloop import Mainloop
|
||||
from Audio import Audio
|
||||
from Display import Display
|
||||
from Configuration import Configuration
|
||||
from Delegate import Delegate
|
||||
from Input import Input
|
||||
from ScreenGrabber import ScreenGrabber
|
||||
from Profile import Profile
|
||||
from VideoRecorder import VideoRecorder
|
||||
from Interpolator import Interpolator
|
||||
from TimeFilter import TimeFilter
|
||||
from .GameChild import GameChild
|
||||
from .Mainloop import Mainloop
|
||||
from .Audio import Audio
|
||||
from .Display import Display
|
||||
from .Configuration import Configuration
|
||||
from .Delegate import Delegate
|
||||
from .Input import Input
|
||||
from .ScreenGrabber import ScreenGrabber
|
||||
from .Profile import Profile
|
||||
from .VideoRecorder import VideoRecorder
|
||||
from .Interpolator import Interpolator
|
||||
from .TimeFilter import TimeFilter
|
||||
|
||||
class Game(GameChild):
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
from os.path import exists, join, basename, normpath, abspath
|
||||
from sys import argv
|
||||
from sys import argv, version_info
|
||||
|
||||
from pygame import mixer, event, time
|
||||
from pygame.locals import *
|
||||
|
||||
import Game
|
||||
if version_info[0] >= 3:
|
||||
from . import Game
|
||||
else:
|
||||
import Game
|
||||
|
||||
class GameChild:
|
||||
|
||||
|
@ -73,7 +76,7 @@ class GameChild:
|
|||
|
||||
def print_debug(self, statement):
|
||||
if self.is_debug_mode():
|
||||
print statement
|
||||
print(statement)
|
||||
|
||||
def is_debug_mode(self):
|
||||
return self.check_command_line("d")
|
||||
|
|
|
@ -4,7 +4,7 @@ from pygame import joystick as joy
|
|||
from pygame.key import get_pressed
|
||||
from pygame.locals import *
|
||||
|
||||
from GameChild import *
|
||||
from .GameChild import *
|
||||
|
||||
class Input(GameChild):
|
||||
|
||||
|
@ -67,7 +67,7 @@ class Input(GameChild):
|
|||
cancel = event.type == KEYUP
|
||||
posted = None
|
||||
key = event.key
|
||||
for cmd, keys in self.key_map.iteritems():
|
||||
for cmd, keys in self.key_map.items():
|
||||
if key in keys:
|
||||
self.post_command(cmd, cancel=cancel)
|
||||
posted = cmd
|
||||
|
@ -85,7 +85,7 @@ class Input(GameChild):
|
|||
if not self.suppressed:
|
||||
cancel = event.type == JOYBUTTONUP
|
||||
posted = None
|
||||
for command, button in self.joy_button_map.iteritems():
|
||||
for command, button in self.joy_button_map.items():
|
||||
if int(button) == event.button:
|
||||
self.post_command(command, cancel=cancel)
|
||||
posted = command
|
||||
|
@ -175,11 +175,11 @@ class Input(GameChild):
|
|||
post("mouse-double-click-left", pos=pos)
|
||||
last = get_secs()
|
||||
self.last_mouse_down_left = last
|
||||
if "mouse" not in self.any_press_ignored_keys:
|
||||
self.post_any_command(event.button)
|
||||
if event.type == MOUSEBUTTONUP:
|
||||
if "mouse" not in self.any_press_ignored_keys:
|
||||
self.post_any_command(event.button, True)
|
||||
if "mouse" not in self.any_press_ignored_keys:
|
||||
self.post_any_command(event.button)
|
||||
if event.type == MOUSEBUTTONUP:
|
||||
if "mouse" not in self.any_press_ignored_keys:
|
||||
self.post_any_command(event.button, True)
|
||||
|
||||
def get_axes(self):
|
||||
axes = {}
|
||||
|
@ -230,5 +230,5 @@ class Joystick:
|
|||
return js.get_axis(0) < 0
|
||||
|
||||
def get_button(self, id):
|
||||
if self.js:
|
||||
return self.js.get_button(id)
|
||||
if self.js:
|
||||
return self.js.get_button(id)
|
||||
|
|
|
@ -7,9 +7,9 @@ from pygame.font import Font
|
|||
from pygame.draw import aaline
|
||||
from pygame.locals import *
|
||||
|
||||
from GameChild import GameChild
|
||||
from Sprite import Sprite
|
||||
from Animation import Animation
|
||||
from .GameChild import GameChild
|
||||
from .Sprite import Sprite
|
||||
from .Animation import Animation
|
||||
|
||||
class Interpolator(list, GameChild):
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ from pygame import display
|
|||
from pygame.font import Font
|
||||
from pygame.time import get_ticks, wait
|
||||
|
||||
from GameChild import GameChild
|
||||
from .GameChild import GameChild
|
||||
|
||||
class Mainloop(GameChild):
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ from time import strftime
|
|||
from os import mkdir
|
||||
from os.path import join, exists
|
||||
|
||||
from GameChild import GameChild
|
||||
from .GameChild import GameChild
|
||||
|
||||
class Profile(cProfile.Profile, GameChild):
|
||||
|
||||
|
|
|
@ -5,8 +5,8 @@ from time import strftime
|
|||
|
||||
from pygame import image
|
||||
|
||||
from GameChild import *
|
||||
from Input import *
|
||||
from .GameChild import *
|
||||
from .Input import *
|
||||
|
||||
class ScreenGrabber(GameChild):
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ from pygame.image import load
|
|||
from pygame.transform import flip
|
||||
from pygame.locals import *
|
||||
|
||||
from Animation import Animation
|
||||
from Vector import Vector, EVector
|
||||
from extension import get_hue_shifted_surface, get_step
|
||||
from .Animation import Animation
|
||||
from .Vector import Vector, EVector
|
||||
from .extension import get_hue_shifted_surface, get_step
|
||||
|
||||
class Sprite(Animation):
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Sprite(Animation):
|
|||
return self.locations[0]
|
||||
if hasattr(Animation, "__getattr__"):
|
||||
return Animation.__getattr__(self, name)
|
||||
raise AttributeError, name
|
||||
raise AttributeError(name)
|
||||
|
||||
def set_frameset(self, identifier):
|
||||
if isinstance(identifier, str):
|
||||
|
@ -144,13 +144,13 @@ class Sprite(Animation):
|
|||
|
||||
def add_location(self, topleft=None, offset=(0, 0), count=1, base=0):
|
||||
if topleft is not None:
|
||||
for ii in xrange(count):
|
||||
for ii in range(count):
|
||||
self.locations.append(Location(
|
||||
self, Rect(topleft, self.locations[0].size)))
|
||||
else:
|
||||
base = self.locations[base]
|
||||
current_offset = list(offset)
|
||||
for ii in xrange(count):
|
||||
for ii in range(count):
|
||||
self.locations.append(Location(self,
|
||||
base.move(*current_offset)))
|
||||
current_offset[0] += offset[0]
|
||||
|
@ -255,7 +255,8 @@ class Location(Rect):
|
|||
def update_motion_overflow(self, dx, dy):
|
||||
overflow = self.motion_overflow
|
||||
overflow.move(dx - int(dx), dy - int(dy))
|
||||
excess = map(int, overflow)
|
||||
excess = [int(value) for value in overflow]
|
||||
# excess = map(int, overflow)
|
||||
overflow[0] -= int(overflow[0])
|
||||
overflow[1] -= int(overflow[1])
|
||||
return excess
|
||||
|
@ -341,7 +342,7 @@ class Fader(Surface):
|
|||
frame = sprite.get_current_frame()
|
||||
else:
|
||||
frame = substitute
|
||||
if self.fade_remaining >= 0:
|
||||
if self.fade_remaining is not None and self.fade_remaining >= 0:
|
||||
self.update_alpha()
|
||||
self.clear()
|
||||
frame.set_alpha(255)
|
||||
|
@ -352,8 +353,8 @@ class Fader(Surface):
|
|||
ratio = self.get_alpha() / 255.0
|
||||
pixels = PixelArray(frame.copy())
|
||||
color = Color(0, 0, 0)
|
||||
for x in xrange(len(pixels)):
|
||||
for y in xrange(len(pixels[0])):
|
||||
for x in range(len(pixels)):
|
||||
for y in range(len(pixels[0])):
|
||||
h, s, l, a = Color(*frame.unmap_rgb(pixels[x][y])).hsla
|
||||
if a:
|
||||
color.hsla = h, s, l, int(a * ratio)
|
||||
|
@ -363,7 +364,7 @@ class Fader(Surface):
|
|||
else:
|
||||
self.blit_to_display(self, areas)
|
||||
elif self.fade_remaining is None or self.get_alpha() >= sprite.alpha:
|
||||
if self.fade_remaining >= 0:
|
||||
if self.fade_remaining is not None and self.fade_remaining >= 0:
|
||||
self.update_alpha()
|
||||
if not self.location.is_hidden():
|
||||
self.blit_to_display(frame, areas)
|
||||
|
@ -474,5 +475,5 @@ class RainbowSprite(Sprite):
|
|||
|
||||
def __init__(self, parent, image, hue_shift=8, framerate=None):
|
||||
Sprite.__init__(self, parent, framerate)
|
||||
for hue in xrange(0, 360, hue_shift):
|
||||
for hue in range(0, 360, hue_shift):
|
||||
self.add_frame(get_hue_shifted_surface(image, hue))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from pygame.time import get_ticks
|
||||
|
||||
from GameChild import GameChild
|
||||
from .GameChild import GameChild
|
||||
|
||||
class TimeFilter(GameChild):
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from math import pi, degrees
|
||||
|
||||
from extension import get_delta, get_distance, get_angle
|
||||
from .extension import get_delta, get_distance, get_angle
|
||||
|
||||
class Vector(list):
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from time import strftime
|
|||
from pygame.image import tostring, frombuffer, save
|
||||
from pygame.time import get_ticks
|
||||
|
||||
from GameChild import GameChild
|
||||
from .GameChild import GameChild
|
||||
|
||||
class VideoRecorder(GameChild):
|
||||
|
||||
|
@ -82,7 +82,7 @@ class VideoRecorder(GameChild):
|
|||
"")):
|
||||
path = join(root, "%04i.png" % ii)
|
||||
save(frombuffer(frame, size, self.frame_format), path)
|
||||
print "wrote video frames to " + root
|
||||
print("wrote video frames to " + root)
|
||||
if self.check_command_line("-enable-sound-recording"):
|
||||
import pyaudio
|
||||
import wave
|
||||
|
|
|
@ -46,7 +46,7 @@ def get_points_on_circle(center, radius, count, offset=0):
|
|||
angle_step = 360.0 / count
|
||||
points = []
|
||||
current_angle = 0
|
||||
for _ in xrange(count):
|
||||
for _ in range(count):
|
||||
points.append(get_point_on_circle(center, radius,
|
||||
current_angle + offset))
|
||||
current_angle += angle_step
|
||||
|
@ -58,7 +58,7 @@ def get_point_on_circle(center, radius, angle, translate_angle=True):
|
|||
return center[0] + sin(angle) * radius, center[1] - cos(angle) * radius
|
||||
|
||||
def get_range_steps(start, end, count):
|
||||
for ii in xrange(count):
|
||||
for ii in range(count):
|
||||
yield start + (end - start) * ii / float(count - 1)
|
||||
|
||||
def get_distance(p0, p1):
|
||||
|
@ -160,7 +160,7 @@ def get_color_swapped_surface(surface, current, replacement):
|
|||
|
||||
def get_busy_channel_count():
|
||||
count = 0
|
||||
for index in xrange(get_num_channels()):
|
||||
for index in range(get_num_channels()):
|
||||
count += Channel(index).get_busy()
|
||||
return count
|
||||
|
||||
|
@ -168,8 +168,8 @@ def get_hue_shifted_surface(base, offset):
|
|||
surface = base.copy()
|
||||
pixels = PixelArray(surface)
|
||||
color = Color(0, 0, 0)
|
||||
for x in xrange(surface.get_width()):
|
||||
for y in xrange(surface.get_height()):
|
||||
for x in range(surface.get_width()):
|
||||
for y in range(surface.get_height()):
|
||||
h, s, l, a = Color(*surface.unmap_rgb(pixels[x][y])).hsla
|
||||
if a:
|
||||
color.hsla = (int(h) + offset) % 360, int(s), int(l), int(a)
|
||||
|
@ -180,20 +180,20 @@ def get_hue_shifted_surface(base, offset):
|
|||
def get_inverted_surface(base):
|
||||
surface = base.copy()
|
||||
pixels = PixelArray(surface)
|
||||
for x in xrange(surface.get_width()):
|
||||
for y in xrange(surface.get_height()):
|
||||
for x in range(surface.get_width()):
|
||||
for y in range(surface.get_height()):
|
||||
color = Color(*surface.unmap_rgb(pixels[x][y]))
|
||||
if color.hsla[3]:
|
||||
color.r = 255 - color.r
|
||||
color.g = 255 - color.g
|
||||
color.b = 255 - color.b
|
||||
color.g = 255 - color.g
|
||||
color.b = 255 - color.b
|
||||
pixels[x][y] = color
|
||||
del pixels
|
||||
return surface
|
||||
|
||||
def fill_tile(surface, tile):
|
||||
for x in xrange(0, surface.get_width(), tile.get_width()):
|
||||
for y in xrange(0, surface.get_height(), tile.get_height()):
|
||||
for x in range(0, surface.get_width(), tile.get_width()):
|
||||
for y in range(0, surface.get_height(), tile.get_height()):
|
||||
surface.blit(tile, (x, y))
|
||||
|
||||
def get_shadowed_text(text, font, offset, color, antialias=True, shadow_color=(0, 0, 0),
|
||||
|
|
Loading…
Reference in New Issue