Add a comment field to mods

ADDTL; Edited the deserialization routine for mods to make it less prone to errors in the event a mod does not contain every field in the NBT data, ex. new comment field would have crashed the deserializer, causing it to skip past the mod or fully reset server settings.
This commit is contained in:
zontreck 2025-01-04 17:25:51 -07:00
parent 82c3a8cbcb
commit e2d64a2a9d
5 changed files with 1951 additions and 10 deletions

1897
dotnet-install.sh vendored Executable file

File diff suppressed because it is too large Load diff

View file

@ -1,3 +1,3 @@
class Consts {
static const VERSION = "1.1.112624.1409";
static const VERSION = "1.1.010425.1723";
}

View file

@ -163,6 +163,7 @@ class ModPageState extends State<ModPage> {
String pak = "Not initialized";
String hash = "";
bool enabled = false;
TextEditingController comment = TextEditingController();
@override
void didChangeDependencies() {
@ -176,6 +177,7 @@ class ModPageState extends State<ModPage> {
pak = args.mod_pak;
hash = args.mod_hash;
enabled = args.enabled;
comment.text = args.comment;
}
}
@ -202,7 +204,8 @@ class ModPageState extends State<ModPage> {
mod_id: idVal,
mod_name: name.text,
newMod: false,
enabled: enabled)));
enabled: enabled,
comment: comment.text)));
},
),
body: SingleChildScrollView(
@ -273,6 +276,24 @@ class ModPageState extends State<ModPage> {
title: Text("Enabled"),
subtitle: Text("Whether mod is enabled or not"),
),
Row(
children: [
SizedBox(
width: 150,
child: ListTile(
leading: Icon(Icons.comment),
title: Text("Comment"),
),
),
Expanded(
child: TextField(
controller: comment,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8))),
))
],
),
if (!isNewMod)
ElevatedButton(
onPressed: () {

View file

@ -10,6 +10,7 @@ class Mod {
String mod_pak = "";
String mod_hash = "";
bool enabled = true;
String comment = "";
bool newMod = false;
UUID _id = UUID.ZERO;
@ -27,7 +28,8 @@ class Mod {
this.newMod = false,
this.mod_pak = "Not Initialized",
this.mod_hash = "",
this.enabled = true});
this.enabled = true,
this.comment = ""});
CompoundTag serialize() {
CompoundTag tag = CompoundTag();
@ -35,6 +37,7 @@ class Mod {
tag.put("id", LongTag.valueOf(mod_id));
tag.put("pak", StringTag.valueOf(mod_pak));
tag.put("hash", StringTag.valueOf(mod_hash));
tag.put("comment", StringTag.valueOf(comment));
NbtUtils.writeBoolean(tag, "enabled", enabled);
return tag;
@ -43,11 +46,31 @@ class Mod {
static Mod deserialize(CompoundTag tag) {
CompoundTag ct = tag;
String modName = "undef";
if (ct.containsKey("name")) modName = ct.get("name")!.asString();
int modID = 0;
if (ct.containsKey("id")) modID = ct.get("id")!.asLong();
String pakFile = "Not yet initialized";
if (ct.containsKey("pak")) pakFile = ct.get("pak")!.asString();
String hash = "1234ABCD";
if (ct.containsKey("hash")) hash = ct.get("hash")!.asString();
bool enabled = true;
if (ct.containsKey("enabled"))
enabled = NbtUtils.readBoolean(tag, "enabled");
String comment = "";
if (ct.containsKey("comment")) comment = ct.get("comment")!.asString();
return Mod(
mod_name: ct.get("name")!.asString(),
mod_id: ct.get("id")!.asLong(),
mod_pak: ct.get("pak")!.asString(),
mod_hash: ct.get("hash")!.asString(),
enabled: NbtUtils.readBoolean(tag, "enabled"));
mod_name: modName,
mod_id: modID,
mod_pak: pakFile,
mod_hash: hash,
enabled: enabled,
comment: comment);
}
}

View file

@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.1.112624+1409
version: 1.1.010425+1723
environment:
sdk: ">=3.1.4 <4.0.0"
@ -92,4 +92,4 @@ flutter:
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
# see https://flutter.dev/custom-fonts/#from-packages