Skip to content

Commit 9da34e4

Browse files
committed
Optimize constant param names in change color param block
1 parent 7baf07a commit 9da34e4

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/blocks/penblocks.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <scratchcpp/iengine.h>
22
#include <scratchcpp/compiler.h>
3+
#include <scratchcpp/input.h>
34
#include <scratchcpp/executioncontext.h>
45
#include <scratchcpp/target.h>
56
#include <scratchcpp/ispritehandler.h>
@@ -142,15 +143,26 @@ CompilerValue *PenBlocks::compileSetPenColorToColor(Compiler *compiler)
142143

143144
CompilerValue *PenBlocks::compileChangePenColorParamBy(Compiler *compiler)
144145
{
145-
CompilerValue *param = compiler->addInput("COLOR_PARAM");
146+
Input *paramInput = compiler->input("COLOR_PARAM");
147+
CompilerValue *param = compiler->addInput(paramInput);
146148
CompilerValue *value = compiler->addInput("VALUE");
147149
CompilerValue *change = compiler->addConstValue(true);
148150

149-
compiler->addTargetFunctionCall(
150-
"pen_set_or_change_color_param",
151-
Compiler::StaticType::Void,
152-
{ Compiler::StaticType::String, Compiler::StaticType::Number, Compiler::StaticType::Bool },
153-
{ param, value, change });
151+
if (paramInput->pointsToDropdownMenu()) {
152+
static const std::unordered_set<std::string> options = { "color", "saturation", "brightness", "transparency" };
153+
std::string option = paramInput->selectedMenuItem();
154+
155+
if (options.find(option) != options.cend()) {
156+
std::string f = "pen_set_or_change_" + option;
157+
compiler->addTargetFunctionCall(f, Compiler::StaticType::Void, { Compiler::StaticType::Number, Compiler::StaticType::Bool }, { value, change });
158+
}
159+
} else {
160+
compiler->addTargetFunctionCall(
161+
"pen_set_or_change_color_param",
162+
Compiler::StaticType::Void,
163+
{ Compiler::StaticType::String, Compiler::StaticType::Number, Compiler::StaticType::Bool },
164+
{ param, value, change });
165+
}
154166

155167
return nullptr;
156168
}

0 commit comments

Comments
 (0)