#! /usr/bin/env python
# Encoding: UTF-8

import os
import yaml

from regeneration.battle.example import loader
from regeneration.battle.field import Field
from regeneration.battle import messages

__copyright__ = 'Copyright 2011, Petr Viktorin'
__license__ = 'MIT'
__email__ = 'encukou@gmail.com'

def message_printer(message):
    if message.shown is not None:
        if isinstance(message, messages.TurnStart):
            print
        print message

def main(path=None):
    if path == None:
        path = os.path.join(os.path.dirname(__file__), 'demo.yaml')

    battledesc = yaml.safe_load(open(path))

    field = Field.load(battledesc, loader)
    field.add_observer(message_printer)

    field.run()

if __name__ == '__main__':
    main()
