Curation round 13: grid entities, more enemies, Caves, boss helpers and five bosses, chests and costumes, curses and alt stages, the Lua API

This commit is contained in:
shweet committed 2026-11-20 16:32:45 -05:00
1 parent f8ce24fc6c
commit 8ae02a8422
160 files changed
+16231 -1689

No files matched your search

+174
View File
@@ -0,0 +1,174 @@
#include "classes.h"
#include "entity_npc.h"
#include "entity_player.h"
#include "game.h"
#include "hud.h"
#include "item_pool.h"
#include "lua_api.h"
#include "manager.h"
#include "music_manager.h"
#include "seeds.h"
#include "sfx_manager.h"
// Registers Lua's Game: the run's level, room, players, pools, seeds and HUD, spawning, and its state flags and
// counters. Game is also the Level it derives from.
static void game_register(lua_State* state)
{
lua_class_begin(state, "Game", LUA_CLASS_GAME);
lua_method(state, "GetLevel", [](Game& game) -> Level& { return game; });
lua_method(state, "GetRoom", [](Game& game) { return game.room.get(); });
lua_method(state, "GetPlayer", [](Game& game, int index) { return game.GetPlayer(index); });
lua_method(state, "GetNumPlayers", [](Game& game) { return (int)game.playerManager.playerList.size(); });
lua_method(state, "GetNearestPlayer", [](Game&, Vector position) { return game_nearest_player(position); });
lua_method(state, "GetItemPool", [](Game& game) -> ItemPool& { return game.itemPool; });
lua_method(state, "GetHUD", [](Game& game) -> HUD& { return game.hud; });
lua_method(state, "GetSeeds", [](Game& game) -> Seeds& { return game.seedEffects; });
lua_method(state, "GetFrameCount", [](Game& game) { return game.frameCount; });
lua_method(state, "IsPaused", [](Game& game) { return game.IsPaused(); });
lua_method(state, "IsGreedMode", [](Game& game) { return game.IsGreedMode(); });
lua_method(state, "GetStateFlag", [](Game& game, GameStateFlag flag) { return game.GetStateFlag(flag); });
lua_method(state, "SetStateFlag", [](Game& game, int flag, bool isSet) {
game.gameStateFlags = isSet ? game.gameStateFlags | 1ull << flag : game.gameStateFlags & ~(1ull << flag);
});
lua_method(state, "ShakeScreen", [](Game&, int timeout) { game_shake_screen(timeout); });
lua_method(state, "Spawn", [](Game& game, int type, int variant, Vector position, Vector velocity, Entity* spawner,
int subType, uint32_t seed) {
return game.Spawn({position, velocity, spawner, subType, type, variant, seed});
});
lua_method(state, "GetVictoryLap", [](Game& game) { return game.victoryLap; });
lua_method(state, "GetDevilRoomDeals", [](Game& game) { return game.devilRoomDeals; });
lua_method(state, "GetLastDevilRoomStage", [](Game& game) { return game.lastDevilRoomStage; });
lua_method(state, "GetTreasureRoomVisitCount", [](Game& game) { return game.treasureRoomsVisited; });
lua_method(state, "GetStagesWithoutDamage", [](Game& game) { return game.stagesWithoutDamage; });
lua_method(state, "GetStagesWithoutHeartsPicked", [](Game& game) { return game.stagesWithoutHeartsPicked; });
lua_method(state, "GetDarknessModifier", [](Game& game) { return game.darknessModifier; });
lua_method(state, "GetScreenShakeCountdown", [](Game& game) { return game.screenShakeTimer; });
lua_field<&Game::challenge>(state, "Challenge");
lua_field<&Game::difficulty>(state, "Difficulty");
lua_field<&Game::timeCounter>(state, "TimeCounter");
lua_field<&Game::blueWombParTime>(state, "BlueWombParTime");
lua_field<&Game::bossRushParTime>(state, "BossRushParTime");
lua_field<&Game::screenShakeOffset>(state, "ScreenShakeOffset");
lua_class_end(state);
}
// Registers Lua's HUD, ItemPool and Seeds, the parts of a run Game hands out.
static void game_parts_register(lua_State* state)
{
lua_class_begin(state, "HUD", LUA_CLASS_HUD);
lua_method(state, "IsVisible", [](HUD& hud) { return hud.IsVisible(); });
lua_method(state, "SetVisible", [](HUD& hud, bool isShown) { hud.SetVisible(isShown); });
lua_method(state, "FlashChargeBar",
[](HUD& hud, Entity_Player* player, int slot) { hud.FlashChargeBar(player, slot); });
lua_method(state, "InvalidateActiveItem",
[](HUD& hud, Entity_Player* player, int slot) { hud.InvalidateActiveItem(player, slot); });
lua_method(state, "InvalidateCraftingItem",
[](HUD& hud, Entity_Player* player) { hud.InvalidateCraftingItem(player); });
lua_method(state, "ShowItemText", [](HUD& hud, Entity_Player* player, ItemConfig_Item* item) {
hud.ShowItemText(player, item);
});
lua_class_end(state);
lua_class_begin(state, "ItemPool", LUA_CLASS_ITEM_POOL);
lua_method(state, "GetCollectible",
[](ItemPool& pool, ItemPoolType poolType, uint32_t seed, uint32_t flags, int defaultItem,
int fallbackPool) { return pool.GetCollectible(poolType, seed, flags, defaultItem, fallbackPool); });
lua_method(state, "RemoveCollectible", [](ItemPool& pool, int collectible) {
return pool.RemoveCollectible(collectible, REMOVE_ANY, REMOVE_APPLY);
});
lua_method(state, "GetTrinket", [](ItemPool& pool, bool isPeek) {
return pool.GetTrinket(isPeek ? TRINKET_DRAW_PEEK : TRINKET_DRAW_TAKE);
});
lua_method(state, "RemoveTrinket", [](ItemPool& pool, int trinket) { return pool.RemoveTrinket(trinket); });
lua_method(state, "ResetTrinkets", [](ItemPool& pool) { pool.ResetTrinkets(); });
lua_method(state, "GetCard", [](ItemPool&, uint32_t seed, bool isPlaying, bool isRunes, bool isOnlyRunes) {
return ItemPool::GetCard(seed, isPlaying, isRunes, isOnlyRunes);
});
lua_method(state, "GetPill", [](ItemPool&, uint32_t seed) { return ItemPool::GetPill(seed); });
lua_method(state, "GetPillEffect",
[](ItemPool& pool, uint32_t color, Entity_Player* player) { return pool.GetPillEffect(color, player); });
lua_method(state, "IdentifyPill", [](ItemPool& pool, uint32_t color) { pool.IdentifyPill(color); });
lua_method(state, "IsPillIdentified", [](ItemPool& pool, uint32_t color) { return pool.IsPillIdentified(color); });
lua_method(state, "ForceAddPillEffect", [](ItemPool& pool, int effect) { return pool.ForceAddPillEffect(effect); });
lua_method(state, "GetLastPool", [](ItemPool& pool) { return pool.GetLastPool(); });
lua_method(state, "GetPoolForRoom",
[](ItemPool& pool, int roomType, uint32_t seed) { return pool.GetPoolForRoom(roomType, seed); });
lua_method(state, "AddRoomBlacklist", [](ItemPool& pool, int collectible) { pool.AddRoomBlacklist(collectible); });
lua_method(state, "ResetRoomBlacklist", [](ItemPool& pool) { pool.ResetRoomBlacklist(); });
lua_method(state, "AddBibleUpgrade",
[](ItemPool& pool, int add, int poolType) { pool.AddBibleUpgrade(add, poolType); });
lua_class_end(state);
lua_class_begin(state, "Seeds", LUA_CLASS_SEEDS);
lua_method(state, "GetStartSeed", [](Seeds& seeds) { return seeds.GetStartSeed(); });
lua_method(state, "IsCustomRun", [](Seeds& seeds) { return seeds.isCustomRun; });
lua_method(state, "GetStartSeedString", [](Seeds& seeds) { return seeds.GetStartSeedString(); });
lua_method(state, "GetNextSeed", [](Seeds& seeds) { return seeds.GetNextSeed(); });
lua_method(state, "GetStageSeed", [](Seeds& seeds, int stage) { return seeds.GetStageSeed(stage); });
lua_method(state, "GetPlayerInitSeed", [](Seeds& seeds) { return seeds.GetPlayerInitSeed(); });
lua_method(state, "HasSeedEffect", [](Seeds& seeds, uint32_t effect) { return seeds.HasSeedEffect(effect); });
lua_method(state, "AddSeedEffect", [](Seeds& seeds, int effect) { seeds.AddSeedEffect(effect); });
lua_method(state, "RemoveSeedEffect", [](Seeds& seeds, int effect) { seeds.RemoveSeedEffect(effect); });
lua_method(state, "CanAddSeedEffect", [](Seeds& seeds, uint32_t effect) { return seeds.CanAddSeedEffect(effect); });
lua_static(state, "Seed2String", [](uint32_t seed) { return Seeds::Seed2String(seed); });
lua_static(state, "String2Seed", [](std::string_view seed) { return Seeds::String2Seed(seed); });
lua_static(state, "IsStringValidSeed", [](std::string_view seed) { return Seeds::IsStringValidSeed(seed); });
lua_class_end(state);
}
// Registers Lua's SFXManager and MusicManager, the sound effects and music the scripts reach through the global
// functions of the same names.
static void sound_register(lua_State* state)
{
lua_class_begin(state, "SFXManager", LUA_CLASS_SFX_MANAGER);
lua_method(state, "Play", [](SFXManager& sfx, int sound, float volume, int frameDelay, bool isLooped, float pitch,
float pan) {
sfx.Play(sound, {volume, frameDelay, isLooped ? SOUND_LOOP : SOUND_ONCE, pitch, pan});
});
lua_method(state, "Stop", [](SFXManager& sfx, int sound) { sfx.Stop(sound); });
lua_method(state, "IsPlaying", [](SFXManager& sfx, int sound) { return sfx.IsPlaying(sound); });
lua_method(state, "Preload", [](SFXManager& sfx, int sound) { sfx.Preload(sound); });
lua_method(state, "AdjustVolume",
[](SFXManager& sfx, int sound, float volume) { sfx.AdjustVolume(sound, volume); });
lua_method(state, "AdjustPitch", [](SFXManager& sfx, int sound, float pitch) { sfx.AdjustPitch(sound, pitch); });
lua_method(state, "StopLoopingSounds", [](SFXManager& sfx) { sfx.StopLoopingSounds(); });
lua_method(state, "SetAmbientSound", [](SFXManager& sfx, int sound, float volume, float pitch) {
sfx.SetAmbientSound(sound, volume, pitch);
});
lua_method(state, "GetAmbientSoundVolume",
[](SFXManager& sfx, int sound) { return sfx.GetAmbientSoundVolume(sound); });
lua_class_end(state);
lua_class_begin(state, "MusicManager", LUA_CLASS_MUSIC_MANAGER);
lua_method(state, "Play", [](MusicManager& music, int track, float volume) { music.Play(track, volume); });
lua_method(state, "Fadein",
[](MusicManager& music, int track, float volume, float rate) { music.Fadein(track, volume, rate); });
lua_method(state, "Crossfade", [](MusicManager& music, int track, float rate) { music.Crossfade(track, rate); });
lua_method(state, "Fadeout", [](MusicManager& music, float rate) { music.Fadeout(rate); });
lua_method(state, "Queue", [](MusicManager& music, int track) { music.Queue(track); });
lua_method(state, "Pause", [](MusicManager& music) { music.Pause(); });
lua_method(state, "Resume", [](MusicManager& music) { music.Resume(); });
lua_method(state, "EnableLayer", [](MusicManager& music, int layer, bool isInstant) {
music.EnableLayer(layer, isInstant ? LAYER_INSTANT : LAYER_FADE);
});
lua_method(state, "DisableLayer", [](MusicManager& music, int layer) { music.DisableLayer(layer); });
lua_method(state, "IsLayerEnabled", [](MusicManager& music, int layer) { return music.IsLayerEnabled(layer); });
lua_method(state, "Enable", [](MusicManager& music) { music.Enable(); });
lua_method(state, "Disable", [](MusicManager& music) { music.Disable(); });
lua_method(state, "IsEnabled", [](MusicManager& music) { return music.IsEnabled(); });
lua_method(state, "PitchSlide", [](MusicManager& music, float pitch) { music.PitchSlide(pitch); });
lua_method(state, "ResetPitch", [](MusicManager& music) { music.ResetPitch(); });
lua_method(state, "VolumeSlide",
[](MusicManager& music, float volume, float rate) { music.VolumeSlide(volume, rate); });
lua_method(state, "UpdateVolume", [](MusicManager& music) { music.UpdateVolume(); });
lua_method(state, "GetCurrentMusicID", [](MusicManager& music) { return music.GetCurrentMusicID(); });
lua_method(state, "GetQueuedMusicID", [](MusicManager& music) { return music.GetQueuedMusicID(); });
lua_class_end(state);
}
void lua_api_game_register(lua_State* state)
{
game_register(state);
game_parts_register(state);
sound_register(state);
}