#pragma once

#if __linux__
# define _GNU_SOURCE
#elif _WIN32

#endif

#define STG_NO_RENDERER

#define STB_SPRINTF_IMPLEMENTATION

#include "stb/stb_sprintf.h"
#include "xxhash/xxhash.h"
#include "fastlz/fastlz.h"

#include "assets.h"
#include "shared_types.h"
#include "ds.h"
#include "platform/platform.h"
#include "util.h"
#include "allocators.h"
#include "renderer.h"
#include "game.h"

#include <stdio.h>

#if __linux__
# include <unistd.h>
# include <dirent.h>
#endif

#define CreateMagicValue(a, b, c, d) (u32)(a << 24) | (u32)(a << 16) | (u32)(a << 8) | (u32)(a)
#define FILE_VERSION 0

typedef struct AssetTag_t
{
	u32 tag_id;
	f32 value;
} AssetTag;

typedef struct AssetFile_t
{
	u64 data_offset;
	u32 asset_id;
} AssetFile;

typedef struct AssetHeader_t
{
	AssetTag  *tags;
	AssetFile *assets;
	u32       tag_count;
	u32       asset_count;
} AssetHeader;

typedef struct FileHeader_t
{
	u32 magic_num;
	u32 version;

	u32 tag_counts[ASSET_TYPE_MAX];
	u32 asset_counts[ASSET_TYPE_MAX];

	u64 tag_offsets[ASSET_TYPE_MAX];
	u64 asset_offsets[ASSET_TYPE_MAX];
} FileHeader;

typedef struct FileMapping_t
{
	c8  *file_name;
	u32 ix;
} FileMapping;

const FileMapping g_Shader_File_Map[] = {
	{ .file_name = "quad.frag.spv", .ix = QUAD_FRAG_SPIRV_SHADER },
	{ .file_name = "quad.vert.spv", .ix = QUAD_VERT_SPIRV_SHADER },
	{ .file_name = "gui.frag.spv", .ix = GUI_FRAG_SPIRV_SHADER },
	{ .file_name = "gui.vert.spv", .ix = GUI_VERT_SPIRV_SHADER },
};

const FileMapping g_Texture_File_Map[] = {
	{ .file_name = "pattermon.png", .ix = PATTERMON_OBESE },
	{ .file_name = "patamon.png", .ix = PATTERMON_ORIENTAL }, 
	{ .file_name = "purplemon.png", .ix = PATTERMON_NIGGER },
};

c8 *g_Shader_File_Names[SHADER_ASSET_MAX] = {};
c8 *g_Texture_File_Names[TEXTURE_ASSET_MAX] = {};

b32 ChangeDir(c8 *dir);
u8 **GetFileNamesInDir(Arena *arena, u32 *count);
b8 DirVisible(c8 *dir);
void InitHeader(FileHeader *header);
i32 WriteHeader(FILE *file, FileHeader *header);
