part of 'game_state.dart'; // ignore_for_file: library_private_types_in_public_api /// A free-form note that lives in the main list as its own row, styled like a /// player/monster row but in a user-pickable colour. /// /// A note can be unlinked (a free-floating row placed wherever the user drags /// it) or linked to a figure (a character or monster row) by that figure's /// [id]. When linked it is kept positioned directly beneath its target by /// [GameState._reflowNoteRows]. For a monster target it may additionally be /// pinned to a specific [standeeNr] to annotate one standee rather than the /// whole group. class NoteRow extends ListItemData { // Slate tone, clearly distinct from character/monster rows. static const int defaultColor = 0xFF4E5D6C; String _text = ""; int _color = defaultColor; // "" means unlinked. String _linkedId = ""; // 0 means "whole group / not standee-specific". int _standeeNr = 0; String get text => _text; int get color => _color; String get linkedId => _linkedId; int get standeeNr => _standeeNr; bool get isLinked => _linkedId.isNotEmpty; NoteRow(String anId) { id = anId; } NoteRow.create( String anId, { String text = "", int color = defaultColor, String linkedId = "", int standeeNr = 0, }) { id = anId; _text = text; _color = color; _linkedId = linkedId; _standeeNr = standeeNr; } NoteRow.fromJson(Map json) { id = json['id'] as String; _applyJson(json); } /// Updates fields in-place (preserving object identity across network /// syncs). void updateFromJson(Map json) { _applyJson(json); } void _applyJson(Map json) { _text = json['text'] as String? ?? ""; _color = json['color'] as int? ?? defaultColor; _linkedId = json['linkedId'] as String? ?? ""; _standeeNr = json['standeeNr'] as int? ?? 0; } void setText(_StateModifier _, String value) { _text = value; } void setColor(_StateModifier _, int value) { _color = value; } /// Links the note to [linkedId] (a figure id; "" to unlink) and, for monster /// targets, an optional [standeeNr] (0 for the whole group). void setLink(_StateModifier _, String linkedId, int standeeNr) { _linkedId = linkedId; _standeeNr = linkedId.isEmpty ? 0 : standeeNr; } @override Map toJson() => { 'id': id, // Discriminator used by GameSaveState.load to rebuild the right type. 'noteRow': true, 'text': _text, 'color': _color, 'linkedId': _linkedId, 'standeeNr': _standeeNr, }; @override String toString() => json.encode(toJson()); }