package org.studiorailgun.interact;

import java.util.Scanner;

import org.studiorailgun.Globals;
import org.studiorailgun.ai.conversation.command.ConvCommandParser;
import org.studiorailgun.sim.character.gen.PlayerCharSourcer;
import org.studiorailgun.sim.eval.GameCommandParser;
import org.studiorailgun.sim.eval.Simulator;
import org.studiorailgun.sim.space.gen.WorldGenerator;
import org.studiorailgun.sim.space.util.LocationResolver;

/**
 * The game loop
 */
public class GameLoop {

    /**
     * Controls whether the main parser loop is running
     */
    public static boolean running = true;

    /**
     * The main method
     */
    public static void main(){
        Globals.init("web.json");
        GameCommandParser.init();
        Globals.world = WorldGenerator.generateWorld();
        Globals.playerCharacter = PlayerCharSourcer.getPlayerCharacter();
        Globals.playerCharacter.move(LocationResolver.first(Globals.world));

        try (Scanner scan = new Scanner(System.in)) {
            String prompt = "";

            System.out.println("Game is ready..");

            //actual main loop
            while(running){

                //handle player statement
                prompt = scan.nextLine();
                if(ConvCommandParser.parseCommands(prompt)){
                    continue;
                }
                GameCommandParser.parse(prompt);
                Simulator.simulate();
            }
        }
    }
}
