view eosd @ 321:61adb5453e46

Implement music playback.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 13 Jun 2012 15:29:43 +0200
parents da53bc29b94a
children 1b4f04b08729
line wrap: on
line source

#!/usr/bin/env python
# -*- 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.
##

import argparse
import os

import pyximport
pyximport.install()

from pytouhou.resource.loader import Loader
from pytouhou.game.background import Background
from pytouhou.ui.gamerunner import GameRunner
from pytouhou.games.eosd import EoSDGame
from pytouhou.game.player import PlayerState
from pytouhou.formats.t6rp import T6RP


def main(path, stage_num, rank, character, replay, data):
    if replay:
        with open(replay, 'rb') as file:
            replay = T6RP.read(file)
        rank = replay.rank
        character = replay.character
        if not replay.levels[stage_num-1]:
            raise Exception
        from pytouhou.utils.random import Random
        prng = Random(replay.levels[stage_num-1].random_seed)
    else:
        prng = None

    resource_loader = Loader(path)

    resource_loader.scan_archives(data)

    # Load stage data
    stage = resource_loader.get_stage('stage%d.std' % stage_num)

    default_power = [0, 64, 128, 128, 128, 128, 0][stage_num - 1]
    game = EoSDGame(resource_loader, [PlayerState(character=character, power=default_power)], stage_num, rank, 16,
                    prng=prng, bgms=stage.bgms)

    background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,))
    background = Background(stage, background_anm_wrapper)

    # Main loop
    runner = GameRunner(resource_loader, game, background, replay=replay)
    runner.start()


pathsep = os.path.pathsep
default_data = (pathsep.join(('CM.DAT', 'th06*_CM.DAT', '*CM.DAT', '*cm.dat')),
                pathsep.join(('ST.DAT', 'th6*ST.DAT', '*ST.DAT', '*st.dat')),
                pathsep.join(('IN.DAT', 'th6*IN.DAT', '*IN.DAT', '*in.dat')),
                pathsep.join(('MD.DAT', 'th6*MD.DAT', '*MD.DAT', '*md.dat')),
                pathsep.join(('102h.exe', '102*.exe', '東方紅魔郷.exe', '*.exe')))


parser = argparse.ArgumentParser(description='Libre reimplementation of the Touhou 6 engine.')

parser.add_argument('data', metavar='DAT', default=default_data, nargs='*', help='Game’s data files')
parser.add_argument('-p', '--path', metavar='DIRECTORY', default='.', help='Game directory path.')
parser.add_argument('-s', '--stage', metavar='STAGE', type=int, required=True, help='Stage, 1 to 7 (Extra).')
parser.add_argument('-r', '--rank', metavar='RANK', type=int, default=0, help='Rank, from 0 (Easy, default) to 3 (Lunatic).')
parser.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
parser.add_argument('--replay', metavar='REPLAY', help='Select a replay')

args = parser.parse_args()

main(args.path, args.stage, args.rank, args.character, args.replay, tuple(args.data))