WwiseTreeItem.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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() && !IsUAssetOutOfDate();
  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::IsUAssetOutOfDate() const
  98. {
  99. for(auto& Asset : Assets)
  100. {
  101. uint32 AssetShortId = 0;
  102. FGuid AssetGuid;
  103. auto GuidValue = Asset.TagsAndValues.FindTag(FName("WwiseGuid"));
  104. auto ShortIdValue = Asset.TagsAndValues.FindTag(FName("WwiseShortId"));
  105. auto WwiseName = Asset.TagsAndValues.FindTag(FName("WwiseName"));
  106. if (GuidValue.IsSet())
  107. {
  108. FString GuidAsString = GuidValue.GetValue();
  109. FGuid Guid = FGuid(GuidAsString);
  110. AssetGuid = Guid;
  111. }
  112. if (ShortIdValue.IsSet())
  113. {
  114. AssetShortId = FCString::Strtoui64(*ShortIdValue.GetValue(), NULL, 10);
  115. }
  116. if (AssetGuid != ItemId || AssetShortId != ShortId || WwiseName != DisplayName)
  117. {
  118. return true;
  119. }
  120. }
  121. return false;
  122. }
  123. bool FWwiseTreeItem::IsItemUpToDate() const
  124. {
  125. return IsUAssetUpToDate() && IsSoundBankUpToDate();
  126. }
  127. bool FWwiseTreeItem::IsFolder() const
  128. {
  129. return IsAuxBus() || IsOfType({
  130. EWwiseItemType::StandaloneWorkUnit,
  131. EWwiseItemType::NestedWorkUnit,
  132. EWwiseItemType::Folder,
  133. EWwiseItemType::Bus,
  134. EWwiseItemType::MotionBus,
  135. EWwiseItemType::PhysicalFolder,
  136. EWwiseItemType::SwitchContainer,
  137. EWwiseItemType::SwitchGroup,
  138. EWwiseItemType::StateGroup,
  139. EWwiseItemType::RandomSequenceContainer
  140. });
  141. }
  142. bool FWwiseTreeItem::IsAuxBus() const
  143. {
  144. return IsOfType({
  145. EWwiseItemType::AuxBus
  146. });
  147. }
  148. bool FWwiseTreeItem::ShouldDisplayInfo() const
  149. {
  150. return !(IsFolder() && !IsAuxBus());
  151. }
  152. bool FWwiseTreeItem::IsRootItem() const
  153. {
  154. return !Parent.Pin();
  155. }
  156. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::GetRoot()
  157. {
  158. if (!Parent.IsValid())
  159. {
  160. return MakeShared<FWwiseTreeItem>(*this);
  161. }
  162. auto Root = Parent.Pin();
  163. while (Root->Parent.IsValid())
  164. {
  165. Root = Root->Parent.Pin();
  166. }
  167. return Root;
  168. }
  169. void FWwiseTreeItem::SetWaapiRef(bool bExistsInWaapi)
  170. {
  171. bWaapiRefExists = bExistsInWaapi;
  172. }
  173. FString FWwiseTreeItem::GetSwitchAssetName() const
  174. {
  175. if(Parent.IsValid())
  176. {
  177. return Parent.Pin()->DisplayName + "-" + DisplayName;
  178. }
  179. return FString();
  180. }
  181. const FString FWwiseTreeItem::GetDefaultAssetName() const
  182. {
  183. if (IsOfType({ EWwiseItemType::Switch , EWwiseItemType::State }))
  184. {
  185. return GetSwitchAssetName();
  186. }
  187. return DisplayName;
  188. }
  189. void FWwiseTreeItem::AddChild(TSharedPtr<FWwiseTreeItem> Child)
  190. {
  191. Child->Parent = TWeakPtr<FWwiseTreeItem>(this->AsShared());
  192. m_Children.Add(Child);
  193. ChildCountInWwise = m_Children.Num();
  194. }
  195. void FWwiseTreeItem::AddChildren(TArray<TSharedPtr<FWwiseTreeItem>> Children)
  196. {
  197. for (auto Child : Children)
  198. {
  199. Child->Parent = TWeakPtr<FWwiseTreeItem>(this->AsShared());
  200. m_Children.Add(Child);
  201. }
  202. ChildCountInWwise = m_Children.Num();
  203. }
  204. void FWwiseTreeItem::EmptyChildren()
  205. {
  206. m_Children.Empty();
  207. ChildCountInWwise = m_Children.Num();
  208. }
  209. void FWwiseTreeItem::RemoveChild(const FGuid& childGuid)
  210. {
  211. m_Children.RemoveAll([childGuid](TSharedPtr<FWwiseTreeItem> child) { return child->ItemId == childGuid; });
  212. ChildCountInWwise = m_Children.Num();
  213. }
  214. void FWwiseTreeItem::RemoveChild(const TSharedPtr< FWwiseTreeItem> child)
  215. {
  216. m_Children.Remove(child);
  217. ChildCountInWwise = m_Children.Num();
  218. }
  219. void FWwiseTreeItem::RemoveChildren(const TArray<TSharedPtr<FWwiseTreeItem>> Children)
  220. {
  221. for (auto& Child : Children)
  222. {
  223. m_Children.Remove(Child);
  224. }
  225. ChildCountInWwise = m_Children.Num();
  226. }
  227. /** Returns true if this item is a child of the specified item */
  228. bool FWwiseTreeItem::IsChildOf(const FWwiseTreeItem& InParent)
  229. {
  230. auto CurrentParent = Parent.Pin();
  231. while (CurrentParent.IsValid())
  232. {
  233. if (CurrentParent.Get() == &InParent)
  234. {
  235. return true;
  236. }
  237. CurrentParent = CurrentParent->Parent.Pin();
  238. }
  239. return false;
  240. }
  241. bool FWwiseTreeItem::IsBrowserType() const
  242. {
  243. return IsOfType({ EWwiseItemType::Event,
  244. EWwiseItemType::Bus,
  245. EWwiseItemType::AuxBus,
  246. EWwiseItemType::AcousticTexture,
  247. EWwiseItemType::State,
  248. EWwiseItemType::Switch,
  249. EWwiseItemType::GameParameter,
  250. EWwiseItemType::Trigger,
  251. EWwiseItemType::EffectShareSet
  252. });
  253. }
  254. bool FWwiseTreeItem::IsOfType(const TArray<EWwiseItemType::Type>& Types) const
  255. {
  256. for (const auto& Type : Types)
  257. {
  258. if (ItemType == Type)
  259. {
  260. return true;
  261. }
  262. }
  263. return false;
  264. }
  265. bool FWwiseTreeItem::IsNotOfType(const TArray<EWwiseItemType::Type>& Types) const
  266. {
  267. return !IsOfType(Types);
  268. }
  269. /** Returns the child item by name or NULL if the child does not exist */
  270. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::GetChild(const FString& InChildName)
  271. {
  272. for (int32 ChildIdx = 0; ChildIdx < m_Children.Num(); ++ChildIdx)
  273. {
  274. if (m_Children[ChildIdx]->DisplayName == InChildName)
  275. {
  276. return m_Children[ChildIdx];
  277. }
  278. }
  279. return TSharedPtr<FWwiseTreeItem>();
  280. }
  281. /** Returns the child item by name or NULL if the child does not exist */
  282. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::GetChild(const FGuid& InGuid, const AkUInt32 InShortId, const FString& InChildName)
  283. {
  284. for (int32 ChildIdx = 0; ChildIdx < m_Children.Num(); ++ChildIdx)
  285. {
  286. if (m_Children[ChildIdx]->ItemId == InGuid && !IsFolder())
  287. {
  288. return m_Children[ChildIdx];
  289. }
  290. if (m_Children[ChildIdx]->ShortId == InShortId && InShortId > 0)
  291. {
  292. return m_Children[ChildIdx];
  293. }
  294. if (m_Children[ChildIdx]->DisplayName == InChildName)
  295. {
  296. return m_Children[ChildIdx];
  297. }
  298. }
  299. return TSharedPtr<FWwiseTreeItem>();
  300. }
  301. /** Finds the child who's path matches the one specified */
  302. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::FindItemRecursive(const FString& InFullPath)
  303. {
  304. if (InFullPath == FolderPath)
  305. {
  306. return SharedThis(this);
  307. }
  308. for (int32 ChildIdx = 0; ChildIdx < m_Children.Num(); ++ChildIdx)
  309. {
  310. if (InFullPath.StartsWith(m_Children[ChildIdx]->FolderPath))
  311. {
  312. const TSharedPtr<FWwiseTreeItem>& Item = m_Children[ChildIdx]->FindItemRecursive(InFullPath);
  313. if (Item.IsValid())
  314. {
  315. return Item;
  316. }
  317. }
  318. }
  319. return TSharedPtr<FWwiseTreeItem>(NULL);
  320. }
  321. /** Finds the child who's Guid matches the one specified */
  322. TSharedPtr<FWwiseTreeItem> FWwiseTreeItem::FindItemRecursive(const TSharedPtr<FWwiseTreeItem>& InItem)
  323. {
  324. if(InItem->ItemType == ItemType)
  325. {
  326. if (InItem->ItemId == ItemId)
  327. {
  328. return SharedThis(this);
  329. }
  330. if(InItem->ShortId == ShortId && ShortId > 0)
  331. {
  332. return SharedThis(this);
  333. }
  334. if(InItem->DisplayName == DisplayName && !InItem->ItemId.IsValid())
  335. {
  336. return SharedThis(this);
  337. }
  338. }
  339. for (int32 ChildIdx = 0; ChildIdx < m_Children.Num(); ++ChildIdx)
  340. {
  341. const TSharedPtr<FWwiseTreeItem>& Item = m_Children[ChildIdx]->FindItemRecursive(InItem);
  342. if (Item.IsValid())
  343. {
  344. return Item;
  345. }
  346. }
  347. return TSharedPtr<FWwiseTreeItem>(NULL);
  348. }
  349. /** Sort the children by name */
  350. void FWwiseTreeItem::SortChildren()
  351. {
  352. m_Children.Sort(FCompareWwiseTreeItem());
  353. }