Skip to content

Commit

Permalink
Fix behavior property generation and value.
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H committed Jan 18, 2025
1 parent 4a685db commit 006777b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
29 changes: 17 additions & 12 deletions Core/GDCore/Project/CustomConfigurationHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ void CustomConfigurationHelper::InitializeContent(
gd::SerializerElement &configurationContent) {
for (auto &&property : properties.GetInternalVector()) {
auto &element = configurationContent.AddChild(property->GetName());
auto propertyType = property->GetType();

const auto &primitiveType = gd::ValueTypeMetadata::GetPrimitiveValueType(
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(propertyType));
if (primitiveType == "string") {
const auto &valueType =
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(
property->GetType());
const auto &primitiveType =
gd::ValueTypeMetadata::GetPrimitiveValueType(valueType);
if (primitiveType == "string" || valueType == "behavior") {
element.SetStringValue(property->GetValue());
} else if (primitiveType == "number") {
element.SetDoubleValue(property->GetValue().To<double>());
Expand All @@ -43,17 +45,19 @@ std::map<gd::String, gd::PropertyDescriptor> CustomConfigurationHelper::GetPrope

for (auto &property : properties.GetInternalVector()) {
const auto &propertyName = property->GetName();
const auto &propertyType = property->GetType();

// Copy the property
objectProperties[propertyName] = *property;

auto &newProperty = objectProperties[propertyName];

const auto &primitiveType = gd::ValueTypeMetadata::GetPrimitiveValueType(
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(propertyType));
const auto &valueType =
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(
property->GetType());
const auto &primitiveType =
gd::ValueTypeMetadata::GetPrimitiveValueType(valueType);
if (configurationContent.HasChild(propertyName)) {
if (primitiveType == "string") {
if (primitiveType == "string" || valueType == "behavior") {
newProperty.SetValue(
configurationContent.GetChild(propertyName).GetStringValue());
} else if (primitiveType == "number") {
Expand Down Expand Up @@ -85,11 +89,12 @@ bool CustomConfigurationHelper::UpdateProperty(
const auto &property = properties.Get(propertyName);

auto &element = configurationContent.AddChild(propertyName);
const gd::String &propertyType = property.GetType();

const auto &primitiveType = gd::ValueTypeMetadata::GetPrimitiveValueType(
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(propertyType));
if (primitiveType == "string") {
const auto &valueType =
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(property.GetType());
const auto &primitiveType =
gd::ValueTypeMetadata::GetPrimitiveValueType(valueType);
if (primitiveType == "string" || valueType == "behavior") {
element.SetStringValue(newValue);
} else if (primitiveType == "number") {
element.SetDoubleValue(newValue.To<double>());
Expand Down
9 changes: 5 additions & 4 deletions GDJS/GDJS/Events/CodeGeneration/BehaviorCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,11 @@ gd::String BehaviorCodeGenerator::GenerateUpdatePropertyFromNetworkSyncDataCode(
gd::String BehaviorCodeGenerator::GeneratePropertyValueCode(
const gd::PropertyDescriptor& property) {

const auto &primitiveType = gd::ValueTypeMetadata::GetPrimitiveValueType(
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(
property.GetType()));
if (primitiveType == "string") {
const auto &valueType =
gd::ValueTypeMetadata::ConvertPropertyTypeToValueType(property.GetType());
const auto &primitiveType =
gd::ValueTypeMetadata::GetPrimitiveValueType(valueType);
if (primitiveType == "string" || valueType == "behavior") {
return EventsCodeGenerator::ConvertToStringExplicit(property.GetValue());
} else if (primitiveType == "number") {
return "Number(" +
Expand Down

0 comments on commit 006777b

Please sign in to comment.