contaminatedarealoader.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // This will be used to parse and load contaminated area related data
  2. class EffectAreaLoader
  3. {
  4. private static string m_Path = "$mission:cfgeffectarea.json";
  5. static void CreateZones()
  6. {
  7. JsonDataContaminatedAreas effectAreaData;
  8. // We confirm the contaminated area configuration file exists in mission folder
  9. if ( !FileExist( m_Path ) )
  10. {
  11. // We fallback to check in data and notify user file was not found in mission
  12. PrintToRPT("[WARNING] :: [EffectAreaLoader CreateZones] :: No contaminated area file found in MISSION folder, your path is " + m_Path + " Attempting DATA folder"); // If the path is invalid, we warn the user
  13. m_Path = "";
  14. GetGame().GetWorldName( m_Path );
  15. m_Path = string.Format("dz/worlds/%1/ce/cfgeffectarea.json", m_Path );
  16. if ( !FileExist( m_Path ) )
  17. {
  18. PrintToRPT("[WARNING] :: [EffectAreaLoader CreateZones] :: No contaminated area file found in DATA folder, your path is " + m_Path); // If the path is invalid, we warn the user
  19. return; // Nothing could be read, just end here
  20. }
  21. }
  22. // We load the data from file, in case of failure we notify user
  23. effectAreaData = EffectAreaLoader.GetData();
  24. if ( effectAreaData )
  25. {
  26. // Now that we have extracted the data we go through every declared area
  27. //Debug.Log("Contaminated area JSON contains : " + effectAreaData.Areas.Count());
  28. for ( int i = 0; i < effectAreaData.Areas.Count(); i++ )
  29. {
  30. EffectAreaParams params = new EffectAreaParams();
  31. // We feed in all relevant data
  32. params.m_ParamName = effectAreaData.Areas.Get( i ).AreaName;
  33. string areaType = effectAreaData.Areas.Get( i ).Type;
  34. params.m_ParamTriggerType = effectAreaData.Areas.Get( i ).TriggerType;
  35. JsonDataAreaData data = effectAreaData.Areas.Get( i ).Data;
  36. // World level area data ( Trigger info, world particles, etc... )
  37. vector pos = Vector( data.Pos[0], data.Pos[1], data.Pos[2] );
  38. params.m_ParamRadius = data.Radius;
  39. params.m_ParamPosHeight = data.PosHeight;
  40. params.m_ParamNegHeight = data.NegHeight;
  41. params.m_ParamInnerRings = data.InnerRingCount;
  42. params.m_ParamInnerSpace = data.InnerPartDist;
  43. params.m_ParamOuterToggle = data.OuterRingToggle;
  44. params.m_ParamOuterSpace = data.OuterPartDist;
  45. params.m_ParamOuterOffset = data.OuterOffset;
  46. params.m_ParamVertLayers = data.VerticalLayers;
  47. params.m_ParamVerticalOffset = data.VerticalOffset;
  48. string particleName = data.ParticleName;
  49. params.m_ParamEffectInterval = data.EffectInterval;
  50. params.m_ParamEffectDuration = data.EffectDuration;
  51. params.m_ParamEffectModifier = data.EffectModifier;
  52. // Local level area data ( Player particles and PPE )
  53. JsonDataPlayerData playerData = effectAreaData.Areas.Get( i ).PlayerData;
  54. string aroundPartName = playerData.AroundPartName;
  55. string tinyPartName = playerData.TinyPartName;
  56. string ppeRequesterType = playerData.PPERequesterType;
  57. // Conversion of particle name to ID for synchronization and loading
  58. if (particleName != "")
  59. params.m_ParamPartId = ParticleList.GetParticleID( particleName );
  60. if (aroundPartName != "")
  61. params.m_ParamAroundPartId = ParticleList.GetParticleID( aroundPartName );
  62. if (tinyPartName != "")
  63. params.m_ParamTinyPartId = ParticleList.GetParticleID( tinyPartName );
  64. params.m_ParamPpeRequesterType = ppeRequesterType;
  65. EffectArea newZone; // Zones MUST inherit from EffectArea
  66. // We snap item position to ground before creating if specified Y is 0
  67. if ( pos[1] == 0 )
  68. {
  69. pos[1] = GetGame().SurfaceRoadY( pos[0], pos[2] );
  70. Class.CastTo( newZone, GetGame().CreateObjectEx( areaType, pos, ECE_PLACE_ON_SURFACE ) );
  71. }
  72. else
  73. Class.CastTo( newZone, GetGame().CreateObjectEx( areaType, pos, ECE_NONE ) );
  74. // We created a new zone, we feed in the data to finalize setup
  75. if ( newZone )
  76. newZone.SetupZoneData( params );
  77. else
  78. Error("[WARNING] :: [EffectAreaLoader CreateZones] :: Cast failed, are you sure your class ( 'Type:' ) inherits from EffectArea and that there are no Typos?");
  79. }
  80. }
  81. else
  82. Error("[WARNING] :: [EffectAreaLoader CreateZones] :: Data could not be read, please check data and syntax"); // Most JSON related errors should be handled, but we have an extra check in case data could not be read
  83. }
  84. static JsonDataContaminatedAreas GetData()
  85. {
  86. string errorMessage;
  87. JsonDataContaminatedAreas data;
  88. if (!JsonFileLoader<JsonDataContaminatedAreas>.LoadFile(m_Path, data, errorMessage))
  89. ErrorEx(errorMessage);
  90. return data;
  91. }
  92. }