RecipieGroupConfig.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "RecipieGroupConfig.h"
  2. #include "Game.h"
  3. RecipieGroupConfig::RecipieGroupConfig()
  4. : Framework::ReferenceCounter()
  5. {}
  6. void RecipieGroupConfig::setGroupName(const Framework::Text& groupName)
  7. {
  8. this->groupName = groupName;
  9. }
  10. const Framework::Text& RecipieGroupConfig::getGroupName() const
  11. {
  12. return groupName;
  13. }
  14. void RecipieGroupConfig::setIconItemType(const Framework::Text& iconItemType)
  15. {
  16. this->iconItemType = iconItemType;
  17. }
  18. const Framework::Text& RecipieGroupConfig::getIconItemType() const
  19. {
  20. return iconItemType;
  21. }
  22. RecipieGroupConfigFactory::RecipieGroupConfigFactory()
  23. : ObjectTypeFactory<RecipieGroupConfig>()
  24. {}
  25. RecipieGroupConfig* RecipieGroupConfigFactory::fromJson(
  26. Framework::JSON::JSONObject* zJson) const
  27. {
  28. RecipieGroupConfig* config = new RecipieGroupConfig();
  29. config->setGroupName(zJson->zValue("groupName")->asString()->getString());
  30. config->setIconItemType(
  31. zJson->zValue("iconItemType")->asString()->getString());
  32. return config;
  33. }
  34. Framework::JSON::JSONObject* RecipieGroupConfigFactory::toJsonObject(
  35. RecipieGroupConfig* zObject) const
  36. {
  37. Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
  38. result->addValue("groupName",
  39. new Framework::JSON::JSONString(zObject->getGroupName().getText()));
  40. result->addValue("iconItemType",
  41. new Framework::JSON::JSONString(zObject->getIconItemType().getText()));
  42. return result;
  43. }
  44. JSONObjectValidationBuilder* RecipieGroupConfigFactory::addToValidator(
  45. JSONObjectValidationBuilder* builder) const
  46. {
  47. return builder->withRequiredString("groupName")
  48. ->finishString()
  49. ->withRequiredAttribute("iconItemType",
  50. Game::INSTANCE->zTypeRegistry()->getValidator<Framework::Text>(
  51. ItemTypeNameFactory::TYPE_ID));
  52. }