Adds in SNBT Editing support
This commit is contained in:
parent
dc6dffc3ba
commit
410bde4c70
10 changed files with 107 additions and 13 deletions
|
@ -5,6 +5,7 @@ import 'package:libac_dart/nbt/NbtIo.dart';
|
|||
import 'package:libac_dart/nbt/Tag.dart';
|
||||
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
||||
import 'package:nbteditor/Constants.dart';
|
||||
import 'package:nbteditor/SessionData.dart';
|
||||
import 'package:nbteditor/tags/CompoundTag.dart';
|
||||
import 'package:nbteditor/tags/Tag.dart';
|
||||
|
||||
|
@ -16,7 +17,7 @@ class Editor extends StatefulWidget {
|
|||
}
|
||||
|
||||
class EditorState extends State<Editor> {
|
||||
List<Node> nodes = [CompoundTag().getNode("/")];
|
||||
//List<Node> nodes = [CompoundTag().getNode("/")];
|
||||
bool compressed = false;
|
||||
|
||||
static EditorState? _inst;
|
||||
|
@ -45,7 +46,8 @@ class EditorState extends State<Editor> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
controller = TreeViewController(children: nodes);
|
||||
controller =
|
||||
TreeViewController(children: [SessionData.ROOT_TAG.getNode("/")]);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
|
@ -68,11 +70,7 @@ class EditorState extends State<Editor> {
|
|||
leading: const Icon(Icons.add),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
nodes.clear();
|
||||
|
||||
// Add a new compound tag as the root
|
||||
Tag tag = CompoundTag();
|
||||
nodes.add(TagExt.getNode("/", tag) as Node);
|
||||
SessionData.ROOT_TAG = CompoundTag();
|
||||
});
|
||||
},
|
||||
),
|
||||
|
@ -97,14 +95,24 @@ class EditorState extends State<Editor> {
|
|||
} else {
|
||||
// String!!
|
||||
CompoundTag ct = await NbtIo.read(filePath);
|
||||
nodes.clear();
|
||||
nodes.add(ct.getNode("/") as Node);
|
||||
|
||||
SessionData.ROOT_TAG = ct;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
controller = TreeViewController(children: nodes);
|
||||
controller = TreeViewController(
|
||||
children: [SessionData.ROOT_TAG.getNode("/")]);
|
||||
});
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: Text("R A W"),
|
||||
subtitle: Text("Edit as raw SNBT"),
|
||||
leading: Icon(Icons.edit),
|
||||
onTap: () async {
|
||||
await Navigator.pushNamed(context, "/snbt");
|
||||
setState(() {});
|
||||
},
|
||||
)
|
||||
]),
|
||||
),
|
||||
|
|
5
lib/SessionData.dart
Normal file
5
lib/SessionData.dart
Normal file
|
@ -0,0 +1,5 @@
|
|||
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
||||
|
||||
class SessionData {
|
||||
static CompoundTag ROOT_TAG = CompoundTag();
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:nbteditor/Editor.dart';
|
||||
import 'package:nbteditor/pages/AddPage.dart';
|
||||
import 'package:nbteditor/pages/SNBTEditor.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MainApp());
|
||||
|
@ -15,7 +16,8 @@ class MainApp extends StatelessWidget {
|
|||
theme: ThemeData.dark(),
|
||||
routes: {
|
||||
"/": (context) => const Editor(),
|
||||
"/add": (context) => AddPage()
|
||||
"/add": (context) => AddPage(),
|
||||
"/snbt": (context) => SnbtEdit()
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
66
lib/pages/SNBTEditor.dart
Normal file
66
lib/pages/SNBTEditor.dart
Normal file
|
@ -0,0 +1,66 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_code_editor/flutter_code_editor.dart';
|
||||
import 'package:flutter_highlight/themes/vs.dart';
|
||||
import 'package:libac_dart/nbt/SnbtIo.dart';
|
||||
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
||||
import 'package:nbteditor/Constants.dart';
|
||||
import 'package:nbteditor/SessionData.dart';
|
||||
|
||||
class SnbtEdit extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return SnbtState();
|
||||
}
|
||||
}
|
||||
|
||||
class SnbtState extends State<SnbtEdit> {
|
||||
CodeController snbt = CodeController();
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
snbt.text = SnbtIo.writeToString(SessionData.ROOT_TAG);
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("SNBT Editor"),
|
||||
backgroundColor: Constants.TITLEBAR_COLOR,
|
||||
),
|
||||
floatingActionButton: ElevatedButton(
|
||||
onPressed: () async {
|
||||
try {
|
||||
CompoundTag ct =
|
||||
(await SnbtIo.readFromString(snbt.text)).asCompoundTag();
|
||||
snbt.text = SnbtIo.writeToString(ct);
|
||||
|
||||
setState(() {
|
||||
SessionData.ROOT_TAG = ct;
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Successfully edited NBT data")));
|
||||
} catch (E) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text("FATAL ERROR: Your SNBT Syntax is not valid")));
|
||||
}
|
||||
},
|
||||
child: Text("Compile"),
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: CodeTheme(
|
||||
data: CodeThemeData(styles: vsTheme),
|
||||
child: SingleChildScrollView(
|
||||
child: CodeField(
|
||||
controller: snbt,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -6,6 +6,10 @@
|
|||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <url_launcher_linux/url_launcher_plugin.h>
|
||||
|
||||
void fl_register_plugins(FlPluginRegistry* registry) {
|
||||
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
|
||||
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
|
||||
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
url_launcher_linux
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
import FlutterMacOS
|
||||
import Foundation
|
||||
|
||||
import url_launcher_macos
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
name: nbteditor
|
||||
description: A Minecraft NBT Editor written in Flutter
|
||||
publish_to: 'none'
|
||||
version: 0.1.0
|
||||
version: 0.070224.1924
|
||||
|
||||
environment:
|
||||
sdk: '>=3.1.5 <4.0.0'
|
||||
|
@ -10,10 +10,12 @@ dependencies:
|
|||
file_picker: ^6.1.1
|
||||
flutter:
|
||||
sdk: flutter
|
||||
flutter_code_editor: ^0.3.2
|
||||
flutter_highlight: ^0.7.0
|
||||
flutter_treeview: ^1.0.7+1
|
||||
libac_dart:
|
||||
hosted: https://git.zontreck.com/api/packages/AriasCreations/pub/
|
||||
version: 1.0.33
|
||||
version: 1.0.35
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
|
||||
#include "generated_plugin_registrant.h"
|
||||
|
||||
#include <url_launcher_windows/url_launcher_windows.h>
|
||||
|
||||
void RegisterPlugins(flutter::PluginRegistry* registry) {
|
||||
UrlLauncherWindowsRegisterWithRegistrar(
|
||||
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#
|
||||
|
||||
list(APPEND FLUTTER_PLUGIN_LIST
|
||||
url_launcher_windows
|
||||
)
|
||||
|
||||
list(APPEND FLUTTER_FFI_PLUGIN_LIST
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue