Skip to content

Commit

Permalink
Merge pull request #123 from gabber235/develop
Browse files Browse the repository at this point in the history
Final Tweaks for 0.4.0
  • Loading branch information
gabber235 authored Jan 8, 2024
2 parents 5568fd8 + bbc533d commit aa2af79
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 60 deletions.
15 changes: 9 additions & 6 deletions app/lib/models/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -345,12 +346,14 @@ extension PageX on Page {
Future<void> 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()),
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion app/lib/models/sounds.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 53 additions & 7 deletions app/lib/widgets/components/app/entries_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,44 @@ List<String> 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<String>? 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);
Expand All @@ -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,
);
}
}

Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit aa2af79

Please sign in to comment.