#pragma once
#include "raylib.h"
#include "lib.h"
#include "sprites.h"
#include <vector>

#include <optional>

using namespace std;

#define TEXTURES_BUF_SIZE 16
#define TARGET_FPS 60
#define MAX_KNIGHTS 50
#define SCREEN_WIDTH 1300
#define SCREEN_HEIGHT 1080

#define DEBUG_MODE_ENABLED

bool global_debug_mode = false;

enum class KnightState {
    IDLE = 0,
    RUNNING = 1,
    ATTACKING = 2,
};

enum class Direction : u8 {
    UP = 0,
    DOWN = 1,
    LEFT = 2,
    RIGHT = 3,
    // DIR_UP_LEFT = 4,
    // DIR_UP_RIGHT = 5,
    // DIR_DOWN_LEFT = 6,
    // DIR_DOWN_RIGHT = 7,
};

struct Knight {
    Point position;
    Point move_target_point;
    Direction look_dir;
    KnightState state;
    u8 selected;
    u8 ordered_to_move;
};

struct Assets {
    Texture2D *textures;
};

struct GameState {
    bool should_reset;
    Camera2D camera;
    int frame_count;
    Point camera_position;

    optional<Point> selected_point;
    Knight *knights;
    SpriteAnimationPlayback *anim_playbacks;

    optional<Point> selection_mouse_start_pos;

    int entity_count;
    Assets assets;

    optional<Point> drag_camera_start_pos;

    Point camera_target_start_pos;

    ~GameState() {
        free(knights);
        free(anim_playbacks);
        for (int i = 0; i < TEXTURES_BUF_SIZE; i++) {
            UnloadTexture(assets.textures[i]);
        }
        free(assets.textures);
        printf("Freeing GameState memory\n");
    }
};
