]> git.sesse.net Git - nageru/blobdiff - nageru/scene.cpp
Make Block.choose() return the effect that was chosen.
[nageru] / nageru / scene.cpp
index a3d3c6a20f172496f58b1509b82c59eccb0050e8..090f95be917884a1044239bb4046fc4d6726d613 100644 (file)
@@ -366,16 +366,16 @@ Scene::get_chain(Theme *theme, lua_State *L, unsigned num, const InputState &inp
                if (!block->alternatives.empty()) {
                        EffectBlueprint *blueprint = block->alternatives[block->currently_chosen_alternative];
                        for (const auto &key_and_tuple : blueprint->int_parameters) {
-                               int_to_set.emplace(make_pair(effect, key_and_tuple.first), key_and_tuple.second);
+                               int_to_set[make_pair(effect, key_and_tuple.first)] = key_and_tuple.second;
                        }
                        for (const auto &key_and_tuple : blueprint->float_parameters) {
-                               float_to_set.emplace(make_pair(effect, key_and_tuple.first), key_and_tuple.second);
+                               float_to_set[make_pair(effect, key_and_tuple.first)] = key_and_tuple.second;
                        }
                        for (const auto &key_and_tuple : blueprint->vec3_parameters) {
-                               vec3_to_set.emplace(make_pair(effect, key_and_tuple.first), key_and_tuple.second);
+                               vec3_to_set[make_pair(effect, key_and_tuple.first)] = key_and_tuple.second;
                        }
                        for (const auto &key_and_tuple : blueprint->vec4_parameters) {
-                               vec4_to_set.emplace(make_pair(effect, key_and_tuple.first), key_and_tuple.second);
+                               vec4_to_set[make_pair(effect, key_and_tuple.first)] = key_and_tuple.second;
                        }
                }
        }
@@ -491,7 +491,7 @@ int Block_display(lua_State* L)
        return 0;
 }
 
-int Block_choose_alternative(lua_State* L)
+int Block_choose(lua_State* L)
 {
        assert(lua_gettop(L) == 2);
        Block *block = *(Block **)luaL_checkudata(L, 1, "Block");
@@ -499,7 +499,7 @@ int Block_choose_alternative(lua_State* L)
        if (lua_isnumber(L, 2)) {
                alternative_idx = luaL_checknumber(L, 2);
        } else if (lua_istable(L, 2)) {
-               // See if it's an Effect metatable (e.g. foo:choose_alternative(ResampleEffect))
+               // See if it's an Effect metatable (e.g. foo:choose(ResampleEffect))
                lua_getfield(L, 2, "__effect_type_id");
                if (lua_isnumber(L, -1)) {
                        EffectType effect_type = EffectType(luaL_checknumber(L, -1));
@@ -509,14 +509,14 @@ int Block_choose_alternative(lua_State* L)
        }
 
        if (alternative_idx == -1) {
-               luaL_error(L, "choose_alternative() called with something that was not an index or an effect type (e.g. ResampleEffect) that was part of the alternatives");
+               luaL_error(L, "choose() called with something that was not an index or an effect type (e.g. ResampleEffect) that was part of the alternatives");
        }
 
        assert(alternative_idx >= 0);
        assert(size_t(alternative_idx) < block->alternatives.size());
        block->currently_chosen_alternative = alternative_idx;
 
-       return 0;
+       return wrap_lua_existing_object_nonowned<EffectBlueprint>(L, "EffectBlueprint", block->alternatives[alternative_idx]);
 }
 
 int Block_enable(lua_State *L)
@@ -537,11 +537,10 @@ int Block_disable(lua_State *L)
        assert(lua_gettop(L) == 1);
        Block *block = *(Block **)luaL_checkudata(L, 1, "Block");
 
-       if (block->alternatives.size() != 2 ||
-           block->alternatives[1]->effect_type != IDENTITY_EFFECT) {
-               luaL_error(L, "disable() called on something that wasn't added with add_optional_effect()");
-       }
        block->currently_chosen_alternative = find_index_of(block, IDENTITY_EFFECT);
+       if (block->currently_chosen_alternative == -1) {
+               luaL_error(L, "disable() called on something that didn't have an IdentityEffect fallback (try add_optional_effect())");
+       }
        assert(block->currently_chosen_alternative != -1);
        return 0;
 }