ScriptComponentFile.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. typedef HashMap<String, VariantType> FieldMap;
  38. typedef HashMap<String, Vector<EnumInfo>> EnumMap;
  39. typedef HashMap<StringHash, FieldMap> ClassFieldMap;
  40. typedef HashMap<StringHash, EnumMap> ClassEnumMap;
  41. typedef HashMap<StringHash, VariantMap> ClassDefaultValueMap;
  42. /// NET Assembly resource.
  43. class ATOMIC_API ScriptComponentFile : public Resource
  44. {
  45. ATOMIC_OBJECT(ScriptComponentFile, Resource);
  46. public:
  47. /// Construct.
  48. ScriptComponentFile(Context* context);
  49. /// Destruct.
  50. virtual ~ScriptComponentFile();
  51. static void RegisterObject(Context* context);
  52. /// Only valid in editor, as we don't inspect classnames at runtime
  53. virtual const Vector<String>& GetClassNames() { return classNames_; }
  54. const EnumMap& GetEnums(const String& classname = String::EMPTY) const;
  55. const FieldMap& GetFields(const String& classname = String::EMPTY) const;
  56. const VariantMap& GetDefaultFieldValues(const String& classname = String::EMPTY) const;
  57. void GetDefaultFieldValue(const String& name, Variant& v,const String& classname = String::EMPTY) const;
  58. protected:
  59. void Clear();
  60. void AddEnum(const String& enumName, const EnumInfo& enumInfo, const String& classname = String::EMPTY);
  61. void AddField(const String& fieldName, VariantType variantType, const String& classname = String::EMPTY);
  62. void AddDefaultValue(const String& fieldName, const Variant& value, const String& classname = String::EMPTY);
  63. // only valid in editor
  64. Vector<String> classNames_;
  65. private:
  66. ClassFieldMap classFields_;
  67. ClassDefaultValueMap classDefaultFieldValues_;
  68. ClassEnumMap classEnums_;
  69. static FieldMap emptyFieldMap_;
  70. static EnumMap emptyEnumMap_;
  71. static VariantMap emptyDefaultValueMap_;
  72. };
  73. }