fix(autogen): set property function return error even when value does get set
This commit is contained in:
parent
b9c8022f6f
commit
ec65c6eddc
3 changed files with 31 additions and 12 deletions
|
@ -5,11 +5,11 @@
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
std::map<std::string, std::string> CATEGORY_STR = {
|
std::map<std::string, std::string> CATEGORY_STR = {
|
||||||
{ "appearance", "PROP_CATEGORY_APPEARENCE" },
|
{ "APPEARANCE", "PROP_CATEGORY_APPEARENCE" },
|
||||||
{ "data", "PROP_CATEGORY_DATA" },
|
{ "DATA", "PROP_CATEGORY_DATA" },
|
||||||
{ "behavior", "PROP_CATEGORY_BEHAVIOR" },
|
{ "BEHAVIOR", "PROP_CATEGORY_BEHAVIOR" },
|
||||||
{ "part", "PROP_CATEGORY_PART" },
|
{ "PART", "PROP_CATEGORY_PART" },
|
||||||
{ "surface", "PROP_CATEGORY_SURFACE" },
|
{ "SURFACE", "PROP_CATEGORY_SURFACE" },
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<std::string, std::string> MAPPED_TYPE = {
|
std::map<std::string, std::string> MAPPED_TYPE = {
|
||||||
|
@ -91,9 +91,17 @@ void writePropertySetHandler(std::ofstream& out, ClassAnalysis state) {
|
||||||
out << "\n }";
|
out << "\n }";
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
out << "\n return " << state.baseClass << "::InternalSetPropertyValue(name, value);";
|
// If it's empty, just return the parent's impl
|
||||||
// out << "\n return MemberNotFound(\"" << state.name << "\", name);";
|
if (state.properties.empty()) {
|
||||||
|
out << "\n return " << state.baseClass << "::InternalSetPropertyValue(name, value);";
|
||||||
|
} else {
|
||||||
|
// Otherwise, add else and return
|
||||||
|
out << "else {";
|
||||||
|
out << "\n return " << state.baseClass << "::InternalSetPropertyValue(name, value);";
|
||||||
|
out << "\n }";
|
||||||
|
out << "\n return {};";
|
||||||
|
}
|
||||||
|
|
||||||
out << "\n};\n\n";
|
out << "\n};\n\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,6 +211,17 @@ result<Data::Variant, MemberNotFound> Instance::InternalGetPropertyValue(std::st
|
||||||
return MemberNotFound(GetClass()->className, name);
|
return MemberNotFound(GetClass()->className, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result<PropertyMeta, MemberNotFound> Instance::InternalGetPropertyMeta(std::string name) {
|
||||||
|
if (name == "Name") {
|
||||||
|
return PropertyMeta { &Data::String::TYPE };
|
||||||
|
} else if (name == "Parent") {
|
||||||
|
return PropertyMeta { &Data::InstanceRef::TYPE, };
|
||||||
|
} else if (name == "ClassName") {
|
||||||
|
return PropertyMeta { &Data::String::TYPE, PROP_NOSAVE | PROP_READONLY };
|
||||||
|
}
|
||||||
|
return MemberNotFound(GetClass()->className, name);
|
||||||
|
}
|
||||||
|
|
||||||
fallible<MemberNotFound, AssignToReadOnlyMember> Instance::InternalSetPropertyValue(std::string name, Data::Variant value) {
|
fallible<MemberNotFound, AssignToReadOnlyMember> Instance::InternalSetPropertyValue(std::string name, Data::Variant value) {
|
||||||
if (name == "Name") {
|
if (name == "Name") {
|
||||||
this->name = (std::string)value.get<Data::String>();
|
this->name = (std::string)value.get<Data::String>();
|
||||||
|
@ -219,8 +230,10 @@ fallible<MemberNotFound, AssignToReadOnlyMember> Instance::InternalSetPropertyVa
|
||||||
SetParent(ref.expired() ? std::nullopt : std::make_optional(ref.lock()));
|
SetParent(ref.expired() ? std::nullopt : std::make_optional(ref.lock()));
|
||||||
} else if (name == "ClassName") {
|
} else if (name == "ClassName") {
|
||||||
return AssignToReadOnlyMember(GetClass()->className, name);
|
return AssignToReadOnlyMember(GetClass()->className, name);
|
||||||
|
} else {
|
||||||
|
return MemberNotFound(GetClass()->className, name);
|
||||||
}
|
}
|
||||||
return MemberNotFound(GetClass()->className, name);
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> Instance::InternalGetProperties() {
|
std::vector<std::string> Instance::InternalGetProperties() {
|
||||||
|
@ -231,8 +244,6 @@ std::vector<std::string> Instance::InternalGetProperties() {
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
result<PropertyMeta, MemberNotFound> Instance::InternalGetPropertyMeta(std::string name) { return MemberNotFound(GetClass()->className, name); }
|
|
||||||
|
|
||||||
void Instance::UpdateProperty(std::string name) {
|
void Instance::UpdateProperty(std::string name) {
|
||||||
// TODO: temporary workaround because I'm too lazy to implement this in autogen
|
// TODO: temporary workaround because I'm too lazy to implement this in autogen
|
||||||
InternalSetPropertyValue(name, InternalGetPropertyValue(name).expect()).expect();
|
InternalSetPropertyValue(name, InternalGetPropertyValue(name).expect()).expect();
|
||||||
|
|
|
@ -75,7 +75,7 @@ Here are its parameters:
|
||||||
- `hidden` - Flag, marks the property as hidden from the editor.
|
- `hidden` - Flag, marks the property as hidden from the editor.
|
||||||
- `no_save` - Flag, the property should not be deserialized nor serialized
|
- `no_save` - Flag, the property should not be deserialized nor serialized
|
||||||
- `readonly` - Flag, the property cannot be assigned to
|
- `readonly` - Flag, the property cannot be assigned to
|
||||||
- `category` - Option, the category the property will appear in in the editor. Accepted values are: `data` (default), `apparance`, `part`, `behavior`, `surface`
|
- `category` - Option, the category the property will appear in in the editor. Accepted values are: `DATA` (default), `APPEARANCE`, `PART`, `BEHAVIOR`, `SURFACE`
|
||||||
- `on_update` - Option, callback to call after the property has been assigned to. Should accept a std::string containing the property name and return void
|
- `on_update` - Option, callback to call after the property has been assigned to. Should accept a std::string containing the property name and return void
|
||||||
|
|
||||||
The type of the property, and conversion to and from it and the datatype system is automatically inferred. `std::string` is interpreted as `Data::String`, and `std::weak_ptr<T>` is also converted to/from `Data::InstanceRef`. In the future, if weird edge-case types are introduced, the code generator may need to be extended. See [Extending Autogen](#extending-autogen)
|
The type of the property, and conversion to and from it and the datatype system is automatically inferred. `std::string` is interpreted as `Data::String`, and `std::weak_ptr<T>` is also converted to/from `Data::InstanceRef`. In the future, if weird edge-case types are introduced, the code generator may need to be extended. See [Extending Autogen](#extending-autogen)
|
||||||
|
|
Loading…
Add table
Reference in a new issue