NETAssemblyFile.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Copyright (c) 2014-2015, 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. #include <Atomic/Core/Context.h>
  23. #include <Atomic/IO/Deserializer.h>
  24. #include <Atomic/IO/Log.h>
  25. #include <Atomic/Core/Profiler.h>
  26. #include <Atomic/Resource/ResourceCache.h>
  27. #include <Atomic/IO/Serializer.h>
  28. #include "NETComponentClass.h"
  29. #include "NETAssemblyFile.h"
  30. namespace Atomic
  31. {
  32. /*
  33. "enums":[
  34. {
  35. "name":"BehaviorState",
  36. "values":{
  37. "Friendly":0,
  38. "Aggressive":10,
  39. "Neutral":11
  40. }
  41. }
  42. ],
  43. */
  44. NETAssemblyFile::NETAssemblyFile(Context* context) :
  45. Resource(context)
  46. {
  47. }
  48. NETAssemblyFile::~NETAssemblyFile()
  49. {
  50. }
  51. NETComponentClass* NETAssemblyFile::GetComponentClass(const String& name)
  52. {
  53. if (!componentClasses_.Contains(name))
  54. return 0;
  55. return componentClasses_[name];
  56. }
  57. bool NETAssemblyFile::ParseAssemblyJSON(const JSONValue& json)
  58. {
  59. componentClasses_.Clear();
  60. enums_.Clear();
  61. const JSONArray& enums = json.Get("enums").GetArray();
  62. for (unsigned i = 0; i < enums.Size(); i++)
  63. {
  64. const JSONValue& ejson = enums.At(i);
  65. String enumName = ejson.Get("name").GetString();
  66. const JSONObject& evalues = ejson.Get("values").GetObject();
  67. JSONObject::ConstIterator itr = evalues.Begin();
  68. Vector<EnumInfo> values;
  69. while(itr != evalues.End())
  70. {
  71. EnumInfo info;
  72. info.name_ = itr->first_;
  73. info.value_ = itr->second_.GetInt();
  74. values.Push(info);
  75. itr++;
  76. }
  77. enums_[enumName] = values;
  78. }
  79. const JSONArray& components = json.Get("components").GetArray();
  80. for (unsigned i = 0; i < components.Size(); i++)
  81. {
  82. const JSONValue& cjson = components.At(i);
  83. SharedPtr<NETComponentClass> c(new NETComponentClass(context_, this));
  84. if (c->ParseJSON(cjson))
  85. componentClasses_[c->GetName()] = c;
  86. }
  87. return true;
  88. }
  89. void NETAssemblyFile::RegisterObject(Context* context)
  90. {
  91. context->RegisterFactory<NETAssemblyFile>();
  92. }
  93. bool NETAssemblyFile::BeginLoad(Deserializer& source)
  94. {
  95. return true;
  96. }
  97. bool NETAssemblyFile::Save(Serializer& dest) const
  98. {
  99. return true;
  100. }
  101. }