summaryrefslogtreecommitdiff
path: root/server/lib/core/commands/set_figure_note_command.dart
blob: 1bd2f8ff74872952912c1d92df5af3e3504e4ad7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'package:collection/collection.dart';

import '../state/game_state.dart';
import 'command_l10n.dart';

/// Sets the free-form inline note shown on a figure's row (character or
/// monster). Undo is handled by the snapshot-based history in [ActionHandler],
/// so no [onUndo] is needed.
class SetFigureNoteCommand extends Command {
  SetFigureNoteCommand(this.note, this.figureId, {required GameState gameState})
    : _gameState = gameState;
  final String note;
  final String figureId;
  final GameState _gameState;

  @override
  void execute() {
    final match = _gameState.currentList.firstWhereOrNull(
      (element) => element.id == figureId,
    );
    if (match != null) {
      match.setNote(stateAccess, note);
    }
  }

  @override
  String describe() {
    return commandL10n.cmdSetCharacterNote(figureId);
  }
}