]> git.sesse.net Git - nageru/commitdiff
Add an enable_if() to Block, for convenience.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 16 Jun 2019 09:02:11 +0000 (11:02 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 16 Jun 2019 09:02:11 +0000 (11:02 +0200)
nageru/scene.cpp
nageru/scene.h
nageru/theme.cpp

index 6c3a0393b8e83d47c7ca6fd202c668f69bf4bf38..ccb3b1bf241c74c7c72ca1a1bcaac4c0f0c927ce 100644 (file)
@@ -531,6 +531,20 @@ int Block_enable(lua_State *L)
        return 0;
 }
 
+int Block_enable_if(lua_State *L)
+{
+       assert(lua_gettop(L) == 2);
+       Block *block = *(Block **)luaL_checkudata(L, 1, "Block");
+
+       if (block->alternatives.size() != 2 ||
+           block->alternatives[1]->effect_type != IDENTITY_EFFECT) {
+               luaL_error(L, "enable_if() called on something that wasn't added with add_optional_effect()");
+       }
+       bool enabled = checkbool(L, 2);
+       block->currently_chosen_alternative = enabled ? 0 : 1;
+       return 0;
+}
+
 int Block_disable(lua_State *L)
 {
        assert(lua_gettop(L) == 1);
index b659429fbd5a8ef9a1ef54ec55cdc3175924739a..7d83a27e13ed3af6842c3082f6172ff68d5be25e 100644 (file)
@@ -110,6 +110,7 @@ struct Block {
 int Block_display(lua_State* L);
 int Block_choose(lua_State* L);
 int Block_enable(lua_State *L);
+int Block_enable_if(lua_State *L);
 int Block_disable(lua_State *L);
 int Block_set_int(lua_State *L);
 int Block_set_float(lua_State *L);
index 53b7543cee3a9f5fe07b1d9c8dc441633fd5b171..d31a4b948f42384c3d554d6a8069ab54b0e5b5d6 100644 (file)
@@ -793,6 +793,7 @@ const luaL_Reg Block_funcs[] = {
        { "display", Block_display },
        { "choose", Block_choose },
        { "enable", Block_enable },
+       { "enable_if", Block_enable_if },
        { "disable", Block_disable },
        { "set_int", Block_set_int },
        { "set_float", Block_set_float },