Skip to content

Commit d635a98

Browse files
committed
Fix renaming teams not working, closes #48
1 parent 42ff534 commit d635a98

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

api/lib/src/event/hybrid.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ final class ObjectIndexChanged extends HybridWorldEvent
127127
final class TeamChanged extends HybridWorldEvent with TeamChangedMappable {
128128
final String name;
129129
final GameTeam team;
130+
final String? newName;
130131

131-
TeamChanged(this.name, this.team);
132+
TeamChanged(this.name, this.team) : newName = null;
133+
TeamChanged.rename(this.name, this.newName, this.team);
132134
}
133135

134136
@MappableClass()

api/lib/src/event/process/server.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,20 @@ ServerProcessed processServerEvent(
246246
..[event.cell.position] = cell.copyWith(objects: newObjects));
247247
}));
248248
case TeamChanged():
249-
return ServerProcessed(
250-
state.copyWith.info.teams.put(event.name, event.team));
249+
var info = state.info;
250+
var newName = event.newName;
251+
var teamMembers = Map<String, Set<int>>.from(state.teamMembers);
252+
if (newName != null) {
253+
info = info.copyWith.teams.remove(event.name);
254+
info = info.copyWith.teams.put(newName, event.team);
255+
teamMembers[newName] = teamMembers.remove(event.name) ?? {};
256+
} else {
257+
info = info.copyWith.teams.put(event.name, event.team);
258+
}
259+
return ServerProcessed(state.copyWith(
260+
info: info,
261+
teamMembers: teamMembers,
262+
));
251263
case TeamRemoved():
252264
return ServerProcessed(state.copyWith(
253265
info: state.info.copyWith.teams.remove(event.team),

app/lib/pages/game/team.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,10 @@ class TeamDialogState extends State<TeamDialog> {
112112
description: _descriptionController.text,
113113
color: _color,
114114
);
115-
_bloc.add(TeamChanged(
116-
widget.team ?? _nameController.text, team));
115+
_bloc.add(TeamChanged.rename(
116+
widget.team ?? _nameController.text,
117+
_nameController.text,
118+
team));
117119
Navigator.of(context).pop();
118120
},
119121
child: Text(_isCreate()

metadata/en-US/changelogs/5.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Add swamp multiplayer support
99
* Add scroll sensitivity setting
1010
* Add remaining empty indicator to editor tabs
11+
* Fix renaming teams not working ([#48](https://github.com/LinwoodDev/Setonix/issues/48))
1112
* Migrate away from flutter_markdown
1213
* Upgrade to flutter 3.29
1314
* Update to agb 8.9

0 commit comments

Comments
 (0)