Skip to content

Commit

Permalink
Allow using resources as behavior properties (#5256)
Browse files Browse the repository at this point in the history
Only show in developer changelog
  • Loading branch information
arthuro555 authored Nov 22, 2023
1 parent 1ac248b commit 4ee9ccd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
18 changes: 11 additions & 7 deletions Core/GDCore/Project/CustomConfigurationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
#include "CustomConfigurationHelper.h"

#include <map>

#include "GDCore/IDE/Project/ArbitraryResourceWorker.h"
#include "GDCore/Project/Behavior.h"
#include "GDCore/Project/Project.h"
Expand All @@ -13,8 +15,6 @@
#include "GDCore/Serialization/Serializer.h"
#include "GDCore/Serialization/SerializerElement.h"

#include <map>

using namespace gd;

void CustomConfigurationHelper::InitializeContent(
Expand All @@ -25,7 +25,8 @@ void CustomConfigurationHelper::InitializeContent(
auto propertyType = property->GetType();

if (propertyType == "String" || propertyType == "Choice" ||
propertyType == "Color" || propertyType == "Behavior") {
propertyType == "Color" || propertyType == "Behavior" ||
propertyType == "resource") {
element.SetStringValue(property->GetValue());
} else if (propertyType == "Number") {
element.SetDoubleValue(property->GetValue().To<double>());
Expand All @@ -51,16 +52,18 @@ std::map<gd::String, gd::PropertyDescriptor> CustomConfigurationHelper::GetPrope

if (configurationContent.HasChild(propertyName)) {
if (propertyType == "String" || propertyType == "Choice" ||
propertyType == "Color" || propertyType == "Behavior") {
propertyType == "Color" || propertyType == "Behavior" ||
propertyType == "resource") {
newProperty.SetValue(
configurationContent.GetChild(propertyName).GetStringValue());
} else if (propertyType == "Number") {
newProperty.SetValue(gd::String::From(
configurationContent.GetChild(propertyName).GetDoubleValue()));
} else if (propertyType == "Boolean") {
newProperty.SetValue(
configurationContent.GetChild(propertyName).GetBoolValue() ? "true"
: "false");
configurationContent.GetChild(propertyName).GetBoolValue()
? "true"
: "false");
}
} else {
// No value was serialized for this property. `newProperty`
Expand All @@ -85,7 +88,8 @@ bool CustomConfigurationHelper::UpdateProperty(
const gd::String &propertyType = property.GetType();

if (propertyType == "String" || propertyType == "Choice" ||
propertyType == "Color" || propertyType == "Behavior") {
propertyType == "Color" || propertyType == "Behavior" ||
propertyType == "resource") {
element.SetStringValue(newValue);
} else if (propertyType == "Number") {
element.SetDoubleValue(newValue.To<double>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ type Props = BehaviorEditorProps;

export default class BehaviorPropertiesEditor extends React.Component<Props> {
render() {
const { behavior, object, onBehaviorUpdated } = this.props;
const {
project,
behavior,
object,
onBehaviorUpdated,
resourceManagementProps,
} = this.props;

const propertiesSchema = propertiesMapToSchema(
behavior.getProperties(),
Expand All @@ -27,9 +33,11 @@ export default class BehaviorPropertiesEditor extends React.Component<Props> {
<Column expand>
{propertiesSchema.length ? (
<PropertiesEditor
project={project}
schema={propertiesSchema}
instances={[behavior]}
onInstancesModified={onBehaviorUpdated}
resourceManagementProps={resourceManagementProps}
/>
) : (
<EmptyMessage>
Expand Down

0 comments on commit 4ee9ccd

Please sign in to comment.