Skip to content

Commit

Permalink
Use the folder structure when choosing an object/group in an action/c…
Browse files Browse the repository at this point in the history
…ondition (#7297)
  • Loading branch information
AlexandreSi authored Jan 16, 2025
1 parent 6242e8c commit 4bf3ef8
Show file tree
Hide file tree
Showing 36 changed files with 2,620 additions and 796 deletions.
9 changes: 9 additions & 0 deletions Core/GDCore/Project/ObjectFolderOrObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ void ObjectFolderOrObject::RemoveRecursivelyObjectNamed(
}
};

void ObjectFolderOrObject::Clear() {
if (IsFolder()) {
for (auto& it : children) {
it->Clear();
}
children.clear();
}
};

bool ObjectFolderOrObject::IsADescendantOf(
const ObjectFolderOrObject& otherObjectFolderOrObject) {
if (parent == nullptr) return false;
Expand Down
4 changes: 4 additions & 0 deletions Core/GDCore/Project/ObjectFolderOrObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class GD_CORE_API ObjectFolderOrObject {
* the instance children and recursively does it for every folder children.
*/
void RemoveRecursivelyObjectNamed(const gd::String& name);
/**
* \brief Clears all children
*/
void Clear();

/**
* \brief Inserts an instance representing the given object at the given
Expand Down
12 changes: 8 additions & 4 deletions Core/GDCore/Project/ObjectsContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

#include <algorithm>

#include "GDCore/Tools/PolymorphicClone.h"
#include "GDCore/Extensions/Platform.h"
#include "GDCore/Project/Object.h"
#include "GDCore/Project/ObjectFolderOrObject.h"
#include "GDCore/Project/Project.h"
#include "GDCore/Serialization/SerializerElement.h"
#include "GDCore/Tools/PolymorphicClone.h"

namespace gd {

Expand All @@ -28,8 +28,7 @@ ObjectsContainer::ObjectsContainer(const ObjectsContainer& other) {
Init(other);
}

ObjectsContainer& ObjectsContainer::operator=(
const ObjectsContainer& other) {
ObjectsContainer& ObjectsContainer::operator=(const ObjectsContainer& other) {
if (this != &other) Init(other);

return *this;
Expand Down Expand Up @@ -69,7 +68,7 @@ void ObjectsContainer::AddMissingObjectsInRootFolder() {

void ObjectsContainer::UnserializeObjectsFrom(
gd::Project& project, const SerializerElement& element) {
initialObjects.clear();
Clear();
element.ConsiderAsArrayOf("object", "Objet");
for (std::size_t i = 0; i < element.GetChildrenCount(); ++i) {
const SerializerElement& objectElement = element.GetChild(i);
Expand Down Expand Up @@ -184,6 +183,11 @@ void ObjectsContainer::RemoveObject(const gd::String& name) {
initialObjects.erase(objectIt);
}

void ObjectsContainer::Clear() {
rootFolder->Clear();
initialObjects.clear();
}

void ObjectsContainer::MoveObjectFolderOrObjectToAnotherContainerInFolder(
gd::ObjectFolderOrObject& objectFolderOrObject,
gd::ObjectsContainer& newContainer,
Expand Down
5 changes: 5 additions & 0 deletions Core/GDCore/Project/ObjectsContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ class GD_CORE_API ObjectsContainer {
gd::ObjectFolderOrObject& newParentFolder,
std::size_t newPosition);

/**
* \brief Clear all groups of the container.
*/
void Clear();

/**
* Provide a raw access to the vector containing the objects
*/
Expand Down
2 changes: 1 addition & 1 deletion Core/GDCore/Project/ProjectScopedContainers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ProjectScopedContainers::MakeNewProjectScopedContainersForEventsBasedObject(
// created below.
// Search for "ProjectScopedContainers wrongly containing temporary objects containers or objects"
// in the codebase.
outputObjectsContainer.GetObjects().clear();
outputObjectsContainer.Clear();
outputObjectsContainer.GetObjectGroups().Clear();

// This object named "Object" represents the parent and is used by events.
Expand Down
1 change: 0 additions & 1 deletion GDJS/GDJS/Extensions/Builtin/FileExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ FileExtension::FileExtension() {
GetAllActions()["DeleteGroupFichier"].SetFunctionName(
"gdjs.evtTools.storage.deleteElementFromJSONFile");
GetAllActions()["DeleteFichier"]
.SetGroup(_("Storage"))
.SetFunctionName("gdjs.evtTools.storage.clearJSONFile");

StripUnimplementedInstructionsAndExpressions(); // Unimplemented things are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,27 +588,28 @@ export const EventsFunctionParametersEditor = ({
);
if (isAnExtensionLifecycleEventsFunction) {
return (
<Column noMargin>
<DismissableAlertMessage
kind="info"
identifier="lifecycle-events-function-included-only-if-extension-used"
>
<Trans>
For the lifecycle functions to be executed, you need the extension
to be used in the game, either by having at least one action,
condition or expression used, or a behavior of the extension added
to an object. Otherwise, the extension won't be included in the
game.
</Trans>
</DismissableAlertMessage>
<EmptyMessage>
<Trans>
This is a "lifecycle function". It will be called automatically by
the game engine. It has no parameters. Only global objects can be
used as the events will be run for all scenes in your game.
</Trans>
</EmptyMessage>
</Column>
<Line>
<Column noMargin>
<DismissableAlertMessage
kind="info"
identifier="lifecycle-events-function-included-only-if-extension-used"
>
<Trans>
For the lifecycle functions to be executed, you need the extension
to be used in the game, either by having at least one action,
condition or expression used, or a behavior of the extension added
to an object. Otherwise, the extension won't be included in the
game.
</Trans>
</DismissableAlertMessage>
<EmptyMessage>
<Trans>
This is a "lifecycle function". It will be called automatically by
the game engine. It has no parameters.
</Trans>
</EmptyMessage>
</Column>
</Line>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,28 @@ export const EventsFunctionPropertiesEditor = ({
);
if (isAnExtensionLifecycleEventsFunction) {
return (
<Column noMargin>
<DismissableAlertMessage
kind="info"
identifier="lifecycle-events-function-included-only-if-extension-used"
>
<Trans>
For the lifecycle functions to be executed, you need the extension
to be used in the game, either by having at least one action,
condition or expression used, or a behavior of the extension added
to an object. Otherwise, the extension won't be included in the
game.
</Trans>
</DismissableAlertMessage>
<EmptyMessage>
<Trans>
This is a "lifecycle function". It will be called automatically by
the game engine. It has no parameters. Only global objects can be
used as the events will be run for all scenes in your game.
</Trans>
</EmptyMessage>
</Column>
<Line>
<Column noMargin>
<DismissableAlertMessage
kind="info"
identifier="lifecycle-events-function-included-only-if-extension-used"
>
<Trans>
For the lifecycle functions to be executed, you need the extension
to be used in the game, either by having at least one action,
condition or expression used, or a behavior of the extension added
to an object. Otherwise, the extension won't be included in the
game.
</Trans>
</DismissableAlertMessage>
<EmptyMessage>
<Trans>
This is a "lifecycle function". It will be called automatically by
the game engine. It has no parameters.
</Trans>
</EmptyMessage>
</Column>
</Line>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class EventsBasedObjectTreeViewItemContent
}

getHtmlId(index: number): ?string {
return `object-item-${index}`;
return null;
}

getThumbnail(): ?string {
Expand All @@ -125,7 +125,7 @@ export class EventsBasedObjectTreeViewItemContent
}

getDataset(): ?HTMLDataset {
return null;
return { objectName: this.eventsBasedObject.getName() };
}

onSelect(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export const useInstructionEditor = ({
chosenObjectName: objectName,
chosenObjectInstructionsInfo,
chosenObjectInstructionsInfoTree: createTree(
chosenObjectInstructionsInfo
chosenObjectInstructionsInfo,
i18n
),
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import InstructionParametersEditor, {
type InstructionParametersEditorInterface,
} from './InstructionParametersEditor';
import InstructionOrObjectSelector, {
type InstructionOrObjectSelectorInterface,
type TabName,
} from './InstructionOrObjectSelector';
import InstructionOrExpressionSelector from './InstructionOrExpressionSelector';
Expand Down Expand Up @@ -138,7 +139,7 @@ const InstructionEditorDialog = ({
chosenObjectName
)
: null;
const freeInstructionComponentRef = React.useRef<?InstructionOrObjectSelector>(
const freeInstructionComponentRef = React.useRef<?InstructionOrObjectSelectorInterface>(
null
);
const [step, setStep] = React.useState(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default class ExpressionSelector extends Component<Props, {||}> {
enumerateAllExpressions(this.props.expressionType, this.props.i18n),
this.props.scope
);
instructionsInfoTree: ExpressionTreeNode = createTree(this.instructionsInfo);
instructionsInfoTree: ExpressionTreeNode = createTree(
this.instructionsInfo,
this.props.i18n
);

render() {
const { expressionType, scope, i18n, ...otherProps } = this.props;
Expand Down

This file was deleted.

Loading

0 comments on commit 4bf3ef8

Please sign in to comment.