mirror of
https://github.com/dancojocaru2000/logic-circuits-simulator.git
synced 2025-02-21 16:49:36 +02:00
Fixed simulation and dependency resolution bugs
This commit is contained in:
parent
6e2dda60e2
commit
b34e65544b
2 changed files with 28 additions and 10 deletions
|
@ -37,7 +37,7 @@ class ComponentState extends ChangeNotifier {
|
|||
await state.setCurrentComponent(
|
||||
project: proj,
|
||||
component: comp,
|
||||
onDependencyNeeded: (projId, compId) async => _dependenciesMap['$projId/$compId'],
|
||||
onDependencyNeeded: (projId, compId) async => _dependenciesMap['${projId == "self" ? proj.projectId : projId}/$compId'],
|
||||
);
|
||||
}
|
||||
return SimulatedComponent(
|
||||
|
@ -108,14 +108,30 @@ class ComponentState extends ChangeNotifier {
|
|||
|
||||
// Load dependencies
|
||||
final unsatisfiedDependencies = <String>[];
|
||||
for (final depId in component.dependencies) {
|
||||
final splitted = depId.split('/');
|
||||
final maybeDep = await onDependencyNeeded(splitted[0], splitted[1]);
|
||||
if (maybeDep == null) {
|
||||
unsatisfiedDependencies.add(depId);
|
||||
}
|
||||
else {
|
||||
addDependency(depId, maybeDep);
|
||||
final neededDependencies = component.dependencies.toList();
|
||||
while (neededDependencies.isNotEmpty) {
|
||||
final tmp = neededDependencies.toList();
|
||||
neededDependencies.clear();
|
||||
for (final depId in tmp) {
|
||||
if (!hasDependency(depId)) {
|
||||
final splitted = depId.split('/');
|
||||
final maybeDep = await onDependencyNeeded(splitted[0], splitted[1]);
|
||||
if (maybeDep == null) {
|
||||
unsatisfiedDependencies.add(depId);
|
||||
}
|
||||
else {
|
||||
addDependency(depId, maybeDep);
|
||||
neededDependencies.addAll(
|
||||
maybeDep.item2.dependencies
|
||||
.map((depId) {
|
||||
final splitted = depId.split('/');
|
||||
final projectId = splitted[0] == 'self' ? maybeDep.item1.projectId : splitted[0];
|
||||
return '$projectId/${splitted[1]}';
|
||||
})
|
||||
.where((depId) => !hasDependency(depId))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (unsatisfiedDependencies.isNotEmpty) {
|
||||
|
|
|
@ -24,7 +24,9 @@ class SimulatedComponent {
|
|||
String instanceId, String? depId) async {
|
||||
if (!_instances.containsKey(instanceId)) {
|
||||
if (depId != null) {
|
||||
_instances[instanceId] = await onRequiredDependency(depId);
|
||||
final splitted = depId.split('/');
|
||||
final projectId = splitted[0] == 'self' ? project.projectId : splitted[0];
|
||||
_instances[instanceId] = await onRequiredDependency('$projectId/${splitted[1]}');
|
||||
} else {
|
||||
throw Exception('Attempted to get instance of unknown component');
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue