mirror of
https://github.com/chenasraf/mudblock.git
synced 2026-05-17 17:48:05 +00:00
fix: button set save fix
This commit is contained in:
@@ -88,35 +88,70 @@ class PluginBase extends ChangeNotifier {
|
||||
|
||||
Future<void> saveAlias(Alias alias) async {
|
||||
debugPrint('MUDProfile.saveAlias: $id/aliases/${alias.id}');
|
||||
notifyListeners();
|
||||
final idx = aliases.indexWhere((a) => a.id == alias.id);
|
||||
if (idx >= 0) {
|
||||
aliases[idx] = alias;
|
||||
} else {
|
||||
aliases.add(alias);
|
||||
}
|
||||
return ProfileStorage.writeProfileFile(
|
||||
id, 'aliases/${alias.id}', alias.toJson());
|
||||
}
|
||||
|
||||
Future<void> deleteAlias(Alias alias) async {
|
||||
debugPrint('MUDProfile.deleteAlias: $id/aliases/${alias.id}');
|
||||
final idx = aliases.indexWhere((a) => a.id == alias.id);
|
||||
if (idx >= 0) {
|
||||
aliases.removeAt(idx);
|
||||
}
|
||||
notifyListeners();
|
||||
return ProfileStorage.deleteProfileFile(id, 'aliases/${alias.id}');
|
||||
}
|
||||
|
||||
Future<void> saveTrigger(Trigger trigger) async {
|
||||
debugPrint('MUDProfile.saveTrigger: $id/triggers/${trigger.id}');
|
||||
final idx = triggers.indexWhere((a) => a.id == trigger.id);
|
||||
if (idx >= 0) {
|
||||
triggers[idx] = trigger;
|
||||
} else {
|
||||
triggers.add(trigger);
|
||||
}
|
||||
notifyListeners();
|
||||
return ProfileStorage.writeProfileFile(
|
||||
id, 'triggers/${trigger.id}', trigger.toJson());
|
||||
}
|
||||
|
||||
Future<void> deleteTrigger(Trigger trigger) async {
|
||||
debugPrint('MUDProfile.deleteTrigger: $id/triggers/${trigger.id}');
|
||||
final idx = triggers.indexWhere((a) => a.id == trigger.id);
|
||||
if (idx >= 0) {
|
||||
triggers.removeAt(idx);
|
||||
}
|
||||
notifyListeners();
|
||||
return ProfileStorage.deleteProfileFile(id, 'triggers/${trigger.id}');
|
||||
}
|
||||
|
||||
Future<void> saveButtonSet(GameButtonSetData buttonSet) async {
|
||||
debugPrint('MUDProfile.saveButtonSet: $id/button_sets/${buttonSet.id}');
|
||||
final idx = buttonSets.indexWhere((a) => a.id == buttonSet.id);
|
||||
if (idx >= 0) {
|
||||
buttonSets[idx] = buttonSet;
|
||||
} else {
|
||||
buttonSets.add(buttonSet);
|
||||
}
|
||||
notifyListeners();
|
||||
return ProfileStorage.writeProfileFile(
|
||||
id, 'button_sets/${buttonSet.id}', buttonSet.toJson());
|
||||
}
|
||||
|
||||
|
||||
Future<void> deleteButtonSet(GameButtonSetData buttonSet) async {
|
||||
debugPrint('MUDProfile.deleteButtonSet: $id/button_sets/${buttonSet.id}');
|
||||
final idx = buttonSets.indexWhere((a) => a.id == buttonSet.id);
|
||||
if (idx >= 0) {
|
||||
buttonSets.removeAt(idx);
|
||||
}
|
||||
notifyListeners();
|
||||
return ProfileStorage.deleteProfileFile(id, 'button_sets/${buttonSet.id}');
|
||||
}
|
||||
|
||||
@@ -130,6 +165,7 @@ class PluginBase extends ChangeNotifier {
|
||||
} else {
|
||||
current.add(update);
|
||||
}
|
||||
notifyListeners();
|
||||
return ProfileStorage.writeProfileFile(
|
||||
id,
|
||||
'vars',
|
||||
@@ -145,6 +181,7 @@ class PluginBase extends ChangeNotifier {
|
||||
if (existing >= 0) {
|
||||
current.removeAt(existing);
|
||||
}
|
||||
notifyListeners();
|
||||
return ProfileStorage.writeProfileFile(
|
||||
id,
|
||||
'vars',
|
||||
|
||||
@@ -21,14 +21,14 @@ const maxLines = 2000;
|
||||
|
||||
class GameStore extends ChangeNotifier {
|
||||
final List<String> _lines = [];
|
||||
late CTelnetClient _client;
|
||||
CTelnetClient get _client => _clientRef!;
|
||||
CTelnetClient? _clientRef;
|
||||
final ScrollController scrollController = ScrollController();
|
||||
final TextEditingController input = TextEditingController();
|
||||
final FocusNode inputFocus = FocusNode();
|
||||
bool isCompressed = false;
|
||||
final ZLibDecoder decoder = ZLibDecoder();
|
||||
final incomingMsgSplitPattern = RegExp("($cr$lf)|($lf$cr)|$cr|$lf");
|
||||
// accepts csp but NOT double csp
|
||||
final ZLibCodec _decoder = ZLibCodec();
|
||||
final StreamController<List<int>> _rawStreamController = StreamController();
|
||||
late Stream<List<int>> _decodedStream;
|
||||
@@ -38,6 +38,8 @@ class GameStore extends ChangeNotifier {
|
||||
bool _clientReady = false;
|
||||
|
||||
String get commandSeparator => currentProfile.settings.commandSeparator;
|
||||
|
||||
/// accepts csp but NOT double csp
|
||||
RegExp get outgoingMsgSplitPattern =>
|
||||
RegExp("(?<!$commandSeparator)$commandSeparator(?!$commandSeparator)");
|
||||
|
||||
@@ -53,18 +55,19 @@ class GameStore extends ChangeNotifier {
|
||||
|
||||
void showConnectionDialog(BuildContext context) async {
|
||||
final profile = await showDialog<MUDProfile?>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return const SelectProfilePage();
|
||||
});
|
||||
context: context,
|
||||
builder: (context) => const SelectProfilePage(),
|
||||
);
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
_currentProfile?.removeListener(notifyListeners);
|
||||
_currentProfile?.removeListener(onProfileUpdate);
|
||||
_currentProfile = profile;
|
||||
currentProfile.addListener(notifyListeners);
|
||||
echo('Connecting...');
|
||||
_client = CTelnetClient(
|
||||
currentProfile.addListener(onProfileUpdate);
|
||||
|
||||
await _clientRef?.disconnect();
|
||||
|
||||
_clientRef = CTelnetClient(
|
||||
host: currentProfile.host,
|
||||
port: currentProfile.port,
|
||||
onConnect: _onConnect,
|
||||
@@ -73,6 +76,7 @@ class GameStore extends ChangeNotifier {
|
||||
onError: onError,
|
||||
);
|
||||
await currentProfile.load();
|
||||
echoSystem('Connecting...');
|
||||
_client.connect();
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -117,7 +121,7 @@ class GameStore extends ChangeNotifier {
|
||||
|
||||
Future<void> _onConnect() async {
|
||||
_clientReady = true;
|
||||
echo('Connected');
|
||||
echoSystem('Connected');
|
||||
if (currentProfile.authMethod != AuthMethod.none &&
|
||||
currentProfile.username.isNotEmpty &&
|
||||
currentProfile.password.isNotEmpty) {
|
||||
@@ -142,7 +146,7 @@ class GameStore extends ChangeNotifier {
|
||||
}
|
||||
|
||||
void onDisconnect() {
|
||||
echo('Disconnected');
|
||||
echoSystem('Disconnected');
|
||||
}
|
||||
|
||||
void onRawData(List<int> bytes) {
|
||||
@@ -154,8 +158,9 @@ class GameStore extends ChangeNotifier {
|
||||
}
|
||||
} catch (e, stack) {
|
||||
debugPrint('error: $e$newline$stack');
|
||||
echo(String.fromCharCodes(bytes));
|
||||
echo('Error: $e');
|
||||
echoError('Error: $e');
|
||||
echoError('The original line was:');
|
||||
echoError(String.fromCharCodes(bytes));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,16 +239,17 @@ class GameStore extends ChangeNotifier {
|
||||
|
||||
/// echoOwn - same as echo, but with predefined color
|
||||
void echoOwn(String line) {
|
||||
_lines.add('$esc[93m$line');
|
||||
notifyListeners();
|
||||
scrollToEnd();
|
||||
echo('$esc[93m$line');
|
||||
}
|
||||
|
||||
/// echoSystem - same as echo, but with predefined color
|
||||
void echoSystem(String line) {
|
||||
_lines.add('$esc[92m$line');
|
||||
notifyListeners();
|
||||
scrollToEnd();
|
||||
echo('$esc[96m$line');
|
||||
}
|
||||
|
||||
/// echoError - same as echo, but with predefined color
|
||||
void echoError(String line) {
|
||||
echo('$esc[31;1m$line');
|
||||
}
|
||||
|
||||
/// sendBytes - raw send bytes - DOES NOT split by outgoingMsgSplitPattern, no processing
|
||||
@@ -428,6 +434,10 @@ class GameStore extends ChangeNotifier {
|
||||
}
|
||||
echoSystem('');
|
||||
}
|
||||
|
||||
void onProfileUpdate() {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
mixin GameStoreMixin {
|
||||
|
||||
@@ -63,7 +63,9 @@ class _ButtonEditorDialogState extends State<ButtonEditorDialog> {
|
||||
label: Text(capitalize(interaction.name)),
|
||||
),
|
||||
onChanged: (value) {
|
||||
data.setAction(interaction, MUDAction(value));
|
||||
setState(() {
|
||||
data.setAction(interaction, MUDAction(value));
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -115,3 +117,4 @@ class _ButtonEditorDialogState extends State<ButtonEditorDialog> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@ class _ButtonSetEditorState extends State<ButtonSetEditor> {
|
||||
onSave: (data) {
|
||||
setState(() {
|
||||
this.data.buttons[index] = data;
|
||||
widget.onUpdate(this.data);
|
||||
});
|
||||
},
|
||||
),
|
||||
@@ -65,6 +66,7 @@ class _ButtonSetEditorState extends State<ButtonSetEditor> {
|
||||
onSave: (data) {
|
||||
setState(() {
|
||||
this.data.buttons[index] = data;
|
||||
widget.onUpdate(this.data);
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user