Skip to content

Commit

Permalink
change API address, add option to turn off the red filter, resolves #63
Browse files Browse the repository at this point in the history
  • Loading branch information
mytja committed Jan 10, 2024
1 parent 46dcd1e commit de7044d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 6 deletions.
23 changes: 18 additions & 5 deletions tarok/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ DiscordRPC rpc = DiscordRPC(
applicationId: '1175161862086721616',
);

const BACKEND_URL =
String BACKEND_URL =
kReleaseMode ? "https://palcka.si/api" : "http://localhost:8080";
const WS_URL =
kReleaseMode ? "wss://palcka.si/api/ws" : "ws://localhost:8080/ws";
const LOBBY_WS_URL =
kReleaseMode ? "wss://palcka.si/api/lobby" : "ws://localhost:8080/lobby";
String WS_URL = kReleaseMode
? "${BACKEND_URL.replaceAll("https://", "wss://").replaceAll("http://", "ws://")}/ws"
: "ws://localhost:8080/ws";
String LOBBY_WS_URL = kReleaseMode
? "${BACKEND_URL.replaceAll("https://", "wss://").replaceAll("http://", "ws://")}/lobby"
: "ws://localhost:8080/lobby";
const RELEASE = "0.1.2";
bool OMOGOCI_STOCKSKIS_PREDLOGE = true;
bool SLEPI_TAROK = false;
Expand All @@ -46,6 +48,7 @@ bool PREMOVE = false;
bool DEVELOPER_MODE = false;
bool SKISFANG = false;
bool DISCORD_RPC = true;
bool RED_FILTER = true;
String THEME = "";
Locale LOCALE = Get.deviceLocale ?? const Locale("sl", "SI");

Expand All @@ -66,6 +69,16 @@ final Player player = Player();
final dio = Dio();
const storage = FlutterSecureStorage();

void parseBackendUrls() {
if (BACKEND_URL == "") BACKEND_URL = "https://palcka.si/api";
WS_URL = kReleaseMode
? "${BACKEND_URL.replaceAll("https://", "wss://").replaceAll("http://", "ws://")}/ws"
: "ws://localhost:8080/ws";
LOBBY_WS_URL = kReleaseMode
? "${BACKEND_URL.replaceAll("https://", "wss://").replaceAll("http://", "ws://")}/lobby"
: "ws://localhost:8080/lobby";
}

