Skip to content

Commit

Permalink
Favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
IonutParau committed Oct 21, 2023
1 parent 82fb330 commit 14db1fd
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 18 deletions.
9 changes: 5 additions & 4 deletions lib/layout/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'dart:io';
import 'dart:math';

import 'package:audioplayers/audioplayers.dart';
import 'package:flame/components.dart';
import 'package:flame/components.dart' hide ButtonState;
import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'package:flame/image_composition.dart';
Expand Down Expand Up @@ -36,16 +36,17 @@ part 'shopui.dart';
part 'achievement.dart';

class ConstantColorButtonState extends ButtonState<Color> {
final Color color;
final Color? color;

ConstantColorButtonState(this.color) : super();

@override
Color resolve(Set<ButtonStates> states) {
return color;
return color ?? Colors.white;
}
}

extension on Color {
extension on Color? {
ConstantColorButtonState get state => ConstantColorButtonState(this);
}

1 change: 1 addition & 0 deletions lib/logic/cell_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ final categories = [
"inctab",
"invis_tool",
"trick_tool",
CellCategory("Favorites", "Your favorite cells! Hold Shift while selecting a cell to add it to your favorites, unless its already there, then it will be removed from your favorites!", [], "flag"),
],
"tool",
),
Expand Down
1 change: 1 addition & 0 deletions lib/logic/core/achievements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final Map<String, Achievement> achievementData = {
"incontrol": Achievement("In control", "Move a puzzle cell around", 50),
"friends": Achievement("Friends??", "Join a multiplayer server", 23),
"circuitry": Achievement("Circuitry", "Use mechanical cells", 50),
"favoritism": Achievement("Favoritism", "You like it more than the others, do you?", 60),
};

class AchievementManager {
Expand Down
46 changes: 45 additions & 1 deletion lib/logic/core/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,49 @@ class PuzzleGame extends FlameGame with TapDetector, KeyboardEvents {
void increaseTemp() => brushTemp++;
void decreaseTemp() => brushTemp--;

void syncFavorites() {
final favorites = storage.getStringList("favorites") ?? [];

late CellCategory favoritesCategory;

for(var cat in categories.first.items) {
if(cat is CellCategory && cat.title == "Favorites") {
favoritesCategory = cat;
}
}

favoritesCategory.opened = false;
buttonManager.clear();
favoritesCategory.items.clear();
favoritesCategory.items.addAll(favorites);
}

void manageFavorites(String cell) async {
final favorites = storage.getStringList("favorites") ?? [];

if(favorites.contains(cell)) {
// Remove cell
favorites.remove(cell);
} else {
favorites.add(cell);
}

if(favorites.isEmpty) {
await storage.remove("favorites");
} else {
await storage.setStringList("favorites", favorites);
}

syncFavorites();

loadAllButtons();
}

void whenSelected(String newSelection) {
if(keys[LogicalKeyboardKey.controlLeft.keyLabel] == true) {
manageFavorites(newSelection);
}

if (newSelection.startsWith("blueprint ")) {
// Blueprint code
loadBlueprint(int.parse(newSelection.split(' ')[1]));
Expand Down Expand Up @@ -1629,6 +1671,7 @@ class PuzzleGame extends FlameGame with TapDetector, KeyboardEvents {

initial = grid.copy;


if (worldIndex != null) {
gridTabIndex = worldIndex!;
}
Expand All @@ -1640,7 +1683,6 @@ class PuzzleGame extends FlameGame with TapDetector, KeyboardEvents {
await Flame.images.load('base.png');
await Flame.images.load(textureMap['missing.png'] ?? 'missing.png');
await Flame.images.load('empty.png');

// Load effects
await Flame.images.loadAll([
"effects/stopped.png",
Expand Down Expand Up @@ -1726,6 +1768,8 @@ class PuzzleGame extends FlameGame with TapDetector, KeyboardEvents {
await Flame.images.load('mechanical/pixel_on.png');
await Flame.images.load('electrical/electric_wire_on.png');

buttonManager = ButtonManager(this);
syncFavorites();
loadAllButtons();

wantedCellSize = defaultCellSize;
Expand Down
26 changes: 13 additions & 13 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ environment:
dependencies:
base_x: ^2.0.0
clipboard: any
cupertino_icons: ^1.0.5
flame: ^1.6.0
audioplayers: ^4.0.1
flame_splash_screen: any
fluent_ui: ^4.6.1
cupertino_icons: ^1.0.6
flame: ^1.10.0
audioplayers: ^5.2.0
flame_splash_screen: ^0.2.0
fluent_ui: ^4.7.6
flutter:
sdk: flutter
flutter_colorpicker: ^1.0.3
font_awesome_flutter: any
http: ^0.13.6
http: ^1.1.0
path: ^1.8.3
shared_preferences: ^2.1.1
toml: ^0.14.0
url_launcher: ^6.1.11
uuid: any
web_socket_channel: any
window_manager: ^0.3.0
window_manager: ^0.3.7
yaml: ^3.1.2
quiver: ^3.1.0
archive: ^3.3.7
file_picker: ^5.3.0
archive: ^3.4.6
file_picker: ^6.0.0
equatable: ^2.0.5
lua_vm_bindings:
git:
Expand All @@ -42,17 +42,17 @@ dependencies:
git:
url: https://github.com/IonutParau/glue_lang
ref: stable
flutter_markdown: ^0.6.13
flutter_markdown: ^0.6.18
shelf: ^1.4.1
shelf_web_socket: ^1.0.4
google_fonts: ^4.0.3
image: ^4.0.17
google_fonts: ^6.1.0
image: ^4.1.3
intl: ^0.18.0

dev_dependencies:
flutter_test:
sdk: flutter
lints: any
lints: ^3.0.0

flutter:
uses-material-design: true
Expand Down

0 comments on commit 14db1fd

Please sign in to comment.