Skip to content

Commit

Permalink
Game Table Signal Patch (#196)
Browse files Browse the repository at this point in the history
* Made match controller 'clear' game table signals on load/unload

* There is no 'first onload', switching to only unload clear signals

* Added on first load/unload reset signals (using match number equality)

* bumped version
  • Loading branch information
CJBuchel authored Dec 3, 2024
1 parent 89b806a commit 2dcaa0d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import 'package:echo_tree_flutter/widgets/echo_tree_provider.dart';
import 'package:tms/generated/infra/database_schemas/game_table.dart';
import 'package:flutter/foundation.dart';
import 'package:tms/generated/infra/network_schemas/socket_protocol/match_state_event.dart';
import 'package:tms/generated/infra/network_schemas/socket_protocol/server_socket_protocol.dart';
import 'package:tms/generated/infra/network_schemas/socket_protocol/table_state_event.dart';
import 'package:tms/mixins/server_event_subscriber_mixin.dart';
import 'package:tms/utils/logger.dart';

class GameTableSignalProvider extends EchoTreeProvider<String, GameTable> with ServerEventSubscribeNotifierMixin {
class GameTableSignalProvider extends ChangeNotifier with ServerEventSubscribeNotifierMixin {
final Map<String, String> _tableSignals = {};
List<String> _loadedMatchNumbers = [];

void _updateTableSignals(String table, String teamNumber) {
// update or add table signal
_tableSignals[table] = teamNumber;
notifyListeners();
}

GameTableSignalProvider()
: super(
tree: ":robot_game:tables",
fromJsonString: (json) => GameTable.fromJsonString(json: json),
) {
GameTableSignalProvider() {
subscribeToEvent(TmsServerSocketEvent.tableStateEvent, (event) {
if (event.message != null) {
// handle table state event
Expand All @@ -30,6 +27,28 @@ class GameTableSignalProvider extends EchoTreeProvider<String, GameTable> with S
}
}
});
subscribeToEvent(TmsServerSocketEvent.matchStateEvent, (event) {
if (event.message != null) {
// handle match state event
try {
TmsServerMatchStateEvent matchStateEvent = TmsServerMatchStateEvent.fromJsonString(json: event.message!);
bool load = matchStateEvent.state == TmsServerMatchState.load;
bool unload = matchStateEvent.state == TmsServerMatchState.unload;

// clear table signals on first load or unload
if (load || unload) {
// check if it's a new match (using match number equality)
if (!listEquals(matchStateEvent.gameMatchNumbers, _loadedMatchNumbers)) {
_loadedMatchNumbers = matchStateEvent.gameMatchNumbers;
_tableSignals.clear();
notifyListeners();
}
}
} catch (e) {
TmsLogger().e("Error parsing match state event: $e");
}
}
});
}

Map<String, String> get tableSignals => _tableSignals;
Expand Down
2 changes: 1 addition & 1 deletion vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# I.e, version of the app, etc.
variables:
- name: tms_version
value: 2024.3.0
value: 2024.3.1

0 comments on commit 2dcaa0d

Please sign in to comment.