view pytouhou/utils/helpers.py @ 56:299de3a9b69f

Filter out off-screen enemies (the same way the official game does)
author Thibaut Girka <thib@sitedethib.com>
date Tue, 23 Aug 2011 00:15:22 +0200
parents ab826bc29aa2
children 3da4de9decd0
line wrap: on
line source

# -*- encoding: utf-8 -*-
##
## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 3 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##

def read_string(file, size, encoding=None):
    data = file.read(size)

    try:
        data = data[:data.index(b'\x00')]
    except ValueError:
        pass

    if encoding:
        return data.decode(encoding)
    else:
        return data