All pastes #824078 Raw Edit

Meins

public text v1 · immutable
·published 2007-12-19 19:45 UTC
rendered paste body
# -*- coding: utf-8 -*-
"""
    tactics.lib.resources
    =====================

    Tactics resources management.

    :copyright: 2007 by Manni
    :license:   GNU GPL
"""
import os, sys
from pygame.surface import Surface
from os.path import abspath, join as pathjoin, dirname

from tactics.lib.display import load_image

RESOURCE_DIR = abspath(pathjoin(dirname(__file__), '..', 'resources'))

def resource_path(name, type=None):
    return type is not None and pathjoin(RESOURCE_DIR, type.lower(), name) \
                             or pathjoin(RESOURCE_DIR, name)

class Resource(file):
    def __init__(self, name, mode='r', type=None):
        file.__init__(self, resource_path(name, type), mode)

class ImageResource(Resource):
    def __new__(cls, name):
        return load_image(resource_path(name, 'images'))