ScriptComponentFile.h 3.5 KB

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