ScriptComponentFile.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. isEnum_ = false;
  35. fixedArraySize_ = 0;
  36. }
  37. FieldInfo(const String& name, VariantType variantType, const String& resourceTypeName = String::EMPTY, bool isArray = false, bool isEnum = false, unsigned fixedArraySize = 0)
  38. {
  39. name_ = name;
  40. variantType_ = variantType;
  41. resourceTypeName_ = resourceTypeName;
  42. isArray_ = isArray;
  43. isEnum_ = isEnum;
  44. fixedArraySize_ = fixedArraySize;
  45. // register field name as significant, for serialization
  46. StringHash::RegisterSignificantString(name);
  47. }
  48. String name_;
  49. VariantType variantType_;
  50. // for resource ref variants
  51. String resourceTypeName_;
  52. bool isArray_;
  53. bool isEnum_;
  54. unsigned fixedArraySize_;
  55. };
  56. struct EnumInfo
  57. {
  58. EnumInfo(const String& name = String::EMPTY, int value = 0)
  59. {
  60. name_ = name;
  61. value_ = value;
  62. }
  63. String name_;
  64. int value_;
  65. };
  66. // TODO: these should be broken out into some class info structs, getting unwieldy
  67. typedef HashMap<String, FieldInfo> FieldMap;
  68. typedef HashMap<String, Vector<EnumInfo>> EnumMap;
  69. typedef HashMap<String, String> FieldTooltipMap;
  70. typedef HashMap<StringHash, FieldMap> ClassFieldMap;
  71. typedef HashMap<StringHash, FieldTooltipMap> ClassFieldTooltipMap;
  72. typedef HashMap<StringHash, EnumMap> ClassEnumMap;
  73. typedef HashMap<StringHash, VariantMap> ClassDefaultValueMap;
  74. /// NET Assembly resource.
  75. class ATOMIC_API ScriptComponentFile : public Resource
  76. {
  77. ATOMIC_OBJECT(ScriptComponentFile, Resource)
  78. public:
  79. /// Construct.
  80. ScriptComponentFile(Context* context);
  81. /// Destruct.
  82. virtual ~ScriptComponentFile();
  83. static void RegisterObject(Context* context);
  84. /// Only valid in editor, as we don't inspect classnames at runtime
  85. virtual const Vector<String>& GetClassNames() { return classNames_; }
  86. const EnumMap& GetEnums(const String& classname = String::EMPTY) const;
  87. const FieldMap& GetFields(const String& classname = String::EMPTY) const;
  88. const FieldTooltipMap& GetFieldTooltips(const String& classname = String::EMPTY) const;
  89. const VariantMap& GetDefaultFieldValues(const String& classname = String::EMPTY) const;
  90. void GetDefaultFieldValue(const String& name, Variant& v,const String& classname = String::EMPTY) const;
  91. protected:
  92. void Clear();
  93. void AddEnum(const String& enumName, const EnumInfo& enumInfo, const String& classname = String::EMPTY);
  94. void AddField(const String& fieldName, VariantType variantType, const String& resourceTypeName = String::EMPTY, bool isArray = false, bool isEnum = false, unsigned fixedArraySize = 0, const String& classname = String::EMPTY, const String& tooltip = String::EMPTY);
  95. void AddDefaultValue(const String& fieldName, const Variant& value, const String& classname = String::EMPTY);
  96. // only valid in editor
  97. Vector<String> classNames_;
  98. private:
  99. ClassFieldMap classFields_;
  100. ClassFieldTooltipMap classFieldTooltips_;
  101. ClassDefaultValueMap classDefaultFieldValues_;
  102. ClassEnumMap classEnums_;
  103. static FieldMap emptyFieldMap_;
  104. static FieldTooltipMap emptyFieldTooltipMap_;
  105. static EnumMap emptyEnumMap_;
  106. static VariantMap emptyDefaultValueMap_;
  107. };
  108. }