Skip to content

Commit

Permalink
Add color() method to extensions
Browse files Browse the repository at this point in the history
Resolves: #582
  • Loading branch information
adazem009 committed Jan 26, 2025
1 parent 2ed0bf3 commit e601288
Show file tree
Hide file tree
Showing 34 changed files with 101 additions and 3 deletions.
7 changes: 4 additions & 3 deletions include/scratchcpp/iextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

#pragma once

#include <string>

#include "global.h"
#include "value_functions.h"

namespace libscratchcpp
{
Expand All @@ -27,6 +25,9 @@ class LIBSCRATCHCPP_EXPORT IExtension
/*! Returns the description of the extension. */
virtual std::string description() const = 0;

/*! Returns the block color of the extension. */
virtual Rgb color() const = 0;

/*! Override this method to register blocks. */
virtual void registerBlocks(IEngine *engine) = 0;

Expand Down
5 changes: 5 additions & 0 deletions src/blocks/controlblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ std::string ControlBlocks::description() const
return name() + " blocks";
}

Rgb ControlBlocks::color() const
{
return rgb(255, 171, 25);
}

void ControlBlocks::registerBlocks(IEngine *engine)
{
engine->addCompileFunction(this, "control_forever", &compileForever);
Expand Down
1 change: 1 addition & 0 deletions src/blocks/controlblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ControlBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;

Expand Down
5 changes: 5 additions & 0 deletions src/blocks/customblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ std::string CustomBlocks::description() const
return name();
}

Rgb CustomBlocks::color() const
{
return rgb(255, 102, 128);
}

void CustomBlocks::registerBlocks(IEngine *engine)
{
engine->addCompileFunction(this, "procedures_definition", [](Compiler *) -> CompilerValue * { return nullptr; });
Expand Down
1 change: 1 addition & 0 deletions src/blocks/customblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CustomBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;

Expand Down
5 changes: 5 additions & 0 deletions src/blocks/eventblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ std::string libscratchcpp::EventBlocks::description() const
return "Event blocks";
}

Rgb EventBlocks::color() const
{
return rgb(255, 191, 0);
}

void EventBlocks::registerBlocks(IEngine *engine)
{
engine->addCompileFunction(this, "event_whentouchingobject", &compileWhenTouchingObject);
Expand Down
1 change: 1 addition & 0 deletions src/blocks/eventblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class EventBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;

Expand Down
5 changes: 5 additions & 0 deletions src/blocks/listblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ std::string ListBlocks::description() const
return "List blocks";
}

Rgb ListBlocks::color() const
{
return rgb(255, 102, 26);
}

void ListBlocks::registerBlocks(IEngine *engine)
{
engine->addCompileFunction(this, "data_addtolist", &compileAddToList);
Expand Down
1 change: 1 addition & 0 deletions src/blocks/listblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ListBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;

Expand Down
5 changes: 5 additions & 0 deletions src/blocks/looksblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ std::string LooksBlocks::description() const
return name() + " blocks";
}

Rgb LooksBlocks::color() const
{
return rgb(153, 102, 255);
}

void LooksBlocks::registerBlocks(IEngine *engine)
{
}
1 change: 1 addition & 0 deletions src/blocks/looksblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LooksBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;
};
Expand Down
5 changes: 5 additions & 0 deletions src/blocks/motionblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ std::string MotionBlocks::description() const
return name() + " blocks";
}

Rgb MotionBlocks::color() const
{
return rgb(76, 151, 255);
}

void MotionBlocks::registerBlocks(IEngine *engine)
{
}
1 change: 1 addition & 0 deletions src/blocks/motionblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MotionBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;
};
Expand Down
5 changes: 5 additions & 0 deletions src/blocks/operatorblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ std::string OperatorBlocks::description() const
return "Operator blocks";
}

Rgb OperatorBlocks::color() const
{
return rgb(89, 192, 89);
}

void OperatorBlocks::registerBlocks(IEngine *engine)
{
engine->addCompileFunction(this, "operator_add", &compileAdd);
Expand Down
1 change: 1 addition & 0 deletions src/blocks/operatorblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class OperatorBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;

Expand Down
5 changes: 5 additions & 0 deletions src/blocks/sensingblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ std::string SensingBlocks::description() const
return name() + " blocks";
}

