Skip to content

Commit

Permalink
minor internationalization bug fixes & password reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mytja committed Nov 17, 2023
1 parent 0e78069 commit e770d07
Show file tree
Hide file tree
Showing 17 changed files with 468 additions and 59 deletions.
24 changes: 12 additions & 12 deletions stockskis/lib/src/gamemodes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
import 'package:stockskis/src/types.dart';

final List<LocalGame> GAMES = [
LocalGame(id: -1, name: "Naprej", playsThree: true, worth: 0),
LocalGame(id: 0, name: "Tri", playsThree: true, worth: 10),
LocalGame(id: 1, name: "Dva", playsThree: true, worth: 20),
LocalGame(id: 2, name: "Ena", playsThree: true, worth: 30),
LocalGame(id: 3, name: "Solo tri", playsThree: false, worth: 40),
LocalGame(id: 4, name: "Solo dva", playsThree: false, worth: 50),
LocalGame(id: 5, name: "Solo ena", playsThree: false, worth: 60),
LocalGame(id: 6, name: "Berač", playsThree: true, worth: 70),
LocalGame(id: 7, name: "Solo brez", playsThree: true, worth: 80),
LocalGame(id: 8, name: "Odprti berač", playsThree: true, worth: 90),
LocalGame(id: 9, name: "Barvni valat", playsThree: false, worth: 250),
LocalGame(id: 10, name: "Valat", playsThree: true, worth: 500),
LocalGame(id: -1, name: "onward", playsThree: true, worth: 0),
LocalGame(id: 0, name: "three", playsThree: true, worth: 10),
LocalGame(id: 1, name: "two", playsThree: true, worth: 20),
LocalGame(id: 2, name: "one", playsThree: true, worth: 30),
LocalGame(id: 3, name: "solo_three", playsThree: false, worth: 40),
LocalGame(id: 4, name: "solo_two", playsThree: false, worth: 50),
LocalGame(id: 5, name: "solo_one", playsThree: false, worth: 60),
LocalGame(id: 6, name: "beggar", playsThree: true, worth: 70),
LocalGame(id: 7, name: "solo_without", playsThree: true, worth: 80),
LocalGame(id: 8, name: "open_beggar", playsThree: true, worth: 90),
LocalGame(id: 9, name: "color_valat", playsThree: false, worth: 250),
LocalGame(id: 10, name: "valat", playsThree: true, worth: 500),
];
3 changes: 2 additions & 1 deletion stockskis/lib/src/stockskis_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,8 @@ class StockSkis {
// evaluation
inspect(modes);

bool isMandatory = userPositions.last == userId;
bool isMandatory =
userPositions.isEmpty ? canLicitateThree : userPositions.last == userId;
List<int> toRemove = [];
for (int i = 0; i < modes.length; i++) {
if (modes[i] == -1) continue;
Expand Down
5 changes: 5 additions & 0 deletions tarok/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:dart_discord_rpc/dart_discord_rpc.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand All @@ -26,6 +27,10 @@ import 'package:tarok/lobby/lobby_controller.dart';

part 'constants.g.dart';

DiscordRPC rpc = DiscordRPC(
applicationId: '1175161862086721616',
);

const BACKEND_URL =
kReleaseMode ? "https://palcka.si/api" : "http://localhost:8080";
const WS_URL =
Expand Down
51 changes: 14 additions & 37 deletions tarok/lib/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class Game extends StatelessWidget {
"player": controller.userHasKing.value
})),
Text("stashed_cards".trParams({
"cards":
"stashed":
jsonEncode(controller.stashAmount.value)
})),
Text("talon_picked".trParams({
Expand Down Expand Up @@ -743,7 +743,8 @@ class Game extends StatelessWidget {
: stockskis
.GAMES[
user.licitiral + 1]
.name,
.name
.tr,
style: const TextStyle(
fontSize: 18,
),
Expand Down Expand Up @@ -771,35 +772,8 @@ class Game extends StatelessWidget {
mainAxisSpacing: 10,
crossAxisCount: 4,
childAspectRatio: 3,
children: [
...controller.games.map((e) {
if (controller.users.length == 3 &&
!e.playsThree) {
return const SizedBox();
}
return SizedBox(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: controller
.suggestions
.contains(e.id)
? Colors.purpleAccent.shade400
: null,
textStyle: TextStyle(
fontSize: fullHeight / 35,
),
),
onPressed: () async {
await controller
.licitiranjeSend(e);
},
child: Text(
e.name,
),
),
);
})
],
children:
controller.gameListAssemble(fullHeight),
),
),
],
Expand Down Expand Up @@ -947,7 +921,7 @@ class Game extends StatelessWidget {
label: Expanded(
child: Text("game".trParams({
"type":
"(${stockskis.GAMES[controller.currentPredictions.value!.gamemode + 1].name == "Naprej" ? "Klop" : stockskis.GAMES[controller.currentPredictions.value!.gamemode + 1].name})"
"(${stockskis.GAMES[controller.currentPredictions.value!.gamemode + 1].name == "onward" ? "klop".tr : stockskis.GAMES[controller.currentPredictions.value!.gamemode + 1].name.tr})"
})),
),
),
Expand Down Expand Up @@ -1069,7 +1043,7 @@ class Game extends StatelessWidget {
-1))
DataRow(
cells: <DataCell>[
DataCell(Text("Kralji".tr)),
DataCell(Text("kings".tr)),
if (controller.myPredictions.value !=
null &&
controller
Expand Down Expand Up @@ -1599,7 +1573,8 @@ class Game extends StatelessWidget {
const SizedBox(
height: 10,
),
if (controller.zaruf.value) Text("zaruf".tr),
if (controller.zaruf.value && !isWebMobile)
Text("zaruf".tr),
ElevatedButton(
onPressed: () {
controller.showTalon.value = false;
Expand Down Expand Up @@ -1829,7 +1804,10 @@ class Game extends StatelessWidget {
if (e.showGamemode)
DataRow(
cells: <DataCell>[
DataCell(Text("game".tr)),
DataCell(Text("game".trParams({
"type":
"(${stockskis.GAMES[controller.results.value!.predictions.gamemode + 1].name == "onward" ? "klop".tr : stockskis.GAMES[controller.results.value!.predictions.gamemode + 1].name.tr})"
}))),
DataCell(Text(
'${pow(2, e.kontraIgra)}x')),
DataCell(Text(
Expand Down Expand Up @@ -2329,8 +2307,7 @@ class Game extends StatelessWidget {
.value.worth
.round()
.toString(),
"pointstext": e.value
.worth ==
"ptext": e.value.worth ==
3 ||
e.value.worth ==
4
Expand Down
106 changes: 105 additions & 1 deletion tarok/lib/game/game_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'dart:math';
import 'dart:typed_data';

import 'package:dart_discord_rpc/dart_discord_rpc.dart';
import 'package:flutter/material.dart';
import 'package:flutter_initicon/flutter_initicon.dart';
import 'package:get/get.dart';
Expand Down Expand Up @@ -124,6 +126,17 @@ class GameController extends GetxController {
playingCount.value = playing;
bots = bbots;

if (Platform.isLinux || Platform.isWindows) {
rpc.updatePresence(
DiscordPresence(
details: 'Igra igro ${bots ? "z boti" : "z igralci"}',
startTimeStamp: DateTime.now().millisecondsSinceEpoch,
largeImageKey: 'palcka_logo',
largeImageText: 'Tarok Palčka',
),
);
}

// BOTI - OFFLINE
if (bots) {
playerId.value = "player";
Expand All @@ -141,9 +154,20 @@ class GameController extends GetxController {
}

@override
void dispose() {
void onClose() {
controller.value.dispose();

if (Platform.isLinux || Platform.isWindows) {
rpc.updatePresence(
DiscordPresence(
details: 'Gleda na začetni zaslon',
startTimeStamp: DateTime.now().millisecondsSinceEpoch,
largeImageKey: 'palcka_logo',
largeImageText: 'Tarok Palčka',
),
);
}

try {
socket.close();
} catch (e) {}
Expand All @@ -170,6 +194,51 @@ class GameController extends GetxController {
);
}

List<Widget> gameListAssemble(double fullHeight) {
List<Widget> gameListAssembly = [];
if (games.isEmpty) return gameListAssembly;

int missingGames = games.length < 2 ? 0 : games[1].id;

debugPrint("missing games $missingGames");

for (int i = 0; i < games.length; i++) {
var e = games[i];
if (users.length == 3 && !e.playsThree) {
continue;
}
gameListAssembly.add(
SizedBox(
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: suggestions.contains(e.id)
? Colors.purpleAccent.shade400
: null,
textStyle: TextStyle(
fontSize: fullHeight / 35,
),
),
onPressed: () async {
await licitiranjeSend(e);
},
child: Text(
e.name.tr,
),
),
),
);
if (e.id == -1) {
for (int i = 0; i < missingGames; i++) {
gameListAssembly.add(const SizedBox());
}
}
if (e.id == 2 || e.id == 5 || e.id == 8) {
gameListAssembly.add(const SizedBox());
}
}
return gameListAssembly;
}

void resetPredictions() {
kontraIgra.value = false;
kontraPagat.value = false;
Expand Down Expand Up @@ -831,6 +900,14 @@ class GameController extends GetxController {
}
}

stockskis.SimpleUser getPlayer() {
for (int i = 0; i < users.length; i++) {
if (users[i].id != playerId.value) continue;
return users[i];
}
throw Exception("Could not find user");
}

void listen() {
socket.messages.listen(
(data) async {
Expand Down Expand Up @@ -1073,6 +1150,7 @@ class GameController extends GetxController {
zaruf.value = false;
requestedGameEnd.value = false;
talon.value = [];
suggestions.value = [];

currentPredictions.value = Messages.Predictions();
copyGames();
Expand Down Expand Up @@ -1192,6 +1270,32 @@ class GameController extends GetxController {
imaPrednost: obvezen,
);
licitiram.value = true;

var user = getPlayer();

var ss = stockskis.StockSkis(
predictions: PredictionsCompLayer.messagesToStockSkis(
currentPredictions.value!),
users: {
userId: stockskis.User(
user: user,
cards: cards
.map((element) =>
stockskis.Card(card: element, user: userId))
.toList(),
playing: false,
secretlyPlaying: false,
botType: "player",
licitiral: false,
),
},
stihiCount: 48 ~/ users.length,
);
suggestions.value = ss.suggestModes(
userId,
canLicitateThree: obvezen,
);
debugPrint(jsonEncode(suggestions));
}
} else if (msg.hasClearDesk()) {
stih.value = [];
Expand Down
Loading

0 comments on commit e770d07

Please sign in to comment.