ConanServerManager/lib/structs/mod.dart
2025-03-02 19:38:31 -07:00

77 lines
2 KiB
Dart

import 'package:libac_dart/nbt/NbtUtils.dart';
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
import 'package:libac_dart/nbt/impl/LongTag.dart';
import 'package:libac_dart/nbt/impl/StringTag.dart';
import 'package:libac_dart/utils/uuid/UUID.dart';
class Mod {
String mod_name = "";
int mod_id = 0;
String mod_pak = "";
String mod_hash = "";
bool enabled = true;
String comment = "";
bool newMod = false;
UUID _id = UUID.ZERO;
String mod_instance_id() {
if (_id.toString() == UUID.ZERO.toString()) {
_id = UUID.generate(4);
}
return _id.toString();
}
Mod(
{this.mod_name = "undef",
this.mod_id = 0,
this.newMod = false,
this.mod_pak = "Not Initialized",
this.mod_hash = "",
this.enabled = true,
this.comment = ""});
CompoundTag serialize() {
CompoundTag tag = CompoundTag();
tag.put("name", StringTag.valueOf(mod_name));
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;
}
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: modName,
mod_id: modID,
mod_pak: pakFile,
mod_hash: hash,
enabled: enabled,
comment: comment);
}
}