#!/usr/bin/env python

# This is the main executable file that will serve as the starter for the game
# The file should be kept simple
# Seperated into:
# 
#
# PreMainLoop()
# MainLoop()
# TextParser()
# 
from databaseconnect import Player, Mobs, Rooms
from commands import Parser, general_commands, admin_commands, movement_commands
from functions import CommandHandler
from skills import *
import os

MAIN_LOOP = 1
command = ""
repeat = True

while MAIN_LOOP:
    ## Load Player Data ##
    room = Player().loadplayer_room()

    ## Show 'room' that you are in ##
    if repeat is False:
        # Don't show room again
        pass
    else:
        room_info = Rooms().show_room(room)

        room_title = room_info[0]   # Str
        room_desc  = room_info[1]   # Str
        mobs       = room_info[2]   # List

        print_room = "\n|G%s\n\n|W%s|x\n" % (room_title, room_desc)
        for mob in mobs:
            print_room += "|M" + mob +'|x is here' + '\n'
        Parser.color(print_room)
        Parser.color(Player().get_prompt())


    ## Handle Command Input ##
    command = raw_input("> ")
    command = command.split()
    if len(command) == 0:
        repeat = False
    else:

        cmd = Parser().text_parser(command[0])
        if cmd == 'quit':
            print "Quitting Game"
            MAIN_LOOP = 0

        elif cmd == 'clear':
            os.system('clear')
            repeat = True
        elif cmd == 'reload':
            Parser.color('\nRebooting...')
            os.execl('main.py','')


        elif cmd is None:
            repeat = False
            CommandHandler().command_handler(cmd, command[1:])

        else:
            repeat = CommandHandler().command_handler(cmd, command[1:])
