Skip to content

Commit 5394cc5

Browse files
authored
Forbid to add Physics behaviors on objects inside custom objects (#7809)
1 parent 5e3dfb0 commit 5394cc5

File tree

18 files changed

+133
-13
lines changed

18 files changed

+133
-13
lines changed

Core/GDCore/Extensions/Metadata/BehaviorMetadata.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,19 @@ class GD_CORE_API BehaviorMetadata : public InstructionOrExpressionContainerMeta
298298
return *this;
299299
}
300300

301+
/**
302+
* Check if the behavior can be used on objects from event-based objects.
303+
*/
304+
bool IsRelevantForChildObjects() const { return isRelevantForChildObjects; }
305+
306+
/**
307+
* Set that behavior can't be used on objects from event-based objects.
308+
*/
309+
BehaviorMetadata &MarkAsIrrelevantForChildObjects() {
310+
isRelevantForChildObjects = false;
311+
return *this;
312+
}
313+
301314
QuickCustomization::Visibility GetQuickCustomizationVisibility() const {
302315
return quickCustomizationVisibility;
303316
}
@@ -393,6 +406,7 @@ class GD_CORE_API BehaviorMetadata : public InstructionOrExpressionContainerMeta
393406
mutable std::vector<gd::String> requiredBehaviors;
394407
bool isPrivate = false;
395408
bool isHidden = false;
409+
bool isRelevantForChildObjects = true;
396410
gd::String openFullEditorLabel;
397411
QuickCustomization::Visibility quickCustomizationVisibility = QuickCustomization::Visibility::Default;
398412

Extensions/Physics2Behavior/JsExtension.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ module.exports = {
531531
physics2Behavior,
532532
sharedData
533533
)
534+
.markAsIrrelevantForChildObjects()
534535
.setIncludeFile('Extensions/Physics2Behavior/physics2runtimebehavior.js')
535536
.addIncludeFile('Extensions/Physics2Behavior/Box2D_v2.3.1_min.wasm.js')
536537
.addRequiredFile('Extensions/Physics2Behavior/Box2D_v2.3.1_min.wasm.wasm')

Extensions/Physics3DBehavior/JsExtension.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ module.exports = {
679679
behavior,
680680
sharedData
681681
)
682+
.markAsIrrelevantForChildObjects()
682683
.addIncludeFile(
683684
'Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.js'
684685
)

Extensions/PhysicsBehavior/Extension.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ void DeclarePhysicsBehaviorExtension(gd::PlatformExtension& extension) {
3737
"res/physics-deprecated32.png",
3838
"PhysicsBehavior",
3939
std::make_shared<PhysicsBehavior>(),
40-
std::make_shared<ScenePhysicsDatas>());
40+
std::make_shared<ScenePhysicsDatas>())
41+
.MarkAsIrrelevantForChildObjects();
4142

