UIReference.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #include "UIReference.h"
  2. #include "Block.h"
  3. #include "Entity.h"
  4. UIReference::UIReference()
  5. : Framework::ReferenceCounter()
  6. {}
  7. UITargetReference::UITargetReference()
  8. : UIReference()
  9. {}
  10. Framework::Text UITargetReference::getReferenceId(
  11. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  12. {
  13. Framework::Text result("");
  14. if (zTarget.isA())
  15. {
  16. result.append() << zTarget.getA()->getDimensionId() << ","
  17. << zTarget.getA()->getPos().x << ","
  18. << zTarget.getA()->getPos().y << ","
  19. << zTarget.getA()->getPos().z;
  20. }
  21. else
  22. {
  23. result.append() << zTarget.getB()->getId();
  24. }
  25. return result;
  26. }
  27. UITargetComponentReference::UITargetComponentReference()
  28. : UIReference(),
  29. componentIndex(0)
  30. {}
  31. Framework::Text UITargetComponentReference::getReferenceId(
  32. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  33. {
  34. Framework::Text result("");
  35. if (zTarget.isA())
  36. {
  37. result.append() << zTarget.getA()->getDimensionId() << ","
  38. << zTarget.getA()->getPos().x << ","
  39. << zTarget.getA()->getPos().y << ","
  40. << zTarget.getA()->getPos().z;
  41. }
  42. else
  43. {
  44. result.append() << zTarget.getB()->getId();
  45. }
  46. result.append() << ":" << componentIndex;
  47. return result;
  48. }
  49. UITActorReference::UITActorReference()
  50. : UIReference()
  51. {}
  52. Framework::Text UITActorReference::getReferenceId(
  53. Framework::Either<Block*, Entity*> zTarget, Entity* zActor) const
  54. {
  55. return Framework::Text(zActor->getId());
  56. }
  57. UITargetReferenceFactory::UITargetReferenceFactory()
  58. : SubTypeFactory<UIReference, UITargetReference>()
  59. {}
  60. JSONObjectValidationBuilder* UITargetReferenceFactory::addToValidator(
  61. JSONObjectValidationBuilder* builder) const
  62. {
  63. return builder;
  64. }
  65. UITargetReference* UITargetReferenceFactory::fromJson(
  66. Framework::JSON::JSONObject* zJson) const
  67. {
  68. return new UITargetReference();
  69. }
  70. Framework::JSON::JSONObject* UITargetReferenceFactory::toJsonObject(
  71. UITargetReference* zObject) const
  72. {
  73. return new Framework::JSON::JSONObject();
  74. }
  75. const char* UITargetReferenceFactory::getTypeToken() const
  76. {
  77. return "target";
  78. }
  79. UITActorReferenceFactory::UITActorReferenceFactory()
  80. : SubTypeFactory<UIReference, UITActorReference>()
  81. {}
  82. JSONObjectValidationBuilder* UITActorReferenceFactory::addToValidator(
  83. JSONObjectValidationBuilder* builder) const
  84. {
  85. return builder;
  86. }
  87. UITActorReference* UITActorReferenceFactory::fromJson(
  88. Framework::JSON::JSONObject* zJson) const
  89. {
  90. return new UITActorReference();
  91. }
  92. Framework::JSON::JSONObject* UITActorReferenceFactory::toJsonObject(
  93. UITActorReference* zObject) const
  94. {
  95. return new Framework::JSON::JSONObject();
  96. }
  97. const char* UITActorReferenceFactory::getTypeToken() const
  98. {
  99. return "actor";
  100. }
  101. UITargetComponentReferenceFactory::UITargetComponentReferenceFactory()
  102. : SubTypeFactory<UIReference, UITargetComponentReference>()
  103. {}
  104. JSONObjectValidationBuilder* UITargetComponentReferenceFactory::addToValidator(
  105. JSONObjectValidationBuilder* builder) const
  106. {
  107. return builder->withRequiredNumber("componentIndex")
  108. ->whichIsGreaterOrEqual(0)
  109. ->finishNumber();
  110. }
  111. UITargetComponentReference* UITargetComponentReferenceFactory::fromJson(
  112. Framework::JSON::JSONObject* zJson) const
  113. {
  114. UITargetComponentReference* result = new UITargetComponentReference();
  115. result->componentIndex
  116. = (int)zJson->zValue("componentIndex")->asNumber()->getNumber();
  117. return result;
  118. }
  119. Framework::JSON::JSONObject* UITargetComponentReferenceFactory::toJsonObject(
  120. UITargetComponentReference* zObject) const
  121. {
  122. Framework::JSON::JSONObject* result = new Framework::JSON::JSONObject();
  123. result->addValue("componentIndex",
  124. new Framework::JSON::JSONNumber(zObject->componentIndex));
  125. return result;
  126. }
  127. const char* UITargetComponentReferenceFactory::getTypeToken() const
  128. {
  129. return "targetComponent";
  130. }