Skip to content

Commit

Permalink
Fix getter and setter generation for animation properties (#7307)
Browse files Browse the repository at this point in the history
- Don't show in changelog
  • Loading branch information
D8H authored Jan 14, 2025
1 parent 4be2386 commit 2638c4f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 38 deletions.
5 changes: 4 additions & 1 deletion Core/GDCore/Extensions/Metadata/ValueTypeMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const gd::String ValueTypeMetadata::colorValueType = "color";
const gd::String ValueTypeMetadata::choiceValueType = "stringWithSelector";
const gd::String ValueTypeMetadata::behaviorValueType = "behavior";
const gd::String ValueTypeMetadata::leaderboardIdValueType = "leaderboardId";
const gd::String ValueTypeMetadata::objectAnimationNameValueType = "objectAnimationName";

const gd::String &ValueTypeMetadata::ConvertPropertyTypeToValueType(
const gd::String &propertyType) {
Expand All @@ -94,8 +95,10 @@ const gd::String &ValueTypeMetadata::ConvertPropertyTypeToValueType(
return behaviorValueType;
} else if (propertyType == "LeaderboardId") {
return leaderboardIdValueType;
} else if (propertyType == "ObjectAnimationName") {
return objectAnimationNameValueType;
}
// For "String" or default
// For "String", "Resource" or default
return stringValueType;
};

Expand Down
1 change: 1 addition & 0 deletions Core/GDCore/Extensions/Metadata/ValueTypeMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ class GD_CORE_API ValueTypeMetadata {
static const gd::String choiceValueType;
static const gd::String behaviorValueType;
static const gd::String leaderboardIdValueType;
static const gd::String objectAnimationNameValueType;
};

} // namespace gd
Expand Down
8 changes: 5 additions & 3 deletions Core/GDCore/IDE/PropertyFunctionGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,11 @@ void PropertyFunctionGenerator::GenerateGetterAndSetter(
bool PropertyFunctionGenerator::CanGenerateGetterAndSetter(
const gd::AbstractEventsBasedEntity &eventsBasedEntity,
const gd::NamedPropertyDescriptor &property) {
auto &type = property.GetType();
if (type != "Boolean" && type != "Number" && type != "String" &&
type != "Choice" && type != "Color" && type != "LeaderboardId") {
const auto &primitiveType = gd::ValueTypeMetadata::GetPrimitiveValueType(
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(
property.GetType()));
if (primitiveType != "boolean" && primitiveType != "number" &&
primitiveType != "string") {
return false;
}

Expand Down
22 changes: 10 additions & 12 deletions Core/GDCore/Project/CustomConfigurationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,16 @@ std::map<gd::String, gd::PropertyDescriptor> CustomConfigurationHelper::GetPrope

auto &newProperty = objectProperties[propertyName];

const auto &primitiveType = gd::ValueTypeMetadata::GetPrimitiveValueType(
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(propertyType));
if (configurationContent.HasChild(propertyName)) {
if (propertyType == "String" || propertyType == "Choice" ||
propertyType == "Color" || propertyType == "Behavior" ||
propertyType == "Resource" || propertyType == "LeaderboardId" ||
propertyType == "AnimationName") {
if (primitiveType == "string") {
newProperty.SetValue(
configurationContent.GetChild(propertyName).GetStringValue());
} else if (propertyType == "Number") {
} else if (primitiveType == "number") {
newProperty.SetValue(gd::String::From(
configurationContent.GetChild(propertyName).GetDoubleValue()));
} else if (propertyType == "Boolean") {
} else if (primitiveType == "boolean") {
newProperty.SetValue(
configurationContent.GetChild(propertyName).GetBoolValue()
? "true"
Expand Down Expand Up @@ -88,14 +87,13 @@ bool CustomConfigurationHelper::UpdateProperty(
auto &element = configurationContent.AddChild(propertyName);
const gd::String &propertyType = property.GetType();

if (propertyType == "String" || propertyType == "Choice" ||
propertyType == "Color" || propertyType == "Behavior" ||
propertyType == "Resource" || propertyType == "LeaderboardId" ||
propertyType == "AnimationName") {
const auto &primitiveType = gd::ValueTypeMetadata::GetPrimitiveValueType(
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(propertyType));
if (primitiveType == "string") {
element.SetStringValue(newValue);
} else if (propertyType == "Number") {
} else if (primitiveType == "number") {
element.SetDoubleValue(newValue.To<double>());
} else if (propertyType == "Boolean") {
} else if (primitiveType == "boolean") {
element.SetBoolValue(newValue == "1");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const createField = (
getDescription,
hasImpactOnAllOtherFields: property.hasImpactOnOtherProperties(),
};
} else if (valueType === 'animationname') {
} else if (valueType === 'objectanimationname') {
return {
getChoices: () => {
if (!object) {
Expand All @@ -245,13 +245,12 @@ const createField = (
object.getConfiguration().getAnimationsCount(),
i => {
const animationName = object.getConfiguration().getAnimationName(i);
if (animationName === '') {
return null;
}
return {
value: animationName,
label: animationName,
};
return animationName === ''
? null
: {
value: animationName,
label: animationName,
};
}
).filter(Boolean);
animationArray.push({ value: '', label: '(no animation)' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,11 +729,6 @@ export default function EventsBasedBehaviorPropertiesEditor({
value="Boolean"
label={t`Boolean (checkbox)`}
/>
<SelectOption
key="property-type-animationname"
value="AnimationName"
label={t`Animation name (text)`}
/>
<SelectOption
key="property-type-choice"
value="Choice"
Expand All @@ -744,6 +739,11 @@ export default function EventsBasedBehaviorPropertiesEditor({
value="Color"
label={t`Color (text)`}
/>
<SelectOption
key="property-type-object-animation-name"
value="ObjectAnimationName"
label={t`Object animation (text)`}
/>
<SelectOption
key="property-type-resource"
value="Resource"
Expand Down Expand Up @@ -809,7 +809,7 @@ export default function EventsBasedBehaviorPropertiesEditor({
{(property.getType() === 'String' ||
property.getType() === 'Number' ||
property.getType() ===
'AnimationName') && (
'ObjectAnimationName') && (
<SemiControlledTextField
commitOnBlur
floatingLabelText={
Expand Down
15 changes: 7 additions & 8 deletions newIDE/app/src/PropertiesEditor/PropertiesMapToSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ const createField = (
getLabel,
getDescription,
};
} else if (valueType === 'animationname') {
} else if (valueType === 'objectanimationname') {
return {
getChoices: () => {
if (!object) {
Expand All @@ -231,13 +231,12 @@ const createField = (
object.getConfiguration().getAnimationsCount(),
i => {
const animationName = object.getConfiguration().getAnimationName(i);
if (animationName === '') {
return null;
}
return {
value: animationName,
label: animationName,
};
return animationName === ''
? null
: {
value: animationName,
label: animationName,
};
}
).filter(Boolean);
animationArray.push({ value: '', label: '(no animation)' });
Expand Down

0 comments on commit 2638c4f

Please sign in to comment.