Skip to content

Commit

Permalink
improve tournament organization
Browse files Browse the repository at this point in the history
add more tournament statistics
improve UX at some parts
add counterclockwise option - resolves a ticket in a Discord server
Potential points for winning a round - resolves #68
  • Loading branch information
mytja committed Feb 8, 2024
1 parent 9c9866c commit e11f097
Show file tree
Hide file tree
Showing 11 changed files with 495 additions and 50 deletions.
11 changes: 11 additions & 0 deletions messages/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ message TournamentStatistics {
int32 top_player_points = 3;
}

message TournamentGameStatisticInner {
int32 game = 1;
bool bots = 2;
int32 amount = 3;
}

message TournamentGameStatistics {
repeated TournamentGameStatisticInner statistics = 1;
}

message ChatMessage {
string user_id = 1;
string message = 2;
Expand Down Expand Up @@ -279,5 +289,6 @@ message Message {
StartEarly start_early = 41;
PrepareGameMode prepare_game_mode = 42;
TournamentStatistics tournament_statistics = 43;
TournamentGameStatistics tournament_game_statistics = 44;
}
}
1 change: 1 addition & 0 deletions tarok/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ bool SKISFANG = false;
bool DISCORD_RPC = true;
bool RED_FILTER = true;
bool COUNTERCLOCKWISE_GAME = false;
bool POINTS_TOOLTIP = false;
String THEME = "";
Locale LOCALE = Get.deviceLocale ?? const Locale("sl", "SI");

Expand Down
197 changes: 194 additions & 3 deletions tarok/lib/game/game.dart

Large diffs are not rendered by default.

90 changes: 67 additions & 23 deletions tarok/lib/game/game_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class GameController extends GetxController {
var gamesPlayed = 0.obs;
var gamesRequired = (-1).obs;
var canExtendGame = true.obs;
var tournamentGameStatistics = <Widget>[].obs;

var unreadMessages = 0.obs;

Expand All @@ -110,7 +111,7 @@ class GameController extends GetxController {
Timer? currentTimer;

final bool bbots = Get.parameters["bots"] == "true";
final String gameId = Get.parameters["gameId"]!;
final String? gameId = Get.parameters["gameId"];
final int playing = int.parse(Get.parameters["playing"]!);
final bool replay = Get.parameters["replay"] == "true";

Expand Down Expand Up @@ -156,8 +157,13 @@ class GameController extends GetxController {
return;
}

if (gameId == null) {
super.onInit();
return;
}

// ONLINE
connect(gameId);
connect(gameId!);
listen();

super.onInit();
Expand Down Expand Up @@ -220,26 +226,34 @@ class GameController extends GetxController {
if (users.length == 3 && !e.playsThree) {
continue;
}

Widget button = ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor:
suggestions.contains(e.id) ? Colors.purpleAccent.shade400 : null,
),
onPressed: () async {
await licitiranjeSend(e);
},
child: Text(
e.name.tr,
maxLines: 1,
),
);

gameListAssembly.add(
SizedBox(
width: fullHeight / 25,
height: fullHeight / 25,
child: FittedBox(
fit: BoxFit.contain,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: suggestions.contains(e.id)
? Colors.purpleAccent.shade400
: null,
),
onPressed: () async {
await licitiranjeSend(e);
},
child: Text(
e.name.tr,
maxLines: 1,
),
),
child: POINTS_TOOLTIP
? Tooltip(
message: "points_prediction"
.trParams({"points": e.worth.toString()}),
child: button,
)
: button,
),
),
);
Expand Down Expand Up @@ -1081,9 +1095,9 @@ class GameController extends GetxController {
break;
}

if (userId != playerId.value) {
break;
}
//if (userId != playerId.value) {
// break;
//}

turn.value = false;

Expand Down Expand Up @@ -1274,9 +1288,20 @@ class GameController extends GetxController {
}

if (COUNTERCLOCKWISE_GAME) {
debugPrint("Obračam igro.");

userWidgets.value = [
...userWidgets.sublist(0, userWidgets.length - 1).reversed
...userWidgets.sublist(0, userWidgets.length - 1).reversed,
userWidgets.last,
];
users.value = [...users.reversed];
for (int i = 0; i < users.length; i++) {
final newUser = users[i];
if (newUser.id == playerId.value) {
myPosition.value = i;
break;
}
}
}

