/*******************************************************************************************
*
*   NetWorld basic viewer
*   Copyright (c) 2020-2020 Guillaume Lozenguez
*
********************************************************************************************/

#include "raylib.h"

#include <stdlib.h>
#include <stdio.h>

#include "networld.h"
#include "controlpanel.h"

// Program attributes
//-------------------
const int screenWidth = 800;
const int screenHeight = 600;
const int targetFPS = 60;

void game_update(NetWorld * world);

// Game attributes
//-----------------
bool game_end;

int main(int nbArg, char ** arg)
{
    // Game Initialization
    //--------------------
    game_end= false;
    NetWorld * world= NetWorld_new(3);
    Node_set( &(world->nodes[0]), (Vector2){1.4f, 1.28f}, RED );
    Node_set( &(world->nodes[1]), (Vector2){21.0f, 22.8f}, MAGENTA );
    Node_set( &(world->nodes[2]), (Vector2){18.4f, -12.2f}, GRAY );

    NetWorld_connect(world, 0, 1);
    NetWorld_connect(world, 1, 2);
    NetWorld_biconnect(world, 2, 0);

    Panel * panel= Panel_new();
    Panel_initialize(panel, world);

    // Raylib Initialization
    //----------------------
    InitWindow(screenWidth, screenHeight, "NetWorld basic viewer");
    SetTargetFPS(targetFPS);

    // Some verificcations
    //--------------------
    puts("world variable:");
    NetWorld_print(world);
    puts("world expected:\n[10.4, 12.8]\n[110.4, 52.8]\n[384.5, 422.2]");
    Panel_print(panel);
    Vector2 position= {1.f, 1.f};
    position= Panel_pixelFromPosition( panel, &position );
    printf("[%.2f,%.2f]\n", position.x, position.y);

    // Main game loop
    while (!game_end && !WindowShouldClose())    // Detect window close button or ESC key
    {
        Panel_control(panel);
        game_update(world);
        Panel_draw(panel);
    }

    // proper closing
    //---------------
    NetWorld_delete(world);
    CloseWindow();   // Close window and OpenGL context
 
    return 0;
}

void game_update(NetWorld * world)
{

}
