@@ -81,6 +81,7 @@ void PenBlocks::registerBlocks(IEngine *engine)
8181 engine->addCompileFunction (this , " pen_penUp" , &compilePenUp);
8282 engine->addCompileFunction (this , " pen_setPenColorToColor" , &compileSetPenColorToColor);
8383 engine->addCompileFunction (this , " pen_changePenColorParamBy" , &compileChangePenColorParamBy);
84+ engine->addCompileFunction (this , " pen_setPenColorParamTo" , &compileSetPenColorParamTo);
8485}
8586
8687CompilerValue *PenBlocks::compileClear (Compiler *compiler)
@@ -141,29 +142,39 @@ CompilerValue *PenBlocks::compileSetPenColorToColor(Compiler *compiler)
141142 return nullptr ;
142143}
143144
144- CompilerValue * PenBlocks::compileChangePenColorParamBy (Compiler *compiler)
145+ void PenBlocks::compileSetOrChangePenColorParam (Compiler *compiler, bool change )
145146{
146147 Input *paramInput = compiler->input (" COLOR_PARAM" );
147148 CompilerValue *param = compiler->addInput (paramInput);
148149 CompilerValue *value = compiler->addInput (" VALUE" );
149- CompilerValue *change = compiler->addConstValue (true );
150+ CompilerValue *changeValue = compiler->addConstValue (change );
150151
151152 if (paramInput->pointsToDropdownMenu ()) {
152153 static const std::unordered_set<std::string> options = { " color" , " saturation" , " brightness" , " transparency" };
153154 std::string option = paramInput->selectedMenuItem ();
154155
155156 if (options.find (option) != options.cend ()) {
156157 std::string f = " pen_set_or_change_" + option;
157- compiler->addTargetFunctionCall (f, Compiler::StaticType::Void, { Compiler::StaticType::Number, Compiler::StaticType::Bool }, { value, change });
158+ compiler->addTargetFunctionCall (f, Compiler::StaticType::Void, { Compiler::StaticType::Number, Compiler::StaticType::Bool }, { value, changeValue });
158159 }
159160 } else {
160161 compiler->addTargetFunctionCall (
161162 " pen_set_or_change_color_param" ,
162163 Compiler::StaticType::Void,
163164 { Compiler::StaticType::String, Compiler::StaticType::Number, Compiler::StaticType::Bool },
164- { param, value, change });
165+ { param, value, changeValue });
165166 }
167+ }
168+
169+ CompilerValue *PenBlocks::compileChangePenColorParamBy (Compiler *compiler)
170+ {
171+ compileSetOrChangePenColorParam (compiler, true );
172+ return nullptr ;
173+ }
166174
175+ CompilerValue *PenBlocks::compileSetPenColorParamTo (Compiler *compiler)
176+ {
177+ compileSetOrChangePenColorParam (compiler, false );
167178 return nullptr ;
168179}
169180
0 commit comments