-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial support for adding & removing maps
BlueMap's default maps folder becomes the map-templates folder, instead, and a new empty maps folder gets created. Users can click on the "New map" button to create a new map config from one of those templates. There is also a delete button which closes the config file in the editor if it's open, and then deletes the file the next frame. The config tree UI is updated through a file watcher.
- Loading branch information
1 parent
7596712
commit 6e22c2f
Showing
4 changed files
with
142 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import "dart:io"; | ||
|
||
import "package:flutter/material.dart"; | ||
import "package:flutter_riverpod/flutter_riverpod.dart"; | ||
import "package:path/path.dart" as p; | ||
|
||
import "dual_pane.dart"; | ||
|
||
class MapTile extends ConsumerWidget { | ||
final File configFile; | ||
|
||
const MapTile(this.configFile, {super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
final File? openConfig = ref.watch(openConfigProvider); | ||
|
||
return ListTile( | ||
trailing: IconButton( | ||
icon: const Icon(Icons.delete), | ||
onPressed: () { | ||
//TODO: Show confirmation dialog | ||
|
||
//close the editor if it's open on that file | ||
if (openConfig != null && p.equals(openConfig.path, configFile.path)) { | ||
ref.read(openConfigProvider.notifier).close(); | ||
} | ||
//delete the file next frame, to ensure the editor is closed | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
configFile.delete(); | ||
}); | ||
}, | ||
), | ||
title: Text(_toHuman(configFile)), | ||
onTap: () { | ||
ref.read(openConfigProvider.notifier).open(configFile); | ||
}, | ||
selected: openConfig != null && p.equals(openConfig.path, configFile.path), | ||
); | ||
} | ||
|
||
static String _toHuman(File file) { | ||
final String name = p.basename(file.path).replaceAll(".conf", ""); | ||
if (name == "Sql") return "SQL"; | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import "dart:io"; | ||
import "dart:math"; | ||
|
||
import "package:flutter/material.dart"; | ||
import "package:flutter_riverpod/flutter_riverpod.dart"; | ||
import "package:path/path.dart" as p; | ||
|
||
import "main.dart"; | ||
|
||
class NewMapButton extends ConsumerWidget { | ||
const NewMapButton({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return Padding( | ||
padding: const EdgeInsets.all(8), | ||
child: ListTile( | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(80), | ||
), | ||
tileColor: Theme.of(context).colorScheme.secondary, | ||
title: const Row( | ||
children: [ | ||
Icon(Icons.add), | ||
SizedBox(width: 8), | ||
Text("New map"), | ||
], | ||
), | ||
onTap: () { | ||
Directory? projectDirectory = ref.read(projectDirectoryProvider); | ||
if (projectDirectory == null) return; | ||
|
||
File templateConfig = File( | ||
p.join(projectDirectory.path, "config", "map-templates", "overworld.conf"), | ||
); | ||
|
||
File newConfig = File( | ||
p.join(projectDirectory.path, "config", "maps", | ||
"new-map-${Random().nextInt(999)}.conf"), | ||
); | ||
|
||
templateConfig.copySync(newConfig.path); | ||
|
||
//TODO: Show options dialog | ||
// - which template? (overworld, nether, end) | ||
// - map name? (gets turned into a map ID and compared against existing map IDs) | ||
// other options won't be in this initial dialog, but in the actual config screen | ||
// which will get opened after this dialog | ||
}, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters