ScriptComponentFile.h 3.9 KB

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