Declare capabilities.

This commit is contained in:
Davy Hélard
2023-06-13 11:16:28 +02:00
parent b305acddba
commit 3cfd831d45
26 changed files with 229 additions and 63 deletions

View File

@@ -323,11 +323,8 @@ gd::String EventsCodeGenerator::GenerateConditionCode(
const ObjectMetadata& objInfo =
MetadataProvider::GetObjectMetadata(platform, objectType);
if (objInfo.IsUnsupportedBaseObjectCapability(
if (objInfo.IsSupportedBaseObjectCapability(
instrInfos.GetRequiredBaseObjectCapability())) {
conditionCode +=
"/* Object with unsupported capability - skipped. */\n";
} else {
AddIncludeFiles(objInfo.includeFiles);
context.SetCurrentObject(realObjects[i]);
context.ObjectsListNeeded(realObjects[i]);
@@ -344,6 +341,9 @@ gd::String EventsCodeGenerator::GenerateConditionCode(
context);
context.SetNoCurrentObject();
} else {
conditionCode +=
"/* Object with unsupported capability - skipped. */\n";
}
}
}
@@ -515,10 +515,8 @@ gd::String EventsCodeGenerator::GenerateActionCode(
const ObjectMetadata& objInfo =
MetadataProvider::GetObjectMetadata(platform, objectType);
if (objInfo.IsUnsupportedBaseObjectCapability(
if (objInfo.IsSupportedBaseObjectCapability(
instrInfos.GetRequiredBaseObjectCapability())) {
actionCode += "/* Object with unsupported capability - skipped. */\n";
} else {
AddIncludeFiles(objInfo.includeFiles);
context.SetCurrentObject(realObjects[i]);
context.ObjectsListNeeded(realObjects[i]);
@@ -535,6 +533,8 @@ gd::String EventsCodeGenerator::GenerateActionCode(
optionalAsyncCallbackName);
context.SetNoCurrentObject();
} else {
actionCode += "/* Object with unsupported capability - skipped. */\n";
}
}
}

View File

@@ -270,11 +270,8 @@ gd::String ExpressionCodeGenerator::GenerateObjectFunctionCode(
const ObjectMetadata& objInfo = MetadataProvider::GetObjectMetadata(
codeGenerator.GetPlatform(), objectType);
if (objInfo.IsUnsupportedBaseObjectCapability(
if (objInfo.IsSupportedBaseObjectCapability(
expressionMetadata.GetRequiredBaseObjectCapability())) {
// Do nothing, skipping objects not supporting the capability required by
// this expression.
} else {
codeGenerator.AddIncludeFiles(objInfo.includeFiles);
functionOutput = codeGenerator.GenerateObjectFunctionCall(
realObjects[i],
@@ -283,6 +280,9 @@ gd::String ExpressionCodeGenerator::GenerateObjectFunctionCode(
parametersCode,
functionOutput,
context);
} else {
// Do nothing, skipping objects not supporting the capability required by
// this expression.
}
}

View File

@@ -1672,6 +1672,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
.AddParameter("object", _("Object"), "Object")
.UseStandardParameters("number",
gd::ParameterOptions::MakeNewOptions())
.SetRequiresBaseObjectCapability("resizable")
.MarkAsAdvanced();
// The expression is standard.
@@ -1687,6 +1688,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
.AddParameter("object", _("Object"), "Object")
.UseStandardParameters("number",
gd::ParameterOptions::MakeNewOptions())
.SetRequiresBaseObjectCapability("resizable")
.MarkAsAdvanced();
obj.AddAction("SetSize",
@@ -1699,6 +1701,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
.AddParameter("object", _("Object"))
.AddParameter("expression", _("Width"))
.AddParameter("expression", _("Height"))
.SetRequiresBaseObjectCapability("resizable")
.MarkAsAdvanced();
}
// Instruction for Scalable capability.
@@ -1716,6 +1719,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
"number",
gd::ParameterOptions::MakeNewOptions().SetDescription(
_("Scale (1 by default)")))
.SetRequiresBaseObjectCapability("scalable")
.MarkAsAdvanced();
obj.AddExpressionAndConditionAndAction(
@@ -1731,6 +1735,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
"number",
gd::ParameterOptions::MakeNewOptions().SetDescription(
_("Scale (1 by default)")))
.SetRequiresBaseObjectCapability("scalable")
.MarkAsAdvanced();
obj.AddExpressionAndConditionAndAction(
@@ -1746,8 +1751,57 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
"number",
gd::ParameterOptions::MakeNewOptions().SetDescription(
_("Scale (1 by default)")))
.SetRequiresBaseObjectCapability("scalable")
.MarkAsAdvanced();
}
// Instruction for Flippable capability.
{
obj.AddAction("FlipX",
_("Flip the object horizontally"),
_("Flip the object horizontally"),
_("Flip horizontally _PARAM0_: _PARAM1_"),
_("Effects"),
"res/actions/flipX24.png",
"res/actions/flipX.png")
.AddParameter("object", _("Object"), "Object")
.AddParameter("yesorno", _("Activate flipping"))
.SetRequiresBaseObjectCapability("flippable")
.MarkAsSimple();
obj.AddAction("FlipY",
_("Flip the object vertically"),
_("Flip the object vertically"),
_("Flip vertically _PARAM0_: _PARAM1_"),
_("Effects"),
"res/actions/flipY24.png",
"res/actions/flipY.png")
.AddParameter("object", _("Object"), "Object")
.AddParameter("yesorno", _("Activate flipping"))
.SetRequiresBaseObjectCapability("flippable")
.MarkAsSimple();
obj.AddCondition("FlippedX",
_("Horizontally flipped"),
_("Check if the object is horizontally flipped"),
_("_PARAM0_ is horizontally flipped"),
_("Effects"),
"res/actions/flipX24.png",
"res/actions/flipX.png")
.AddParameter("object", _("Object"), "Object")
.SetRequiresBaseObjectCapability("flippable");
obj.AddCondition("FlippedY",
_("Vertically flipped"),
_("Check if the object is vertically flipped"),
_("_PARAM0_ is vertically flipped"),
_("Effects"),
"res/actions/flipY24.png",
"res/actions/flipY.png")
.AddParameter("object", _("Object"), "Object")
.SetRequiresBaseObjectCapability("flippable");
}
}
} // namespace gd

View File

@@ -32,7 +32,10 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(
_("Animated object which can be used for "
"most elements of a game"),
"CppPlatform/Extensions/spriteicon.png")
.SetCategoryFullName(_("General"));
.SetCategoryFullName(_("General"))
.MarkBaseObjectCapabilityAsSupported("resizable")
.MarkBaseObjectCapabilityAsSupported("scalable")
.MarkBaseObjectCapabilityAsSupported("flippable");
obj.AddAction("Opacity",
_("Sprite opacity"),
@@ -472,9 +475,9 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(
_("Effects"),
"res/actions/flipX24.png",
"res/actions/flipX.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("yesorno", _("Activate flipping"))
.SetHidden()
.MarkAsSimple();
obj.AddAction("FlipY",
@@ -484,9 +487,9 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(
_("Effects"),
"res/actions/flipY24.png",
"res/actions/flipY.png")
.AddParameter("object", _("Object"), "Sprite")
.AddParameter("yesorno", _("Activate flipping"))
.SetHidden()
.MarkAsSimple();
obj.AddCondition("FlippedX",
@@ -496,8 +499,8 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(
_("Effects"),
"res/actions/flipX24.png",
"res/actions/flipX.png")
.AddParameter("object", _("Object"), "Sprite");
.AddParameter("object", _("Object"), "Sprite")
.SetHidden();
obj.AddCondition("FlippedY",
_("Vertically flipped"),
@@ -506,8 +509,8 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(
_("Effects"),
"res/actions/flipY24.png",
"res/actions/flipY.png")
.AddParameter("object", _("Object"), "Sprite");
.AddParameter("object", _("Object"), "Sprite")
.SetHidden();
obj.AddAction("TourneVers",
"Rotate an object toward another",

View File

@@ -39,6 +39,7 @@ ObjectMetadata::ObjectMetadata(const gd::String& extensionNamespace_,
return blueprintObject_->Clone();
}) {
blueprintObject = blueprintObject_;
supportedBaseObjectCapabilities.insert("effect");
}
ObjectMetadata::ObjectMetadata(const gd::String& extensionNamespace_,
@@ -56,7 +57,9 @@ ObjectMetadata::ObjectMetadata(const gd::String& extensionNamespace_,
"Error: Event-based objects don't have blueprint. "
"This method should not never be called.");
return nullptr;
}) {}
}) {
supportedBaseObjectCapabilities.insert("effect");
}
ObjectMetadata::ObjectMetadata(const gd::String& extensionNamespace_,
const gd::String& name_,
@@ -70,6 +73,7 @@ ObjectMetadata::ObjectMetadata(const gd::String& extensionNamespace_,
extensionNamespace(extensionNamespace_) {
SetFullName(gd::String(fullname_));
SetDescription(gd::String(description_));
supportedBaseObjectCapabilities.insert("effect");
}
gd::InstructionMetadata& ObjectMetadata::AddCondition(

View File

@@ -225,29 +225,41 @@ class GD_CORE_API ObjectMetadata : public InstructionOrExpressionContainerMetada
/**
* \brief The "capabilities" that are offered by the base object that are
* *not* supported by this object, and should be hidden in the editor
* supported by this object, and should *not* be hidden in the editor
* interface.
*/
const std::set<gd::String>& GetUnsupportedBaseObjectCapabilities() const {
return unsupportedBaseObjectCapabilities;
const std::set<gd::String>& GetSupportedBaseObjectCapabilities() const {
return supportedBaseObjectCapabilities;
}
/**
* \brief Add a "capability" that is offered by the base object that is *not*
* supported by this object, and should be hidden in the editor interface.
* \brief Add a "capability" that is offered by the base object that is
* supported by this object, and should *not* be hidden in the editor interface.
*/
ObjectMetadata& AddUnsupportedBaseObjectCapability(
ObjectMetadata& MarkBaseObjectCapabilityAsSupported(
const gd::String& capability) {
unsupportedBaseObjectCapabilities.insert(capability);
supportedBaseObjectCapabilities.insert(capability);
return *this;
}
/**
* \brief Check if a "capability" that is offered by the base object is *not*
* \brief Remove a "capability" that is offered by the base object that is *not*
* supported by this object, and should be hidden in the editor interface.
*/
bool IsUnsupportedBaseObjectCapability(const gd::String& capability) const {
return unsupportedBaseObjectCapabilities.find(capability) != unsupportedBaseObjectCapabilities.end();
ObjectMetadata& MarkBaseObjectCapabilityAsUnsupported(
const gd::String& capability) {
supportedBaseObjectCapabilities.erase(capability);
return *this;
}
/**
* \brief Check if a "capability" that is offered by the base object is
* supported by this object, and should *not* be hidden in the editor interface.
*/
bool IsSupportedBaseObjectCapability(const gd::String& capability) const {
return capability.empty() ||
supportedBaseObjectCapabilities.find(capability) !=
supportedBaseObjectCapabilities.end();
}
const gd::String& GetName() const override { return name; }
@@ -331,7 +343,7 @@ class GD_CORE_API ObjectMetadata : public InstructionOrExpressionContainerMetada
gd::String description;
gd::String iconFilename;
gd::String categoryFullName;
std::set<gd::String> unsupportedBaseObjectCapabilities;
std::set<gd::String> supportedBaseObjectCapabilities;
bool hidden = false;
std::shared_ptr<gd::ObjectConfiguration>

View File

@@ -105,7 +105,7 @@ ExpressionValidator::Type ExpressionValidator::ValidateFunction(const gd::Functi
const gd::ObjectMetadata &objectMetadata =
MetadataProvider::GetObjectMetadata(platform, objectType);
if (objectMetadata.IsUnsupportedBaseObjectCapability(
if (!objectMetadata.IsSupportedBaseObjectCapability(
metadata.GetRequiredBaseObjectCapability())) {
RaiseTypeError(
_("This expression exists, but it can't be used on this object."),

View File

@@ -403,7 +403,8 @@ void SetupProjectWithDummyPlatform(gd::Project& project,
"FakeObjectWithUnsupportedCapability",
"This is FakeObjectWithUnsupportedCapability",
"")
.AddUnsupportedBaseObjectCapability("effect");
.MarkBaseObjectCapabilityAsUnsupported("effect")
.MarkBaseObjectCapabilityAsSupported("resizable");
}
// Actions and expressions with several parameter types.

View File

@@ -48,7 +48,10 @@ module.exports = {
new gd.Model3DObjectConfiguration()
)
.setCategoryFullName(_('3D'))
.addUnsupportedBaseObjectCapability('effect')
.markBaseObjectCapabilityAsUnsupported('effect')
.markBaseObjectCapabilityAsSupported('resizable')
.markBaseObjectCapabilityAsSupported('scalable')
.markBaseObjectCapabilityAsSupported('flippable')
.setIncludeFile('Extensions/3D/A_RuntimeObject3D.js')
.addIncludeFile('Extensions/3D/A_RuntimeObject3DRenderer.js')
.addIncludeFile('Extensions/3D/Model3DRuntimeObject.js')
@@ -85,6 +88,7 @@ module.exports = {
.setFunctionName('setDepth')
.setGetter('getDepth');
// Deprecated
object
.addScopedAction(
'SetWidth',
@@ -100,10 +104,12 @@ module.exports = {
'number',
gd.ParameterOptions.makeNewOptions()
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setWidth')
.setGetter('getWidth');
// Deprecated
object
.addScopedCondition(
'Width',
@@ -119,9 +125,11 @@ module.exports = {
'number',
gd.ParameterOptions.makeNewOptions()
)
.setHidden()
.markAsAdvanced()
.setFunctionName('getWidth');
// Deprecated
object
.addScopedAction(
'SetHeight',
@@ -137,10 +145,12 @@ module.exports = {
'number',
gd.ParameterOptions.makeNewOptions()
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setHeight')
.setGetter('getHeight');
// Deprecated
object
.addScopedCondition(
'Height',
@@ -156,9 +166,11 @@ module.exports = {
'number',
gd.ParameterOptions.makeNewOptions()
)
.setHidden()
.markAsAdvanced()
.setFunctionName('getHeight');
// Deprecated
object
.addExpressionAndConditionAndAction(
'number',
@@ -171,9 +183,11 @@ module.exports = {
)
.addParameter('object', _('3D model'), 'Model3DObject', false)
.useStandardParameters('number', gd.ParameterOptions.makeNewOptions())
.setHidden()
.setFunctionName('setHeight')
.setGetter('getHeight');
// Deprecated
object
.addScopedAction(
'Scale',
@@ -191,10 +205,12 @@ module.exports = {
_('Scale (1 by default)')
)
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setScale')
.setGetter('getScale');
// Deprecated
object
.addExpressionAndConditionAndAction(
'number',
@@ -212,10 +228,12 @@ module.exports = {
_('Scale (1 by default)')
)
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setScaleX')
.setGetter('getScaleX');
// Deprecated
object
.addExpressionAndConditionAndAction(
'number',
@@ -233,6 +251,7 @@ module.exports = {
_('Scale (1 by default)')
)
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setScaleY')
.setGetter('getScaleY');
@@ -258,6 +277,7 @@ module.exports = {
.setFunctionName('setScaleZ')
.setGetter('getScaleZ');
// Deprecated
object
.addScopedAction(
'FlipX',
@@ -270,9 +290,11 @@ module.exports = {
)
.addParameter('object', _('3D model'), 'Model3DObject')
.addParameter('yesorno', _('Activate flipping'))
.setHidden()
.markAsSimple()
.setFunctionName('flipX');
// Deprecated
object
.addScopedAction(
'FlipY',
@@ -285,6 +307,7 @@ module.exports = {
)
.addParameter('object', _('3D model'), 'Model3DObject')
.addParameter('yesorno', _('Activate flipping'))
.setHidden()
.markAsSimple()
.setFunctionName('flipY');
@@ -303,6 +326,7 @@ module.exports = {
.markAsSimple()
.setFunctionName('flipZ');
// Deprecated
object
.addScopedCondition(
'FlippedX',
@@ -314,8 +338,10 @@ module.exports = {
'res/actions/flipX.png'
)
.addParameter('object', _('3D model'), 'Model3DObject')
.setHidden()
.setFunctionName('isFlippedX');
// Deprecated
object
.addScopedCondition(
'FlippedY',
@@ -327,6 +353,7 @@ module.exports = {
'res/actions/flipY.png'
)
.addParameter('object', _('3D model'), 'Model3DObject')
.setHidden()
.setFunctionName('isFlippedY');
object
@@ -864,7 +891,10 @@ module.exports = {
Cube3DObject
)
.setCategoryFullName(_('3D'))
.addUnsupportedBaseObjectCapability('effect')
.markBaseObjectCapabilityAsUnsupported('effect')
.markBaseObjectCapabilityAsSupported('resizable')
.markBaseObjectCapabilityAsSupported('scalable')
.markBaseObjectCapabilityAsSupported('flippable')
.setIncludeFile('Extensions/3D/A_RuntimeObject3D.js')
.addIncludeFile('Extensions/3D/A_RuntimeObject3DRenderer.js')
.addIncludeFile('Extensions/3D/Cube3DRuntimeObject.js')
@@ -901,6 +931,7 @@ module.exports = {
.setFunctionName('setDepth')
.setGetter('getDepth');
// Deprecated
object
.addScopedAction(
'SetWidth',
@@ -916,10 +947,12 @@ module.exports = {
'number',
gd.ParameterOptions.makeNewOptions()
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setWidth')
.setGetter('getWidth');
// Deprecated
object
.addScopedCondition(
'Width',
@@ -935,9 +968,11 @@ module.exports = {
'number',
gd.ParameterOptions.makeNewOptions()
)
.setHidden()
.markAsAdvanced()
.setFunctionName('getWidth');
// Deprecated
object
.addScopedAction(
'SetHeight',
@@ -953,10 +988,12 @@ module.exports = {
'number',
gd.ParameterOptions.makeNewOptions()
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setHeight')
.setGetter('getHeight');
// Deprecated
object
.addScopedCondition(
'Height',
@@ -972,9 +1009,11 @@ module.exports = {
'number',
gd.ParameterOptions.makeNewOptions()
)
.setHidden()
.markAsAdvanced()
.setFunctionName('getHeight');
// Deprecated
object
.addScopedAction(
'Scale',
@@ -992,10 +1031,12 @@ module.exports = {
_('Scale (1 by default)')
)
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setScale')
.setGetter('getScale');
// Deprecated
object
.addExpressionAndConditionAndAction(
'number',
@@ -1013,10 +1054,12 @@ module.exports = {
_('Scale (1 by default)')
)
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setScaleX')
.setGetter('getScaleX');
// Deprecated
object
.addExpressionAndConditionAndAction(
'number',
@@ -1034,6 +1077,7 @@ module.exports = {
_('Scale (1 by default)')
)
)
.setHidden()
.markAsAdvanced()
.setFunctionName('setScaleY')
.setGetter('getScaleY');
@@ -1059,6 +1103,7 @@ module.exports = {
.setFunctionName('setScaleZ')
.setGetter('getScaleZ');
// Deprecated
object
.addScopedAction(
'FlipX',
@@ -1072,8 +1117,10 @@ module.exports = {
.addParameter('object', _('3D cube'), 'Cube3DObject')
.addParameter('yesorno', _('Activate flipping'))
.markAsSimple()
.setHidden()
.setFunctionName('flipX');
// Deprecated
object
.addScopedAction(
'FlipY',
@@ -1087,6 +1134,7 @@ module.exports = {
.addParameter('object', _('3D cube'), 'Cube3DObject')
.addParameter('yesorno', _('Activate flipping'))
.markAsSimple()
.setHidden()
.setFunctionName('flipY');
object
@@ -1104,6 +1152,7 @@ module.exports = {
.markAsSimple()
.setFunctionName('flipZ');
// Deprecated
object
.addScopedCondition(
'FlippedX',
@@ -1115,8 +1164,10 @@ module.exports = {
'res/actions/flipX.png'
)
.addParameter('object', _('3D cube'), 'Cube3DObject')
.setHidden()
.setFunctionName('isFlippedX');
// Deprecated
object
.addScopedCondition(
'FlippedY',
@@ -1128,6 +1179,7 @@ module.exports = {
'res/actions/flipY.png'
)
.addParameter('object', _('3D cube'), 'Cube3DObject')
.setHidden()
.setFunctionName('isFlippedY');
object

View File

@@ -38,7 +38,8 @@ void DeclarePanelSpriteObjectExtension(gd::PlatformExtension& extension) {
"from "
"the full image."),
"CppPlatform/Extensions/PanelSpriteIcon.png")
.SetCategoryFullName(_("General"));
.SetCategoryFullName(_("General"))
.MarkBaseObjectCapabilityAsSupported("resizable");
obj.AddCondition("Opacity",
_("Opacity"),

View File

@@ -31,6 +31,9 @@ void DeclarePrimitiveDrawingExtension(gd::PlatformExtension& extension) {
_("Allows you to draw simple shapes on the screen using the "
"events."),
"CppPlatform/Extensions/primitivedrawingicon.png")
.MarkBaseObjectCapabilityAsSupported("resizable")
.MarkBaseObjectCapabilityAsSupported("scalable")
.MarkBaseObjectCapabilityAsSupported("flippable")
.SetCategoryFullName(_("Advanced"));
#if defined(GD_IDE_ONLY)
@@ -669,6 +672,7 @@ void DeclarePrimitiveDrawingExtension(gd::PlatformExtension& extension) {
"res/actions/flipX.png")
.AddParameter("object", _("Object"), "Drawer")
.AddParameter("yesorno", _("Activate flipping"))
.SetHidden()
.MarkAsSimple();
obj.AddAction("FlipY",
@@ -680,6 +684,7 @@ void DeclarePrimitiveDrawingExtension(gd::PlatformExtension& extension) {
"res/actions/flipY.png")
.AddParameter("object", _("Object"), "Drawer")
.AddParameter("yesorno", _("Activate flipping"))
.SetHidden()
.MarkAsSimple();
obj.AddCondition("FlippedX",
@@ -689,7 +694,8 @@ void DeclarePrimitiveDrawingExtension(gd::PlatformExtension& extension) {
_("Effects"),
"res/actions/flipX24.png",
"res/actions/flipX.png")
.AddParameter("object", _("Object"), "Drawer");
.AddParameter("object", _("Object"), "Drawer")
.SetHidden();
obj.AddCondition("FlippedY",
_("Vertically flipped"),
@@ -698,7 +704,8 @@ void DeclarePrimitiveDrawingExtension(gd::PlatformExtension& extension) {
_("Effects"),
"res/actions/flipY24.png",
"res/actions/flipY.png")
.AddParameter("object", _("Object"), "Drawer");
.AddParameter("object", _("Object"), "Drawer")
.SetHidden();
// Deprecated
obj.AddAction("Width",

View File

@@ -283,7 +283,7 @@ module.exports = {
textInputObject
)
.setCategoryFullName(_('User interface'))
.addUnsupportedBaseObjectCapability('effect')
.markBaseObjectCapabilityAsUnsupported('effect')
.setIncludeFile('Extensions/TextInput/textinputruntimeobject.js')
.addIncludeFile(
'Extensions/TextInput/textinputruntimeobject-pixi-renderer.js'

View File

@@ -205,6 +205,8 @@ const defineTileMap = function (
objectTileMap
)
.setCategoryFullName(_('Advanced'))
.markBaseObjectCapabilityAsSupported("resizable")
.markBaseObjectCapabilityAsSupported("scalable")
.setIncludeFile('Extensions/TileMap/tilemapruntimeobject.js')
.addIncludeFile('Extensions/TileMap/TileMapRuntimeManager.js')
.addIncludeFile('Extensions/TileMap/tilemapruntimeobject-pixi-renderer.js')
@@ -799,6 +801,8 @@ const defineCollisionMask = function (
collisionMaskObject
)
.setCategoryFullName(_('Advanced'))
.markBaseObjectCapabilityAsSupported("resizable")
.markBaseObjectCapabilityAsSupported("scalable")
.setIncludeFile('Extensions/TileMap/tilemapcollisionmaskruntimeobject.js')
.addIncludeFile('Extensions/TileMap/TileMapRuntimeManager.js')
.addIncludeFile('Extensions/TileMap/pako/dist/pako.min.js')

View File

@@ -34,6 +34,7 @@ void DeclareTiledSpriteObjectExtension(gd::PlatformExtension& extension) {
_("Tiled Sprite"),
_("Displays an image repeated over an area."),
"CppPlatform/Extensions/TiledSpriteIcon.png")
.MarkBaseObjectCapabilityAsSupported("resizable")
.SetCategoryFullName(_("General"));
obj.AddCondition("Opacity",

View File

@@ -382,6 +382,12 @@ BaseObjectExtension::BaseObjectExtension() {
.SetFunctionName("setScaleY")
.SetIncludeFile("runtimeobject.js");
// Instructions for the Flippable capability
objectActions["FlipX"].SetFunctionName("flipX");
objectActions["FlipY"].SetFunctionName("flipY");
objectConditions["FlippedX"].SetFunctionName("isFlippedX");
objectConditions["FlippedY"].SetFunctionName("isFlippedY");
GetAllActions()["MoveObjects"].SetCustomCodeGenerator(
[](gd::Instruction &,
gd::EventsCodeGenerator &,

View File

@@ -1,12 +1,10 @@
/*
* GDevelop JS Platform
* Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
declare namespace gdjs {
export interface Resizable {
export interface Resizable {
/**
* Change the width of the object. This changes the scale on X axis of the object.
*
@@ -28,9 +26,9 @@ export interface Resizable {
* @param newHeight The new height of the object, in pixels.
*/
setSize(newWidth: float, newHeight: float): void;
}
}
export interface Scalable {
export interface Scalable {
/**
* Change the scale on X and Y axis of the object.
*
@@ -73,4 +71,14 @@ export interface Scalable {
*/
getScaleX(): float;
}
}
export interface Flippable {
flipX(enable: boolean): void;
flipY(enable: boolean): void;
isFlippedX(): boolean;
isFlippedY(): boolean;
}
}

View File

@@ -153,7 +153,8 @@ namespace gdjs {
* A `gdjs.RuntimeObject` should not be instantiated directly, always a child class
* (because gdjs.RuntimeObject don't call onCreated at the end of its constructor).
*/
export class RuntimeObject implements EffectsTarget, gdjs.Resizable, gdjs.Scalable {
export class RuntimeObject
implements EffectsTarget, gdjs.Resizable, gdjs.Scalable, gdjs.Flippable {
name: string;
type: string;
x: float = 0;
@@ -2557,6 +2558,16 @@ namespace gdjs {
return 1;
}
// Implementation of the Flippable interface.
flipX(enable: boolean) {}
flipY(enable: boolean) {}
isFlippedX(): boolean {
return false;
}
isFlippedY(): boolean {
return false;
}
/**
* Get the identifier associated to an object name.
* Some features may want to compare objects name a large number of time. In this case,

View File

@@ -1633,9 +1633,10 @@ interface ObjectMetadata {
[Ref] ObjectMetadata SetIncludeFile([Const] DOMString includeFile);
[Ref] ObjectMetadata AddIncludeFile([Const] DOMString includeFile);
[Const, Ref] SetString GetUnsupportedBaseObjectCapabilities();
[Ref] ObjectMetadata AddUnsupportedBaseObjectCapability([Const] DOMString capability);
boolean IsUnsupportedBaseObjectCapability([Const] DOMString capability);
[Const, Ref] SetString GetSupportedBaseObjectCapabilities();
[Ref] ObjectMetadata MarkBaseObjectCapabilityAsUnsupported([Const] DOMString capability);
[Ref] ObjectMetadata MarkBaseObjectCapabilityAsSupported([Const] DOMString capability);
boolean IsSupportedBaseObjectCapability([Const] DOMString capability);
[Ref] ObjectMetadata SetHidden();
boolean IsHidden();

View File

@@ -137,7 +137,7 @@ module.exports = {
'',
fakeObject
)
.addUnsupportedBaseObjectCapability('effect');
.markBaseObjectCapabilityAsUnsupported('effect');
platform.addNewExtension(extension);
extension.delete(); // Release the extension as it was copied inside gd.JsPlatform

View File

@@ -21,9 +21,10 @@ declare class gdObjectMetadata {
getAllStrExpressions(): gdMapStringExpressionMetadata;
setIncludeFile(includeFile: string): gdObjectMetadata;
addIncludeFile(includeFile: string): gdObjectMetadata;
getUnsupportedBaseObjectCapabilities(): gdSetString;
addUnsupportedBaseObjectCapability(capability: string): gdObjectMetadata;
isUnsupportedBaseObjectCapability(capability: string): boolean;
getSupportedBaseObjectCapabilities(): gdSetString;
markBaseObjectCapabilityAsUnsupported(capability: string): gdObjectMetadata;
markBaseObjectCapabilityAsSupported(capability: string): gdObjectMetadata;
isSupportedBaseObjectCapability(capability: string): boolean;
setHidden(): gdObjectMetadata;
isHidden(): boolean;
delete(): void;

View File

@@ -25,7 +25,7 @@ const enumerateExpressionMetadataMap = (
if (
scope.objectMetadata &&
scope.objectMetadata.isUnsupportedBaseObjectCapability(
!scope.objectMetadata.isSupportedBaseObjectCapability(
exprMetadata.getRequiredBaseObjectCapability()
)
)

View File

@@ -220,7 +220,7 @@ const enumerateExtensionInstructions = (
if (
scope.objectMetadata &&
scope.objectMetadata.isUnsupportedBaseObjectCapability(
!scope.objectMetadata.isSupportedBaseObjectCapability(
instrMetadata.getRequiredBaseObjectCapability()
)
)

View File

@@ -185,12 +185,12 @@ const InnerDialog = (props: InnerDialogProps) => {
label: <Trans>Variables</Trans>,
value: 'variables',
},
objectMetadata.isUnsupportedBaseObjectCapability('effect')
? null
: {
label: <Trans>Effects</Trans>,
value: 'effects',
},
objectMetadata.isSupportedBaseObjectCapability('effect')
? {
label: <Trans>Effects</Trans>,
value: 'effects',
}
: null,
].filter(Boolean)}
/>
}

View File

@@ -145,7 +145,7 @@ const checkHasRequiredCapability = ({
project.getCurrentPlatform(),
object.getType()
);
return !objectMetadata.isUnsupportedBaseObjectCapability(
return objectMetadata.isSupportedBaseObjectCapability(
requiredObjectCapability
);
};

View File

@@ -739,7 +739,7 @@ const ObjectsList = React.forwardRef<Props, ObjectsListInterface>(
{
label: i18n._(t`Edit effects`),
click: () => onEditObject(object, 'effects'),
enabled: !objectMetadata.isUnsupportedBaseObjectCapability(
enabled: objectMetadata.isSupportedBaseObjectCapability(
'effect'
),
},

View File

@@ -300,7 +300,7 @@ export const makeTestExtensions = (gd: libGDevelop) => {
'',
fakeObject
)
.addUnsupportedBaseObjectCapability('effect');
.markBaseObjectCapabilityAsUnsupported('effect');
platform.addNewExtension(extension);
extension.delete(); // Release the extension as it was copied inside gd.JsPlatform