Skip to content

Commit

Permalink
Merge pull request #68 from ChicoState/bugFixSettings
Browse files Browse the repository at this point in the history
Fixed settings for themes so they work with the ones we can implement
  • Loading branch information
enlegato authored Dec 4, 2024
2 parents b31d269 + 54f94fa commit 280263d
Show file tree
Hide file tree
Showing 8 changed files with 334 additions and 249 deletions.
6 changes: 3 additions & 3 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -872,12 +872,12 @@ The authentication provides http responses to signup and login. The signup creat
# Sprint 3 Goals for Backend

- Game Entity to store game information
- Websockets for the game?
- CI/CD with good unit testing
- ~~Websockets?~~
- ~~CI/CD with good unit testing~~

# Long Term Goals

- Add websockets for real time communications
- ~~Add websockets for real time communications~~
- Be able to send and recieve pictures
- Store images somehow for chatrooms
- Containerize using docker and docker compose
Expand Down
6 changes: 4 additions & 2 deletions fightme_webapp/lib/Cosmetics/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import 'package:flutter/material.dart';
// Don't know when secondary comes in.

List<ColorScheme> themes = [
ColorScheme.fromSeed(seedColor: Colors.lightBlueAccent),
// ColorScheme.fromSeed(seedColor: Colors.lightBlueAccent),
const ColorScheme.light(),
const ColorScheme.dark(),
const ColorScheme(brightness: Brightness.light, primary: Colors.tealAccent, onPrimary: Colors.black, secondary: Colors.pinkAccent, onSecondary: Colors.black, surface: Colors.deepPurple, onSurface: Colors.black, error: Colors.red, onError: Colors.black),
];

// TODO: Match the element in themes.
List<String> themeNames = [
"Default",
// "Default",
"Light",
"Dark",
"Vaporwave",
];
Expand Down
23 changes: 11 additions & 12 deletions fightme_webapp/lib/Providers/settings_provider.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:fightme_webapp/Cosmetics/profile_pictures.dart'; // Import the profile pictures list
import 'package:fightme_webapp/Cosmetics/themes.dart';

class SettingsProvider with ChangeNotifier {
static const _themeModeKey = 'themeMode';
static const _profilePictureIndexKey = 'profilePictureIndex';
static const _themeIndexKey = 'themeIndex';

ThemeMode _themeMode = ThemeMode.light;
int _profilePictureIndex = 0;
int _themeIndex = 0;

ThemeMode get themeMode => _themeMode;
int get themeIndex => _themeIndex;
int get profilePictureIndex => _profilePictureIndex;

// Get the current profile picture path
String get profilePicture => profilePictures[_profilePictureIndex];
// Get the current theme
ColorScheme get theme => themes[_themeIndex];

// Load settings from SharedPreferences
Future<void> loadSettings() async {
final prefs = await SharedPreferences.getInstance();
_themeMode = (prefs.getString(_themeModeKey) ?? 'light') == 'dark'
? ThemeMode.dark
: ThemeMode.light;
_themeIndex = prefs.getInt(_themeIndexKey) ?? 0;
_profilePictureIndex = prefs.getInt(_profilePictureIndexKey) ?? 0;
notifyListeners();
}

// Update theme mode
Future<void> updateTheme(ThemeMode mode) async {
_themeMode = mode;
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_themeModeKey, mode == ThemeMode.dark ? 'dark' : 'light');
Future<void> updateTheme(int themeIndex) async {
_themeIndex = themeIndex;
final prefs = await SharedPreferences.getInstance();
await prefs.setInt(_themeIndexKey, themeIndex);
notifyListeners();
}

Expand Down
5 changes: 3 additions & 2 deletions fightme_webapp/lib/fight_game_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'package:provider/provider.dart';
import 'globals.dart' as globals;

class FightGamePage extends StatefulWidget {
const FightGamePage({super.key});
final String pfp;
const FightGamePage({super.key, required this.pfp});

@override
State<FightGamePage> createState() => FightGamePageState();
Expand All @@ -26,7 +27,7 @@ class FightGamePageState extends State<FightGamePage> {
@override
void initState() {
super.initState();
_fightGame = FightGame();
_fightGame = FightGame(pfp: widget.pfp);
_loadUserStats();
}

Expand Down
7 changes: 5 additions & 2 deletions fightme_webapp/lib/game/FightGame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import 'package:fightme_webapp/game/StatsSpriteComponent.dart';
import 'package:flame/events.dart';
import 'package:flame/game.dart';
import 'package:flame/components.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class FightGame extends FlameGame with KeyboardEvents {
late final String pfp;
late final SpriteComponent character;
Vector2 movement = Vector2.zero();
final List<StatSpriteComponent> statSprites = []; // Changed to correct type
Expand All @@ -18,6 +18,8 @@ class FightGame extends FlameGame with KeyboardEvents {

// Game boundaries
late final Vector2 gameSize;

FightGame({required this.pfp});

@override
Color backgroundColor() => const Color.fromARGB(255, 40, 196, 227);
Expand All @@ -28,8 +30,9 @@ class FightGame extends FlameGame with KeyboardEvents {

gameSize = size; // Store game size for boundary checking


character = SpriteComponent()
..sprite = await Sprite.load('ErrorSprite.png')
..sprite = await Sprite.load(pfp)
..size = Vector2(100.0, 100.0)
..position = size / 2 - Vector2(50.0, 50.0);
await add(character); // Add await here
Expand Down
7 changes: 3 additions & 4 deletions fightme_webapp/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:fightme_webapp/fight_game_page.dart';
import 'package:fightme_webapp/Providers/settings_provider.dart'; // Import the SettingsProvider
import 'package:fightme_webapp/Providers/stats_provider.dart';
import 'package:fightme_webapp/training_area_page.dart';
import 'home.dart';
import 'Models/user.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -36,10 +37,8 @@ class MyApp extends StatelessWidget {

return MaterialApp(
title: 'Fight Me',
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: settingsProvider.themeMode, // Use the theme mode from the provider
home: globals.loggedIn ? const FightGamePage() : Home(),
theme: ThemeData.from(colorScheme: settingsProvider.theme),
home: globals.loggedIn ? TrainingAreaPage(curUser: globals.curUser) : Home(),
);
}
}
Loading

0 comments on commit 280263d

Please sign in to comment.