diff --git a/app/lib/models/page.dart b/app/lib/models/page.dart index 60e2313b1e..c39324d788 100644 --- a/app/lib/models/page.dart +++ b/app/lib/models/page.dart @@ -10,6 +10,7 @@ import "package:typewriter/models/entry.dart"; import "package:typewriter/utils/extensions.dart"; import "package:typewriter/utils/passing_reference.dart"; import "package:typewriter/utils/popups.dart"; +import "package:typewriter/widgets/components/app/entries_graph.dart"; import "package:typewriter/widgets/components/app/entry_search.dart"; import "package:typewriter/widgets/components/app/search_bar.dart"; import "package:typewriter/widgets/inspector/inspector.dart"; @@ -345,12 +346,14 @@ extension PageX on Page { Future extendsWithDuplicate(PassingRef ref, String entryId) async { final entry = ref.read(entryProvider(pageName, entryId)); if (entry == null) return; - final triggerPaths = ref.read(modifierPathsProvider(entry.type, "trigger")); - if (!triggerPaths.contains("triggers.*")) { - debugPrint("Cannot duplicate entry with no triggers.*"); + final isTrigger = ref.read(isTriggerEntryProvider(entryId)); + if (!isTrigger) { + debugPrint("Cannot extend a non-trigger entry."); return; } + final triggerPaths = ref.read(modifierPathsProvider(entry.type, "trigger")); + final newEntry = triggerPaths .fold( entry.copyWith("id", getRandomString()), @@ -368,9 +371,9 @@ extension PageX on Page { void extendsWith(PassingRef ref, String entryId) { final entry = ref.read(entryProvider(pageName, entryId)); if (entry == null) return; - final triggerPaths = ref.read(modifierPathsProvider(entry.type, "trigger")); - if (!triggerPaths.contains("triggers.*")) { - debugPrint("Cannot extend entry with no triggers.*"); + final isTrigger = ref.read(isTriggerEntryProvider(entryId)); + if (!isTrigger) { + debugPrint("Cannot extend a non-trigger entry."); return; } diff --git a/app/lib/models/sounds.g.dart b/app/lib/models/sounds.g.dart index f9a91afedc..56631c8fa0 100644 --- a/app/lib/models/sounds.g.dart +++ b/app/lib/models/sounds.g.dart @@ -40,7 +40,7 @@ final minecraftSoundsProvider = ); typedef MinecraftSoundsRef = FutureProviderRef>>; -String _$minecraftSoundHash() => r'3a6806c1a0d534e49af8e067f895dfa0912868ee'; +String _$minecraftSoundHash() => r'360718281dd98a11b4669309eee983425b822717'; /// Copied from Dart SDK class _SystemHash { diff --git a/app/lib/widgets/components/app/entries_graph.dart b/app/lib/widgets/components/app/entries_graph.dart index 7e97299ebb..4c50c45a57 100644 --- a/app/lib/widgets/components/app/entries_graph.dart +++ b/app/lib/widgets/components/app/entries_graph.dart @@ -31,6 +31,44 @@ List graphableEntryIds(GraphableEntryIdsRef ref) { return entries.map((entry) => entry.id).toList(); } +@riverpod +bool isTriggerEntry(IsTriggerEntryRef ref, String entryId) { + final entry = ref.watch(globalEntryProvider(entryId)); + if (entry == null) return false; + + final tags = ref.watch(entryTagsProvider(entry.type)); + if (!tags.contains("trigger")) return false; + + final modifiers = ref.watch(modifierPathsProvider(entry.type, "trigger")); + + return modifiers.contains("triggers.*"); +} + +@riverpod +bool isTriggerableEntry(IsTriggerableEntryRef ref, String entryId) { + final entry = ref.watch(globalEntryProvider(entryId)); + if (entry == null) return false; + + final tags = ref.watch(entryTagsProvider(entry.type)); + return tags.contains("triggerable"); +} + +@riverpod +Set? entryTriggers(EntryTriggersRef ref, String entryId) { + final entry = ref.watch(globalEntryProvider(entryId)); + if (entry == null) return null; + + // Check if this entry is a trigger + if (!ref.read(isTriggerEntryProvider(entryId))) return null; + + final modifiers = ref.watch(modifierPathsProvider(entry.type, "trigger")); + return modifiers + .expand(entry.getAll) + .map((id) => id as String) + .where((id) => id.isNotEmpty) + .toSet(); +} + @riverpod Graph graph(GraphRef ref) { final entries = ref.watch(graphableEntriesProvider); @@ -42,14 +80,18 @@ Graph graph(GraphRef ref) { } for (final entry in entries) { - final modifiers = ref.watch(fieldModifiersProvider(entry.type, "trigger")); - final triggeredEntryIds = - modifiers.entries.map((e) => e.key).expand(entry.getAll).where((id) => id.isNotEmpty).toSet(); + final triggeredEntryIds = ref.watch(entryTriggersProvider(entry.id)); + if (triggeredEntryIds == null) continue; - final color = ref.watch(entryBlueprintProvider(entry.type))?.color ?? Colors.grey; + final color = + ref.watch(entryBlueprintProvider(entry.type))?.color ?? Colors.grey; for (final triggeredEntryId in triggeredEntryIds) { - graph.addEdge(Node.Id(entry.id), Node.Id(triggeredEntryId), paint: Paint()..color = color); + graph.addEdge( + Node.Id(entry.id), + Node.Id(triggeredEntryId), + paint: Paint()..color = color, + ); } } @@ -103,12 +145,16 @@ class EntriesGraph extends HookConsumerWidget { final entryOnPage = entryIds.contains(id); if (!entryOnPage) { - final globalEntryWithPage = ref.watch(globalEntryWithPageProvider(id)); + final globalEntryWithPage = + ref.watch(globalEntryWithPageProvider(id)); if (globalEntryWithPage == null) { return const InvalidEntry(); } - return ExternalEntryNode(pageId: globalEntryWithPage.key, entry: globalEntryWithPage.value); + return ExternalEntryNode( + pageId: globalEntryWithPage.key, + entry: globalEntryWithPage.value, + ); } return EntryNode( entryId: id, diff --git a/app/lib/widgets/components/app/entries_graph.g.dart b/app/lib/widgets/components/app/entries_graph.g.dart index 8ab4d22fc6..57cf4cf5be 100644 --- a/app/lib/widgets/components/app/entries_graph.g.dart +++ b/app/lib/widgets/components/app/entries_graph.g.dart @@ -36,7 +36,413 @@ final graphableEntryIdsProvider = AutoDisposeProvider>.internal( ); typedef GraphableEntryIdsRef = AutoDisposeProviderRef>; -String _$graphHash() => r'7269326e7ddcfc6d7d7d305a4be789fc3b3ec1e0'; +String _$isTriggerEntryHash() => r'917683e8c329400c0068ea5a34a064cb729e32ab'; + +/// Copied from Dart SDK +class _SystemHash { + _SystemHash._(); + + static int combine(int hash, int value) { + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + value); + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10)); + return hash ^ (hash >> 6); + } + + static int finish(int hash) { + // ignore: parameter_assignments + hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); + // ignore: parameter_assignments + hash = hash ^ (hash >> 11); + return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); + } +} + +/// See also [isTriggerEntry]. +@ProviderFor(isTriggerEntry) +const isTriggerEntryProvider = IsTriggerEntryFamily(); + +/// See also [isTriggerEntry]. +class IsTriggerEntryFamily extends Family { + /// See also [isTriggerEntry]. + const IsTriggerEntryFamily(); + + /// See also [isTriggerEntry]. + IsTriggerEntryProvider call( + String entryId, + ) { + return IsTriggerEntryProvider( + entryId, + ); + } + + @override + IsTriggerEntryProvider getProviderOverride( + covariant IsTriggerEntryProvider provider, + ) { + return call( + provider.entryId, + ); + } + + static const Iterable? _dependencies = null; + + @override + Iterable? get dependencies => _dependencies; + + static const Iterable? _allTransitiveDependencies = null; + + @override + Iterable? get allTransitiveDependencies => + _allTransitiveDependencies; + + @override + String? get name => r'isTriggerEntryProvider'; +} + +/// See also [isTriggerEntry]. +class IsTriggerEntryProvider extends AutoDisposeProvider { + /// See also [isTriggerEntry]. + IsTriggerEntryProvider( + String entryId, + ) : this._internal( + (ref) => isTriggerEntry( + ref as IsTriggerEntryRef, + entryId, + ), + from: isTriggerEntryProvider, + name: r'isTriggerEntryProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') + ? null + : _$isTriggerEntryHash, + dependencies: IsTriggerEntryFamily._dependencies, + allTransitiveDependencies: + IsTriggerEntryFamily._allTransitiveDependencies, + entryId: entryId, + ); + + IsTriggerEntryProvider._internal( + super._createNotifier, { + required super.name, + required super.dependencies, + required super.allTransitiveDependencies, + required super.debugGetCreateSourceHash, + required super.from, + required this.entryId, + }) : super.internal(); + + final String entryId; + + @override + Override overrideWith( + bool Function(IsTriggerEntryRef provider) create, + ) { + return ProviderOverride( + origin: this, + override: IsTriggerEntryProvider._internal( + (ref) => create(ref as IsTriggerEntryRef), + from: from, + name: null, + dependencies: null, + allTransitiveDependencies: null, + debugGetCreateSourceHash: null, + entryId: entryId, + ), + ); + } + + @override + AutoDisposeProviderElement createElement() { + return _IsTriggerEntryProviderElement(this); + } + + @override + bool operator ==(Object other) { + return other is IsTriggerEntryProvider && other.entryId == entryId; + } + + @override + int get hashCode { + var hash = _SystemHash.combine(0, runtimeType.hashCode); + hash = _SystemHash.combine(hash, entryId.hashCode); + + return _SystemHash.finish(hash); + } +} + +mixin IsTriggerEntryRef on AutoDisposeProviderRef { + /// The parameter `entryId` of this provider. + String get entryId; +} + +class _IsTriggerEntryProviderElement extends AutoDisposeProviderElement + with IsTriggerEntryRef { + _IsTriggerEntryProviderElement(super.provider); + + @override + String get entryId => (origin as IsTriggerEntryProvider).entryId; +} + +String _$isTriggerableEntryHash() => + r'4b5b533dee75d07eb970a077785ab5defb6dcfe6'; + +/// See also [isTriggerableEntry]. +@ProviderFor(isTriggerableEntry) +const isTriggerableEntryProvider = IsTriggerableEntryFamily(); + +/// See also [isTriggerableEntry]. +class IsTriggerableEntryFamily extends Family { + /// See also [isTriggerableEntry]. + const IsTriggerableEntryFamily(); + + /// See also [isTriggerableEntry]. + IsTriggerableEntryProvider call( + String entryId, + ) { + return IsTriggerableEntryProvider( + entryId, + ); + } + + @override + IsTriggerableEntryProvider getProviderOverride( + covariant IsTriggerableEntryProvider provider, + ) { + return call( + provider.entryId, + ); + } + + static const Iterable? _dependencies = null; + + @override + Iterable? get dependencies => _dependencies; + + static const Iterable? _allTransitiveDependencies = null; + + @override + Iterable? get allTransitiveDependencies => + _allTransitiveDependencies; + + @override + String? get name => r'isTriggerableEntryProvider'; +} + +/// See also [isTriggerableEntry]. +class IsTriggerableEntryProvider extends AutoDisposeProvider { + /// See also [isTriggerableEntry]. + IsTriggerableEntryProvider( + String entryId, + ) : this._internal( + (ref) => isTriggerableEntry( + ref as IsTriggerableEntryRef, + entryId, + ), + from: isTriggerableEntryProvider, + name: r'isTriggerableEntryProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') + ? null + : _$isTriggerableEntryHash, + dependencies: IsTriggerableEntryFamily._dependencies, + allTransitiveDependencies: + IsTriggerableEntryFamily._allTransitiveDependencies, + entryId: entryId, + ); + + IsTriggerableEntryProvider._internal( + super._createNotifier, { + required super.name, + required super.dependencies, + required super.allTransitiveDependencies, + required super.debugGetCreateSourceHash, + required super.from, + required this.entryId, + }) : super.internal(); + + final String entryId; + + @override + Override overrideWith( + bool Function(IsTriggerableEntryRef provider) create, + ) { + return ProviderOverride( + origin: this, + override: IsTriggerableEntryProvider._internal( + (ref) => create(ref as IsTriggerableEntryRef), + from: from, + name: null, + dependencies: null, + allTransitiveDependencies: null, + debugGetCreateSourceHash: null, + entryId: entryId, + ), + ); + } + + @override + AutoDisposeProviderElement createElement() { + return _IsTriggerableEntryProviderElement(this); + } + + @override + bool operator ==(Object other) { + return other is IsTriggerableEntryProvider && other.entryId == entryId; + } + + @override + int get hashCode { + var hash = _SystemHash.combine(0, runtimeType.hashCode); + hash = _SystemHash.combine(hash, entryId.hashCode); + + return _SystemHash.finish(hash); + } +} + +mixin IsTriggerableEntryRef on AutoDisposeProviderRef { + /// The parameter `entryId` of this provider. + String get entryId; +} + +class _IsTriggerableEntryProviderElement + extends AutoDisposeProviderElement with IsTriggerableEntryRef { + _IsTriggerableEntryProviderElement(super.provider); + + @override + String get entryId => (origin as IsTriggerableEntryProvider).entryId; +} + +String _$entryTriggersHash() => r'2cdd643e8ce0f19c5b6dea06b5574c03276aad76'; + +/// See also [entryTriggers]. +@ProviderFor(entryTriggers) +const entryTriggersProvider = EntryTriggersFamily(); + +/// See also [entryTriggers]. +class EntryTriggersFamily extends Family?> { + /// See also [entryTriggers]. + const EntryTriggersFamily(); + + /// See also [entryTriggers]. + EntryTriggersProvider call( + String entryId, + ) { + return EntryTriggersProvider( + entryId, + ); + } + + @override + EntryTriggersProvider getProviderOverride( + covariant EntryTriggersProvider provider, + ) { + return call( + provider.entryId, + ); + } + + static const Iterable? _dependencies = null; + + @override + Iterable? get dependencies => _dependencies; + + static const Iterable? _allTransitiveDependencies = null; + + @override + Iterable? get allTransitiveDependencies => + _allTransitiveDependencies; + + @override + String? get name => r'entryTriggersProvider'; +} + +/// See also [entryTriggers]. +class EntryTriggersProvider extends AutoDisposeProvider?> { + /// See also [entryTriggers]. + EntryTriggersProvider( + String entryId, + ) : this._internal( + (ref) => entryTriggers( + ref as EntryTriggersRef, + entryId, + ), + from: entryTriggersProvider, + name: r'entryTriggersProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') + ? null + : _$entryTriggersHash, + dependencies: EntryTriggersFamily._dependencies, + allTransitiveDependencies: + EntryTriggersFamily._allTransitiveDependencies, + entryId: entryId, + ); + + EntryTriggersProvider._internal( + super._createNotifier, { + required super.name, + required super.dependencies, + required super.allTransitiveDependencies, + required super.debugGetCreateSourceHash, + required super.from, + required this.entryId, + }) : super.internal(); + + final String entryId; + + @override + Override overrideWith( + Set? Function(EntryTriggersRef provider) create, + ) { + return ProviderOverride( + origin: this, + override: EntryTriggersProvider._internal( + (ref) => create(ref as EntryTriggersRef), + from: from, + name: null, + dependencies: null, + allTransitiveDependencies: null, + debugGetCreateSourceHash: null, + entryId: entryId, + ), + ); + } + + @override + AutoDisposeProviderElement?> createElement() { + return _EntryTriggersProviderElement(this); + } + + @override + bool operator ==(Object other) { + return other is EntryTriggersProvider && other.entryId == entryId; + } + + @override + int get hashCode { + var hash = _SystemHash.combine(0, runtimeType.hashCode); + hash = _SystemHash.combine(hash, entryId.hashCode); + + return _SystemHash.finish(hash); + } +} + +mixin EntryTriggersRef on AutoDisposeProviderRef?> { + /// The parameter `entryId` of this provider. + String get entryId; +} + +class _EntryTriggersProviderElement + extends AutoDisposeProviderElement?> with EntryTriggersRef { + _EntryTriggersProviderElement(super.provider); + + @override + String get entryId => (origin as EntryTriggersProvider).entryId; +} + +String _$graphHash() => r'95895c4970adb0f53701f0bce28678009313d140'; /// See also [graph]. @ProviderFor(graph) diff --git a/app/lib/widgets/components/app/entry_node.dart b/app/lib/widgets/components/app/entry_node.dart index 11442b56a9..6ba05944aa 100644 --- a/app/lib/widgets/components/app/entry_node.dart +++ b/app/lib/widgets/components/app/entry_node.dart @@ -1,6 +1,5 @@ import "package:dotted_border/dotted_border.dart"; import "package:flutter/material.dart"; -import "package:flutter/widgets.dart"; import "package:flutter_animate/flutter_animate.dart"; import "package:font_awesome_flutter/font_awesome_flutter.dart"; import "package:hooks_riverpod/hooks_riverpod.dart"; @@ -12,6 +11,7 @@ import "package:typewriter/models/writers.dart"; import "package:typewriter/pages/page_editor.dart"; import "package:typewriter/utils/extensions.dart"; import "package:typewriter/utils/passing_reference.dart"; +import "package:typewriter/widgets/components/app/entries_graph.dart"; import "package:typewriter/widgets/components/app/select_entries.dart"; import "package:typewriter/widgets/components/app/writers.dart"; import "package:typewriter/widgets/components/general/context_menu_region.dart"; @@ -124,18 +124,12 @@ class _EntryNode extends HookConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { - final canTrigger = ref.read( - modifierPathsProvider(type, "trigger") - .select((value) => value.contains("triggers.*")), - ); - final canBeTriggered = ref.watch( - entryBlueprintProvider(type) - .select((b) => b?.tags.contains("triggerable") ?? false), - ); + final canTrigger = ref.watch(isTriggerEntryProvider(id)); + final canBeTriggered = ref.watch(isTriggerableEntryProvider(id)); return WritersIndicator( provider: _writersProvider(id), - child: Draggable( + child: LongPressDraggable( data: EntryDrag(entryId: id), feedback: FakeEntryNode(entryId: id), childWhenDragging: ColoredBox( @@ -170,12 +164,9 @@ class _EntryNode extends HookConsumerWidget { child: DragTarget( onWillAcceptWithDetails: (details) { if (!canTrigger) return false; - final entry = ref.read(globalEntryProvider(details.data.entryId)); - if (entry == null) return false; - final blueprint = ref.read(entryBlueprintProvider(entry.type)); + final targetId = details.data.entryId; - // Check if the entry is triggerable - return blueprint?.tags.contains("triggerable") ?? false; + return ref.read(isTriggerableEntryProvider(targetId)); }, onAcceptWithDetails: (details) { final page = ref.read(currentPageProvider); @@ -433,7 +424,7 @@ class ExternalEntryNode extends HookConsumerWidget { return const InvalidEntry(); } - return Draggable( + return LongPressDraggable( data: EntryDrag(entryId: entry.id), feedback: FakeEntryNode(entryId: entry.id), childWhenDragging: DottedBorder( diff --git a/app/lib/widgets/inspector/editors.g.dart b/app/lib/widgets/inspector/editors.g.dart index 64a715f2e0..94375314b2 100644 --- a/app/lib/widgets/inspector/editors.g.dart +++ b/app/lib/widgets/inspector/editors.g.dart @@ -172,7 +172,7 @@ class _FieldValueProviderElement extends AutoDisposeProviderElement dynamic get defaultValue => (origin as FieldValueProvider).defaultValue; } -String _$editorFiltersHash() => r'168b4998335c3de63d58cbd8c0bba07b574b53ec'; +String _$editorFiltersHash() => r'd65a7ab818dcdaa709c8817d39a28e9fb1157851'; /// See also [editorFilters]. @ProviderFor(editorFilters) diff --git a/app/lib/widgets/inspector/operations.dart b/app/lib/widgets/inspector/operations.dart index 7bd71badc6..a8d99d855c 100644 --- a/app/lib/widgets/inspector/operations.dart +++ b/app/lib/widgets/inspector/operations.dart @@ -1,11 +1,11 @@ import "package:flutter/material.dart" hide FilledButton; import "package:font_awesome_flutter/font_awesome_flutter.dart"; import "package:hooks_riverpod/hooks_riverpod.dart"; -import "package:typewriter/models/adapter.dart"; import "package:typewriter/models/page.dart"; import "package:typewriter/pages/page_editor.dart"; import "package:typewriter/utils/extensions.dart"; import "package:typewriter/utils/passing_reference.dart"; +import "package:typewriter/widgets/components/app/entries_graph.dart"; import "package:typewriter/widgets/components/general/context_menu_region.dart"; import "package:typewriter/widgets/components/general/filled_button.dart"; import "package:typewriter/widgets/components/general/outline_button.dart"; @@ -24,11 +24,8 @@ class Operations extends HookConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final type = ref.watch(inspectingEntryProvider.select((e) => e?.type)); if (type == null) return const SizedBox(); - final canTrigger = ref.watch( - modifierPathsProvider(type, "trigger").select((value) => value.contains("triggers.*")), - ); - final canBeTriggered = ref - .watch(inspectingEntryDefinitionProvider.select((def) => def?.blueprint.tags.contains("triggerable") ?? false)); + final canTrigger = ref.watch(isTriggerEntryProvider(type)); + final canBeTriggered = ref.watch(isTriggerableEntryProvider(type)); return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/app/pubspec.lock b/app/pubspec.lock index 41db4412ee..50b1a012eb 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -627,26 +627,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: e45c31f458d01fd9ef4a214feb2e153b72d5b1907435f4332b1637a2f348c021 + sha256: "04be76c4a4bb50f14904e64749237e541e7c7bcf7ec0b196907322ab5d2fc739" url: "https://pub.dev" source: hosted - version: "9.0.18" - leak_tracker_flutter_testing: - dependency: transitive - description: - name: leak_tracker_flutter_testing - sha256: "54808cfcfa87dbc0d74c61ac063d624adf1bd5c0407301f32b06c783c60dc4ca" - url: "https://pub.dev" - source: hosted - version: "2.0.0" + version: "9.0.16" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: "7e71be3c161472f6c9158ac8875dd8de575060d60b5d159ebca3600ea32c9116" + sha256: b06739349ec2477e943055aea30172c5c7000225f79dad4702e2ec0eda79a6ff url: "https://pub.dev" source: hosted - version: "1.0.6" + version: "1.0.5" lints: dependency: transitive description: @@ -667,10 +659,10 @@ packages: dependency: transitive description: name: matcher - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e" url: "https://pub.dev" source: hosted - version: "0.12.16+1" + version: "0.12.16" material_color_utilities: dependency: transitive description: @@ -707,10 +699,10 @@ packages: dependency: transitive description: name: path - sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917" url: "https://pub.dev" source: hosted - version: "1.9.0" + version: "1.8.3" path_drawing: dependency: transitive description: diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/entry/dialogue/DialogueSequence.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/entry/dialogue/DialogueSequence.kt index c955e9a4be..d67064d691 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/entry/dialogue/DialogueSequence.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/entry/dialogue/DialogueSequence.kt @@ -23,7 +23,6 @@ class DialogueSequence(private val player: Player, initialEntry: DialogueEntry) private var currentMessenger = messengerFinder.findMessenger(player, initialEntry) private var cycle = 0 var isActive = false - private set val triggers: List get() = currentMessenger.triggers diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/interaction/Interaction.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/interaction/Interaction.kt index f761ed75ac..ab919d89ed 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/interaction/Interaction.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/interaction/Interaction.kt @@ -6,7 +6,6 @@ import me.gabber235.typewriter.entry.dialogue.DialogueSequence import me.gabber235.typewriter.entry.entries.* import me.gabber235.typewriter.entry.entries.SystemTrigger.* import me.gabber235.typewriter.entry.matches -import me.gabber235.typewriter.entry.triggerEntriesFor import me.gabber235.typewriter.entry.triggerFor import org.bukkit.entity.Player import org.koin.core.component.KoinComponent @@ -56,7 +55,7 @@ class Interaction(val player: Player) : KoinComponent { } } - private fun handleDialogue(event: Event) { + private suspend fun handleDialogue(event: Event) { if (DIALOGUE_END in event) { val dialogue = dialogue ?: return this.dialogue = null @@ -103,13 +102,17 @@ class Interaction(val player: Player) : KoinComponent { * Called when the player clicks the next button. If there is no next dialogue, the sequence * will be ended. */ - private fun onDialogueNext() { + private suspend fun onDialogueNext() { val dialog = dialogue ?: return + dialog.isActive = false if (dialog.triggers.isEmpty()) { - DIALOGUE_END triggerFor player + // We need to immediately end the dialogue, otherwise it may be triggered again + onEvent(Event(player, listOf(DIALOGUE_END))) return } - dialog.triggers triggerEntriesFor player + + // We need to immediately end the dialogue, otherwise it may be triggered again + onEvent(Event(player, dialog.triggers.map(::EntryTrigger))) return }