Implement dependency graphing resolving
This commit is contained in:
252
lib/main.dart
252
lib/main.dart
@@ -19,7 +19,7 @@ class RimWorldModManager extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'RimWorld Mod Manager',
|
||||
title: 'Rimworld Mod Manager',
|
||||
theme: ThemeData.dark().copyWith(
|
||||
primaryColor: const Color(0xFF3D4A59),
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
@@ -57,7 +57,7 @@ class _ModManagerHomePageState extends State<ModManagerHomePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('RimWorld Mod Manager')),
|
||||
appBar: AppBar(title: const Text('Rimworld Mod Manager')),
|
||||
body: _pages[_selectedIndex],
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
currentIndex: _selectedIndex,
|
||||
@@ -95,7 +95,7 @@ class _ModListPageState extends State<ModListPage> {
|
||||
bool _isLoading = false;
|
||||
String _loadingStatus = '';
|
||||
int _totalModsFound = 0;
|
||||
bool _skipFileCount = true; // Skip file counting by default for faster loading
|
||||
bool _skipFileCount = false; // Skip file counting by default for faster loading
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -116,7 +116,7 @@ class _ModListPageState extends State<ModListPage> {
|
||||
Text('Mod List', style: Theme.of(context).textTheme.headlineMedium),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Ready to scan for RimWorld mods.',
|
||||
'Ready to scan for Rimworld mods.',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -263,35 +263,235 @@ class _ModListPageState extends State<ModListPage> {
|
||||
}
|
||||
|
||||
// Page to manage mod load order with dependency visualization
|
||||
class LoadOrderPage extends StatelessWidget {
|
||||
class LoadOrderPage extends StatefulWidget {
|
||||
const LoadOrderPage({super.key});
|
||||
|
||||
@override
|
||||
State<LoadOrderPage> createState() => _LoadOrderPageState();
|
||||
}
|
||||
|
||||
class _LoadOrderPageState extends State<LoadOrderPage> {
|
||||
bool _isLoading = false;
|
||||
String _statusMessage = '';
|
||||
List<Mod> _sortedMods = [];
|
||||
bool _hasCycles = false;
|
||||
List<String>? _cycleInfo;
|
||||
List<List<String>> _incompatibleMods = [];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.reorder, size: 64),
|
||||
const SizedBox(height: 16),
|
||||
Text('Load Order', style: Theme.of(context).textTheme.headlineMedium),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Manage your mod loading order with dependency resolution.',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
// TODO: Implement automatic load order sorting
|
||||
},
|
||||
child: const Text('Auto-sort Mods'),
|
||||
),
|
||||
],
|
||||
return Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Mod Load Order',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Automatically sort mods based on dependencies.',
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: _isLoading ? null : _sortMods,
|
||||
child: const Text('Auto-sort Mods'),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
ElevatedButton(
|
||||
onPressed: _isLoading || _sortedMods.isEmpty ? null : _saveModOrder,
|
||||
child: const Text('Save Load Order'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (_isLoading)
|
||||
const LinearProgressIndicator(),
|
||||
if (_statusMessage.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Text(
|
||||
_statusMessage,
|
||||
style: TextStyle(
|
||||
color: _hasCycles || _incompatibleMods.isNotEmpty
|
||||
? Colors.orange
|
||||
: Colors.green,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_hasCycles && _cycleInfo != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Text(
|
||||
'Dependency cycle detected: ${_cycleInfo!.join(" -> ")}',
|
||||
style: TextStyle(color: Colors.orange),
|
||||
),
|
||||
),
|
||||
if (_incompatibleMods.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Incompatible mods detected:',
|
||||
style: TextStyle(color: Colors.orange),
|
||||
),
|
||||
...List.generate(_incompatibleMods.length > 5 ? 5 : _incompatibleMods.length, (index) {
|
||||
final pair = _incompatibleMods[index];
|
||||
return Text(
|
||||
'- ${modManager.mods[pair[0]]?.name} and ${modManager.mods[pair[1]]?.name}',
|
||||
style: TextStyle(color: Colors.orange),
|
||||
);
|
||||
}),
|
||||
if (_incompatibleMods.length > 5)
|
||||
Text('...and ${_incompatibleMods.length - 5} more'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: _sortedMods.isEmpty
|
||||
? Center(
|
||||
child: Text(
|
||||
'Click "Auto-sort Mods" to generate a load order based on dependencies.',
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
itemCount: _sortedMods.length,
|
||||
itemBuilder: (context, index) {
|
||||
final mod = _sortedMods[index];
|
||||
return Card(
|
||||
margin: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: ListTile(
|
||||
leading: Text('${index + 1}'),
|
||||
title: Text(mod.name),
|
||||
subtitle: Text(mod.id),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (mod.hardDependencies.isNotEmpty)
|
||||
Tooltip(
|
||||
message: 'Hard dependencies: ${mod.hardDependencies.length}',
|
||||
child: Icon(Icons.link, color: Colors.orange, size: 16),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
if (mod.softDependencies.isNotEmpty)
|
||||
Tooltip(
|
||||
message: 'Soft dependencies: ${mod.softDependencies.length}',
|
||||
child: Icon(Icons.link_off, color: Colors.blue, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _sortMods() async {
|
||||
if (modManager.mods.isEmpty) {
|
||||
setState(() {
|
||||
_statusMessage = 'No mods have been loaded yet. Please load mods first.';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_statusMessage = 'Sorting mods based on dependencies...';
|
||||
_hasCycles = false;
|
||||
_cycleInfo = null;
|
||||
_incompatibleMods = [];
|
||||
});
|
||||
|
||||
// This could be slow so run in a separate isolate or compute
|
||||
await Future.delayed(Duration.zero); // Allow UI to update
|
||||
|
||||
try {
|
||||
// Check for cycles first
|
||||
final hardGraph = modManager.buildDependencyGraph();
|
||||
final cycle = modManager.detectCycle(hardGraph);
|
||||
|
||||
if (cycle != null) {
|
||||
setState(() {
|
||||
_hasCycles = true;
|
||||
_cycleInfo = cycle;
|
||||
});
|
||||
}
|
||||
|
||||
// Get incompatibilities
|
||||
_incompatibleMods = modManager.findIncompatibilities();
|
||||
|
||||
// Get the sorted mods
|
||||
final sortedMods = modManager.getModsInLoadOrder();
|
||||
|
||||
setState(() {
|
||||
_sortedMods = sortedMods;
|
||||
_isLoading = false;
|
||||
_statusMessage = 'Sorting complete! ${sortedMods.length} mods sorted.';
|
||||
if (_hasCycles) {
|
||||
_statusMessage += ' Warning: Dependency cycles were found and fixed.';
|
||||
}
|
||||
if (_incompatibleMods.isNotEmpty) {
|
||||
_statusMessage += ' Warning: ${_incompatibleMods.length} incompatible mod pairs found.';
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_statusMessage = 'Error sorting mods: $e';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _saveModOrder() async {
|
||||
if (_sortedMods.isEmpty) return;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
_statusMessage = 'Saving mod load order...';
|
||||
});
|
||||
|
||||
try {
|
||||
// Create a ConfigFile instance
|
||||
final configFile = ConfigFile(path: configPath);
|
||||
|
||||
// Load the current config
|
||||
configFile.load();
|
||||
|
||||
// Replace the mods with our sorted list
|
||||
// We need to convert our Mods to the format expected by the config file
|
||||
configFile.mods.clear();
|
||||
for (final mod in _sortedMods) {
|
||||
configFile.mods.add(mod);
|
||||
}
|
||||
|
||||
// Save the updated config
|
||||
configFile.save();
|
||||
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_statusMessage = 'Mod load order saved successfully!';
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
_statusMessage = 'Error saving mod load order: $e';
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Page for troubleshooting problematic mods
|
||||
|
Reference in New Issue
Block a user