class CardWidget {
const CardWidget(
{required this.position, required this.widget, required this.angle});
Expand Down
2 changes: 1 addition & 1 deletion tarok/lib/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@ class Game extends StatelessWidget {
),
),
),
if (!controller.turn.value)
if (!controller.turn.value && RED_FILTER)
Container(
color: Colors.red.withAlpha(120),
height: cardSize,
Expand Down
18 changes: 18 additions & 0 deletions tarok/lib/internationalization/languages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ class Messages extends Translations {
"Radelci are given to all players whenever a game of at least beggar is played (or klop). Radelci are represented by small circles (✪). Each radelc can double one's points in one of the future games. In case the game difference is positive, it doubles the total sum of the game and deletes itself. In case the game difference is not positive, it doubles the total sum of the game and doesn't delete itself. At the end of entire game, -40 is given for each unused radelc.",
"quiet_predictions":
"Players, if not too sure of their chances, may also opt into \"quiet\" predictions, where they don't predict, yet in the end make the predictions. In the case they don't make the prediction, nothing is written, but if they make it, half points of the normal prediction are received. Quiet predictions cannot be predicted.",
"toggle_red_filter": "Toggle red filter",
"toggle_red_filter_desc":
"Toggle red filter above cards. The filter shows the card's validity to play. This setting applies only to the time when it is not your move. Red filter will still be shown when having to play.",
"api_url": "API URL",
"api_url_desc":
"ATTENTION! If not sure, what you're doing, don't change the defaults here. Improper configuration can open the door to attackers, which can afterwards hijack your session token and manage your account. As Palčka is an open-source program, anybody can host the server. In case one would want to play on their server, the API URL may be changed here. The default URL is https://palcka.si/api. Due to the CORS policy, it is possible that URL change might not work.",
},
"fr_FR": {
"login": "Connexion",
Expand Down Expand Up @@ -869,6 +875,12 @@ class Messages extends Translations {
"Radelci are given to all players whenever a game of at least beggar is played (or klop). Radelci are represented by small circles (✪). Each radelc can double one's points in one of the future games. In case the game difference is positive, it doubles the total sum of the game and deletes itself. In case the game difference is not positive, it doubles the total sum of the game and doesn't delete itself. At the end of entire game, -40 is given for each unused radelc.",
"quiet_predictions":
"Players, if not too sure of their chances, may also opt into \"quiet\" predictions, where they don't predict, yet in the end make the predictions. In the case they don't make the prediction, nothing is written, but if they make it, half points of the normal prediction are received. Quiet predictions cannot be predicted.",
"toggle_red_filter": "Toggle red filter",
"toggle_red_filter_desc":
"Toggle red filter above cards. The filter shows the card's validity to play. This setting applies only to the time when it is not your move. Red filter will still be shown when having to play.",
"api_url": "API URL",
"api_url_desc":
"ATTENTION! If not sure, what you're doing, don't change the defaults here. Improper configuration can open the door to attackers, which can afterwards hijack your session token and manage your account. As Palčka is an open-source program, anybody can host the server. In case one would want to play on their server, the API URL may be changed here. The default URL is https://palcka.si/api. Due to the CORS policy, it is possible that URL change might not work.",
},
"sl_SI": {
"login": "Prijava",
Expand Down Expand Up @@ -1296,6 +1308,12 @@ class Messages extends Translations {
"Radelci so dani vsem igralcem, ko se je igralo vsaj berača (ali klopa). Radelci so zastopani z manjšimi krogci (✪). Vsak radelc lahko podvoji točke igralcem v bodočih igrah. V primeru, da je igra pozitivna, radelc podvoji skupni seštevek igre in se izbriše. V primeru, da igra ni pozitivna, podvoji skupni seštevek igre in se ne izbriše. Na koncu celotne igre se za vsak neporabljen radelc odšteje 40 točk.",
"quiet_predictions":
"Če igralci niso dovolj prepričani v možnosti za izvedbe določene napovedi, lahko še vedno delajo t. i. \"tihe\" napovedi, kjer ničesar ne napovejo, a konec koncev še vedno naredijo napoved. V primeru, da ne naredijo tihe napovedi se ničesar ne piše, a če jo naredijo, dobijo polovico točk originalne napovedi. Tihe napovedi ne morejo biti napovedane.",
"toggle_red_filter": "Preklopi rdeči filter",
"toggle_red_filter_desc":
"Izklopi oz. vključi rdeči filter nad kartami, ki prikazuje veljavnost kart. Velja samo za vmesni čas, ko ni vaš čas za igranje.",
"api_url": "URL naslov API-ja",
"api_url_desc":
"POZOR! Če niste prepričani, kaj delate, ne spreminjajte. To lahko odpre možnost za napadalce, ki lahko ukradejo prijavni piškotek, če boste spreminjali to vrednost. Ker je Palčka odprtokoden program lahko kdorkoli gosti strežnik. Če si kdo želi slučajno igrati na lastnem strežniku, lahko tukaj spremeni API naslov, ki je privzeto https://palcka.si/api. Na spletu je možno, da ne deluje zaradi CORS politike.",
}
};
}
6 changes: 6 additions & 0 deletions tarok/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ void main() async {
SOUNDS_ENABLED = prefs.getBool("sounds") ?? true;
DEVELOPER_MODE = prefs.getBool("developer_mode") ?? false;
DISCORD_RPC = prefs.getBool("discordRpc") ?? true;
RED_FILTER = prefs.getBool("red_filter") ?? true;
NEXT_ROUND_DELAY = prefs.getInt("next_round_delay") ?? 10;
BOT_DELAY = prefs.getInt("bot_delay") ?? 500;
CARD_CLEANUP_DELAY = prefs.getInt("card_cleanup_delay") ?? 1000;

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

if (!kIsWeb && (Platform.isLinux || Platform.isWindows) && DISCORD_RPC) {
DiscordRPC.initialize();
rpc.start(autoRegister: true);
Expand Down
48 changes: 48 additions & 0 deletions tarok/lib/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ class Settings extends StatefulWidget {
}

class _SettingsState extends State<Settings> {
TextEditingController controller = TextEditingController();

@override
Widget build(BuildContext context) {
controller.text = BACKEND_URL;

return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
Expand Down Expand Up @@ -68,6 +72,19 @@ class _SettingsState extends State<Settings> {
title: Text("dark_mode".tr),
description: Text("use_dark_mode".tr),
),
SettingsTile.switchTile(
onToggle: (value) async {
final SharedPreferences prefs =
await SharedPreferences.getInstance();
await prefs.setBool("red_filter", value);
RED_FILTER = prefs.getBool("red_filter") ?? true;
setState(() {});
},
initialValue: RED_FILTER,
leading: const Icon(Icons.filter),
title: Text("toggle_red_filter".tr),
description: Text("toggle_red_filter_desc".tr),
),
],
),
SettingsSection(
Expand Down Expand Up @@ -369,6 +386,37 @@ class _SettingsState extends State<Settings> {
title: Text("developer_mode".tr),
description: Text("developer_mode_desc".tr),
),
SettingsTile(
title: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("api_url".tr),
const SizedBox(
height: 10,
),
Text(
"api_url_desc".tr,
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.normal,
),
),
TextField(
controller: controller,
onSubmitted: (String s) async {
final SharedPreferences prefs =
await SharedPreferences.getInstance();
await prefs.setString("api_url", controller.text);
BACKEND_URL = prefs.getString("api_url") ??
"https://palcka.si/api";
parseBackendUrls();
setState(() {});
},
),
],
),
),
if (!BARVIC && !BERAC)
SettingsTile.switchTile(
onToggle: (value) async {
Expand Down

0 comments on commit de7044d

Please sign in to comment.