ResourceManager.bf 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Reflection;
  5. using Beefy.utils;
  6. using Beefy.gfx;
  7. using System.Runtime.InteropServices;
  8. namespace Beefy.res
  9. {
  10. public class ResInfo
  11. {
  12. public String mName ~ delete _;
  13. public String mFilePath ~ delete _;
  14. public Guid mResId;
  15. public Object mLoadedObject;
  16. }
  17. public class ResImageInfo : ResInfo
  18. {
  19. }
  20. public class ResGroup
  21. {
  22. public List<ResInfo> mResInfoList = new List<ResInfo>() ~ DeleteContainerAndItems!(_);
  23. }
  24. public class ResourceManager
  25. {
  26. /*[StdCall, CLink]
  27. static extern void Wwise_Shutdown();*/
  28. public Dictionary<String, ResGroup> mResGroupMap = new Dictionary<String, ResGroup>() ~ delete _;
  29. public Dictionary<Guid, ResInfo> mIdToResInfoMap = new Dictionary<Guid, ResInfo>() ~ delete _;
  30. public ~this()
  31. {
  32. //Wwise_Shutdown();
  33. }
  34. public void ParseConfigData(StructuredData data)
  35. {
  36. ThrowUnimplemented();
  37. /*int fileResVer = data.GetInt("ResVer");
  38. using (data.Open("Groups"))
  39. {
  40. for (int groupIdx = 0; groupIdx < data.Count; groupIdx++)
  41. {
  42. using (data.Open(groupIdx))
  43. {
  44. ResGroup resGroup = new ResGroup();
  45. mResGroupMap[data.GetString("Name")] = resGroup;
  46. using (data.Open("Resources"))
  47. {
  48. for (int resIdx = 0; resIdx < data.Count; resIdx++)
  49. {
  50. using (data.Open(resIdx))
  51. {
  52. ResInfo resInfo = null;
  53. string aType = data.GetString("Type");
  54. if (aType == "Image")
  55. {
  56. resInfo = new ResImageInfo();
  57. }
  58. resInfo.mName = data.GetString("Name");
  59. resInfo.mResId = Guid.Parse(data.GetString("Id"));
  60. resInfo.mFilePath = data.GetString("Path");
  61. resGroup.mResInfoList.Add(resInfo);
  62. }
  63. }
  64. }
  65. }
  66. }
  67. }
  68. Type appType = BFApp.sApp.GetType();
  69. Type resourcesType = appType.Assembly.GetType(appType.Namespace + ".Res");
  70. if (resourcesType == null)
  71. return;
  72. Type soundBanksTypes = resourcesType.GetNestedType("SoundBanks");
  73. if (soundBanksTypes != null)
  74. {
  75. using (data.Open("SoundBanks"))
  76. {
  77. for (int soundBanksIdx = 0; soundBanksIdx < data.Count; soundBanksIdx++)
  78. {
  79. string name = data.Keys[soundBanksIdx];
  80. uint wwiseId = data.GetUInt(soundBanksIdx);
  81. SoundBank soundBank = new SoundBank();
  82. soundBank.mName = name;
  83. soundBank.mWwiseSoundId = wwiseId;
  84. FieldInfo fieldInfo = soundBanksTypes.GetField(name);
  85. fieldInfo.SetValue(null, soundBank);
  86. }
  87. }
  88. }
  89. Type soundEventsTypes = resourcesType.GetNestedType("SoundEvents");
  90. if (soundEventsTypes != null)
  91. {
  92. using (data.Open("SoundEvents"))
  93. {
  94. for (int soundBanksIdx = 0; soundBanksIdx < data.Count; soundBanksIdx++)
  95. {
  96. string name = data.Keys[soundBanksIdx];
  97. uint wwiseId = data.GetUInt(soundBanksIdx);
  98. SoundEvent soundRes = new SoundEvent();
  99. soundRes.mWwiseEventId = wwiseId;
  100. FieldInfo fieldInfo = soundEventsTypes.GetField(name);
  101. fieldInfo.SetValue(null, soundRes);
  102. }
  103. }
  104. }
  105. Type soundParametersTypes = resourcesType.GetNestedType("SoundParameters");
  106. if (soundParametersTypes != null)
  107. {
  108. using (data.Open("SoundParameters"))
  109. {
  110. for (int soundBanksIdx = 0; soundBanksIdx < data.Count; soundBanksIdx++)
  111. {
  112. string name = data.Keys[soundBanksIdx];
  113. uint wwiseId = data.GetUInt(soundBanksIdx);
  114. SoundParameter soundParameter = new SoundParameter();
  115. soundParameter.mWwiseParamId = wwiseId;
  116. FieldInfo fieldInfo = soundParametersTypes.GetField(name);
  117. fieldInfo.SetValue(null, soundParameter);
  118. }
  119. }
  120. }*/
  121. }
  122. public bool LoadResGroup(String groupName)
  123. {
  124. ThrowUnimplemented();
  125. /*Type appType = BFApp.sApp.GetType();
  126. Type resourcesType = appType.Assembly.GetType(appType.Namespace + ".Res");
  127. Type imagesType = resourcesType.GetNestedType("Images");
  128. ResGroup resGroup = mResGroupMap[groupName];
  129. foreach (ResInfo resInfo in resGroup.mResInfoList)
  130. {
  131. if (resInfo is ResImageInfo)
  132. {
  133. string fileName = resInfo.mFilePath;
  134. if (!fileName.Contains(':'))
  135. fileName = BFApp.sApp.mInstallDir + resInfo.mFilePath;
  136. Image image = Image.LoadFromFile(fileName, false);
  137. FieldInfo fieldInfo = imagesType.GetField(resInfo.mName);
  138. fieldInfo.SetValue(null, image);
  139. }
  140. }
  141. return true;*/
  142. }
  143. public Object GetResourceById(Guid id, bool allowLoad = false)
  144. {
  145. ThrowUnimplemented();
  146. /*ResInfo resInfo = mIdToResInfoMap[id];
  147. if ((resInfo.mLoadedObject == null) && (allowLoad))
  148. {
  149. if (resInfo is ResImageInfo)
  150. resInfo.mLoadedObject = Image.LoadFromFile(resInfo.mFilePath, false);
  151. }
  152. return resInfo.mLoadedObject;*/
  153. }
  154. }
  155. }