debugPrint("anotacije so bile dodane");
Expand Down Expand Up @@ -1346,6 +1371,8 @@ class GameController extends GetxController {
} else if (msg.hasResults()) {
final r = msg.results;

tournamentGameStatistics.value = [];

if (!msg.silent) {
results.value = r;
}
Expand Down Expand Up @@ -1566,6 +1593,23 @@ class GameController extends GetxController {
}
} else if (msg.hasTournamentStatistics()) {
tournamentStatistics.value = msg.tournamentStatistics;
} else if (msg.hasTournamentGameStatistics()) {
var a = msg.tournamentGameStatistics.statistics;
a.sort((a, b) => b.amount.compareTo(a.amount));
for (int i = 0; i < a.length; i++) {
if (a[i].bots) {
tournamentGameStatistics.add(Text("bot_plays".trParams({
"game": stockskis.GAMES[a[i].game + 1].name.tr,
"times": a[i].amount.toString(),
})));
continue;
}
tournamentGameStatistics.add(Text("player_plays".trParams({
"game": stockskis.GAMES[a[i].game + 1].name.tr,
"times": a[i].amount.toString(),
})));
}
tournamentGameStatistics.refresh();
}
},
onDone: () {
Expand Down Expand Up @@ -1687,9 +1731,9 @@ class GameController extends GetxController {
userWidgets.removeAt(0);
userWidgets.add(w);
if (COUNTERCLOCKWISE_GAME) {
userWidgets.value = [
...userWidgets.sublist(0, userWidgets.length - 1).reversed
];
//userWidgets.value = [
// ...userWidgets.sublist(0, userWidgets.length - 1).reversed
//];
stockskisContext!.userPositions = [
...stockskisContext!.userPositions.reversed
];
Expand Down
26 changes: 26 additions & 0 deletions tarok/lib/internationalization/languages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,15 @@ class Messages extends Translations {
"counterclockwise_gameplay_desc":
"The game will be running counterclockwise. You have to restart the game or leave it to apply this change.",
"reset_websocket": "Reset the WebSocket connection",
"points_prediction": "@points points",
"enable_points_tooltip": "Enable point tooltips",
"enable_points_tooltip_desc":
"Values of all games will be shown during the licitation process. You will have to restart the game to apply the change.",
"accessibility": "Accessibility",
"bot_plays": "Bots 🤖 are playing \"@game\" @times times",
"player_plays": "Players 👤 are playing \"@game\" @times times",
"other_players_are_playing":
"Other players are currently playing following games",
},
"fr_FR": {
"login": "Connexion",
Expand Down Expand Up @@ -920,6 +929,15 @@ class Messages extends Translations {
"counterclockwise_gameplay_desc":
"The game will be running counterclockwise. You have to restart the game or leave it to apply this change.",
"reset_websocket": "Reset the WebSocket connection",
"points_prediction": "@points points",
"enable_points_tooltip": "Enable point tooltips",
"enable_points_tooltip_desc":
"Values of all games will be shown during the licitation process. You will have to restart the game to apply the change.",
"accessibility": "Accessibility",
"bot_plays": "Bots 🤖 are playing \"@game\" @times times",
"player_plays": "Players 👤 are playing \"@game\" @times times",
"other_players_are_playing":
"Other players are currently playing following games",
},
"sl_SI": {
"login": "Prijava",
Expand Down Expand Up @@ -1365,6 +1383,14 @@ class Messages extends Translations {
"counterclockwise_gameplay_desc":
"Igra bo potekala v nasprotni smeri urinega kazalca. Ko to vključite, morate zapustiti igro.",
"reset_websocket": "Resetiraj WebSocket povezavo",
"points_prediction": "@points točk",
"enable_points_tooltip": "Vključi prikaze točk za igre",
"enable_points_tooltip_desc":
"Vrednost vseh iger se bo prikazala na zaslonu med igro. Igro boste morali znova zagnati, da se spremembe uveljavijo.",
"accessibility": "Dostopnost",
"bot_plays": "Boti 🤖 igrajo \"@game\" @times-krat",
"player_plays": "Igralci 👤 igrajo \"@game\" @times-krat",
"other_players_are_playing": "Drugi igralci igrajo naslednje igre",
}
};
}
1 change: 1 addition & 0 deletions tarok/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void main() async {
BOT_DELAY = prefs.getInt("bot_delay") ?? 500;
CARD_CLEANUP_DELAY = prefs.getInt("card_cleanup_delay") ?? 1000;
COUNTERCLOCKWISE_GAME = prefs.getBool("counterclockwise_game") ?? false;
POINTS_TOOLTIP = prefs.getBool("points_tooltip") ?? false;

if (kReleaseMode) {
BACKEND_URL = prefs.getString("api_url") ?? "https://palcka.si/api";
Expand Down
Loading

0 comments on commit e11f097

Please sign in to comment.