diff --git a/lib/background/wemFilesIndexer.dart b/lib/background/wemFilesIndexer.dart index fcaeeb0..f1f4373 100644 --- a/lib/background/wemFilesIndexer.dart +++ b/lib/background/wemFilesIndexer.dart @@ -21,16 +21,18 @@ class WemFilesLookup { loadingCompleter = Completer(); lookup.clear(); var prefs = PreferencesData(); - var waiExtractDir = prefs.waiExtractDir?.value; - if (waiExtractDir == null || waiExtractDir.isEmpty) { + var waiExtractDir = prefs.waiExtractDir?.value ?? ""; + var wemExtractDir = prefs.wemExtractDir?.value ?? ""; + if (waiExtractDir.isEmpty && wemExtractDir.isEmpty) { loadingCompleter!.complete(); return; } try { - await _indexDir(waiExtractDir); - if (prefs.wemExtractDir != null && prefs.wemExtractDir!.value.isNotEmpty) - await _indexDir(prefs.wemExtractDir!.value); + if (waiExtractDir.isNotEmpty) + await _indexDir(waiExtractDir); + if (wemExtractDir.isNotEmpty) + await _indexDir(wemExtractDir); } catch (e, s) { print("Error indexing WAI files:"); print("$e\n$s"); diff --git a/lib/utils/wwiseProjectGenerator/elements/wwiseActorMixer.dart b/lib/utils/wwiseProjectGenerator/elements/wwiseActorMixer.dart index 2c1a15c..ae976eb 100644 --- a/lib/utils/wwiseProjectGenerator/elements/wwiseActorMixer.dart +++ b/lib/utils/wwiseProjectGenerator/elements/wwiseActorMixer.dart @@ -5,5 +5,5 @@ import 'hierarchyBaseElements.dart'; class WwiseActorMixer extends WwiseHierarchyElement { WwiseActorMixer({required super.wuId, required super.project, required super.chunk}) : - super(tagName: "ActorMixer", name: wwiseIdToStr(chunk.uid, fallbackPrefix: "Actor Mixer"), shortId: chunk.uid); + super(tagName: "ActorMixer", name: makeElementName(project, id: chunk.uid, parentId: chunk.baseParams.directParentID, category: "Actor Mixer"), shortId: chunk.uid); } diff --git a/lib/utils/wwiseProjectGenerator/elements/wwiseAttenuations.dart b/lib/utils/wwiseProjectGenerator/elements/wwiseAttenuations.dart index b215641..4017317 100644 --- a/lib/utils/wwiseProjectGenerator/elements/wwiseAttenuations.dart +++ b/lib/utils/wwiseProjectGenerator/elements/wwiseAttenuations.dart @@ -113,7 +113,7 @@ Future saveAttenuationsIntoWu(WwiseProjectGenerator project) async { var attenuationElement = WwiseAttenuation( wuId: project.attenuationsWu.id, project: project, - name: wwiseIdToStr(attenuation.uid, fallbackPrefix: "Attenuation"), + name: makeElementName(project, id: attenuation.uid, category: "Attenuation"), attenuation: attenuation ); project.attenuationsWu.children.add(attenuationElement); diff --git a/lib/utils/wwiseProjectGenerator/elements/wwiseEffect.dart b/lib/utils/wwiseProjectGenerator/elements/wwiseEffect.dart index 0311562..72563f0 100644 --- a/lib/utils/wwiseProjectGenerator/elements/wwiseEffect.dart +++ b/lib/utils/wwiseProjectGenerator/elements/wwiseEffect.dart @@ -25,7 +25,7 @@ class WwiseEffect extends WwiseElement { _config = config, super( tagName: "Effect", - name: wwiseIdToStr(effect.uid, fallbackPrefix: "Effect"), + name: makeElementName(project, id: effect.uid, category: "Effect"), shortId: effect.uid, comment: project.getComment(effect.uid), properties: config.handler(effect.pluginData), diff --git a/lib/utils/wwiseProjectGenerator/elements/wwiseMusicSwitch.dart b/lib/utils/wwiseProjectGenerator/elements/wwiseMusicSwitch.dart index 1943aa0..d8cc876 100644 --- a/lib/utils/wwiseProjectGenerator/elements/wwiseMusicSwitch.dart +++ b/lib/utils/wwiseProjectGenerator/elements/wwiseMusicSwitch.dart @@ -14,7 +14,7 @@ class WwiseMusicSwitch extends WwiseHierarchyElement { WwiseMusicSwitch({required super.wuId, required super.project, required super.chunk}) : super( tagName: "MusicSwitchContainer", - name: "${wemIdsToNames[chunk.ulGroupID] ?? chunk.ulGroupID.toString()} Music Switch Container", + name: makeElementName(project, id: chunk.uid, parentId: chunk.getBaseParams().directParentID, name: wemIdsToNames[chunk.ulGroupID], category: "Music Switch Container"), shortId: chunk.uid, properties: [ if (chunk.bIsContinuousValidation != 1) diff --git a/lib/utils/wwiseProjectGenerator/elements/wwiseMusicTrack.dart b/lib/utils/wwiseProjectGenerator/elements/wwiseMusicTrack.dart index 9207f3f..29fd205 100644 --- a/lib/utils/wwiseProjectGenerator/elements/wwiseMusicTrack.dart +++ b/lib/utils/wwiseProjectGenerator/elements/wwiseMusicTrack.dart @@ -34,12 +34,12 @@ const _bnkFadeInterpolationToWwiseShape = { class WwiseMusicTrack extends WwiseHierarchyElement { WwiseMusicTrack({required super.wuId, required super.project, required super.chunk}) : super( tagName: "MusicTrack", - name: "${wemIdsToNames[chunk.sources.first.sourceID] ?? wemIdsToNames[chunk.sources.first.fileID] ?? chunk.uid.toString()} Music Track", + name: makeElementName(project, id: chunk.uid, parentId: chunk.baseParams.directParentID, name: wemIdsToNames[chunk.sources.first.sourceID] ?? wemIdsToNames[chunk.sources.first.fileID], category: "Music Track"), shortId: chunk.uid, properties: [ if (project.options.streaming && (chunk.sources.firstOrNull?.streamType ?? 0) >= 1) WwiseProperty("IsStreamingEnabled", "bool", values: ["True"]), - if (project.options.streaming && (chunk.sources.firstOrNull?.streamType ?? 0) == 2) + if (project.options.streaming && project.options.streamingPrefetch && (chunk.sources.firstOrNull?.streamType ?? 0) == 2) WwiseProperty("IsZeroLantency", "bool", values: ["True"]), if (chunk.iLookAheadTime != 100) WwiseProperty("LookAheadTime", "int16", value: chunk.iLookAheadTime.toString()), diff --git a/lib/utils/wwiseProjectGenerator/elements/wwiseSound.dart b/lib/utils/wwiseProjectGenerator/elements/wwiseSound.dart index 746941c..7a9acc8 100644 --- a/lib/utils/wwiseProjectGenerator/elements/wwiseSound.dart +++ b/lib/utils/wwiseProjectGenerator/elements/wwiseSound.dart @@ -20,7 +20,7 @@ class WwiseSound extends WwiseHierarchyElement { properties: [ if (project.options.streaming && chunk.bankData.streamType >= 1) WwiseProperty("IsStreamingEnabled", "bool", values: ["True"]), - if (project.options.streaming && chunk.bankData.streamType == 2) + if (project.options.streaming && project.options.streamingPrefetch && chunk.bankData.streamType == 2) WwiseProperty("IsZeroLantency", "bool", values: ["True"]), ], children: [ diff --git a/lib/utils/wwiseProjectGenerator/elements/wwiseSwitchContainer.dart b/lib/utils/wwiseProjectGenerator/elements/wwiseSwitchContainer.dart index dd6a480..fceff36 100644 --- a/lib/utils/wwiseProjectGenerator/elements/wwiseSwitchContainer.dart +++ b/lib/utils/wwiseProjectGenerator/elements/wwiseSwitchContainer.dart @@ -2,6 +2,7 @@ import 'package:xml/xml.dart'; import '../../../fileTypeUtils/audio/bnkIO.dart'; +import '../../../fileTypeUtils/audio/wemIdsToNames.dart'; import '../../utils.dart'; import '../wwiseElement.dart'; import '../wwiseProperty.dart'; @@ -14,7 +15,7 @@ class WwiseSwitchContainer extends WwiseHierarchyElement { WwiseSwitchContainer({required super.wuId, required super.project, required super.chunk, required this.childElements}) : super( tagName: "SwitchContainer", - name: "${wwiseIdToStr(chunk.ulGroupID, fallbackPrefix: "Switch Container")} (${chunk.uid})", + name: makeElementName(project, id: chunk.uid, parentId: chunk.baseParams.directParentID, name: wemIdsToNames[chunk.ulGroupID], category: "Switch Container"), shortId: chunk.uid, properties: [ if (chunk.eGroupType == 1) diff --git a/lib/utils/wwiseProjectGenerator/wwiseProjectGenerator.dart b/lib/utils/wwiseProjectGenerator/wwiseProjectGenerator.dart index 6a34e8e..8d2cacc 100644 --- a/lib/utils/wwiseProjectGenerator/wwiseProjectGenerator.dart +++ b/lib/utils/wwiseProjectGenerator/wwiseProjectGenerator.dart @@ -40,41 +40,26 @@ class WwiseProjectGeneratorOptions { final bool audioHierarchy; final bool wems; final bool streaming; + final bool streamingPrefetch; final bool seekTable; final bool translate; final bool events; final bool actions; + final bool nameId; + final bool namePrefix; WwiseProjectGeneratorOptions({ - this.audioHierarchy = true, - this.wems = true, - this.streaming = true, - this.seekTable = true, - this.translate = true, - this.events = true, - this.actions = true, + required this.audioHierarchy, + required this.wems, + required this.streaming, + required this.streamingPrefetch, + required this.seekTable, + required this.translate, + required this.events, + required this.actions, + required this.nameId, + required this.namePrefix, }); - - WwiseProjectGeneratorOptions copyWith({ - bool? audioHierarchy, - bool? gameSyncs, - bool? wems, - bool? streaming, - bool? seekTable, - bool? translate, - bool? events, - bool? actions, - }) { - return WwiseProjectGeneratorOptions( - audioHierarchy: audioHierarchy ?? this.audioHierarchy, - wems: wems ?? this.wems, - streaming: streaming ?? this.streaming, - seekTable: seekTable ?? this.seekTable, - translate: translate ?? this.translate, - events: events ?? this.events, - actions: actions ?? this.actions, - ); - } } class WwiseProjectGeneratorStatus { @@ -100,6 +85,7 @@ class WwiseProjectGenerator { final Map _elements = {}; final Map shortToFullId = {}; final WwiseIdGenerator idGen; + final Map> _usedNamesByParent = {}; final Map soundFiles = {}; final Map stateGroups = {}; final Map switchGroups = {}; @@ -288,6 +274,23 @@ class WwiseProjectGenerator { return comment; } + String makeName(String name, int parentId) { + if (!_usedNamesByParent.containsKey(parentId)) + _usedNamesByParent[parentId] = {}; + var usedNames = _usedNamesByParent[parentId]!; + var i = _usedNamesByParent[parentId]![name] ?? 1; + var newName = name; + if (i > 1) + newName = "$name $i"; + i++; + while (usedNames.containsKey(newName)) { + i++; + newName = "$name $i"; + } + usedNames[name] = i; + return newName; + } + Future _enableSeekTable() async { var wuPath = join(projectPath, "Conversion Settings", "Factory Conversion Settings.wwu"); var wuDoc = XmlDocument.parse(await File(wuPath).readAsString()); diff --git a/lib/utils/wwiseProjectGenerator/wwiseUtils.dart b/lib/utils/wwiseProjectGenerator/wwiseUtils.dart index 7bd2ab5..3159e3a 100644 --- a/lib/utils/wwiseProjectGenerator/wwiseUtils.dart +++ b/lib/utils/wwiseProjectGenerator/wwiseUtils.dart @@ -95,9 +95,9 @@ String getCommonString(List strings) { return strings.first.substring(0, minLen); } -String makeElementName(WwiseProjectGenerator project, {required int id, required String category, String? name, int? parentId, List? childIds, bool addId = false}) { +String makeElementName(WwiseProjectGenerator project, {required int id, required String category, int parentId = 0, String? name, List? childIds, bool addId = false}) { String? parentPrefix; - if (parentId != null) { + if (parentId != 0 && project.options.namePrefix) { var parent = project.hircChunkById(parentId); int? stateId; if (parent is BnkSoundSwitch) { @@ -138,7 +138,7 @@ String makeElementName(WwiseProjectGenerator project, {required int id, required name ??= category; if (parentPrefix != null) name = parentPrefix + name; - if (addId) + if (addId && project.options.nameId) name += " ($id)"; - return name; + return project.makeName(name, parentId); } diff --git a/lib/widgets/misc/wwiseProjectGeneratorPopup.dart b/lib/widgets/misc/wwiseProjectGeneratorPopup.dart index 0e8e6fe..c305df5 100644 --- a/lib/widgets/misc/wwiseProjectGeneratorPopup.dart +++ b/lib/widgets/misc/wwiseProjectGeneratorPopup.dart @@ -49,11 +49,13 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu final optAudioHierarchy = BoolProp(true, fileId: null); final optWems = BoolProp(true, fileId: null); final optStreaming = BoolProp(true, fileId: null); + final optStreamingPrefetch = BoolProp(true, fileId: null); final optSeekTable = BoolProp(true, fileId: null); final optTranslate = BoolProp(true, fileId: null); + final optNameId = BoolProp(false, fileId: null); + final optNamePrefix = BoolProp(true, fileId: null); final optEvents = BoolProp(true, fileId: null); final optActions = BoolProp(true, fileId: null); - final List<(String, BoolProp)> labeledOptions = []; final savePath = StringProp("", fileId: null); WwiseProjectGenerator? generator; bool hasStarted = false; @@ -66,15 +68,6 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu super.initState(); if (!widget.bnkName.contains("BGM")) optSeekTable.value = false; - labeledOptions.addAll([ - ("Actor-Mixer & Interactive Music Hierarchy", optAudioHierarchy), - ("Events", optEvents), - ("Actions", optActions), - ("WAV sources (requires \"WEM Extract Directory\" from settings)", optWems), - ("Use seek table for wems", optSeekTable), - ("Copy streaming settings", optStreaming), - ("Translate Japanese notes", optTranslate), - ]); var prefs = PreferencesData(); savePath.value = prefs.lastWwiseProjectDir?.value ?? ""; status.logs.addListener(onNewLog); @@ -104,6 +97,20 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu } List _makeOptions(BuildContext context) { + var labeledOptions = [ + ("Actor-Mixer & Interactive Music Hierarchy", optAudioHierarchy), + ("Events", optEvents), + ("Actions", optActions), + ("WAV sources (requires \"WEM Extract Directory\" from settings)", optWems), + ("Use seek table for wems", optSeekTable), + ("Copy streaming settings", optStreaming), + ("Copy streaming zero latency settings", optStreamingPrefetch), + ("Translate Japanese notes", optTranslate), + ]; + var labeledNameOptions = [ + ("Parent state as prefix", optNamePrefix), + ("Object ID", optNameId), + ]; return [ Row( children: [ @@ -142,6 +149,31 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu ), ], ), + Row( + children: [ + Text("Name settings: ", style: Theme.of(context).textTheme.bodyMedium), + for (var (label, prop) in labeledNameOptions) + Row( + children: [ + BoolPropCheckbox(prop: prop), + const SizedBox(width: 5), + GestureDetector( + onTap: () => prop.value = !prop.value, + child: Text(label, style: Theme.of(context).textTheme.bodyMedium) + ), + ], + ), + ], + ), + ChangeNotifierBuilder( + notifiers: [optNameId, optNamePrefix], + builder: (context) => Text( + "Preview: " + "${(optNamePrefix.value ? "[Intro] " : "")}" + "Stage_Prologue " + "${(optNameId.value ? "(715346925)" : "")}", + ), + ), const SizedBox(height: 15), Align( alignment: Alignment.center, @@ -216,10 +248,13 @@ class __WwiseProjectGeneratorPopupState extends State<_WwiseProjectGeneratorPopu audioHierarchy: optAudioHierarchy.value, wems: optWems.value, streaming: optStreaming.value, + streamingPrefetch: optStreamingPrefetch.value, seekTable: optSeekTable.value, translate: optTranslate.value, events: optEvents.value, actions: optActions.value, + nameId: optNameId.value, + namePrefix: optNamePrefix.value, ); hasStarted = true; setState(() {});