Rgb SensingBlocks::color() const
{
return rgb(92, 177, 214);
}

void SensingBlocks::registerBlocks(IEngine *engine)
{
}
1 change: 1 addition & 0 deletions src/blocks/sensingblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SensingBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;
};
Expand Down
5 changes: 5 additions & 0 deletions src/blocks/soundblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ std::string SoundBlocks::description() const
return name() + " blocks";
}

Rgb SoundBlocks::color() const
{
return rgb(207, 99, 207);
}

void SoundBlocks::registerBlocks(IEngine *engine)
{
}
1 change: 1 addition & 0 deletions src/blocks/soundblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SoundBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;
};
Expand Down
5 changes: 5 additions & 0 deletions src/blocks/variableblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ std::string VariableBlocks::description() const
return "Variable blocks";
}

Rgb VariableBlocks::color() const
{
return rgb(255, 140, 26);
}

void VariableBlocks::registerBlocks(IEngine *engine)
{
engine->addCompileFunction(this, "data_variable", &compileVariable);
Expand Down
1 change: 1 addition & 0 deletions src/blocks/variableblocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class VariableBlocks : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;

Expand Down
5 changes: 5 additions & 0 deletions test/extensions/testextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ std::string TestExtension::description() const
return "Test extension";
}

Rgb TestExtension::color() const
{
return rgb(0, 0, 0);
}

void TestExtension::registerBlocks(IEngine *engine)
{
engine->clear();
Expand Down
1 change: 1 addition & 0 deletions test/extensions/testextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TestExtension : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;
void onInit(IEngine *engine) override;
Expand Down
1 change: 1 addition & 0 deletions test/mocks/extensionmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class ExtensionMock : public IExtension
public:
MOCK_METHOD(std::string, name, (), (const, override));
MOCK_METHOD(std::string, description, (), (const, override));
MOCK_METHOD(Rgb, color, (), (const, override));

MOCK_METHOD(void, registerBlocks, (IEngine *), (override));
MOCK_METHOD(void, onInit, (IEngine *), (override));
Expand Down
5 changes: 5 additions & 0 deletions test/scratch_classes/testextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ std::string TestExtension::description() const
return "";
}

Rgb TestExtension::color() const
{
return rgb(0, 0, 0);
}

void TestExtension::registerBlocks(IEngine *engine)
{
}
1 change: 1 addition & 0 deletions test/scratch_classes/testextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TestExtension : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;
};
Expand Down
5 changes: 5 additions & 0 deletions test/scratchconfiguration/extension1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ std::string Extension1::name() const
{
return "ext 1";
}

Rgb Extension1::color() const
{
return rgb(0, 0, 0);
}
1 change: 1 addition & 0 deletions test/scratchconfiguration/extension1.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Extension1 : public ExtensionBase
{
public:
std::string name() const override;
Rgb color() const override;
};

} // namespace libscratchcpp
5 changes: 5 additions & 0 deletions test/scratchconfiguration/extension2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ std::string Extension2::name() const
{
return "ext 2";
}

Rgb Extension2::color() const
{
return rgb(0, 0, 0);
}
1 change: 1 addition & 0 deletions test/scratchconfiguration/extension2.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Extension2 : public ExtensionBase
{
public:
std::string name() const override;
Rgb color() const override;
};

} // namespace libscratchcpp
5 changes: 5 additions & 0 deletions test/scratchconfiguration/extension3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ std::string Extension3::name() const
{
return "ext 3";
}

Rgb Extension3::color() const
{
return rgb(0, 0, 0);
}
1 change: 1 addition & 0 deletions test/scratchconfiguration/extension3.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Extension3 : public ExtensionBase
{
public:
std::string name() const override;
Rgb color() const override;
};

} // namespace libscratchcpp
5 changes: 5 additions & 0 deletions test/test_api/testextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ std::string TestExtension::description() const
return "";
}

Rgb TestExtension::color() const
{
return rgb(0, 0, 0);
}

void TestExtension::registerBlocks(IEngine *engine)
{
engine->addCompileFunction(this, "test_simple", &compileSimple);
Expand Down
1 change: 1 addition & 0 deletions test/test_api/testextension.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TestExtension : public IExtension
public:
std::string name() const override;
std::string description() const override;
Rgb color() const override;

void registerBlocks(IEngine *engine) override;

Expand Down

0 comments on commit e601288

Please sign in to comment.