#pragma once

#include "pxl8_types.h"
#include <string.h>

static const char embed_fennel[] = {
#embed "lib/fennel/fennel.lua"
, 0 };

static const char embed_pxl8[] = {
#embed "src/lua/pxl8.lua"
, 0 };

static const char embed_pxl8_anim[] = {
#embed "src/lua/pxl8/anim.lua"
, 0 };

static const char embed_pxl8_bytes[] = {
#embed "src/lua/pxl8/bytes.lua"
, 0 };

static const char embed_pxl8_core[] = {
#embed "src/lua/pxl8/core.lua"
, 0 };

static const char embed_pxl8_effects[] = {
#embed "src/lua/pxl8/effects.lua"
, 0 };

static const char embed_pxl8_gfx2d[] = {
#embed "src/lua/pxl8/gfx2d.lua"
, 0 };

static const char embed_pxl8_gfx3d[] = {
#embed "src/lua/pxl8/gfx3d.lua"
, 0 };

static const char embed_pxl8_gui[] = {
#embed "src/lua/pxl8/gui.lua"
, 0 };

static const char embed_pxl8_input[] = {
#embed "src/lua/pxl8/input.lua"
, 0 };

static const char embed_pxl8_math[] = {
#embed "src/lua/pxl8/math.lua"
, 0 };

static const char embed_pxl8_net[] = {
#embed "src/lua/pxl8/net.lua"
, 0 };

static const char embed_pxl8_particles[] = {
#embed "src/lua/pxl8/particles.lua"
, 0 };

static const char embed_pxl8_sfx[] = {
#embed "src/lua/pxl8/sfx.lua"
, 0 };

static const char embed_pxl8_tilemap[] = {
#embed "src/lua/pxl8/tilemap.lua"
, 0 };

static const char embed_pxl8_transition[] = {
#embed "src/lua/pxl8/transition.lua"
, 0 };

static const char embed_pxl8_world[] = {
#embed "src/lua/pxl8/world.lua"
, 0 };

#define PXL8_EMBED_ENTRY(var, name) {name, var, sizeof(var) - 1}

typedef struct { const char* name; const char* data; u32 size; } pxl8_embed;

static const pxl8_embed pxl8_embeds[] = {
    PXL8_EMBED_ENTRY(embed_fennel,          "fennel"),
    PXL8_EMBED_ENTRY(embed_pxl8,            "pxl8"),
    PXL8_EMBED_ENTRY(embed_pxl8_anim,       "pxl8.anim"),
    PXL8_EMBED_ENTRY(embed_pxl8_bytes,      "pxl8.bytes"),
    PXL8_EMBED_ENTRY(embed_pxl8_core,       "pxl8.core"),
    PXL8_EMBED_ENTRY(embed_pxl8_effects,    "pxl8.effects"),
    PXL8_EMBED_ENTRY(embed_pxl8_gfx2d,      "pxl8.gfx2d"),
    PXL8_EMBED_ENTRY(embed_pxl8_gfx3d,      "pxl8.gfx3d"),
    PXL8_EMBED_ENTRY(embed_pxl8_gui,        "pxl8.gui"),
    PXL8_EMBED_ENTRY(embed_pxl8_input,      "pxl8.input"),
    PXL8_EMBED_ENTRY(embed_pxl8_math,       "pxl8.math"),
    PXL8_EMBED_ENTRY(embed_pxl8_net,        "pxl8.net"),
    PXL8_EMBED_ENTRY(embed_pxl8_particles,  "pxl8.particles"),
    PXL8_EMBED_ENTRY(embed_pxl8_sfx,        "pxl8.sfx"),
    PXL8_EMBED_ENTRY(embed_pxl8_tilemap,    "pxl8.tilemap"),
    PXL8_EMBED_ENTRY(embed_pxl8_transition, "pxl8.transition"),
    PXL8_EMBED_ENTRY(embed_pxl8_world,      "pxl8.world"),
    {0}
};

static inline const pxl8_embed* pxl8_embed_find(const char* name) {
    for (const pxl8_embed* e = pxl8_embeds; e->name; e++)
        if (strcmp(e->name, name) == 0) return e;
    return NULL;
}
