Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/rive/game_button.bk.riv
Binary file not shown.
Binary file modified assets/rive/game_button.riv
Binary file not shown.
3 changes: 2 additions & 1 deletion lib/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ Future<void> bootstrap(FutureOr<Widget> Function() builder) async {
Bloc.observer = const AppBlocObserver();

// Add cross-flavor configuration here
WidgetsFlutterBinding.ensureInitialized();
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: kIsWeb
? HydratedStorage.webStorageDirectory
: await getApplicationDocumentsDirectory(),
);
unawaited(RiveFile.initialize());
unawaited(RiveNative.init());
runApp(await builder());
}
61 changes: 32 additions & 29 deletions lib/core/common/widgets/game_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rive/rive.dart';
import 'package:sozzle/core/extensions/rive_extensions.dart';
import 'package:sozzle/core/res/media.dart';

class GameButton extends StatefulWidget {
Expand All @@ -18,9 +17,9 @@ class GameButton extends StatefulWidget {
}

class _GameButtonState extends State<GameButton> {
RiveFile? _riveFile;
File? _riveFile;

StateMachineController? controller;
late RiveWidgetController controller;

bool clicked = false;

Expand All @@ -32,15 +31,34 @@ class _GameButtonState extends State<GameButton> {

@override
void dispose() {
controller?.dispose();
controller.dispose();
super.dispose();
}

void _preload() {
rootBundle.load(Media.gameButton).then((data) {
setState(() {
_riveFile = RiveFile.import(data);
});
Future<void> _preload() async {
final data = await rootBundle.load(Media.gameButton);
_riveFile = await File.decode(
data.buffer.asUint8List(),
riveFactory: Factory.rive,
);
controller = RiveWidgetController(_riveFile!);
_onInit(controller.artboard);
setState(() {});
}

void _onInit(Artboard artboard) {
artboard.setText('buttonText', widget.text);

final viewModelInstance = controller.dataBind(DataBind.auto());

final currentState = viewModelInstance.string('currentState');
currentState?.addListener((value) {
if (value == 'click') {
clicked = true;
} else if (value == 'rest' && clicked) {
clicked = false;
widget.onPressed?.call();
}
});
}

Expand All @@ -51,26 +69,11 @@ class _GameButtonState extends State<GameButton> {
child: SizedBox(
width: 200,
height: 50,
child: RiveAnimation.direct(
_riveFile!,
fit: BoxFit.cover,
stateMachines: const ['Button Animation'],
onInit: (artboard) {
artboard.textRun('buttonText')!.text = widget.text;
controller = StateMachineController.fromArtboard(
artboard,
'Button Animation',
onStateChange: (stateMachine, stateName) {
if (stateName == 'Click') {
clicked = true;
} else if (stateName == 'Rest' && clicked) {
clicked = false;
widget.onPressed?.call();
}
},
);
artboard.addController(controller!);
},
child: RiveWidget(
controller: controller,
fit: Fit.cover,
cursor: SystemMouseCursors.click,
// stateMachines: const ['Button Animation'],
),
),
);
Expand Down
6 changes: 0 additions & 6 deletions lib/core/extensions/rive_extensions.dart

This file was deleted.

66 changes: 36 additions & 30 deletions lib/src/game_play/view/components/hint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,61 +21,68 @@ class Hint extends StatefulWidget {
}

class _HintState extends State<Hint> {
RiveFile? _hintFile;
SMIBool? _luminance;
SMIBool? _theme;
File? _hintFile;
late RiveWidgetController _controller;
late StateMachine? _stateController;
late StateMachine? _themeController;
BooleanInput? _luminance;
BooleanInput? _theme;

@override
void initState() {
super.initState();
preload();
}

void preload() {
rootBundle.load(Media.animatedHint).then((data) {
setState(() {
_hintFile = RiveFile.import(data);
});
});
Future<void> preload() async {
final data = await rootBundle.load(Media.animatedHint);
_hintFile = await File.decode(
data.buffer.asUint8List(),
riveFactory: Factory.rive,
);
_controller = RiveWidgetController(_hintFile!);
_onInit(_controller.artboard);
setState(() {});
}

void _onInit(Artboard artboard) {
final stateController = StateMachineController.fromArtboard(
artboard,
'bulb',
);
final themeController = StateMachineController.fromArtboard(
artboard,
'theme',
);
artboard
..addController(stateController!)
..addController(themeController!);
_luminance = stateController.findInput<bool>('pressed')! as SMIBool;
_theme = themeController.findInput<bool>('isDark')! as SMIBool;
_stateController = artboard.stateMachine('bulb');
_themeController = artboard.stateMachine('theme');
_luminance = _stateController?.boolean('pressed');
_theme = _themeController?.boolean('isDark');
flipBulbByBooster(context.read<UserStatsCubit>().state);
_theme?.change(context.read<ThemeCubit>().state is ThemeStateDark);
_theme?.value = context.read<ThemeCubit>().state is ThemeStateDark;
}

void flipBulbByBooster(UserStatsState statsState) {
final userHasHint = statsState.progress.boosters.any(
(booster) => booster is UseAHint && booster.boosterCount > 0,
);
if (userHasHint) {
_luminance?.change(true);
_luminance?.value = true;
} else {
_luminance?.change(false);
_luminance?.value = false;
}
}

@override
void dispose() {
_controller.dispose();
_stateController?.dispose();
_themeController?.dispose();
_luminance?.dispose();
_theme?.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
if (_hintFile == null) return const SizedBox.shrink();
return Tooltip(
message: 'Use a hint',
child: BlocConsumer<ThemeCubit, ThemeState>(
listener: (context, themeState) {
_theme?.change(themeState is ThemeStateDark);
_theme?.value = themeState is ThemeStateDark;
},
builder: (context, themeState) {
return BlocConsumer<UserStatsCubit, UserStatsState>(
Expand Down Expand Up @@ -123,11 +130,10 @@ class _HintState extends State<Hint> {
baseline: 45,
child: SizedBox(
width: 50,
child: RiveAnimation.direct(
child: RiveWidget(
key: UniqueKey(),
_hintFile!,
fit: BoxFit.cover,
onInit: _onInit,
controller: _controller,
fit: Fit.cover,
),
),
),
Expand Down
42 changes: 36 additions & 6 deletions lib/src/level_won/view/level_complete_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,46 @@ import 'package:go_router/go_router.dart';
import 'package:level_data/level_data.dart';
import 'package:rive/rive.dart';
import 'package:sozzle/core/common/widgets/sozzle_app_bar.dart';
import 'package:sozzle/core/res/media.dart';
import 'package:sozzle/src/game_play/view/game_play_page.dart';
import 'package:sozzle/src/home/view/home_page.dart';
import 'package:sozzle/src/level_won/level_won.dart';

class LevelCompletePage extends StatelessWidget {
class LevelCompletePage extends StatefulWidget {
const LevelCompletePage({required this.levelData, super.key});

static const path = '/won';
final LevelData levelData;

@override
State<LevelCompletePage> createState() => _LevelCompletePageState();
}

class _LevelCompletePageState extends State<LevelCompletePage> {
late File file;
late RiveWidgetController controller;

bool isInitialized = false;

@override
void initState() {
super.initState();
initRive();
}

Future<void> initRive() async {
file = (await File.asset(Media.lake, riveFactory: Factory.rive))!;
controller = RiveWidgetController(file);
setState(() => isInitialized = true);
}

@override
void dispose() {
file.dispose();
controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -30,10 +60,10 @@ class LevelCompletePage extends StatelessWidget {
builder: (scaffoldContext) {
return Stack(
children: [
const RiveAnimation.asset(
'assets/rive/small_lake_on_a_rainy_day.riv',
fit: BoxFit.cover,
),
if (!isInitialized)
const Center(child: CircularProgressIndicator())
else
RiveWidget(controller: controller, fit: Fit.cover),
Center(
child: SafeArea(
child: Column(
Expand Down Expand Up @@ -63,7 +93,7 @@ class LevelCompletePage extends StatelessWidget {
child: NextLevelButton(
onPressed: () {
context.go(
'${GamePlayPage.path}/${levelData.levelId + 1}',
'${GamePlayPage.path}/${widget.levelData.levelId + 1}',
);
},
),
Expand Down
8 changes: 4 additions & 4 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#include "generated_plugin_registrant.h"

#include <audioplayers_linux/audioplayers_linux_plugin.h>
#include <rive_common/rive_plugin.h>
#include <rive_native/rive_native_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar);
g_autoptr(FlPluginRegistrar) rive_common_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "RivePlugin");
rive_plugin_register_with_registrar(rive_common_registrar);
g_autoptr(FlPluginRegistrar) rive_native_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "RiveNativePlugin");
rive_native_plugin_register_with_registrar(rive_native_registrar);
}
2 changes: 1 addition & 1 deletion linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_linux
rive_common
rive_native
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
4 changes: 2 additions & 2 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import Foundation

import audioplayers_darwin
import path_provider_foundation
import rive_common
import rive_native
import shared_preferences_foundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
RivePlugin.register(with: registry.registrar(forPlugin: "RivePlugin"))
RiveNativePlugin.register(with: registry.registrar(forPlugin: "RiveNativePlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ dependencies:
path: packages/level_data
localstore: ^1.4.0
path_provider: ^2.1.3
rive: ^0.13.5
uuid: ^4.4.0
# TODO(RIVE): Reinstall flutter on linux and uncomment level_complete_page.dart
# rive: ^0.12.3
rive: ^0.14.0-dev.11

dev_dependencies:
bloc_test: ^9.1.7
Expand Down
6 changes: 3 additions & 3 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "generated_plugin_registrant.h"

#include <audioplayers_windows/audioplayers_windows_plugin.h>
#include <rive_common/rive_plugin.h>
#include <rive_native/rive_native_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
AudioplayersWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
RivePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("RivePlugin"));
RiveNativePluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("RiveNativePlugin"));
}
2 changes: 1 addition & 1 deletion windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_windows
rive_common
rive_native
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
Loading