ScriptComponentFile.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Copyright (c) 2014-2016, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Resource/Resource.h"
  24. #include "../Core/Variant.h"
  25. namespace Atomic
  26. {
  27. struct FieldInfo
  28. {
  29. FieldInfo()
  30. {
  31. name_ = "UNINITIALIZED_FIELDINFO";
  32. variantType_ = VAR_NONE;
  33. isArray_ = false;
  34. fixedArraySize_ = 0;
  35. }
  36. FieldInfo(const String& name, VariantType variantType, const String& resourceTypeName = String::EMPTY, bool isArray = false, unsigned fixedArraySize = 0)
  37. {
  38. name_ = name;
  39. variantType_ = variantType;
  40. resourceTypeName_ = resourceTypeName;
  41. isArray_ = isArray;
  42. fixedArraySize_ = fixedArraySize;
  43. }
  44. String name_;
  45. VariantType variantType_;
  46. // for resource ref variants
  47. String resourceTypeName_;
  48. bool isArray_;
  49. unsigned fixedArraySize_;
  50. };
  51. struct EnumInfo
  52. {
  53. EnumInfo(const String& name = String::EMPTY, const Variant& v = Variant::EMPTY)
  54. {
  55. name_ = name;
  56. value_ = v;
  57. }
  58. String name_;
  59. Variant value_;
  60. };
  61. // TODO: these should be broken out into some class info structs, getting unwieldy
  62. typedef HashMap<String, FieldInfo> FieldMap;
  63. typedef HashMap<String, Vector<EnumInfo>> EnumMap;
  64. typedef HashMap<String, String> FieldTooltipMap;
  65. typedef HashMap<StringHash, FieldMap> ClassFieldMap;
  66. typedef HashMap<StringHash, FieldTooltipMap> ClassFieldTooltipMap;
  67. typedef HashMap<StringHash, EnumMap> ClassEnumMap;
  68. typedef HashMap<StringHash, VariantMap> ClassDefaultValueMap;
  69. /// NET Assembly resource.
  70. class ATOMIC_API ScriptComponentFile : public Resource
  71. {
  72. ATOMIC_OBJECT(ScriptComponentFile, Resource)
  73. public:
  74. /// Construct.
  75. ScriptComponentFile(Context* context);
  76. /// Destruct.
  77. virtual ~ScriptComponentFile();
  78. static void RegisterObject(Context* context);
  79. /// Only valid in editor, as we don't inspect classnames at runtime
  80. virtual const Vector<String>& GetClassNames() { return classNames_; }
  81. const EnumMap& GetEnums(const String& classname = String::EMPTY) const;
  82. const FieldMap& GetFields(const String& classname = String::EMPTY) const;
  83. const FieldTooltipMap& GetFieldTooltips(const String& classname = String::EMPTY) const;
  84. const VariantMap& GetDefaultFieldValues(const String& classname = String::EMPTY) const;
  85. void GetDefaultFieldValue(const String& name, Variant& v,const String& classname = String::EMPTY) const;
  86. protected:
  87. void Clear();
  88. void AddEnum(const String& enumName, const EnumInfo& enumInfo, const String& classname = String::EMPTY);
  89. void AddField(const String& fieldName, VariantType variantType, const String& resourceTypeName = String::EMPTY, bool isArray = false, unsigned fixedArraySize = 0, const String& classname = String::EMPTY, const String& tooltip = String::EMPTY);
  90. void AddDefaultValue(const String& fieldName, const Variant& value, const String& classname = String::EMPTY);
  91. // only valid in editor
  92. Vector<String> classNames_;
  93. private:
  94. ClassFieldMap classFields_;
  95. ClassFieldTooltipMap classFieldTooltips_;
  96. ClassDefaultValueMap classDefaultFieldValues_;
  97. ClassEnumMap classEnums_;
  98. static FieldMap emptyFieldMap_;
  99. static FieldTooltipMap emptyFieldTooltipMap_;
  100. static EnumMap emptyEnumMap_;
  101. static VariantMap emptyDefaultValueMap_;
  102. };
  103. }