WwiseTreeItem.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. /*******************************************************************************
  2. The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
  3. Technology released in source code form as part of the game integration package.
  4. The content of this file may not be used without valid licenses to the
  5. AUDIOKINETIC Wwise Technology.
  6. Note that the use of the game engine is subject to the Unreal(R) Engine End User
  7. License Agreement at https://www.unrealengine.com/en-US/eula/unreal
  8. License Usage
  9. Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
  10. this file in accordance with the end user license agreement provided with the
  11. software or, alternatively, in accordance with the terms contained
  12. in a written agreement between you and Audiokinetic Inc.
  13. Copyright (c) 2023 Audiokinetic Inc.
  14. *******************************************************************************/
  15. #include "WaapiPicker/WwiseTreeItem.h"
  16. bool FWwiseTreeItem::UEAssetExists() const
  17. {
  18. return Assets.Num() > 0;
  19. }
  20. bool FWwiseTreeItem::WwiseBankRefExists() const
  21. {
  22. #if WITH_EDITORONLY_DATA
  23. return WwiseItemRef.IsValid() && WwiseItemRef->GUID.IsValid();
  24. #endif
  25. return false;
  26. }
  27. bool FWwiseTreeItem::WaapiRefExists() const
  28. {
  29. return bWaapiRefExists;
  30. }
  31. bool FWwiseTreeItem::IsRenamedInWwise() const
  32. {
  33. if (!WwiseBankRefExists() || !WaapiRefExists())
  34. {
  35. return false;
  36. }
  37. return DisplayName != WaapiName;
  38. }
  39. bool FWwiseTreeItem::IsDeletedInWwise() const
  40. {
  41. return !WaapiRefExists() && WwiseBankRefExists();
  42. }
  43. bool FWwiseTreeItem::IsNotInWwiseOrSoundBank() const
  44. {
  45. return !WaapiRefExists() && !WwiseBankRefExists();
  46. }
  47. bool FWwiseTreeItem::IsNewInWwise() const
  48. {
  49. return WaapiRefExists() && !WwiseBankRefExists();
  50. }
  51. bool FWwiseTreeItem::IsMovedInWwise() const
  52. {
  53. return !bSameLocation && !IsRenamedInWwise();
  54. }
  55. bool FWwiseTreeItem::IsSoundBankUpToDate() const
  56. {
  57. return WwiseBankRefExists() && WaapiRefExists()
  58. && !IsRenamedInWwise() && !IsMovedInWwise();
  59. }
  60. bool FWwiseTreeItem::IsRenamedInSoundBank() const
  61. {
  62. if (!WwiseBankRefExists() || !HasUniqueUAsset())
  63. {
  64. return false;
  65. }
  66. FString NameToCompare = DisplayName;
  67. if(IsOfType({ EWwiseItemType::Switch , EWwiseItemType::State }))
  68. {
  69. NameToCompare = GetSwitchAssetName();
  70. }
  71. return FName(NameToCompare) != UAssetName;
  72. }
  73. bool FWwiseTreeItem::IsUAssetMissing() const
  74. {
  75. return WwiseBankRefExists() && !UEAssetExists();
  76. }
  77. bool FWwiseTreeItem::IsUAssetOrphaned() const
  78. {
  79. return !WwiseBankRefExists() && UEAssetExists();
  80. }
  81. bool FWwiseTreeItem::IsNotInSoundBankOrUnreal() const
  82. {
  83. return !WwiseBankRefExists() && !UEAssetExists();
  84. }
  85. bool FWwiseTreeItem::IsUAssetUpToDate() const
  86. {
  87. return WwiseBankRefExists() && HasUniqueUAsset() && !IsRenamedInSoundBank();
  88. }
  89. bool FWwiseTreeItem::HasUniqueUAsset() const
  90. {
  91. return Assets.Num() == 1;
  92. }
  93. bool FWwiseTreeItem::HasMultipleUAssets() const
  94. {
  95. return Assets.Num() > 1;
  96. }
  97. bool FWwiseTreeItem::IsItemUpToDate() const
  98. {
  99. return IsUAssetUpToDate() && IsSoundBankUpToDate();
  100. }
  101. bool FWwiseTreeItem::IsFolder() const
  102. {
  103. return IsAuxBus() || IsOfType({
  104. EWwiseItemType::StandaloneWorkUnit,
  105. EWwiseItemType::NestedWorkUnit,
  106. EWwiseItemType::Folder,
  107. EWwiseItemType::Bus,
  108. EWwiseItemType::MotionBus,
  109. EWwiseItemType::PhysicalFolder,
  110. EWwiseItemType::SwitchContainer,
  111. EWwiseItemType::SwitchGroup,
  112. EWwiseItemType::StateGroup,
  113. EWwiseItemType::RandomSequenceContainer
  114. });
  115. }
  116. bool FWwiseTreeItem::IsAuxBus() const
  117. {
  118. return IsOfType({
  119. EWwiseItemType::AuxBus
  120. });
  121. }
  122. bool FWwiseTreeItem::ShouldDisplayInfo() const
  123. {
  124. return !(IsFolder() && !IsAuxBus());
  125. }
  126. bool FWwiseTreeItem::IsRootItem() const
  127. {
  128. return !Parent.Pin();
  129. }
  130. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::GetRoot()
  131. {
  132. if (!Parent.IsValid())
  133. {
  134. return MakeShared<FWwiseTreeItem>(*this);
  135. }
  136. auto Root = Parent.Pin();
  137. while (Root->Parent.IsValid())
  138. {
  139. Root = Root->Parent.Pin();
  140. }
  141. return Root;
  142. }
  143. void FWwiseTreeItem::SetWaapiRef(bool bExistsInWaapi)
  144. {
  145. bWaapiRefExists = bExistsInWaapi;
  146. }
  147. FString FWwiseTreeItem::GetSwitchAssetName() const
  148. {
  149. if(Parent.IsValid())
  150. {
  151. return Parent.Pin()->DisplayName + "-" + DisplayName;
  152. }
  153. return FString();
  154. }
  155. const FString FWwiseTreeItem::GetDefaultAssetName() const
  156. {
  157. if (IsOfType({ EWwiseItemType::Switch , EWwiseItemType::State }))
  158. {
  159. return GetSwitchAssetName();
  160. }
  161. return DisplayName;
  162. }
  163. void FWwiseTreeItem::AddChild(TSharedPtr<FWwiseTreeItem> Child)
  164. {
  165. Child->Parent = TWeakPtr<FWwiseTreeItem>(this->AsShared());
  166. m_Children.Add(Child);
  167. ChildCountInWwise = m_Children.Num();
  168. }
  169. void FWwiseTreeItem::AddChildren(TArray<TSharedPtr<FWwiseTreeItem>> Children)
  170. {
  171. for (auto Child : Children)
  172. {
  173. Child->Parent = TWeakPtr<FWwiseTreeItem>(this->AsShared());
  174. m_Children.Add(Child);
  175. }
  176. ChildCountInWwise = m_Children.Num();
  177. }
  178. void FWwiseTreeItem::EmptyChildren()
  179. {
  180. m_Children.Empty();
  181. ChildCountInWwise = m_Children.Num();
  182. }
  183. void FWwiseTreeItem::RemoveChild(const FGuid& childGuid)
  184. {
  185. m_Children.RemoveAll([childGuid](TSharedPtr<FWwiseTreeItem> child) { return child->ItemId == childGuid; });
  186. ChildCountInWwise = m_Children.Num();
  187. }
  188. void FWwiseTreeItem::RemoveChild(const TSharedPtr< FWwiseTreeItem> child)
  189. {
  190. m_Children.Remove(child);
  191. ChildCountInWwise = m_Children.Num();
  192. }
  193. void FWwiseTreeItem::RemoveChildren(const TArray<TSharedPtr<FWwiseTreeItem>> Children)
  194. {
  195. for (auto& Child : Children)
  196. {
  197. m_Children.Remove(Child);
  198. }
  199. ChildCountInWwise = m_Children.Num();
  200. }
  201. /** Returns true if this item is a child of the specified item */
  202. bool FWwiseTreeItem::IsChildOf(const FWwiseTreeItem& InParent)
  203. {
  204. auto CurrentParent = Parent.Pin();
  205. while (CurrentParent.IsValid())
  206. {
  207. if (CurrentParent.Get() == &InParent)
  208. {
  209. return true;
  210. }
  211. CurrentParent = CurrentParent->Parent.Pin();
  212. }
  213. return false;
  214. }
  215. bool FWwiseTreeItem::IsBrowserType() const
  216. {
  217. return IsOfType({ EWwiseItemType::Event,
  218. EWwiseItemType::Bus,
  219. EWwiseItemType::AuxBus,
  220. EWwiseItemType::AcousticTexture,
  221. EWwiseItemType::State,
  222. EWwiseItemType::Switch,
  223. EWwiseItemType::GameParameter,
  224. EWwiseItemType::Trigger,
  225. EWwiseItemType::EffectShareSet
  226. });
  227. }
  228. bool FWwiseTreeItem::IsOfType(const TArray<EWwiseItemType::Type>& Types) const
  229. {
  230. for (const auto& Type : Types)
  231. {
  232. if (ItemType == Type)
  233. {
  234. return true;
  235. }
  236. }
  237. return false;
  238. }
  239. bool FWwiseTreeItem::IsNotOfType(const TArray<EWwiseItemType::Type>& Types) const
  240. {
  241. return !IsOfType(Types);
  242. }
  243. /** Returns the child item by name or NULL if the child does not exist */
  244. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::GetChild(const FString& InChildName)
  245. {
  246. for (int32 ChildIdx = 0; ChildIdx < m_Children.Num(); ++ChildIdx)
  247. {
  248. if (m_Children[ChildIdx]->DisplayName == InChildName)
  249. {
  250. return m_Children[ChildIdx];
  251. }
  252. }
  253. return TSharedPtr<FWwiseTreeItem>();
  254. }
  255. /** Returns the child item by name or NULL if the child does not exist */
  256. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::GetChild(const FGuid& InGuid, const AkUInt32 InShortId, const FString& InChildName)
  257. {
  258. for (int32 ChildIdx = 0; ChildIdx < m_Children.Num(); ++ChildIdx)
  259. {
  260. if (m_Children[ChildIdx]->ItemId == InGuid && !IsFolder())
  261. {
  262. return m_Children[ChildIdx];
  263. }
  264. if (m_Children[ChildIdx]->ShortId == InShortId && InShortId > 0)
  265. {
  266. return m_Children[ChildIdx];
  267. }
  268. if (m_Children[ChildIdx]->DisplayName == InChildName)
  269. {
  270. return m_Children[ChildIdx];
  271. }
  272. }
  273. return TSharedPtr<FWwiseTreeItem>();
  274. }
  275. /** Finds the child who's path matches the one specified */
  276. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::FindItemRecursive(const FString& InFullPath)
  277. {
  278. if (InFullPath == FolderPath)
  279. {
  280. return SharedThis(this);
  281. }
  282. for (int32 ChildIdx = 0; ChildIdx < m_Children.Num(); ++ChildIdx)
  283. {
  284. if (InFullPath.StartsWith(m_Children[ChildIdx]->FolderPath))
  285. {
  286. const TSharedPtr<FWwiseTreeItem>& Item = m_Children[ChildIdx]->FindItemRecursive(InFullPath);
  287. if (Item.IsValid())
  288. {
  289. return Item;
  290. }
  291. }
  292. }
  293. return TSharedPtr<FWwiseTreeItem>(NULL);
  294. }
  295. /** Finds the child who's Guid matches the one specified */
  296. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::FindItemRecursive(const TSharedPtr<FWwiseTreeItem>& InItem)
  297. {
  298. if(InItem->ItemType == ItemType)
  299. {
  300. if (InItem->ItemId == ItemId)
  301. {
  302. return SharedThis(this);
  303. }
  304. if(InItem->ShortId == ShortId && ShortId > 0)
  305. {
  306. return SharedThis(this);
  307. }
  308. if(InItem->DisplayName == DisplayName)
  309. {
  310. return SharedThis(this);
  311. }
  312. }
  313. for (int32 ChildIdx = 0; ChildIdx < m_Children.Num(); ++ChildIdx)
  314. {
  315. const TSharedPtr<FWwiseTreeItem>& Item = m_Children[ChildIdx]->FindItemRecursive(InItem);
  316. if (Item.IsValid())
  317. {
  318. return Item;
  319. }
  320. }
  321. return TSharedPtr<FWwiseTreeItem>(NULL);
  322. }
  323. /** Sort the children by name */
  324. void FWwiseTreeItem::SortChildren()
  325. {
  326. m_Children.Sort(FCompareWwiseTreeItem());
  327. }