diff --git a/autogen/src/codegen.cpp b/autogen/src/codegen.cpp index f5b8c1c..0cc0934 100644 --- a/autogen/src/codegen.cpp +++ b/autogen/src/codegen.cpp @@ -5,11 +5,11 @@ #include std::map CATEGORY_STR = { - { "appearance", "PROP_CATEGORY_APPEARENCE" }, - { "data", "PROP_CATEGORY_DATA" }, - { "behavior", "PROP_CATEGORY_BEHAVIOR" }, - { "part", "PROP_CATEGORY_PART" }, - { "surface", "PROP_CATEGORY_SURFACE" }, + { "APPEARANCE", "PROP_CATEGORY_APPEARENCE" }, + { "DATA", "PROP_CATEGORY_DATA" }, + { "BEHAVIOR", "PROP_CATEGORY_BEHAVIOR" }, + { "PART", "PROP_CATEGORY_PART" }, + { "SURFACE", "PROP_CATEGORY_SURFACE" }, }; std::map MAPPED_TYPE = { @@ -91,9 +91,17 @@ void writePropertySetHandler(std::ofstream& out, ClassAnalysis state) { out << "\n }"; first = false; } - - out << "\n return " << state.baseClass << "::InternalSetPropertyValue(name, value);"; - // out << "\n return MemberNotFound(\"" << state.name << "\", name);"; + + // If it's empty, just return the parent's impl + 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"; } diff --git a/core/src/objects/base/instance.cpp b/core/src/objects/base/instance.cpp index 7fcf768..5d37592 100644 --- a/core/src/objects/base/instance.cpp +++ b/core/src/objects/base/instance.cpp @@ -211,6 +211,17 @@ result Instance::InternalGetPropertyValue(std::st return MemberNotFound(GetClass()->className, name); } +result 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 Instance::InternalSetPropertyValue(std::string name, Data::Variant value) { if (name == "Name") { this->name = (std::string)value.get(); @@ -219,8 +230,10 @@ fallible Instance::InternalSetPropertyVa SetParent(ref.expired() ? std::nullopt : std::make_optional(ref.lock())); } else if (name == "ClassName") { return AssignToReadOnlyMember(GetClass()->className, name); + } else { + return MemberNotFound(GetClass()->className, name); } - return MemberNotFound(GetClass()->className, name); + return {}; } std::vector Instance::InternalGetProperties() { @@ -231,8 +244,6 @@ std::vector Instance::InternalGetProperties() { return members; } -result Instance::InternalGetPropertyMeta(std::string name) { return MemberNotFound(GetClass()->className, name); } - void Instance::UpdateProperty(std::string name) { // TODO: temporary workaround because I'm too lazy to implement this in autogen InternalSetPropertyValue(name, InternalGetPropertyValue(name).expect()).expect(); diff --git a/docs/autogen.md b/docs/autogen.md index b396e22..825381b 100644 --- a/docs/autogen.md +++ b/docs/autogen.md @@ -75,7 +75,7 @@ Here are its parameters: - `hidden` - Flag, marks the property as hidden from the editor. - `no_save` - Flag, the property should not be deserialized nor serialized - `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 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` 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)