Skip to content

Commit

Permalink
Show instructions about objects with the other object instructions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H authored Nov 13, 2023
1 parent b180f50 commit 88063a4
Show file tree
Hide file tree
Showing 24 changed files with 816 additions and 678 deletions.
4 changes: 2 additions & 2 deletions Core/GDCore/Extensions/Builtin/BaseObjectExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
_("Cast a ray from _PARAM1_;_PARAM2_, angle: _PARAM3_ and max "
"distance: _PARAM4_px, against _PARAM0_, and save the "
"result in _PARAM5_, _PARAM6_"),
"",
_("Collision"),
"res/conditions/raycast24.png",
"res/conditions/raycast.png")
.AddParameter("objectList", _("Objects to test against the ray"))
Expand Down Expand Up @@ -1655,7 +1655,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension(
_("Cast a ray from _PARAM1_;_PARAM2_ to _PARAM3_;_PARAM4_ "
"against _PARAM0_, and save the "
"result in _PARAM5_, _PARAM6_"),
"",
_("Collision"),
"res/conditions/raycast24.png",
"res/conditions/raycast.png")
.AddParameter("objectList", _("Objects to test against the ray"))
Expand Down
4 changes: 2 additions & 2 deletions Core/GDCore/Extensions/Builtin/CameraExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsCameraExtension(
.AddParameter("expression", _("Camera number (default : 0)"), "", true)
.SetDefaultValue("0");

// TODO Deprecated: hide this action in a future release.
extension
.AddAction(
"FixCamera",
Expand All @@ -339,6 +338,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsCameraExtension(
"",
"res/actions/camera24.png",
"res/actions/camera.png")
.SetHidden()
.AddCodeOnlyParameter("currentScene", "")
.AddParameter("objectPtr", _("Object"))
.AddParameter("expression",
Expand Down Expand Up @@ -386,7 +386,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsCameraExtension(
_("Center the camera on an object"),
_("Center the camera on the specified object."),
_("Center camera on _PARAM1_ (layer: _PARAM3_)"),
"",
_("Layers and cameras"),
"res/actions/camera24.png",
"res/actions/camera.png")
.AddCodeOnlyParameter("currentScene", "")
Expand Down
2 changes: 1 addition & 1 deletion Extensions/3D/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ module.exports = {
'Change the camera rotation to look at an object. The camera top always face the screen.'
),
_('Change the camera rotation of _PARAM2_ to look at _PARAM1_'),
'',
_("Layers and cameras"),
'res/conditions/3d_box.svg',
'res/conditions/3d_box.svg'
)
Expand Down
10 changes: 5 additions & 5 deletions Extensions/LinkedObjects/Extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void DeclareLinkedObjectsExtension(gd::PlatformExtension& extension) {
_("Link two objects together, so as to be able to get one "
"from the other."),
_("Link _PARAM1_ and _PARAM2_"),
"",
_("Objects"),
"CppPlatform/Extensions/LinkedObjectsicon24.png",
"CppPlatform/Extensions/LinkedObjectsicon24.png")

Expand All @@ -49,7 +49,7 @@ void DeclareLinkedObjectsExtension(gd::PlatformExtension& extension) {
_("Unlink two objects"),
_("Unlink two objects."),
_("Unlink _PARAM1_ and _PARAM2_"),
"",
_("Objects"),
"CppPlatform/Extensions/LinkedObjectsicon24.png",
"CppPlatform/Extensions/LinkedObjectsicon24.png")

Expand All @@ -64,7 +64,7 @@ void DeclareLinkedObjectsExtension(gd::PlatformExtension& extension) {
_("Unlink all objects from an object"),
_("Unlink all objects from an object."),
_("Unlink all objects from _PARAM1_"),
"",
_("Objects"),
"CppPlatform/Extensions/LinkedObjectsicon24.png",
"CppPlatform/Extensions/LinkedObjectsicon24.png")

Expand All @@ -80,7 +80,7 @@ void DeclareLinkedObjectsExtension(gd::PlatformExtension& extension) {
"next conditions and actions.\nThe condition will return "
"false if no object was taken into account."),
_("Take into account all \"_PARAM1_\" linked to _PARAM2_"),
"",
_("Objects"),
"CppPlatform/Extensions/LinkedObjectsicon24.png",
"CppPlatform/Extensions/LinkedObjectsicon24.png")

Expand All @@ -97,7 +97,7 @@ void DeclareLinkedObjectsExtension(gd::PlatformExtension& extension) {
_("Take into account linked objects"),
_("Take objects linked to the object into account for next actions."),
_("Take into account all \"_PARAM1_\" linked to _PARAM2_"),
"",
_("Objects"),
"CppPlatform/Extensions/LinkedObjectsicon24.png",
"CppPlatform/Extensions/LinkedObjectsicon24.png")

Expand Down
2 changes: 1 addition & 1 deletion Extensions/Physics2Behavior/JsExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ module.exports = {
'While an object is needed, this will apply to all objects using the behavior.'
),
_('Set the world time scale of _PARAM0_ to _PARAM2_'),
'',
_('Global'),
'res/physics32.png',
'res/physics32.png'
)
Expand Down
27 changes: 10 additions & 17 deletions newIDE/app/src/EventsSheet/InstructionEditor/InstructionEditor.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @flow
import * as React from 'react';
import { type I18n as I18nType } from '@lingui/core';
import {
enumerateObjectAndBehaviorsInstructions,
isObjectInstruction,
getObjectParameterIndex,
} from '../../InstructionOrExpression/EnumerateInstructions';
import {
Expand Down Expand Up @@ -47,6 +47,7 @@ type Parameters = {|
scope: EventsScope,
globalObjectsContainer: gdObjectsContainer,
objectsContainer: gdObjectsContainer,
i18n: I18nType,
|};

type InstructionEditorState = {|
Expand Down Expand Up @@ -86,6 +87,7 @@ export const useInstructionEditor = ({
scope,
globalObjectsContainer,
objectsContainer,
i18n,
}: Parameters): [InstructionEditorState, InstructionEditorSetters] => {
const getChosenObjectState = (
objectName: string,
Expand All @@ -96,7 +98,8 @@ export const useInstructionEditor = ({
isCondition,
globalObjectsContainer,
objectsContainer,
objectName
objectName,
i18n
),
scope
);
Expand Down Expand Up @@ -139,22 +142,12 @@ export const useInstructionEditor = ({
project.getCurrentPlatform(),
instructionType
);
if (
isObjectInstruction(
project.getCurrentPlatform(),
instruction,
isCondition
)
) {
const objectParameterIndex = getObjectParameterIndex(
instructionMetadata
const objectParameterIndex = getObjectParameterIndex(instructionMetadata);
if (objectParameterIndex !== -1) {
return getChosenObjectState(
instruction.getParameter(objectParameterIndex).getPlainString(),
false /* Even if the instruction is invalid for the object, show it as it's what we have already */
);
if (objectParameterIndex !== -1) {
return getChosenObjectState(
instruction.getParameter(objectParameterIndex).getPlainString(),
false /* Even if the instruction is invalid for the object, show it as it's what we have already */
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Props = {|
extension: gdPlatformExtension,
type: string
) => void,
i18n: I18nType,
anchorEl?: any, // Unused
canPasteInstructions: boolean, // Unused
onPasteInstructions: () => void, // Unused
Expand Down Expand Up @@ -102,6 +103,7 @@ const InstructionEditorDialog = ({
onSubmit,
resourceManagementProps,
openInstructionOrExpression,
i18n,
}: Props) => {
const forceUpdate = useForceUpdate();
const [
Expand All @@ -115,6 +117,7 @@ const InstructionEditorDialog = ({
scope,
globalObjectsContainer,
objectsContainer,
i18n,
});
const {
chosenObjectName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { Trans } from '@lingui/macro';
import { I18n } from '@lingui/react';
import { type I18n as I18nType } from '@lingui/core';
import Popover from '@material-ui/core/Popover';
import * as React from 'react';
import { type ResourceManagementProps } from '../../ResourcesList/ResourceSource';
Expand Down Expand Up @@ -50,6 +51,7 @@ type Props = {|
extension: gdPlatformExtension,
type: string
) => void,
i18n: I18nType,
canPasteInstructions: boolean, // Unused
onPasteInstructions: () => void, // Unused
|};
Expand All @@ -72,6 +74,7 @@ const InstructionEditorMenu = ({
onSubmit,
canPasteInstructions,
onPasteInstructions,
i18n,
}: Props) => {
const forceUpdate = useForceUpdate();
const [
Expand All @@ -85,6 +88,7 @@ const InstructionEditorMenu = ({
scope,
globalObjectsContainer,
objectsContainer,
i18n,
});
const {
chosenObjectName,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import React, { Component } from 'react';
import { type I18n as I18nType } from '@lingui/core';
import { enumerateAllExpressions } from '../../../InstructionOrExpression/EnumerateExpressions';
import InstructionOrExpressionSelector from './index';
import {
Expand All @@ -18,6 +19,7 @@ type Props = {|
selectedType: string,
onChoose: (type: string, EnumeratedExpressionMetadata) => void,
scope: EventsScope,
i18n: I18nType,
|};

const style = {
Expand All @@ -28,13 +30,13 @@ const style = {

export default class ExpressionSelector extends Component<Props, {||}> {
instructionsInfo: Array<EnumeratedExpressionMetadata> = filterEnumeratedInstructionOrExpressionMetadataByScope(
enumerateAllExpressions(this.props.expressionType),
enumerateAllExpressions(this.props.expressionType, this.props.i18n),
this.props.scope
);
instructionsInfoTree: ExpressionTreeNode = createTree(this.instructionsInfo);

render() {
const { expressionType, scope, ...otherProps } = this.props;
const { expressionType, scope, i18n, ...otherProps } = this.props;
return (
<InstructionOrExpressionSelector
id="expression-selector"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @flow
import React, { Component } from 'react';
import { I18n } from '@lingui/react';
import { type I18n as I18nType } from '@lingui/core';
import InstructionOrExpressionSelector from './index';
import {
createTree,
Expand All @@ -18,6 +20,7 @@ type Props = {|
selectedType: string,
onChoose: (type: string, EnumeratedInstructionMetadata) => void,
scope: EventsScope,
i18n: I18nType,
|};

const style = {
Expand All @@ -28,13 +31,13 @@ const style = {

export default class InstructionSelector extends Component<Props, {||}> {
instructionsInfo: Array<EnumeratedInstructionMetadata> = filterEnumeratedInstructionOrExpressionMetadataByScope(
enumerateAllInstructions(this.props.isCondition),
enumerateAllInstructions(this.props.isCondition, this.props.i18n),
this.props.scope
);
instructionsInfoTree: InstructionTreeNode = createTree(this.instructionsInfo);

render() {
const { isCondition, scope, ...otherProps } = this.props;
const { isCondition, scope, i18n, ...otherProps } = this.props;
return (
<InstructionOrExpressionSelector
style={style}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
} from '../../InstructionOrExpression/CreateTree';
import {
enumerateAllInstructions,
deduplicateInstructionsList,
enumerateFreeInstructionsWithTranslatedCategories,
enumerateFreeInstructions,
} from '../../InstructionOrExpression/EnumerateInstructions';
import {
type EnumeratedInstructionMetadata,
Expand Down Expand Up @@ -125,10 +124,7 @@ export default class InstructionOrObjectSelector extends React.PureComponent<

// Free instructions, to be displayed in a tab next to the objects.
freeInstructionsInfo: Array<EnumeratedInstructionMetadata> = filterEnumeratedInstructionOrExpressionMetadataByScope(
enumerateFreeInstructionsWithTranslatedCategories(
this.props.isCondition,
this.props.i18n
),
enumerateFreeInstructions(this.props.isCondition, this.props.i18n),
this.props.scope
);
freeInstructionsInfoTree: InstructionOrExpressionTreeNode = createTree(
Expand All @@ -146,10 +142,7 @@ export default class InstructionOrObjectSelector extends React.PureComponent<

reEnumerateInstructions = (i18n: I18nType) => {
this.freeInstructionsInfo = filterEnumeratedInstructionOrExpressionMetadataByScope(
enumerateFreeInstructionsWithTranslatedCategories(
this.props.isCondition,
i18n
),
enumerateFreeInstructions(this.props.isCondition, i18n),
this.props.scope
);
this.freeInstructionsInfoTree = createTree(this.freeInstructionsInfo);
Expand All @@ -159,7 +152,7 @@ export default class InstructionOrObjectSelector extends React.PureComponent<
// All the instructions, to be used when searching, so that the search is done
// across all the instructions (including object and behaviors instructions).
allInstructionsInfo: Array<EnumeratedInstructionMetadata> = filterEnumeratedInstructionOrExpressionMetadataByScope(
enumerateAllInstructions(this.props.isCondition),
enumerateAllInstructions(this.props.isCondition, this.props.i18n),
this.props.scope
);

Expand All @@ -181,16 +174,13 @@ export default class InstructionOrObjectSelector extends React.PureComponent<
),
];

this.instructionSearchApi = new Fuse(
deduplicateInstructionsList(this.allInstructionsInfo),
{
...sharedFuseConfiguration,
keys: [
{ name: 'displayedName', weight: 5 },
{ name: 'fullGroupName', weight: 1 },
],
}
);
this.instructionSearchApi = new Fuse(this.allInstructionsInfo, {
...sharedFuseConfiguration,
keys: [
{ name: 'displayedName', weight: 5 },
{ name: 'fullGroupName', weight: 1 },
],
});
this.objectSearchApi = new Fuse(allObjectsList, {
...sharedFuseConfiguration,
getFn: (item, property) => item.object.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ import {
enumerateObjectExpressions,
} from '../../../InstructionOrExpression/EnumerateExpressions';

// $FlowExpectedError
const makeFakeI18n = (fakeI18n): I18nType => ({
...fakeI18n,
_: message => message.id,
});

describe('FormatExpressionCall', () => {
it('properly formats a free function, with one or more arguments', () => {
const freeExpressions = enumerateFreeExpressions('number|string');
const freeExpressions = enumerateFreeExpressions(
'number|string',
makeFakeI18n()
);
const countExpression = filterExpressions(
freeExpressions,
'PickedInstancesCount'
Expand All @@ -32,7 +41,10 @@ describe('FormatExpressionCall', () => {
});

it('properly formats a free function, with "code-only" parameters', () => {
const freeExpressions = enumerateFreeExpressions('number|string');
const freeExpressions = enumerateFreeExpressions(
'number|string',
makeFakeI18n()
);
const cameraHeightExpression = filterExpressions(
freeExpressions,
'CameraHeight'
Expand All @@ -45,7 +57,10 @@ describe('FormatExpressionCall', () => {
});

it('properly formats a free function, with "code-only" and optional parameters', () => {
const freeExpressions = enumerateFreeExpressions('number|string');
const freeExpressions = enumerateFreeExpressions(
'number|string',
makeFakeI18n()
);
const touchExpression = filterExpressions(freeExpressions, 'TouchX')[0];
expect(
formatExpressionCall(touchExpression, ['', '1'], {
Expand Down
Loading

0 comments on commit 88063a4

Please sign in to comment.