#include "classes.h" #include "grid_entity.h" #include "grid_entity_door.h" #include "grid_entity_pit.h" #include "grid_entity_poop.h" #include "grid_entity_pressure_plate.h" #include "grid_entity_rock.h" #include "grid_entity_spikes.h" #include "grid_entity_tnt.h" #include "lua_api.h" // Adds a To method casting a grid entity to a subclass, nil when it is not one. template static void grid_cast_add(lua_State* state, const char* name) { lua_method(state, name, [](GridEntity* grid) { return dynamic_cast(grid); }); } // Registers Lua's GridEntityDesc, a cell's saved state. GridEntity.Desc hands out a copy of the entity's. static void grid_entity_desc_register(lua_State* state) { lua_class_begin(state, "GridEntityDesc", LUA_CLASS_GRID_ENTITY_DESC); lua_field<&GridEntityDesc::_type>(state, "Type"); lua_field<&GridEntityDesc::_variant>(state, "Variant"); lua_field<&GridEntityDesc::_state>(state, "State"); lua_field<&GridEntityDesc::_spawnCount>(state, "SpawnCount"); lua_field<&GridEntityDesc::_spawnSeed>(state, "SpawnSeed"); lua_field<&GridEntityDesc::_varData>(state, "VarData"); lua_field<&GridEntityDesc::_initialized>(state, "Initialized"); lua_field<&GridEntityDesc::_variableSeed>(state, "VariableSeed"); lua_class_end(state); } // Registers Lua's GridEntity, the base of rocks, pits, doors and the other tiles of a room. static void grid_entity_base_register(lua_State* state) { lua_class_begin(state, "GridEntity", LUA_CLASS_GRID_ENTITY); lua_method(state, "GetType", [](GridEntity& grid) { return grid.type; }); lua_method(state, "GetVariant", [](GridEntity& grid) { return grid.variant; }); lua_method(state, "SetType", [](GridEntity& grid, GridEntityType type) { grid.type = type; }); lua_method(state, "SetVariant", [](GridEntity& grid, int variant) { grid.variant = variant; }); lua_method(state, "GetGridIndex", [](GridEntity& grid) { return grid.gridIndex; }); lua_method(state, "GetSprite", [](GridEntity& grid) -> ANM2& { return grid.sprite; }); lua_method(state, "GetRNG", [](GridEntity& grid) -> RNG& { return grid.rng; }); lua_method(state, "GetSaveState", [](GridEntity& grid) { return grid.desc_save(); }); lua_method(state, "Init", [](GridEntity& grid, uint32_t seed) { grid.Init(seed); }); lua_method(state, "Update", [](GridEntity& grid) { grid.Update(); }); lua_method(state, "Render", [](GridEntity& grid, Vector offset) { grid.Render(offset); }); lua_method(state, "PostInit", [](GridEntity& grid) { grid.PostInit(); }); lua_method(state, "Hurt", [](GridEntity& grid, int damage) { return grid.Hurt(damage, EntityRef()); }); lua_method(state, "HurtWithSource", [](GridEntity& grid, int damage, const EntityRef& source) { return grid.Hurt(damage, source); }); lua_method(state, "Destroy", [](GridEntity& grid, bool isImmediate) { return grid.Destroy(isImmediate, EntityRef()); }); lua_method(state, "DestroyWithSource", [](GridEntity& grid, bool isImmediate, const EntityRef& source) { return grid.Destroy(isImmediate, source); }); lua_property(state, "Position", [](GridEntity& grid) { return grid.Position(); }); lua_property(state, "Desc", [](GridEntity& grid) { return grid.desc_save(); }); lua_field<&GridEntity::state>(state, "State"); lua_field<&GridEntity::varData>(state, "VarData"); lua_field<&GridEntity::collisionClass>(state, "CollisionClass"); grid_cast_add(state, "ToDoor"); grid_cast_add(state, "ToPit"); grid_cast_add(state, "ToPoop"); grid_cast_add(state, "ToPressurePlate"); grid_cast_add(state, "ToRock"); grid_cast_add(state, "ToSpikes"); grid_cast_add(state, "ToTNT"); lua_class_end(state); } // Registers Lua's GridEntityDoor: the rooms it joins, its locks and its animations. static void grid_entity_door_register(lua_State* state) { lua_class_begin(state, "GridEntityDoor", LUA_CLASS_GRID_ENTITY_DOOR, LUA_CLASS_GRID_ENTITY); lua_method(state, "SetRoomTypes", [](GridEntity_Door& door, int current, int target) { door.SetRoomTypes(current, target); }); lua_method(state, "Open", [](GridEntity_Door& door) { door.Open(); }); lua_method(state, "Close", [](GridEntity_Door& door, bool isForce) { door.Close(isForce); }); lua_method(state, "Bar", [](GridEntity_Door& door) { door.Bar(); }); lua_method(state, "SpawnDust", [](GridEntity_Door& door) { door.SpawnDust(); }); lua_method(state, "CanBlowOpen", [](GridEntity_Door& door) { return door.CanBlowOpen(); }); lua_method(state, "TryBlowOpen", [](GridEntity_Door& door, bool isFromExplosion, Entity* source) { return door.TryBlowOpen(isFromExplosion, source); }); lua_method(state, "TryUnlock", [](GridEntity_Door& door, Entity_Player& player, bool isForce) { return door.TryUnlock(player, isForce); }); lua_method(state, "IsOpen", [](GridEntity_Door& door) { return door.IsOpen(); }); lua_method(state, "IsKeyFamiliarTarget", [](GridEntity_Door& door) { return door.IsKeyFamiliarTarget(); }); lua_method(state, "SetLocked", [](GridEntity_Door& door, bool isLocked) { door.SetLocked(isLocked); }); lua_method(state, "IsLocked", [](GridEntity_Door& door) { return door.IsLocked(); }); lua_method(state, "IsBusted", [](GridEntity_Door& door) { return door.isBusted; }); lua_method(state, "IsRoomType", [](GridEntity_Door& door, int roomType) { return door.IsRoomType(roomType); }); lua_method(state, "IsTargetRoomArcade", [](GridEntity_Door& door) { return door.IsTargetRoomArcade(); }); lua_method(state, "GetSpriteOffset", [](GridEntity_Door& door) -> Vector& { return door.sprite.offset; }); lua_field<&GridEntity_Door::slot>(state, "Slot"); lua_field<&GridEntity_Door::direction>(state, "Direction"); lua_field<&GridEntity_Door::currentRoomType>(state, "CurrentRoomType"); lua_field<&GridEntity_Door::targetRoomType>(state, "TargetRoomType"); lua_field<&GridEntity_Door::targetRoomIdx>(state, "TargetRoomIndex"); lua_field<&GridEntity_Door::previousState>(state, "PreviousState"); lua_field<&GridEntity_Door::previousVariant>(state, "PreviousVariant"); lua_field<&GridEntity_Door::isBusted>(state, "Busted"); lua_field<&GridEntity_Door::isExtraVisible>(state, "ExtraVisible"); lua_property(state, "ExtraSprite", [](GridEntity_Door& door) -> ANM2& { return door.extraSprite; }); lua_field<&GridEntity_Door::openAnimation>(state, "OpenAnimation"); lua_field<&GridEntity_Door::closeAnimation>(state, "CloseAnimation"); lua_field<&GridEntity_Door::lockedAnimation>(state, "LockedAnimation"); lua_field<&GridEntity_Door::openLockedAnimation>(state, "OpenLockedAnimation"); lua_class_end(state); } // Registers Lua's GridEntityPit, GridEntityPoop, GridEntityPressurePlate, GridEntityRock, GridEntitySpikes and // GridEntityTNT. static void grid_entity_kinds_register(lua_State* state) { lua_class_begin(state, "GridEntityPit", LUA_CLASS_GRID_ENTITY_PIT, LUA_CLASS_GRID_ENTITY); lua_method(state, "MakeBridge", [](GridEntity_Pit& pit, GridEntity* building) { pit.MakeBridge(dynamic_cast(building), 0); }); lua_method(state, "SetLadder", [](GridEntity_Pit& pit, bool isLadder) { pit.SetLadder(isLadder); }); lua_method(state, "UpdateCollision", [](GridEntity_Pit& pit) { pit.UpdateCollision(); }); lua_field<&GridEntity_Pit::hasLadder>(state, "HasLadder"); lua_class_end(state); lua_class_begin(state, "GridEntityPoop", LUA_CLASS_GRID_ENTITY_POOP, LUA_CLASS_GRID_ENTITY); lua_method(state, "RespawnRedPoop", [](GridEntity_Poop& poop) { poop.RespawnRedPoop(); }); lua_method(state, "ReduceSpawnRate", [](GridEntity_Poop& poop) { poop.varData = 1; }); lua_field<&GridEntity_Poop::reviveTimer>(state, "ReviveTimer"); lua_field<&GridEntity_Poop::stateAnimation>(state, "StateAnimation"); lua_field<&GridEntity_Poop::isUnderPlayer>(state, "UnderPlayer"); lua_class_end(state); lua_class_begin(state, "GridEntityPressurePlate", LUA_CLASS_GRID_ENTITY_PRESSURE_PLATE, LUA_CLASS_GRID_ENTITY); lua_method(state, "Reward", [](GridEntity_PressurePlate& plate) { plate.Reward(); }); lua_property(state, "TimerPlate", [](GridEntity_PressurePlate& plate) -> ANM2& { return plate.timerPlate; }); lua_field_get<&GridEntity_PressurePlate::nextGreedAnimation>(state, "NextGreedAnimation"); lua_property(state, "GreedModeRNG", [](GridEntity_PressurePlate& plate) -> RNG& { return plate.greedModeRNG; }); lua_class_end(state); lua_class_begin(state, "GridEntityRock", LUA_CLASS_GRID_ENTITY_ROCK, LUA_CLASS_GRID_ENTITY); lua_method(state, "GetRubbleAnim", [](GridEntity_Rock& rock) { return rock.rubbleAnim; }); lua_method(state, "SetBigRockFrame", [](GridEntity_Rock& rock, int frame) { rock.SetBigRockFrame(frame); }); lua_method(state, "GetBigRockFrame", [](GridEntity_Rock& rock) { return rock.GetBigRockFrame(); }); lua_method(state, "UpdateAnimFrame", [](GridEntity_Rock& rock) { rock.UpdateAnimFrame(); }); lua_field<&GridEntity_Rock::anim>(state, "Anim"); lua_field<&GridEntity_Rock::rubbleAnim>(state, "RubbleAnim"); lua_field<&GridEntity_Rock::fuseFrames>(state, "FrameCnt"); lua_class_end(state); lua_class_begin(state, "GridEntitySpikes", LUA_CLASS_GRID_ENTITY_SPIKES, LUA_CLASS_GRID_ENTITY); lua_field<&GridEntity_Spikes::timeout>(state, "Timeout"); lua_class_end(state); lua_class_begin(state, "GridEntityTNT", LUA_CLASS_GRID_ENTITY_TNT, LUA_CLASS_GRID_ENTITY); lua_field<&GridEntity_TNT::fuseFrames>(state, "FrameCnt"); lua_class_end(state); } // Registers the grid entity classes, the base before the kinds that name it as their parent. void lua_api_grid_entity_register(lua_State* state) { grid_entity_desc_register(state); grid_entity_base_register(state); grid_entity_door_register(state); grid_entity_kinds_register(state); }