mirror of
https://github.com/chenasraf/mudblock.git
synced 2026-05-18 01:48:57 +00:00
feat: more lua bindings
This commit is contained in:
@@ -97,7 +97,6 @@ class Automation {
|
||||
|
||||
void invokeEffect(GameStore store, String line) {
|
||||
invokeCount++;
|
||||
line = MUDAction.doVariableReplacements(store, line);
|
||||
action.invoke(store, this, allMatches(line));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,30 @@ class LuaInterpreter {
|
||||
state.setGlobal("GetVariable");
|
||||
state.pushDartFunction(bindings.setVariable);
|
||||
state.setGlobal("SetVariable");
|
||||
state.pushDartFunction(bindings.enableTrigger);
|
||||
state.setGlobal("EnableTrigger");
|
||||
state.pushDartFunction(bindings.disableTrigger);
|
||||
state.setGlobal("DisableTrigger");
|
||||
state.pushDartFunction(bindings.enableTriggerGroup);
|
||||
state.setGlobal("EnableTriggerGroup");
|
||||
state.pushDartFunction(bindings.disableTriggerGroup);
|
||||
state.setGlobal("DisableTriggerGroup");
|
||||
state.pushDartFunction(bindings.enableAlias);
|
||||
state.setGlobal("EnableAlias");
|
||||
state.pushDartFunction(bindings.disableAlias);
|
||||
state.setGlobal("DisableAlias");
|
||||
state.pushDartFunction(bindings.enableAliasGroup);
|
||||
state.setGlobal("EnableAliasGroup");
|
||||
state.pushDartFunction(bindings.disableAliasGroup);
|
||||
state.setGlobal("DisableAliasGroup");
|
||||
state.pushDartFunction(bindings.enableButtonSet);
|
||||
state.setGlobal("EnableButtonSet");
|
||||
state.pushDartFunction(bindings.disableButtonSet);
|
||||
state.setGlobal("DisableButtonSet");
|
||||
state.pushDartFunction(bindings.enableButtonGroup);
|
||||
state.setGlobal("EnableButtonGroup");
|
||||
state.pushDartFunction(bindings.disableButtonGroup);
|
||||
state.setGlobal("DisableButtonGroup");
|
||||
}
|
||||
|
||||
void loadString(String string) {
|
||||
@@ -92,4 +116,150 @@ class LuaBindings {
|
||||
.saveVariable(store.variables.values.toList(), store.variables[name]!);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enableTrigger(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.enableTrigger $id");
|
||||
store.triggers.firstWhere((trigger) => trigger.id == id).enabled = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disableTrigger(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.disableTrigger $id");
|
||||
store.triggers.firstWhere((trigger) => trigger.id == id).enabled = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enableTriggerGroup(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.enableTriggerGroup $id");
|
||||
store.triggers
|
||||
.where((trigger) => trigger.group == id)
|
||||
.forEach((trigger) => trigger.enabled = true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disableTriggerGroup(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.disableTriggerGroup $id");
|
||||
store.triggers
|
||||
.where((trigger) => trigger.group == id)
|
||||
.forEach((trigger) => trigger.enabled = false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enableAlias(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.enableAlias $id");
|
||||
store.aliases.firstWhere((alias) => alias.id == id).enabled = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disableAlias(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.disableAlias $id");
|
||||
store.aliases.firstWhere((alias) => alias.id == id).enabled = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enableAliasGroup(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.enableAliasGroup $id");
|
||||
store.aliases
|
||||
.where((alias) => alias.group == id)
|
||||
.forEach((alias) => alias.enabled = true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disableAliasGroup(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.disableAliasGroup $id");
|
||||
store.aliases
|
||||
.where((alias) => alias.group == id)
|
||||
.forEach((alias) => alias.enabled = false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// int enableTimer(LuaState ls) {
|
||||
// final id = ls.checkString(1)!;
|
||||
// ls.pop(1);
|
||||
// debugPrint("lua.enableTimer $id");
|
||||
// store.timers.firstWhere((timer) => timer.id == id).enabled = true;
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// int disableTimer(LuaState ls) {
|
||||
// final id = ls.checkString(1)!;
|
||||
// ls.pop(1);
|
||||
// debugPrint("lua.disableTimer $id");
|
||||
// store.timers.firstWhere((timer) => timer.id == id).enabled = false;
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// int enableTimerGroup(LuaState ls) {
|
||||
// final id = ls.checkString(1)!;
|
||||
// ls.pop(1);
|
||||
// debugPrint("lua.enableTimerGroup $id");
|
||||
// store.timers
|
||||
// .where((timer) => timer.group == id)
|
||||
// .forEach((timer) => timer.enabled = true);
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// int disableTimerGroup(LuaState ls) {
|
||||
// final id = ls.checkString(1)!;
|
||||
// ls.pop(1);
|
||||
// debugPrint("lua.disableTimerGroup $id");
|
||||
// store.timers
|
||||
// .where((timer) => timer.group == id)
|
||||
// .forEach((timer) => timer.enabled = false);
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
int enableButtonSet(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.enableButtonSet $id");
|
||||
store.buttonSets.firstWhere((buttonSet) => buttonSet.id == id).enabled =
|
||||
true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disableButtonSet(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.disableButtonSet $id");
|
||||
store.buttonSets.firstWhere((buttonSet) => buttonSet.id == id).enabled =
|
||||
false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int enableButtonGroup(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.enableButtonGroup $id");
|
||||
store.buttonSets
|
||||
.where((buttonSet) => buttonSet.group == id)
|
||||
.forEach((buttonSet) => buttonSet.enabled = true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int disableButtonGroup(LuaState ls) {
|
||||
final id = ls.checkString(1)!;
|
||||
ls.pop(1);
|
||||
debugPrint("lua.disableButtonGroup $id");
|
||||
store.buttonSets
|
||||
.where((buttonSet) => buttonSet.group == id)
|
||||
.forEach((buttonSet) => buttonSet.enabled = false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,17 +4,25 @@ import 'package:flutter/services.dart';
|
||||
import 'store.dart';
|
||||
|
||||
class KeyboardIntent extends Intent {
|
||||
const KeyboardIntent(this.key, this.context);
|
||||
const KeyboardIntent(this.key);
|
||||
|
||||
final NumpadKey key;
|
||||
final BuildContext context;
|
||||
}
|
||||
|
||||
class KeyboardAction extends Action<KeyboardIntent> with GameStoreMixin {
|
||||
class KeyboardAction extends ContextAction<KeyboardIntent> with GameStoreMixin {
|
||||
@override
|
||||
void invoke(covariant KeyboardIntent intent) {
|
||||
final store = storeOf(intent.context);
|
||||
store.onShortcut(intent.key, intent.context);
|
||||
void invoke(covariant KeyboardIntent intent, [BuildContext? context]) {
|
||||
if (context == null) return;
|
||||
final store = storeOf(context);
|
||||
store.onShortcut(intent.key, context);
|
||||
}
|
||||
|
||||
@override
|
||||
bool isEnabled(KeyboardIntent intent, [BuildContext? context]) {
|
||||
if (context == null) return false;
|
||||
final store = storeOf(context);
|
||||
if (store.keyboardShortcuts.get(intent.key).isEmpty) return false;
|
||||
return super.isEnabled(intent, context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,23 +66,23 @@ class KeyboardShortcuts {
|
||||
String numpadEqual;
|
||||
|
||||
KeyboardShortcuts({
|
||||
this.numpad0 = '',
|
||||
this.numpad1 = '',
|
||||
this.numpad2 = '',
|
||||
this.numpad3 = '',
|
||||
this.numpad4 = '',
|
||||
this.numpad5 = '',
|
||||
this.numpad6 = '',
|
||||
this.numpad7 = '',
|
||||
this.numpad8 = '',
|
||||
this.numpad9 = '',
|
||||
this.numpadEnter = '',
|
||||
this.numpadDecimal = '',
|
||||
this.numpadAdd = '',
|
||||
this.numpadSubtract = '',
|
||||
this.numpadMultiply = '',
|
||||
this.numpadDivide = '',
|
||||
this.numpadEqual = '',
|
||||
required this.numpad0,
|
||||
required this.numpad1,
|
||||
required this.numpad2,
|
||||
required this.numpad3,
|
||||
required this.numpad4,
|
||||
required this.numpad5,
|
||||
required this.numpad6,
|
||||
required this.numpad7,
|
||||
required this.numpad8,
|
||||
required this.numpad9,
|
||||
required this.numpadEnter,
|
||||
required this.numpadDecimal,
|
||||
required this.numpadAdd,
|
||||
required this.numpadSubtract,
|
||||
required this.numpadMultiply,
|
||||
required this.numpadDivide,
|
||||
required this.numpadEqual,
|
||||
});
|
||||
|
||||
factory KeyboardShortcuts.empty() => KeyboardShortcuts(
|
||||
@@ -223,42 +231,40 @@ class KeyboardShortcuts {
|
||||
);
|
||||
}
|
||||
|
||||
Map<ShortcutActivator, Intent> numpadKeysIntentMap(BuildContext context) =>
|
||||
<ShortcutActivator, Intent>{
|
||||
// SingleActivator(LogicalKeyboardKey.enter): ActivateIntent(),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad0):
|
||||
KeyboardIntent(NumpadKey.numpad0, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad1):
|
||||
KeyboardIntent(NumpadKey.numpad1, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad2):
|
||||
KeyboardIntent(NumpadKey.numpad2, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad3):
|
||||
KeyboardIntent(NumpadKey.numpad3, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad4):
|
||||
KeyboardIntent(NumpadKey.numpad4, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad5):
|
||||
KeyboardIntent(NumpadKey.numpad5, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad6):
|
||||
KeyboardIntent(NumpadKey.numpad6, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad7):
|
||||
KeyboardIntent(NumpadKey.numpad7, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad8):
|
||||
KeyboardIntent(NumpadKey.numpad8, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpad9):
|
||||
KeyboardIntent(NumpadKey.numpad9, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpadDivide):
|
||||
KeyboardIntent(NumpadKey.numpadDivide, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpadMultiply):
|
||||
KeyboardIntent(NumpadKey.numpadMultiply, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpadSubtract):
|
||||
KeyboardIntent(NumpadKey.numpadSubtract, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpadAdd):
|
||||
KeyboardIntent(NumpadKey.numpadAdd, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpadDecimal):
|
||||
KeyboardIntent(NumpadKey.numpadDecimal, context),
|
||||
const SingleActivator(LogicalKeyboardKey.numpadEnter):
|
||||
KeyboardIntent(NumpadKey.numpadEnter, context),
|
||||
};
|
||||
const numpadKeysIntentMap = <ShortcutActivator, Intent>{
|
||||
SingleActivator(LogicalKeyboardKey.numpad0):
|
||||
KeyboardIntent(NumpadKey.numpad0),
|
||||
SingleActivator(LogicalKeyboardKey.numpad1):
|
||||
KeyboardIntent(NumpadKey.numpad1),
|
||||
SingleActivator(LogicalKeyboardKey.numpad2):
|
||||
KeyboardIntent(NumpadKey.numpad2),
|
||||
SingleActivator(LogicalKeyboardKey.numpad3):
|
||||
KeyboardIntent(NumpadKey.numpad3),
|
||||
SingleActivator(LogicalKeyboardKey.numpad4):
|
||||
KeyboardIntent(NumpadKey.numpad4),
|
||||
SingleActivator(LogicalKeyboardKey.numpad5):
|
||||
KeyboardIntent(NumpadKey.numpad5),
|
||||
SingleActivator(LogicalKeyboardKey.numpad6):
|
||||
KeyboardIntent(NumpadKey.numpad6),
|
||||
SingleActivator(LogicalKeyboardKey.numpad7):
|
||||
KeyboardIntent(NumpadKey.numpad7),
|
||||
SingleActivator(LogicalKeyboardKey.numpad8):
|
||||
KeyboardIntent(NumpadKey.numpad8),
|
||||
SingleActivator(LogicalKeyboardKey.numpad9):
|
||||
KeyboardIntent(NumpadKey.numpad9),
|
||||
SingleActivator(LogicalKeyboardKey.numpadDivide):
|
||||
KeyboardIntent(NumpadKey.numpadDivide),
|
||||
SingleActivator(LogicalKeyboardKey.numpadMultiply):
|
||||
KeyboardIntent(NumpadKey.numpadMultiply),
|
||||
SingleActivator(LogicalKeyboardKey.numpadSubtract):
|
||||
KeyboardIntent(NumpadKey.numpadSubtract),
|
||||
SingleActivator(LogicalKeyboardKey.numpadAdd):
|
||||
KeyboardIntent(NumpadKey.numpadAdd),
|
||||
SingleActivator(LogicalKeyboardKey.numpadDecimal):
|
||||
KeyboardIntent(NumpadKey.numpadDecimal),
|
||||
SingleActivator(LogicalKeyboardKey.numpadEnter):
|
||||
KeyboardIntent(NumpadKey.numpadEnter),
|
||||
};
|
||||
|
||||
final numpadKeyLabels = {
|
||||
NumpadKey.numpad0: '0',
|
||||
|
||||
@@ -11,6 +11,7 @@ import 'package:provider/provider.dart';
|
||||
|
||||
import 'color_utils.dart';
|
||||
import 'consts.dart';
|
||||
import 'features/action.dart';
|
||||
import 'features/alias.dart';
|
||||
import 'features/game_button_set.dart';
|
||||
import 'features/profile.dart';
|
||||
@@ -49,7 +50,7 @@ class GameStore extends ChangeNotifier {
|
||||
final List<Alias> aliases = [];
|
||||
final Map<String, Variable> variables = {};
|
||||
final List<GameButtonSetData> buttonSets = [];
|
||||
KeyboardShortcuts keyboardShortcuts = KeyboardShortcuts();
|
||||
KeyboardShortcuts keyboardShortcuts = KeyboardShortcuts.empty();
|
||||
|
||||
MUDProfile get currentProfile => _currentProfile!;
|
||||
|
||||
@@ -318,6 +319,7 @@ class GameStore extends ChangeNotifier {
|
||||
/// execute - process aliases and triggers, then send, also split by outgoingMsgSplitPattern
|
||||
void execute(String text) {
|
||||
for (var line in _splitCsp(text)) {
|
||||
line = MUDAction.doVariableReplacements(this, line);
|
||||
debugPrint('processing aliases for: $line');
|
||||
var sendLine = processAliases(line);
|
||||
if (sendLine) {
|
||||
@@ -437,6 +439,7 @@ class GameStore extends ChangeNotifier {
|
||||
final action = keyboardShortcuts.get(key);
|
||||
if (action.isNotEmpty) {
|
||||
submitInput(action);
|
||||
selectInput();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class HomePageState extends State<HomePage>
|
||||
final inputStyle = consoleStyle.copyWith(color: Colors.grey);
|
||||
|
||||
return Shortcuts(
|
||||
shortcuts: numpadKeysIntentMap(context),
|
||||
shortcuts: numpadKeysIntentMap,
|
||||
child: Actions(
|
||||
actions: {
|
||||
KeyboardIntent: KeyboardAction(),
|
||||
|
||||
@@ -7,6 +7,7 @@ import '../core/features/alias.dart';
|
||||
import '../core/features/profile.dart';
|
||||
import '../core/features/trigger.dart';
|
||||
import '../core/features/variable.dart';
|
||||
import '../core/platform_utils.dart';
|
||||
import '../core/routes.dart';
|
||||
import '../core/store.dart';
|
||||
|
||||
@@ -92,11 +93,12 @@ class HomeScaffold extends StatelessWidget with GameStoreMixin {
|
||||
leading: const Icon(Variable.iconData),
|
||||
onTap: () => Navigator.pushNamed(context, Paths.variables),
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('Keyboard Shortcuts'),
|
||||
leading: const Icon(Icons.keyboard),
|
||||
onTap: () => Navigator.pushNamed(context, Paths.shortcuts),
|
||||
),
|
||||
if (PlatformUtils.isDesktop)
|
||||
ListTile(
|
||||
title: const Text('Keyboard Shortcuts'),
|
||||
leading: const Icon(Icons.keyboard),
|
||||
onTap: () => Navigator.pushNamed(context, Paths.shortcuts),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
title: const Text('Settings'),
|
||||
|
||||
Reference in New Issue
Block a user