-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathChildObjectPropertiesEditor.js
More file actions
105 lines (97 loc) · 3.4 KB
/
ChildObjectPropertiesEditor.js
File metadata and controls
105 lines (97 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// @flow
import * as React from 'react';
import { Trans } from '@lingui/macro';
import { CompactPropertiesEditorByVisibility } from '../../CompactPropertiesEditor/CompactPropertiesEditorByVisibility';
import propertiesMapToSchema from '../../PropertiesEditor/PropertiesMapToSchema';
import { type ResourceManagementProps } from '../../ResourcesList/ResourceSource';
import { type UnsavedChanges } from '../../MainFrame/UnsavedChangesContext';
import { ColumnStackLayout } from '../../UI/Layout';
import { getSchemaWithOpenFullEditorButton } from './CompactObjectPropertiesSchema';
import { useForceRecompute } from '../../Utils/UseForceUpdate';
const gd: libGDevelop = global.gd;
type Props = {|
project: gdProject,
resourceManagementProps: ResourceManagementProps,
unsavedChanges?: ?UnsavedChanges,
customObjectConfiguration: gdCustomObjectConfiguration,
childObject: gdObject,
onEditObject: () => void,
|};
export const ChildObjectPropertiesEditor = ({
project,
resourceManagementProps,
unsavedChanges,
customObjectConfiguration,
childObject,
onEditObject,
}: Props): React.Node => {
// Don't use a memo for this because metadata from custom objects are built
// from event-based object when extensions are refreshed after an extension
// installation.
const objectMetadata = gd.MetadataProvider.getObjectMetadata(
project.getCurrentPlatform(),
childObject.getType()
);
const fullEditorLabel = objectMetadata
? objectMetadata.getOpenFullEditorLabel()
: null;
const childObjectConfiguration = customObjectConfiguration.getChildObjectConfiguration(
childObject.getName()
);
const childObjectConfigurationAsGd = gd.castObject(
// $FlowFixMe[incompatible-exact]
childObjectConfiguration,
gd.ObjectConfiguration
);
const [schemaRecomputeTrigger, forceRecomputeSchema] = useForceRecompute();
// Properties:
const schema = React.useMemo(
() => {
if (schemaRecomputeTrigger) {
// schemaRecomputeTrigger allows to invalidate the schema when required.
}
return propertiesMapToSchema({
properties: childObjectConfigurationAsGd.getProperties(),
defaultValueProperties: null,
getPropertyValue: ({ object, objectConfiguration }, name) =>
objectConfiguration
.getProperties()
.get(name)
.getValue(),
onUpdateProperty: ({ object, objectConfiguration }, name, value) =>
objectConfiguration.updateProperty(name, value),
visibility: 'All',
});
},
[schemaRecomputeTrigger, childObjectConfigurationAsGd]
);
return (
<ColumnStackLayout noMargin noOverflowParent>
<CompactPropertiesEditorByVisibility
project={project}
resourceManagementProps={resourceManagementProps}
unsavedChanges={unsavedChanges}
schema={schema}
instances={[
{
object: childObject,
objectConfiguration: childObjectConfigurationAsGd,
},
]}
onInstancesModified={() => {
// TODO: undo/redo?
}}
onRefreshAllFields={forceRecomputeSchema}
placeholder={<Trans>This object has no properties.</Trans>}
customizeBasicSchema={schema =>
getSchemaWithOpenFullEditorButton({
schema,
fullEditorLabel,
object: childObject,
onEditObject,
})
}
/>
</ColumnStackLayout>
);
};