Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Core/GDCore/Events/Builtin/ElseEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ ElseEvent::ElseEvent()

ElseEvent::~ElseEvent(){};

gd::InstructionsList* ElseEvent::GetInstructionList(const gd::String& label) {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}
const gd::InstructionsList* ElseEvent::GetInstructionList(
const gd::String& label) const {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}

vector<const gd::InstructionsList*> ElseEvent::GetAllConditionsVectors() const {
vector<const gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
Expand Down
3 changes: 3 additions & 0 deletions Core/GDCore/Events/Builtin/ElseEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class GD_CORE_API ElseEvent : public gd::BaseEvent {
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };

virtual gd::InstructionsList* GetInstructionList(const gd::String& label) override;
virtual const gd::InstructionsList* GetInstructionList(const gd::String& label) const override;

virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors() const;
virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors() const;
virtual std::vector<gd::InstructionsList*> GetAllConditionsVectors();
Expand Down
13 changes: 13 additions & 0 deletions Core/GDCore/Events/Builtin/ForEachChildVariableEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ ForEachChildVariableEvent::ForEachChildVariableEvent()
iterableVariableName(""),
variables(gd::VariablesContainer::SourceType::Local) {}

gd::InstructionsList* ForEachChildVariableEvent::GetInstructionList(
const gd::String& label) {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}
const gd::InstructionsList* ForEachChildVariableEvent::GetInstructionList(
const gd::String& label) const {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}

vector<gd::InstructionsList*> ForEachChildVariableEvent::GetAllConditionsVectors() {
vector<gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
Expand Down
3 changes: 3 additions & 0 deletions Core/GDCore/Events/Builtin/ForEachChildVariableEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class GD_CORE_API ForEachChildVariableEvent : public gd::BaseEvent {
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };

virtual gd::InstructionsList* GetInstructionList(const gd::String& label) override;
virtual const gd::InstructionsList* GetInstructionList(const gd::String& label) const override;

/**
* \brief Get the iterable variable name attached to the event.
*
Expand Down
13 changes: 13 additions & 0 deletions Core/GDCore/Events/Builtin/ForEachEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ ForEachEvent::ForEachEvent()
limit(""),
variables(gd::VariablesContainer::SourceType::Local) {}

gd::InstructionsList* ForEachEvent::GetInstructionList(
const gd::String& label) {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}
const gd::InstructionsList* ForEachEvent::GetInstructionList(
const gd::String& label) const {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}

vector<gd::InstructionsList*> ForEachEvent::GetAllConditionsVectors() {
vector<gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
Expand Down
3 changes: 3 additions & 0 deletions Core/GDCore/Events/Builtin/ForEachEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class GD_CORE_API ForEachEvent : public gd::BaseEvent {
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };

virtual gd::InstructionsList* GetInstructionList(const gd::String& label) override;
virtual const gd::InstructionsList* GetInstructionList(const gd::String& label) const override;

const gd::String& GetObjectToPick() const {
return objectsToPick.GetPlainString();
};
Expand Down
12 changes: 12 additions & 0 deletions Core/GDCore/Events/Builtin/RepeatEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ RepeatEvent::RepeatEvent()
variables(gd::VariablesContainer::SourceType::Local),
repeatNumberExpressionSelected(false) {}

gd::InstructionsList* RepeatEvent::GetInstructionList(const gd::String& label) {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}
const gd::InstructionsList* RepeatEvent::GetInstructionList(
const gd::String& label) const {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}

vector<gd::InstructionsList*> RepeatEvent::GetAllConditionsVectors() {
vector<gd::InstructionsList*> allConditions;
allConditions.push_back(&conditions);
Expand Down
3 changes: 3 additions & 0 deletions Core/GDCore/Events/Builtin/RepeatEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class GD_CORE_API RepeatEvent : public gd::BaseEvent {
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };

virtual gd::InstructionsList* GetInstructionList(const gd::String& label) override;
virtual const gd::InstructionsList* GetInstructionList(const gd::String& label) const override;

const gd::Expression& GetRepeatExpression() const {
return repeatNumberExpression;
};
Expand Down
13 changes: 13 additions & 0 deletions Core/GDCore/Events/Builtin/StandardEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ StandardEvent::StandardEvent()

StandardEvent::~StandardEvent(){};

gd::InstructionsList* StandardEvent::GetInstructionList(
const gd::String& label) {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}
const gd::InstructionsList* StandardEvent::GetInstructionList(
const gd::String& label) const {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
return nullptr;
}

vector<const gd::InstructionsList*> StandardEvent::GetAllConditionsVectors()
const {
vector<const gd::InstructionsList*> allConditions;
Expand Down
3 changes: 3 additions & 0 deletions Core/GDCore/Events/Builtin/StandardEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class GD_CORE_API StandardEvent : public gd::BaseEvent {
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };

virtual gd::InstructionsList* GetInstructionList(const gd::String& label) override;
virtual const gd::InstructionsList* GetInstructionList(const gd::String& label) const override;

virtual std::vector<const gd::InstructionsList*> GetAllConditionsVectors()
const;
virtual std::vector<const gd::InstructionsList*> GetAllActionsVectors() const;
Expand Down
14 changes: 14 additions & 0 deletions Core/GDCore/Events/Builtin/WhileEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ using namespace std;

namespace gd {

gd::InstructionsList* WhileEvent::GetInstructionList(const gd::String& label) {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
if (label == BaseEvent::whileConditionsLabel) return &whileConditions;
return nullptr;
}
const gd::InstructionsList* WhileEvent::GetInstructionList(
const gd::String& label) const {
if (label == BaseEvent::conditionsLabel) return &conditions;
if (label == BaseEvent::actionsLabel) return &actions;
if (label == BaseEvent::whileConditionsLabel) return &whileConditions;
return nullptr;
}

vector<gd::InstructionsList*> WhileEvent::GetAllConditionsVectors() {
vector<gd::InstructionsList*> allConditions;
allConditions.push_back(&whileConditions);
Expand Down
3 changes: 3 additions & 0 deletions Core/GDCore/Events/Builtin/WhileEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class GD_CORE_API WhileEvent : public gd::BaseEvent {
const gd::InstructionsList& GetActions() const { return actions; };
gd::InstructionsList& GetActions() { return actions; };

virtual gd::InstructionsList* GetInstructionList(const gd::String& label) override;
virtual const gd::InstructionsList* GetInstructionList(const gd::String& label) const override;

const gd::InstructionsList& GetWhileConditions() const {
return whileConditions;
};
Expand Down
3 changes: 3 additions & 0 deletions Core/GDCore/Events/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ namespace gd {

EventsList BaseEvent::badSubEvents;
VariablesContainer BaseEvent::badLocalVariables;
const gd::String BaseEvent::conditionsLabel = "conditions";
const gd::String BaseEvent::actionsLabel = "actions";
const gd::String BaseEvent::whileConditionsLabel = "whileConditions";

BaseEvent::BaseEvent()
: totalTimeDuringLastSession(0),
Expand Down
20 changes: 20 additions & 0 deletions Core/GDCore/Events/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ class GD_CORE_API BaseEvent {
*/
bool HasVariables() const;

/**
* \brief Return the instruction list identified by \a label, or nullptr if
* the event has no such list.
*
* Supported labels are "conditions", "actions", and "whileConditions" (only
* for WhileEvent). Derived classes should override this; the base
* implementation always returns nullptr.
*/
virtual gd::InstructionsList* GetInstructionList(const gd::String& label) {
return nullptr;
};
virtual const gd::InstructionsList* GetInstructionList(
const gd::String& label) const {
return nullptr;
};

static const gd::String conditionsLabel;
static const gd::String actionsLabel;
static const gd::String whileConditionsLabel;

/**
* \brief Return a list of all conditions of the event.
* \note Used to preprocess or search in the conditions.
Expand Down
2 changes: 2 additions & 0 deletions GDevelop.js/Bindings/Bindings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -2499,6 +2499,8 @@ interface BaseEvent {
boolean IsFolded();
void SetFolded(boolean folded);

InstructionsList GetInstructionList([Const] DOMString label);

void SerializeTo([Ref] SerializerElement element);
void UnserializeFrom([Ref] Project project, [Const, Ref] SerializerElement element);

Expand Down
1 change: 1 addition & 0 deletions GDevelop.js/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1925,6 +1925,7 @@ export class BaseEvent extends EmscriptenObject {
setDisabled(disable: boolean): void;
isFolded(): boolean;
setFolded(folded: boolean): void;
getInstructionList(label: string): InstructionsList;
serializeTo(element: SerializerElement): void;
unserializeFrom(project: Project, element: SerializerElement): void;
getAiGeneratedEventId(): string;
Expand Down
1 change: 1 addition & 0 deletions GDevelop.js/types/gdbaseevent.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare class gdBaseEvent extends gdBaseEvent {
setDisabled(disable: boolean): void;
isFolded(): boolean;
setFolded(folded: boolean): void;
getInstructionList(label: string): gdInstructionsList;
serializeTo(element: gdSerializerElement): void;
unserializeFrom(project: gdProject, element: gdSerializerElement): void;
getAiGeneratedEventId(): string;
Expand Down
13 changes: 10 additions & 3 deletions newIDE/app/src/EventsSheet/EventsTree/EventHeightsCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
* the size of each event - which we only know after the event has been rendered.
*/
export default class EventHeightsCache {
// $FlowFixMe[missing-local-annot]
eventHeights = {};
updateTimeoutId: ?TimeoutID = null;
eventHeights: { [number]: number } = {};
_onHeightsChanged: ?() => void = null;

setEventHeight(event: gdBaseEvent, height: number) {
if (this.eventHeights[event.ptr] === height) return;
this.eventHeights[event.ptr] = height;
if (this._onHeightsChanged) {
this._onHeightsChanged();
}
}

getEventHeight(event: gdBaseEvent): number {
return this.eventHeights[event.ptr] || 0;
}

setOnHeightsChanged(callback: ?() => void) {
this._onHeightsChanged = callback;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class WhileEvent extends React.Component<
projectScopedContainersAccessor={
this.props.projectScopedContainersAccessor
}
idPrefix={this.props.idPrefix}
idPrefix={`${this.props.idPrefix}-while`}
highlightedSearchText={this.props.highlightedSearchText}
highlightedSearchMatchCase={this.props.highlightedSearchMatchCase}
/>
Expand Down
7 changes: 5 additions & 2 deletions newIDE/app/src/EventsSheet/EventsTree/SortableEventsTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Props = {|
searchFocusOffset?: ?number,
searchFocusedEvent?: ?gdBaseEvent,
className?: string,
eventsSheetWidth?: number,
reactVirtualizedListProps?: {
ref?: (list: {
scrollToRow: (row: number) => void,
Expand Down Expand Up @@ -365,6 +366,7 @@ const SortableEventsTree = ({
searchFocusOffset,
searchFocusedEvent,
className,
eventsSheetWidth,
reactVirtualizedListProps,
}: Props): React.MixedElement => {
// $FlowFixMe[value-as-type]
Expand All @@ -390,7 +392,7 @@ const SortableEventsTree = ({
[flatData, searchMethod, searchQuery]
);

React.useEffect(
React.useLayoutEffect(
() => {
if (!reactVirtualizedListProps || !reactVirtualizedListProps.ref) return;
reactVirtualizedListProps.ref({
Expand Down Expand Up @@ -464,7 +466,7 @@ const SortableEventsTree = ({

return (
<div className={className}>
<AutoSizer>
<AutoSizer defaultWidth={eventsSheetWidth || 0}>
{({ width, height }) => (
<VariableSizeList
ref={listRef}
Expand All @@ -477,6 +479,7 @@ const SortableEventsTree = ({
itemData={itemData}
itemKey={itemKey}
onScroll={handleScroll}
overscanCount={10}
>
{TreeRow}
</VariableSizeList>
Expand Down
Loading
Loading