#import <raylib.h>
#import <yeslib.h>
//#import <Foundation/Foundation.h>

//#import "Enemy.h"
#import "Camera.h"
//#import "SoundPlayer.h"
#import "InputHandler.h"
#import "AssetLoader.h"
#import "Renderer.h"
#import "Gravitator.h"
#import "PhysObject.h"
#import "NPC.h"
#import "DialogueBox.h"
#import "properties.h"


const int winWidth = 800;
const int winHeight = 600;

int main(int argc, const char *argv[]) {
    

    //insert custom properties loader here

    InitWindow(default_properties.width, default_properties.height, "Game :3");
    
    SetTargetFPS(60);
    DisableCursor();

    GameCamera *camera = [GameCamera alloc];
    [camera init];

    Player *player = [[Player alloc] init];
    InputHandler *input = [[InputHandler alloc] init];
    AssetLoader *assetLoader = [[AssetLoader alloc] init];
    Renderer *renderer = [[Renderer alloc] init];
    Gravitator *gravitator = [[Gravitator alloc] init];
    NPC *npc = [NPC new];
    DialogueBox *dbox = [DialogueBox newWithText: "Cock and ball torture, from wikipedia, the free encyclopedia,\nat wikipedia.org"];

    input->controllable = player;

    gravitator->acceleration = (Vector3){0.0f, -1.0f, 0.0f};

    //player.soundPlayer = sp;
    
    [camera attach: player];


    
    [assetLoader loadAssetFile: "assets.al"];


    int i;
    for (i = 0; i < assetLoader->count; i++) {
        [assetLoader sendObject: assetLoader->array[i] to: renderer];
        [assetLoader sendObject: assetLoader->array[i] to: gravitator];
    }


    [player->activators addObject: npc];


    while (!WindowShouldClose()) {
        [camera update];

        //hard coded input handler
        [input handleInput];
        [gravitator applyGravity];

        BeginDrawing();
            ClearBackground(RAYWHITE);
            BeginMode3D(camera->camera);
                DrawPlane((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector2){ 32.0f, 32.0f }, LIGHTGRAY);
                DrawCube((Vector3){ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE);     // Draw a blue wall
                DrawCube((Vector3){ 16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, LIME);      // Draw a green wall
                DrawCube((Vector3){ 0.0f, 2.5f, 16.0f }, 32.0f, 5.0f, 1.0f, GOLD);
                DrawCube((Vector3){ 0.0f, 2.5f, -16.0f }, 32.0f, 5.0f, 1.0f, RED);
                [npc draw: camera->camera];
                [renderer render];
            EndMode3D();

            [camera showPos];
            [camera showTarget];
            [player showPos];
            [camera drawCrosshair];
            [dbox draw];
            //[camera raycast];
            //[enemy Render: [camera camera]];
            //DrawTexture(tex, default_properties.width - tex.width, default_properties.height - tex.height, WHITE);

        EndDrawing();
    }

    CloseWindow();
    //[pool drain];
    return 0;
}