Fix mod editor

This commit is contained in:
zontreck 2024-08-28 12:39:49 -07:00
parent 3819b67e34
commit ebcad1f8fc

View file

@ -88,13 +88,15 @@ class ModManagerState extends State<ModManager> {
enabled: mod.enabled));
if (reply != null) {
if (reply is bool) {
ModEditReturnArgs MERA = reply as ModEditReturnArgs;
if (MERA.delete) {
setState(() {
settings.inst!.mods.removeAt(idx);
});
return;
}
setState(() {
settings.inst!.mods[idx] = reply as Mod;
settings.inst!.mods[idx] = MERA.mod!;
});
}
},
@ -110,10 +112,11 @@ class ModManagerState extends State<ModManager> {
final reply = await Navigator.pushNamed(context, "/server/mods/edit",
arguments: Mod(newMod: true));
if (reply != null && reply is! bool) {
Mod mod = reply as Mod;
if (reply != null) {
ModEditReturnArgs MERA = reply as ModEditReturnArgs;
setState(() {
settings.inst!.mods.add(mod);
settings.inst!.mods.add(MERA.mod!);
});
}
},
@ -132,7 +135,6 @@ class ModPageState extends State<ModPage> {
TextEditingController name = TextEditingController();
String instance = "";
bool isNewMod = false;
bool willDelete = false;
String pak = "Not initialized";
String hash = "";
bool enabled = false;
@ -167,17 +169,15 @@ class ModPageState extends State<ModPage> {
idVal = int.parse(id.text);
} catch (E) {}
if (willDelete) {
Navigator.pop(context, true);
} else {
Navigator.pop(
context,
Mod(
mod_id: idVal,
mod_name: name.text,
newMod: false,
enabled: enabled));
}
Navigator.pop(
context,
ModEditReturnArgs(
delete: false,
mod: Mod(
mod_id: idVal,
mod_name: name.text,
newMod: false,
enabled: enabled)));
},
),
body: SingleChildScrollView(
@ -248,8 +248,7 @@ class ModPageState extends State<ModPage> {
if (!isNewMod)
ElevatedButton(
onPressed: () {
willDelete = true;
Navigator.pop(context);
Navigator.pop(context, ModEditReturnArgs(delete: true));
},
child: Row(
children: [
@ -265,3 +264,10 @@ class ModPageState extends State<ModPage> {
);
}
}
class ModEditReturnArgs {
bool delete;
Mod? mod;
ModEditReturnArgs({required this.delete, this.mod});
}