4243
aut.AddAction("SetStatic",
4344
("Make the object static"),

GDevelop.js/Bindings/Bindings.idl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,9 @@ interface BehaviorMetadata {
21452145
boolean IsHidden();
21462146
[Ref] BehaviorMetadata SetHidden();
21472147

2148+
boolean IsRelevantForChildObjects();
2149+
[Ref] BehaviorMetadata MarkAsIrrelevantForChildObjects();
2150+
21482151
QuickCustomization_Visibility GetQuickCustomizationVisibility();
21492152
[Ref] BehaviorMetadata SetQuickCustomizationVisibility(QuickCustomization_Visibility visibility);
21502153

GDevelop.js/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,8 @@ export class BehaviorMetadata extends EmscriptenObject {
16711671
setPrivate(): BehaviorMetadata;
16721672
isHidden(): boolean;
16731673
setHidden(): BehaviorMetadata;
1674+
isRelevantForChildObjects(): boolean;
1675+
markAsIrrelevantForChildObjects(): BehaviorMetadata;
16741676
getQuickCustomizationVisibility(): QuickCustomization_Visibility;
16751677
setQuickCustomizationVisibility(visibility: QuickCustomization_Visibility): BehaviorMetadata;
16761678
setOpenFullEditorLabel(label: string): BehaviorMetadata;

GDevelop.js/types/gdbehaviormetadata.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ declare class gdBehaviorMetadata {
3333
setPrivate(): gdBehaviorMetadata;
3434
isHidden(): boolean;
3535
setHidden(): gdBehaviorMetadata;
36+
isRelevantForChildObjects(): boolean;
37+
markAsIrrelevantForChildObjects(): gdBehaviorMetadata;
3638
getQuickCustomizationVisibility(): QuickCustomization_Visibility;
3739
setQuickCustomizationVisibility(visibility: QuickCustomization_Visibility): gdBehaviorMetadata;
3840
setOpenFullEditorLabel(label: string): gdBehaviorMetadata;

newIDE/app/src/AssetStore/BehaviorStore/BehaviorListItem.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Props = {|
3333
id?: string,
3434
objectType: string,
3535
objectBehaviorsTypes: Array<string>,
36+
isChildObject: boolean,
3637
behaviorShortHeader: BehaviorShortHeader,
3738
matches: ?Array<SearchMatch>,
3839
onChoose: () => void,
@@ -45,6 +46,7 @@ export const BehaviorListItem = ({
4546
id,
4647
objectType,
4748
objectBehaviorsTypes,
49+
isChildObject,
4850
behaviorShortHeader,
4951
matches,
5052
onChoose,
@@ -53,20 +55,28 @@ export const BehaviorListItem = ({
5355
platform,
5456
}: Props) => {
5557
const alreadyAdded = objectBehaviorsTypes.includes(behaviorShortHeader.type);
56-
// An empty object type means the base object, i.e: any object.
58+
59+
const behaviorMetadata = gd.MetadataProvider.getBehaviorMetadata(
60+
platform,
61+
behaviorShortHeader.type
62+
);
5763
const isObjectCompatible =
64+
// An empty object type means the base object, i.e: any object.
5865
(!behaviorShortHeader.objectType ||
5966
objectType === behaviorShortHeader.objectType) &&
67+
(!isChildObject || behaviorMetadata.isRelevantForChildObjects()) &&
6068
behaviorShortHeader.allRequiredBehaviorTypes.every(requiredBehaviorType => {
6169
const behaviorMetadata = gd.MetadataProvider.getBehaviorMetadata(
6270
platform,
6371
requiredBehaviorType
6472
);
6573
return (
66-
!behaviorMetadata.isHidden() ||
67-
objectBehaviorsTypes.includes(requiredBehaviorType)
74+
(!isChildObject || behaviorMetadata.isRelevantForChildObjects()) &&
75+
(!behaviorMetadata.isHidden() ||
76+
objectBehaviorsTypes.includes(requiredBehaviorType))
6877
);
6978
});
79+
7080
const isEngineCompatible = isCompatibleWithGDevelopVersion(
7181
getIDEVersion(),
7282
behaviorShortHeader.gdevelopVersion

newIDE/app/src/AssetStore/BehaviorStore/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Props = {|
6262
project: gdProject,
6363
objectType: string,
6464
objectBehaviorsTypes: Array<string>,
65+
isChildObject: boolean,
6566
installedBehaviorMetadataList: Array<BehaviorShortHeader>,
6667
deprecatedBehaviorMetadataList: Array<BehaviorShortHeader>,
6768
onInstall: (behaviorShortHeader: BehaviorShortHeader) => Promise<boolean>,
@@ -76,6 +77,7 @@ export const BehaviorStore = ({
7677
project,
7778
objectType,
7879
objectBehaviorsTypes,
80+
isChildObject,
7981
installedBehaviorMetadataList,
8082
deprecatedBehaviorMetadataList,
8183
onInstall,
@@ -316,6 +318,7 @@ export const BehaviorStore = ({
316318
key={behaviorShortHeader.type}
317319
objectType={objectType}
318320
objectBehaviorsTypes={objectBehaviorsTypes}
321+
isChildObject={isChildObject}
319322
onHeightComputed={onHeightComputed}
320323
behaviorShortHeader={behaviorShortHeader}
321324
matches={getExtensionsMatches(behaviorShortHeader)}

newIDE/app/src/BehaviorsEditor/NewBehaviorDialog.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Props = {|
2929
eventsFunctionsExtension: gdEventsFunctionsExtension | null,
3030
objectType: string,
3131
objectBehaviorsTypes: Array<string>,
32+
isChildObject: boolean,
3233
open: boolean,
3334
onClose: () => void,
3435
onChoose: (type: string, defaultName: string) => void,
@@ -43,6 +44,7 @@ export default function NewBehaviorDialog({
4344
onChoose,
4445
objectType,
4546
objectBehaviorsTypes,
47+
isChildObject,
4648
onExtensionInstalled,
4749
}: Props) {
4850
const [isInstalling, setIsInstalling] = React.useState(false);
@@ -224,6 +226,7 @@ export default function NewBehaviorDialog({
224226
project={project}
225227
objectType={objectType}
226228
objectBehaviorsTypes={objectBehaviorsTypes}
229+
isChildObject={isChildObject}
227230
isInstalling={isInstalling}
228231
onInstall={async shortHeader =>
229232
onInstallExtension(i18n, shortHeader)

0 commit comments

Comments
 (0)