diff --git a/assets/Makefile b/assets/Makefile index ee672ba..d42c758 100644 --- a/assets/Makefile +++ b/assets/Makefile @@ -9,6 +9,9 @@ ASSETS := \ maps/dungeon_entry.map \ maps/dungeon_room_1.map +LUA_SOURCES := \ + enemy_system.lua + OBJECTS := $(ASSETS:%=$(BUILD_DIR)/$(notdir $(ASSETS_DIR))/%.o) ifeq ($(TOTAL_BUILD_FILES),) diff --git a/src/components/components.def b/src/components/components.def index a59eaa6..a00f213 100644 --- a/src/components/components.def +++ b/src/components/components.def @@ -6,10 +6,12 @@ COMPONENT(TRANSFORM_COMPONENT, transform_component, DRAW) COMPONENT(HITBOX_COMPONENT, hitbox_component, DRAW) COMPONENT(INTERACT_COMPONENT, interact_component, DRAW) +COMPONENT(LUA_COMPONENT, lua_component, DRAW) #else COMPONENT(TRANSFORM_COMPONENT, transform_component, NO_DRAW) COMPONENT(HITBOX_COMPONENT, hitbox_component, NO_DRAW) COMPONENT(INTERACT_COMPONENT, interact_component, NO_DRAW) +COMPONENT(LUA_COMPONENT, lua_component, NO_DRAW) #endif // DEBUG >= 2 COMPONENT(PHYSICS_SYSTEM, physics_system, NO_DRAW) @@ -18,7 +20,6 @@ COMPONENT(ANIMATION_SYSTEM, animation_system, NO_DRAW) COMPONENT(PLAYER_SYSTEM, player_system, NO_DRAW) COMPONENT(LEVER_COMPONENT, lever_component, NO_DRAW) COMPONENT(DOOR_COMPONENT, door_component, NO_DRAW) -// COMPONENT(LUA_COMPONENT, lua_component, NO_DRAW) // Add new components definition here #undef COMPONENT diff --git a/src/components/lua_component.c b/src/components/lua_component.c index 367d4e5..c04666b 100644 --- a/src/components/lua_component.c +++ b/src/components/lua_component.c @@ -1,6 +1,51 @@ -#ifndef LUA_COMPONENT_H -#define LUA_COMPONENT_H +#include "lua_component.h" +#include +#include +#include +#include "game.h" +#include "ecs.h" +#include "memory_alloc.h" +#include "errors.h" +inline int lua_component_init(component_t *component) +{ + lua_component_data_t *component_data = component->data; -#endif // LUA_COMPONENT_H \ No newline at end of file + component_data->lua_state = luaL_newstate(); + + luaL_openlibs(component_data->lua_state); + + luaL_dostring(component_data->lua_state, "function f (a) print(a) end"); + + return EXIT_SUCCESS; +} + +inline int lua_component_update(component_t *component __attribute__((unused))) +{ + lua_component_data_t *component_data = component->data; + + luaL_dostring(component_data->lua_state, "f(\"prout\")"); + + return EXIT_SUCCESS; +} + +#if DEBUG >= 2 +#include "display.h" + +inline int lua_component_draw(const component_t *component) +{ + return EXIT_SUCCESS; +} +#endif // DEBUG >= 2 + +inline int lua_component_destroy(component_t *component) +{ + lua_component_data_t *component_data = component->data; + + lua_close(component_data->lua_state); + + free(component_data); + + return EXIT_SUCCESS; +} diff --git a/src/components/lua_component.h b/src/components/lua_component.h index e69de29..bfd6051 100644 --- a/src/components/lua_component.h +++ b/src/components/lua_component.h @@ -0,0 +1,19 @@ +#ifndef LUA_COMPONENT_H +#define LUA_COMPONENT_H + +#include "ecs.h" +#include "lua.h" +#include "errors.h" + +typedef struct lua_component_data_t { + lua_State *lua_state; +} lua_component_data_t; + +int lua_component_init(component_t *component); +int lua_component_update(component_t *component); +#if DEBUG >= 2 +int lua_component_draw(const component_t *component); +#endif // DEBUG >= 2 +int lua_component_destroy(component_t *component); + +#endif // LUA_COMPONENT_H \ No newline at end of file diff --git a/src/game.c b/src/game.c index 5b6984f..60e2bcc 100644 --- a/src/game.c +++ b/src/game.c @@ -21,7 +21,7 @@ int game_init(void) entity_manager_init(); if(asset_manager_init()) return_failure_int; - asset_t *map_asset = asset_manager_load_asset("dungeon_room_1", ASSET_MAP); + asset_t *map_asset = asset_manager_load_asset("dungeon_entry", ASSET_MAP); if(!map_asset) return_failure_int; game.map = map_asset->data; @@ -119,6 +119,14 @@ int game_init(void) if(!entity_new_component(player_entity, PLAYER_SYSTEM)) return_failure_int; } + /* ======== Enemy ======== */ + { + entity_t *enemy_entity = entity_manager_new_entity(1); + if(!enemy_entity) return_failure_int; + + if(!entity_new_component(enemy_entity, LUA_COMPONENT)) return_failure_int; + } + game.is_running = true; return EXIT_SUCCESS; diff --git a/src/lua/enemy-system.lua b/src/lua/enemy_system.lua similarity index 100% rename from src/lua/enemy-system.lua rename to src/lua/enemy_system.lua