undergroundarealoader.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. class JsonUndergroundTriggers
  2. {
  3. ref array<ref JsonUndergroundAreaTriggerData> Triggers;
  4. }
  5. class JsonUndergroundAreaBreadcrumb
  6. {
  7. vector GetPosition()
  8. {
  9. return Vector(Position[0],Position[1],Position[2]);
  10. }
  11. ref array<float> Position;
  12. float EyeAccommodation;
  13. bool UseRaycast;
  14. float Radius;
  15. bool LightLerp; // only used in LinePointFade
  16. }
  17. class JsonUndergroundAreaTriggerData
  18. {
  19. vector GetPosition()
  20. {
  21. return Vector(Position[0],Position[1],Position[2]);
  22. }
  23. vector GetOrientation()
  24. {
  25. return Vector(Orientation[0],Orientation[1],Orientation[2]);
  26. }
  27. vector GetSize()
  28. {
  29. return Vector(Size[0],Size[1],Size[2]);
  30. }
  31. ref array<float> Position;
  32. ref array<float> Orientation;
  33. ref array<float> Size;
  34. float EyeAccommodation;
  35. float InterpolationSpeed;
  36. bool UseLinePointFade; // simple fade between points which are defined using existing breadcrumbs array
  37. string AmbientSoundType; // type of ambient sound which will be played by sound controller
  38. ref array<ref JsonUndergroundAreaBreadcrumb> Breadcrumbs;
  39. };
  40. class UndergroundAreaLoader
  41. {
  42. private static string m_Path = "$mission:cfgundergroundtriggers.json";
  43. static ref JsonUndergroundTriggers m_JsonData;
  44. static JsonUndergroundTriggers GetData()
  45. {
  46. if (!FileExist(m_Path))
  47. {
  48. // We fallback to check in data and notify user file was not found in mission
  49. PrintToRPT("[WARNING] :: [UndergroundAreaLoader GetData()] :: file not found in MISSION folder, your path is " + m_Path + " Attempting DATA folder");
  50. string worldName;
  51. GetGame().GetWorldName(worldName);
  52. m_Path = string.Format("dz/worlds/%1/ce/cfgundergroundtriggers.json", worldName);
  53. if (!FileExist(m_Path))
  54. {
  55. PrintToRPT("[WARNING] :: [UndergroundAreaLoader GetData()] ::file not found in DATA folder, your path is " + m_Path);
  56. return null; // Nothing could be read, just end here
  57. }
  58. }
  59. string errorMessage;
  60. JsonUndergroundTriggers data;
  61. if (!JsonFileLoader<JsonUndergroundTriggers>.LoadFile(m_Path, data, errorMessage))
  62. ErrorEx(errorMessage);
  63. return data;
  64. }
  65. static void SpawnAllTriggerCarriers()
  66. {
  67. if (!m_JsonData)
  68. {
  69. m_JsonData = GetData();
  70. }
  71. if (!m_JsonData || !m_JsonData.Triggers)
  72. {
  73. return;
  74. }
  75. foreach (int i, auto data:m_JsonData.Triggers)
  76. {
  77. SpawnTriggerCarrier(i, data);
  78. }
  79. }
  80. static void SpawnTriggerCarrier(int index, JsonUndergroundAreaTriggerData data)
  81. {
  82. UndergroundTriggerCarrierBase carrier = UndergroundTriggerCarrierBase.Cast(GetGame().CreateObjectEx( "UndergroundTriggerCarrier", data.GetPosition(), ECE_NONE ));
  83. //Print("spawning trigger carrier at pos :" +data.GetPosition());
  84. if (carrier)
  85. {
  86. carrier.SetIndex(index);
  87. carrier.SetOrientation(data.GetOrientation());
  88. }
  89. }
  90. //---------------------------------------------------------------------------------------
  91. static void SyncDataSend(PlayerIdentity identity)
  92. {
  93. GetGame().RPCSingleParam(null, ERPCs.RPC_UNDERGROUND_SYNC, new Param1<JsonUndergroundTriggers>(m_JsonData), true, identity);
  94. }
  95. //---------------------------------------------------------------------------------------
  96. static void OnRPC(ParamsReadContext ctx)
  97. {
  98. Param1<JsonUndergroundTriggers> data = new Param1< JsonUndergroundTriggers>(null);
  99. if ( ctx.Read(data) )
  100. {
  101. m_JsonData = data.param1;
  102. }
  103. else
  104. {
  105. ErrorEx("UndergroundAreaLoader datasynced - failed to read");
  106. }
  107. }
  108. }